diff --git a/src/js/game/systems/logic_gate.js b/src/js/game/systems/logic_gate.js index 4111b2f3..a56ffa18 100644 --- a/src/js/game/systems/logic_gate.js +++ b/src/js/game/systems/logic_gate.js @@ -3,8 +3,8 @@ import { enumColors } from "../colors"; import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate"; import { enumPinSlotType } from "../components/wired_pins"; import { GameSystemWithFilter } from "../game_system_with_filter"; -import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTrueItem, isTruthyItem } from "../items/boolean_item"; -import { COLOR_ITEM_SINGLETONS } from "../items/color_item"; +import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTruthyItem, BooleanItem } from "../items/boolean_item"; +import { COLOR_ITEM_SINGLETONS, ColorItem } from "../items/color_item"; import { ShapeDefinition } from "../shape_definition"; import { ShapeItem } from "../items/shape_item"; @@ -245,13 +245,38 @@ export class LogicGateSystem extends GameSystemWithFilter { const itemA = parameters[0]; const itemB = parameters[1]; - return itemA && - itemB && - itemA.getItemType() === "shape" && - itemB.getItemType() === "shape" && - /** @type {ShapeItem} */ (itemA).definition.getHash() === - /** @type {ShapeItem} */ (itemB).definition.getHash() - ? BOOL_TRUE_SINGLETON - : BOOL_FALSE_SINGLETON; + if (!itemA || !itemB) { + // Empty + return BOOL_FALSE_SINGLETON; + } + + if (itemA.getItemType() !== itemB.getItemType()) { + // Not the same type + return BOOL_FALSE_SINGLETON; + } + + switch (itemA.getItemType()) { + case "shape": { + return /** @type {ShapeItem} */ (itemA).definition.getHash() === + /** @type {ShapeItem} */ (itemB).definition.getHash() + ? BOOL_TRUE_SINGLETON + : BOOL_FALSE_SINGLETON; + } + case "color": { + return /** @type {ColorItem} */ (itemA).color === /** @type {ColorItem} */ (itemB).color + ? BOOL_TRUE_SINGLETON + : BOOL_FALSE_SINGLETON; + } + + case "boolean": { + return /** @type {BooleanItem} */ (itemA).value === /** @type {BooleanItem} */ (itemB).value + ? BOOL_TRUE_SINGLETON + : BOOL_FALSE_SINGLETON; + } + + default: { + assertAlways(false, "Bad item type: " + itemA.getItemType()); + } + } } } diff --git a/translations/base-en.yaml b/translations/base-en.yaml index f0c84937..2a61474e 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -628,8 +628,8 @@ buildings: description: Returns the topmost layer to the right, and the remaining ones on the left. shapecompare: - name: Compare Shapes - description: Returns true if both shapes are exactly equal + name: Compare + description: Returns true if both items are exactly equal. Can compare shapes, items and booleans. storyRewards: # Those are the rewards gained from completing the store