Format circuit

master
Louis Pearson 2022-08-07 21:23:13 -06:00
parent 55c12f4828
commit ae51861c6e
1 changed files with 32 additions and 32 deletions

View File

@ -672,40 +672,40 @@ pub const Database = struct {
pub fn updateCircuit(db: *Database) void { pub fn updateCircuit(db: *Database) void {
for (db.circuit_info) |node, i| { for (db.circuit_info) |node, i| {
switch (node.kind) { switch (node.kind) {
.And => |And| { .And => |And| {
const input1 = db.circuit_info[And[0]].energized; const input1 = db.circuit_info[And[0]].energized;
const input2 = db.circuit_info[And[1]].energized; const input2 = db.circuit_info[And[1]].energized;
db.circuit_info[i].energized = (input1 and input2); db.circuit_info[i].energized = (input1 and input2);
}, },
.Xor => |Xor| { .Xor => |Xor| {
const input1 = db.circuit_info[Xor[0]].energized; const input1 = db.circuit_info[Xor[0]].energized;
const input2 = db.circuit_info[Xor[1]].energized; const input2 = db.circuit_info[Xor[1]].energized;
db.circuit_info[i].energized = (input1 and !input2) or (input2 and !input1); db.circuit_info[i].energized = (input1 and !input2) or (input2 and !input1);
}, },
.Source => db.circuit_info[i].energized = true, .Source => db.circuit_info[i].energized = true,
.Conduit => |Conduit| { .Conduit => |Conduit| {
const input1 = db.circuit_info[Conduit[0]].energized; const input1 = db.circuit_info[Conduit[0]].energized;
const input2 = db.circuit_info[Conduit[1]].energized; const input2 = db.circuit_info[Conduit[1]].energized;
db.circuit_info[i].energized = (input1 or input2); db.circuit_info[i].energized = (input1 or input2);
}, },
.Plug => |plug_opt| { .Plug => |plug_opt| {
if (plug_opt) |input| { if (plug_opt) |input| {
db.circuit_info[i].energized = db.circuit_info[input].energized; db.circuit_info[i].energized = db.circuit_info[input].energized;
} else { } else {
db.circuit_info[i].energized = false;
}
},
.Switch => |state| {
// TODO Rework switch to make sense
db.circuit_info[i].energized = false; db.circuit_info[i].energized = false;
} _ = state;
}, },
.Switch => |state| { .Join => |Join| {
// TODO Rework switch to make sense db.circuit_info[i].energized = db.circuit_info[Join].energized;
db.circuit_info[i].energized = false; },
_ = state; .Outlet => |Outlet| {
}, db.circuit_info[i].energized = db.circuit_info[Outlet].energized;
.Join => |Join| { },
db.circuit_info[i].energized = db.circuit_info[Join].energized;
},
.Outlet => |Outlet| {
db.circuit_info[i].energized = db.circuit_info[Outlet].energized;
},
} }
} }
} }