From c74506bc1c07ceba1668369073f7ef3b81894f41 Mon Sep 17 00:00:00 2001 From: royd2023 Date: Mon, 23 Mar 2026 19:55:03 -0400 Subject: [PATCH] Made sure conditionals and loops work with the code --- src/js/SceneClasses/LevelHelper.js | 6 ++++++ src/js/SceneClasses/QueueManager.js | 11 +++++++++++ src/js/candy.js | 6 ++++-- src/js/level1.js | 16 ++++++++++------ src/js/level2.js | 11 +++++++---- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/js/SceneClasses/LevelHelper.js b/src/js/SceneClasses/LevelHelper.js index a1143d2..849b790 100644 --- a/src/js/SceneClasses/LevelHelper.js +++ b/src/js/SceneClasses/LevelHelper.js @@ -84,6 +84,12 @@ export default class LevelHelper { if (queueManager && typeof queueManager.reset === "function") { queueManager.reset(); } + if (queueManager && typeof queueManager.setOnSuccessfulDump === "function") { + queueManager.setOnSuccessfulDump(() => { + C4C.Interpreter.run(programText); + queueManager.startExecution(); + }); + } C4C.Interpreter.run(programText); if (queueManager && typeof queueManager.startExecution === "function") { queueManager.startExecution(); diff --git a/src/js/SceneClasses/QueueManager.js b/src/js/SceneClasses/QueueManager.js index 2a114a1..9ac0e5e 100644 --- a/src/js/SceneClasses/QueueManager.js +++ b/src/js/SceneClasses/QueueManager.js @@ -5,6 +5,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, @@ -16,9 +17,14 @@ export default class QueueManager { this._onDumpComplete(result); } + setOnSuccessfulDump(fn) { + this.onSuccessfulDump = fn; + } + reset() { this.queue = []; this.plannedPosition = this.pathManager.getCurrentPosition(); + this.onSuccessfulDump = null; console.log( "[QueueManager] Reset. Planned position:", this.plannedPosition, @@ -157,6 +163,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 8253661..39a7fb8 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() { @@ -53,15 +54,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 @@ -95,6 +93,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: () => {