diff --git a/src/circuit.zig b/src/circuit.zig index 318d0ba..90d48f5 100644 --- a/src/circuit.zig +++ b/src/circuit.zig @@ -341,6 +341,23 @@ pub fn fill(this: *@This(), alloc: std.mem.Allocator, db: world.Database, level: try q.insert(.{ .node_id = new_id, .coord = node.coord.add(.{ 0, -1 }) }); continue; } + if (T.is_switch(tile)) { + const n = node.coord.add(.{0,-1}) ; + const w = node.coord.add(.{-1,0}) ; + const e = node.coord.add(.{1,0}) ; + const s = node.coord.add(.{0,1}) ; + + const nid = db.getLevelNodeID(level, n) ; + const wid = db.getLevelNodeID(level, w) ; + const eid = db.getLevelNodeID(level, e) ; + const sid = db.getLevelNodeID(level, s) ; + + if(nid) |new_id| try q.insert(.{ .node_id = new_id, .coord = n }); + if(wid) |new_id| try q.insert(.{ .node_id = new_id, .coord = w }); + if(eid) |new_id| try q.insert(.{ .node_id = new_id, .coord = e }); + if(sid) |new_id| try q.insert(.{ .node_id = new_id, .coord = s }); + continue; + } for (get_outputs(tile)) |conductor, i| { // w4.tracef("[fill] outputs"); if (!conductor) continue; diff --git a/tools/LDtkImport.zig b/tools/LDtkImport.zig index 7da4a33..3bab744 100644 --- a/tools/LDtkImport.zig +++ b/tools/LDtkImport.zig @@ -480,7 +480,7 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL // Add switch outlets if (input_dir != .West and west) { const out_node = @intCast(world.NodeID, nodes.items.len); - const new_coord = coord.add(.{1, 0}); + const new_coord = coord.add(.{-1, 0}); try nodes.append(.{ .kind = .{ .SwitchOutlet = .{ .source = next_node, @@ -499,7 +499,7 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL if (input_dir != .East and east) { const out_node = @intCast(world.NodeID, nodes.items.len); - const new_coord = coord.add(.{-1, 0}); + const new_coord = coord.add(.{1, 0}); try nodes.append(.{ .kind = .{ .SwitchOutlet = .{ .source = next_node, @@ -614,9 +614,18 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL }); } try multi_input.put(coord, next_node); + const up = try alloc.create(Node); + up.* = Node{ .data = .{ + .last_node = next_node, + .coord = coord.add(.{ 0, -1 }), + .last_coord = coord, + } }; + bfs_queue.append(up); + continue; } }, .Xor => { + std.log.warn("XOR XOR XOR",.{}); // TODO: verify Xor gate is properly connected const last_coord = node.data.last_coord.?; const Side = enum { O, L, R }; @@ -660,6 +669,14 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL }); } try multi_input.put(coord, next_node); + const up = try alloc.create(Node); + up.* = Node{ .data = .{ + .last_node = next_node, + .coord = coord.add(.{ 0, -1 }), + .last_coord = coord, + } }; + bfs_queue.append(up); + continue; } }, .None => continue, @@ -695,6 +712,7 @@ pub fn buildCircuit(alloc: std.mem.Allocator, levels: []world.Level) !std.ArrayL bfs_queue.append(left); bfs_queue.append(down); bfs_queue.append(up); + } } }