Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/js/SceneClasses/LevelHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export default class LevelHelper {
if (this.queueManager && typeof this.queueManager.reset === "function") {
this.queueManager.reset();
}
if (queueManager && typeof queueManager.setOnSuccessfulDump === "function") {
queueManager.setOnSuccessfulDump(() => {
C4C.Interpreter.run(programText);
queueManager.startExecution();
});
}
C4C.Interpreter.run(programText);
if (
this.queueManager &&
Expand Down
13 changes: 12 additions & 1 deletion src/js/SceneClasses/QueueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class QueueManager {
this.queue = [];
// plannedPosition represents the logical position after queued-but-not-yet-animated moves
this.plannedPosition = this.pathManager.getCurrentPosition();
this.onSuccessfulDump = null;
console.log(
"[QueueManager] Initialized. Planned position:",
this.plannedPosition,
Expand All @@ -26,9 +27,14 @@ export default class QueueManager {
this._onDumpComplete(result);
}

setOnSuccessfulDump(fn) {
this.onSuccessfulDump = fn;
}

reset() {
this.queue = [];
this.plannedPosition = this.pathManager.getStartingPosition();
this.plannedPosition = this.pathManager.getCurrentPosition();
this.onSuccessfulDump = null;
console.log(
"[QueueManager] Reset. Planned position:",
this.plannedPosition,
Expand Down Expand Up @@ -201,6 +207,11 @@ export default class QueueManager {
result.success === true && result.hasMoreCandies === false;
if (allCandiesSucessfullyDumped) {
alert(`All Candies Sorted! Congrats! Move onto the next level`);
return;
}
if (result.success && result.hasMoreCandies && this.onSuccessfulDump) {
this.onSuccessfulDump();
return;
}
// continue execution, should probably check if empty queue here
console.log("[QueueManager] Continuing execution after dump.");
Expand Down
6 changes: 4 additions & 2 deletions src/js/candy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ export default class Candy {
this.color = color;
this.shape = shape;
this.pattern = pattern;
console.log("ImagePath: " + imagePath);
this.imagePath = imagePath;
console.log("ImagePath: " + imagePath);
}

get type() {
return `${this.color}-${this.shape}`;
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/js/level1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AnimationExecutor from "./SceneClasses/AnimationExecutor.js";
import CommandManager from "./SceneClasses/CommandManager.js";
import QueueManager from "./SceneClasses/QueueManager.js";
import LevelHelper from "./SceneClasses/LevelHelper.js";
import Candy, { Colors, Shapes, Patterns } from "./candy.js";

export default class Level1 extends Phaser.Scene {
constructor() {
Expand Down Expand Up @@ -55,15 +56,12 @@ export default class Level1 extends Phaser.Scene {
}

setupLevelCandies() {
//Define the candies for this level
//TODO: Adjust this to use the Candy class!
const candies = [
{ type: "blue-circle", id: 1 },
{ type: "red-square", id: 2 },
{ type: "green-triangle", id: 3 },
new Candy(Colors.BLUE, Shapes.CIRCLE, Patterns.PLAIN),
new Candy(Colors.RED, Shapes.SQUARE, Patterns.PLAIN),
new Candy(Colors.GREEN, Shapes.TRIANGLE, Patterns.PLAIN),
];

//Define goal positions for each candy type. Again, adjust to using the Candy class
const goalPositions = {
"blue-circle": { x: 200, y: 400 }, // Left bin
"red-square": { x: 600, y: 400 }, // Right bin
Expand Down Expand Up @@ -97,6 +95,12 @@ export default class Level1 extends Phaser.Scene {
"This is an example custom command, should run immediately",
);
},
isBlue: () => this.pathManager.getCurrentCandy()?.color === Colors.BLUE,
isRed: () => this.pathManager.getCurrentCandy()?.color === Colors.RED,
isGreen: () => this.pathManager.getCurrentCandy()?.color === Colors.GREEN,
isCircle: () => this.pathManager.getCurrentCandy()?.shape == Shapes.CIRCLE,
isSquare: () => this.pathManager.getCurrentCandy()?.shape == Shapes.SQUARE,
isTriangle: () => this.pathManager.getCurrentCandy()?.shape == Shapes.TRIANGLE,
},
queued: {
queuedCommand: () => {
Expand Down
11 changes: 7 additions & 4 deletions src/js/level2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AnimationExecutor from "./SceneClasses/AnimationExecutor.js";
import CommandManager from "./SceneClasses/CommandManager.js";
import QueueManager from "./SceneClasses/QueueManager.js";
import LevelHelper from "./SceneClasses/LevelHelper.js";
import Candy, { Colors, Shapes, Patterns } from "./candy.js";

export default class Level2 extends Phaser.Scene {
constructor() {
Expand Down Expand Up @@ -55,11 +56,10 @@ export default class Level2 extends Phaser.Scene {

setupLevelCandies() {
//Define the candies for this level
//TODO: Adjust this to use the Candy class!
const candies = [
{ type: "blue-circle", id: 1 },
{ type: "red-square", id: 2 },
{ type: "green-triangle", id: 3 },
new Candy(Colors.BLUE, Shapes.CIRCLE, Patterns.PLAIN),
new Candy(Colors.RED, Shapes.SQUARE, Patterns.PLAIN),
new Candy(Colors.GREEN, Shapes.TRIANGLE, Patterns.PLAIN),
];

//Define goal positions for each candy type. Again, adjust to using the Candy class
Expand Down Expand Up @@ -96,6 +96,9 @@ export default class Level2 extends Phaser.Scene {
"This is an example custom command, should run immediately",
);
},
isBlue: () => this.pathManager.getCurrentCandy()?.color === Colors.BLUE,
isRed: () => this.pathManager.getCurrentCandy()?.color === Colors.RED,
isGreen: () => this.pathManager.getCurrentCandy()?.color === Colors.GREEN,
},
queued: {
queuedCommand: () => {
Expand Down