mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Make comparer compare shapes, colors and booleans
This commit is contained in:
parent
238b08d4d1
commit
cf0f02826b
@ -3,8 +3,8 @@ import { enumColors } from "../colors";
|
|||||||
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
|
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
|
||||||
import { enumPinSlotType } from "../components/wired_pins";
|
import { enumPinSlotType } from "../components/wired_pins";
|
||||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTrueItem, isTruthyItem } from "../items/boolean_item";
|
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTruthyItem, BooleanItem } from "../items/boolean_item";
|
||||||
import { COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
import { COLOR_ITEM_SINGLETONS, ColorItem } from "../items/color_item";
|
||||||
import { ShapeDefinition } from "../shape_definition";
|
import { ShapeDefinition } from "../shape_definition";
|
||||||
import { ShapeItem } from "../items/shape_item";
|
import { ShapeItem } from "../items/shape_item";
|
||||||
|
|
||||||
@ -245,13 +245,38 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
|||||||
const itemA = parameters[0];
|
const itemA = parameters[0];
|
||||||
const itemB = parameters[1];
|
const itemB = parameters[1];
|
||||||
|
|
||||||
return itemA &&
|
if (!itemA || !itemB) {
|
||||||
itemB &&
|
// Empty
|
||||||
itemA.getItemType() === "shape" &&
|
return BOOL_FALSE_SINGLETON;
|
||||||
itemB.getItemType() === "shape" &&
|
}
|
||||||
/** @type {ShapeItem} */ (itemA).definition.getHash() ===
|
|
||||||
|
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()
|
/** @type {ShapeItem} */ (itemB).definition.getHash()
|
||||||
? BOOL_TRUE_SINGLETON
|
? BOOL_TRUE_SINGLETON
|
||||||
: BOOL_FALSE_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.
|
description: Returns the topmost layer to the right, and the remaining ones on the left.
|
||||||
|
|
||||||
shapecompare:
|
shapecompare:
|
||||||
name: Compare Shapes
|
name: Compare
|
||||||
description: Returns true if both shapes are exactly equal
|
description: Returns true if both items are exactly equal. Can compare shapes, items and booleans.
|
||||||
|
|
||||||
storyRewards:
|
storyRewards:
|
||||||
# Those are the rewards gained from completing the store
|
# Those are the rewards gained from completing the store
|
||||||
|
Loading…
Reference in New Issue
Block a user