Make comparer compare shapes, colors and booleans

pull/609/head
tobspr 4 years ago
parent 238b08d4d1
commit cf0f02826b

@ -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());
}
}
}
}

@ -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

Loading…
Cancel
Save