Add NOT gate
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 213 KiB After Width: | Height: | Size: 219 KiB |
Before Width: | Height: | Size: 504 KiB After Width: | Height: | Size: 516 KiB |
Before Width: | Height: | Size: 994 KiB After Width: | Height: | Size: 1011 KiB |
BIN
res_raw/sprites/blueprints/logic_gate-not.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
res_raw/sprites/buildings/logic_gate-not.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
@ -6,11 +6,14 @@ import { enumLayer, GameRoot } from "../root";
|
||||
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumLogicGateVariants = {};
|
||||
export const enumLogicGateVariants = {
|
||||
not: "not",
|
||||
};
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumVariantToGate = {
|
||||
[defaultBuildingVariant]: enumLogicGateType.and,
|
||||
[enumLogicGateVariants.not]: enumLogicGateType.not,
|
||||
};
|
||||
|
||||
export class MetaLogicGateBuilding extends MetaBuilding {
|
||||
@ -38,23 +41,24 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
||||
return new Vector(1, 1);
|
||||
}
|
||||
|
||||
getAvailableVariants() {
|
||||
return [defaultBuildingVariant, enumLogicGateVariants.not];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
*/
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
entity.components.LogicGate.type = enumVariantToGate[variant];
|
||||
}
|
||||
const gateType = enumVariantToGate[variant];
|
||||
entity.components.LogicGate.type = gateType;
|
||||
|
||||
/**
|
||||
* Creates the entity at the given location
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
setupEntityComponents(entity) {
|
||||
entity.addComponent(
|
||||
new WiredPinsComponent({
|
||||
slots: [
|
||||
const pinComp = entity.components.WiredPins;
|
||||
|
||||
switch (gateType) {
|
||||
case enumLogicGateType.and: {
|
||||
pinComp.setSlots([
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.top,
|
||||
@ -70,7 +74,39 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
||||
direction: enumDirection.right,
|
||||
type: enumPinSlotType.logicalAcceptor,
|
||||
},
|
||||
],
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
case enumLogicGateType.not: {
|
||||
pinComp.setSlots([
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.top,
|
||||
type: enumPinSlotType.logicalEjector,
|
||||
},
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.bottom,
|
||||
type: enumPinSlotType.logicalAcceptor,
|
||||
},
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
assertAlways("unknown logic gate type: " + gateType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the entity at the given location
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
setupEntityComponents(entity) {
|
||||
entity.addComponent(
|
||||
new WiredPinsComponent({
|
||||
slots: [],
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -3,6 +3,7 @@ import { Component } from "../component";
|
||||
/** @enum {string} */
|
||||
export const enumLogicGateType = {
|
||||
and: "and",
|
||||
not: "not",
|
||||
};
|
||||
|
||||
export class LogicGateComponent extends Component {
|
||||
|
@ -16,7 +16,7 @@ import { MetaWireBuilding } from "./buildings/wire";
|
||||
import { gBuildingVariants, registerBuildingVariant } from "./building_codes";
|
||||
import { defaultBuildingVariant } from "./meta_building";
|
||||
import { MetaConstantSignalBuilding } from "./buildings/constant_signal";
|
||||
import { MetaLogicGateBuilding } from "./buildings/logic_gate";
|
||||
import { MetaLogicGateBuilding, enumLogicGateVariants } from "./buildings/logic_gate";
|
||||
import { MetaLeverBuilding } from "./buildings/lever";
|
||||
|
||||
const logger = createLogger("building_registry");
|
||||
@ -97,6 +97,7 @@ export function initMetaBuildingRegistry() {
|
||||
|
||||
// Logic gate
|
||||
registerBuildingVariant(32, MetaLogicGateBuilding);
|
||||
registerBuildingVariant(34, MetaLogicGateBuilding, enumLogicGateVariants.not);
|
||||
|
||||
// Lever
|
||||
registerBuildingVariant(33, MetaLeverBuilding);
|
||||
|
@ -10,6 +10,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
|
||||
this.boundOperations = {
|
||||
[enumLogicGateType.and]: this.compute_AND.bind(this),
|
||||
[enumLogicGateType.not]: this.compute_NOT.bind(this),
|
||||
};
|
||||
}
|
||||
|
||||
@ -75,4 +76,23 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
|
||||
return BOOL_FALSE_SINGLETON;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<BaseItem|null>} parameters
|
||||
* @returns {BaseItem}
|
||||
*/
|
||||
compute_NOT(parameters) {
|
||||
const item = parameters[0];
|
||||
if (!item) {
|
||||
return BOOL_FALSE_SINGLETON;
|
||||
}
|
||||
|
||||
if (item.getItemType() !== enumItemType.boolean) {
|
||||
// Not a boolean actually
|
||||
return BOOL_FALSE_SINGLETON;
|
||||
}
|
||||
|
||||
const value = /** @type {BooleanItem} */ (item).value;
|
||||
return value ? BOOL_FALSE_SINGLETON : BOOL_TRUE_SINGLETON;
|
||||
}
|
||||
}
|
||||
|
@ -564,6 +564,9 @@ buildings:
|
||||
default:
|
||||
name: &logic_gate AND Gate
|
||||
description: Emits a boolean signal if both inputs are truthy.
|
||||
not:
|
||||
name: NOT
|
||||
description: Inverts the given signal
|
||||
|
||||
storyRewards:
|
||||
# Those are the rewards gained from completing the store
|
||||
|