diff --git a/src/js/SceneClasses/LevelHelper.js b/src/js/SceneClasses/LevelHelper.js index 40162b2..a8c0d05 100644 --- a/src/js/SceneClasses/LevelHelper.js +++ b/src/js/SceneClasses/LevelHelper.js @@ -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 && diff --git a/src/js/SceneClasses/QueueManager.js b/src/js/SceneClasses/QueueManager.js index c3d1c69..64a400c 100644 --- a/src/js/SceneClasses/QueueManager.js +++ b/src/js/SceneClasses/QueueManager.js @@ -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, @@ -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, @@ -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."); diff --git a/src/js/candy.js b/src/js/candy.js index 63a1d97..4dd5726 100644 --- a/src/js/candy.js +++ b/src/js/candy.js @@ -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}`; } } diff --git a/src/js/level1.js b/src/js/level1.js index 374342f..5ddf26a 100644 --- a/src/js/level1.js +++ b/src/js/level1.js @@ -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() { @@ -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 @@ -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: () => { diff --git a/src/js/level2.js b/src/js/level2.js index b1cbd9e..b22a79b 100644 --- a/src/js/level2.js +++ b/src/js/level2.js @@ -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() { @@ -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 @@ -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: () => {