From 7109dd70a20c8dcaa96b84dc1ce2aa7acc16437e Mon Sep 17 00:00:00 2001 From: Redo0 Date: Mon, 7 Jun 2021 15:38:25 -0500 Subject: [PATCH] add rainbow wires --- sim/network.lua | 2 ++ sim/simulation.lua | 5 ++++- sim/wire.lua | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sim/network.lua b/sim/network.lua index c3b4301..f40194f 100644 --- a/sim/network.lua +++ b/sim/network.lua @@ -100,6 +100,8 @@ function network_update() local wire = Simulation.getwirebyref(sim, tonumber(data[i+1])) if wire ~= nil then Wire.setlayer(wire, tonumber(data[i+2])) + else + error("Setlayer: no wire for objref "..tonumber(data[i+1])) end i = i + 2 diff --git a/sim/simulation.lua b/sim/simulation.lua index 5920325..23bb2c5 100644 --- a/sim/simulation.lua +++ b/sim/simulation.lua @@ -184,7 +184,10 @@ function Simulation.connectwireat(sim, wire, x, y, z) for k, obj in pairs(objs) do if obj ~= wire and obj.group ~= nil then if is_wire(obj) then -- wire - if Wire.getlayer(obj) == Wire.getlayer(wire) then -- same layer + local layer1 = Wire.getlayer(wire) + local layer2 = Wire.getlayer(obj) + --if they are on the same real layer, or exactly one is rainbow but not both, then connect + if ((layer1==layer2) or (layer1==-1 and layer2~=-1) or (layer1~=-1 and layer2==-1)) and (not (layer1==-1 and layer2==-1)) then Group.addwire(obj.group, wire) end else -- port diff --git a/sim/wire.lua b/sim/wire.lua index fee0308..a9b39e1 100644 --- a/sim/wire.lua +++ b/sim/wire.lua @@ -20,7 +20,9 @@ function Wire.setlayer(wire, layer) end function Wire.update(wire) - network_send("WU\t" .. (wire.group.state~=0 and "1" or "0") .. "\t" .. wire.objref .. "\n") + if wire.layer~=-1 then + network_send("WU\t" .. (wire.group.state~=0 and "1" or "0") .. "\t" .. wire.objref .. "\n") + end end function Wire.setgroup(wire, group)