1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Add transistor building (Gate)

This commit is contained in:
tobspr
2020-08-13 20:47:33 +02:00
parent f44563fc05
commit ff02508361
17 changed files with 1015 additions and 877 deletions

View File

@@ -3,6 +3,7 @@ import { GameSystemWithFilter } from "../game_system_with_filter";
import { BaseItem, enumItemType } from "../base_item";
import { enumPinSlotType } from "../components/wired_pins";
import { BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON, BooleanItem } from "../items/boolean_item";
import { enumItemProcessorTypes } from "../components/item_processor";
export class LogicGateSystem extends GameSystemWithFilter {
constructor(root) {
@@ -13,6 +14,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
[enumLogicGateType.not]: this.compute_NOT.bind(this),
[enumLogicGateType.xor]: this.compute_XOR.bind(this),
[enumLogicGateType.or]: this.compute_OR.bind(this),
[enumLogicGateType.transistor]: this.compute_IF.bind(this),
};
}
@@ -157,4 +159,31 @@ export class LogicGateSystem extends GameSystemWithFilter {
return BOOL_FALSE_SINGLETON;
}
/**
* @param {Array<BaseItem|null>} parameters
* @returns {BaseItem}
*/
compute_IF(parameters) {
assert(parameters.length === 2, "bad parameter count for IF");
const flag = parameters[0];
const value = parameters[1];
if (!flag || !value) {
// Not enough params
return null;
}
if (flag.getItemType() !== enumItemType.boolean) {
// Flag is not a boolean
return null;
}
// pass through item
if (/** @type {BooleanItem} */ (flag).value) {
return value;
}
return null;
}
}