1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2024-10-27 20:34:29 +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

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 63 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 219 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 KiB

After

Width:  |  Height:  |  Size: 516 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 994 KiB

After

Width:  |  Height:  |  Size: 1011 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -6,11 +6,14 @@ import { enumLayer, GameRoot } from "../root";
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate"; import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
/** @enum {string} */ /** @enum {string} */
export const enumLogicGateVariants = {}; export const enumLogicGateVariants = {
not: "not",
};
/** @enum {string} */ /** @enum {string} */
export const enumVariantToGate = { export const enumVariantToGate = {
[defaultBuildingVariant]: enumLogicGateType.and, [defaultBuildingVariant]: enumLogicGateType.and,
[enumLogicGateVariants.not]: enumLogicGateType.not,
}; };
export class MetaLogicGateBuilding extends MetaBuilding { export class MetaLogicGateBuilding extends MetaBuilding {
@ -38,23 +41,24 @@ export class MetaLogicGateBuilding extends MetaBuilding {
return new Vector(1, 1); return new Vector(1, 1);
} }
getAvailableVariants() {
return [defaultBuildingVariant, enumLogicGateVariants.not];
}
/** /**
* *
* @param {Entity} entity * @param {Entity} entity
* @param {number} rotationVariant * @param {number} rotationVariant
*/ */
updateVariants(entity, rotationVariant, variant) { updateVariants(entity, rotationVariant, variant) {
entity.components.LogicGate.type = enumVariantToGate[variant]; const gateType = enumVariantToGate[variant];
} entity.components.LogicGate.type = gateType;
/** const pinComp = entity.components.WiredPins;
* Creates the entity at the given location
* @param {Entity} entity switch (gateType) {
*/ case enumLogicGateType.and: {
setupEntityComponents(entity) { pinComp.setSlots([
entity.addComponent(
new WiredPinsComponent({
slots: [
{ {
pos: new Vector(0, 0), pos: new Vector(0, 0),
direction: enumDirection.top, direction: enumDirection.top,
@ -70,7 +74,39 @@ export class MetaLogicGateBuilding extends MetaBuilding {
direction: enumDirection.right, direction: enumDirection.right,
type: enumPinSlotType.logicalAcceptor, 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: [],
}) })
); );

View File

@ -3,6 +3,7 @@ import { Component } from "../component";
/** @enum {string} */ /** @enum {string} */
export const enumLogicGateType = { export const enumLogicGateType = {
and: "and", and: "and",
not: "not",
}; };
export class LogicGateComponent extends Component { export class LogicGateComponent extends Component {

View File

@ -16,7 +16,7 @@ import { MetaWireBuilding } from "./buildings/wire";
import { gBuildingVariants, registerBuildingVariant } from "./building_codes"; import { gBuildingVariants, registerBuildingVariant } from "./building_codes";
import { defaultBuildingVariant } from "./meta_building"; import { defaultBuildingVariant } from "./meta_building";
import { MetaConstantSignalBuilding } from "./buildings/constant_signal"; import { MetaConstantSignalBuilding } from "./buildings/constant_signal";
import { MetaLogicGateBuilding } from "./buildings/logic_gate"; import { MetaLogicGateBuilding, enumLogicGateVariants } from "./buildings/logic_gate";
import { MetaLeverBuilding } from "./buildings/lever"; import { MetaLeverBuilding } from "./buildings/lever";
const logger = createLogger("building_registry"); const logger = createLogger("building_registry");
@ -97,6 +97,7 @@ export function initMetaBuildingRegistry() {
// Logic gate // Logic gate
registerBuildingVariant(32, MetaLogicGateBuilding); registerBuildingVariant(32, MetaLogicGateBuilding);
registerBuildingVariant(34, MetaLogicGateBuilding, enumLogicGateVariants.not);
// Lever // Lever
registerBuildingVariant(33, MetaLeverBuilding); registerBuildingVariant(33, MetaLeverBuilding);

View File

@ -10,6 +10,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
this.boundOperations = { this.boundOperations = {
[enumLogicGateType.and]: this.compute_AND.bind(this), [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; 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;
}
} }

View File

@ -564,6 +564,9 @@ buildings:
default: default:
name: &logic_gate AND Gate name: &logic_gate AND Gate
description: Emits a boolean signal if both inputs are truthy. description: Emits a boolean signal if both inputs are truthy.
not:
name: NOT
description: Inverts the given signal
storyRewards: storyRewards:
# Those are the rewards gained from completing the store # Those are the rewards gained from completing the store