mirror of
https://github.com/tobspr-games/shapez.io.git
synced 2026-01-15 13:51:20 -08:00
Add transistor building (Gate)
This commit is contained in:
parent
f44563fc05
commit
ff02508361
17 changed files with 1015 additions and 877 deletions
|
|
@ -10,6 +10,7 @@ export const enumLogicGateVariants = {
|
|||
not: "not",
|
||||
xor: "xor",
|
||||
or: "or",
|
||||
transistor: "transistor",
|
||||
};
|
||||
|
||||
/** @enum {string} */
|
||||
|
|
@ -18,6 +19,7 @@ export const enumVariantToGate = {
|
|||
[enumLogicGateVariants.not]: enumLogicGateType.not,
|
||||
[enumLogicGateVariants.xor]: enumLogicGateType.xor,
|
||||
[enumLogicGateVariants.or]: enumLogicGateType.or,
|
||||
[enumLogicGateVariants.transistor]: enumLogicGateType.transistor,
|
||||
};
|
||||
|
||||
export class MetaLogicGateBuilding extends MetaBuilding {
|
||||
|
|
@ -51,6 +53,7 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
|||
enumLogicGateVariants.not,
|
||||
enumLogicGateVariants.xor,
|
||||
enumLogicGateVariants.or,
|
||||
enumLogicGateVariants.transistor,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -88,6 +91,26 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
|||
]);
|
||||
break;
|
||||
}
|
||||
case enumLogicGateType.transistor: {
|
||||
pinComp.setSlots([
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.top,
|
||||
type: enumPinSlotType.logicalEjector,
|
||||
},
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.left,
|
||||
type: enumPinSlotType.logicalAcceptor,
|
||||
},
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.bottom,
|
||||
type: enumPinSlotType.logicalAcceptor,
|
||||
},
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
case enumLogicGateType.not: {
|
||||
pinComp.setSlots([
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ export const enumLogicGateType = {
|
|||
not: "not",
|
||||
xor: "xor",
|
||||
or: "or",
|
||||
transistor: "transistor",
|
||||
};
|
||||
|
||||
export class LogicGateComponent extends Component {
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ export function initMetaBuildingRegistry() {
|
|||
registerBuildingVariant(34, MetaLogicGateBuilding, enumLogicGateVariants.not);
|
||||
registerBuildingVariant(35, MetaLogicGateBuilding, enumLogicGateVariants.xor);
|
||||
registerBuildingVariant(36, MetaLogicGateBuilding, enumLogicGateVariants.or);
|
||||
registerBuildingVariant(38, MetaLogicGateBuilding, enumLogicGateVariants.transistor);
|
||||
|
||||
// Lever
|
||||
registerBuildingVariant(33, MetaLeverBuilding);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue