Add transistor building (Gate)
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 223 KiB After Width: | Height: | Size: 228 KiB |
Before Width: | Height: | Size: 538 KiB After Width: | Height: | Size: 555 KiB |
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
BIN
res_raw/sprites/blueprints/logic_gate-transistor.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
res_raw/sprites/buildings/logic_gate-transistor.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -574,6 +574,10 @@ buildings:
|
||||
name: OR
|
||||
description: Emits a truthy signal if one of the inputs is truthy.
|
||||
|
||||
transistor:
|
||||
name: Gate
|
||||
description: Only forwards the bottom input if the left input is true.
|
||||
|
||||
filter:
|
||||
default:
|
||||
name: &filter Filter
|
||||
|