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

Add NOT gate

This commit is contained in:
tobspr
2020-08-13 19:33:35 +02:00
parent 52b4d4d742
commit 49da768b73
17 changed files with 970 additions and 829 deletions

View File

@@ -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: [],
})
);