Make logic gates output empty if there is a conflict

This commit is contained in:
tobspr 2020-08-30 16:12:01 +02:00
parent f667329572
commit 244cede010
1 changed files with 22 additions and 0 deletions

View File

@ -35,18 +35,40 @@ export class LogicGateSystem extends GameSystemWithFilter {
const slotValues = [];
// Store if any conflict was found
let anyConflict = false;
// Gather inputs from all connected networks
for (let i = 0; i < slotComp.slots.length; ++i) {
const slot = slotComp.slots[i];
if (slot.type !== enumPinSlotType.logicalAcceptor) {
continue;
}
if (slot.linkedNetwork) {
if (slot.linkedNetwork.valueConflict) {
anyConflict = true;
break;
}
slotValues.push(slot.linkedNetwork.currentValue);
} else {
slotValues.push(null);
}
}
// Handle conflicts
if (anyConflict) {
for (let i = 0; i < slotComp.slots.length; ++i) {
const slot = slotComp.slots[i];
if (slot.type !== enumPinSlotType.logicalEjector) {
continue;
}
slot.value = null;
}
continue;
}
// Compute actual result
const result = this.boundOperations[logicComp.type](slotValues);
if (Array.isArray(result)) {