Rewrite of the linker

This commit is contained in:
2024-05-18 20:06:53 +02:00
parent 3d633619c4
commit 3d9944921f
3 changed files with 148 additions and 25 deletions
+75 -6
View File
@@ -294,14 +294,11 @@ for v4=0,2 do
table.insert(connz,(v4-1)*16+1)
name = name.."_W"..tostring((v4-1)*7+1)
end
if name == "" then
table.insert(nodeboxes, nodebox_disconnected)
table.insert(nbconn, 1)
table.insert(connz,(v1-1)*16+0) -- special case of no connection
name = "_zero"
if name ~= "" then
-- Else there is no connection, we don't have to create a cable
createCables(string.sub(name,2,-1),nodeboxes,connz,nbconn)
end
createCables(string.sub(name,2,-1),nodeboxes,connz,nbconn)
end
end
@@ -364,6 +361,78 @@ function logikraft.connectInCable(name,a,b)
return table.getkey1(logikraft.cablesconn,conns)
end
function logikraft.connFromDir(name,dir)
local conns = logikraft.cablesconn[name]
local dir8 = math.pow(2,dir)
for i,c in ipairs(conns)
do
if (math.fmod(c,2*dir8) - dir8 >= 0)
then return i
end
end
return nil
end
--[[
Returns {newcablea,newcableb} if the two cables are contiguous
Returns nil otherwise
--]]
function logikraft.connectContiguousCable(namea,posa,a,nameb,posb,b)
local dira = (posa.y == posb.y) and (
(posa.z + 1 == posb.z and posa.x == posb.x and 3) or
(posa.x + 1 == posb.x and posa.z == posb.z and 2) or
(posa.z - 1 == posb.z and posa.x == posb.x and 1) or
(posa.x - 1 == posb.x and posa.z == posb.z and 0) or
nil) or nil
if dira == nil
then return nil
end
local connsa = table.copy(logikraft.cablesconn[namea])
local connsb = table.copy(logikraft.cablesconn[nameb])
local cia = logikraft.cablesnbconn[namea][a]
local cib = logikraft.cablesnbconn[nameb][b]
local cia2 = logikraft.connFromDir(namea,dira)
local cib2 = logikraft.connFromDir(nameb,3 - dira)
print(dira)
print(cia)
print(cia2)
print(cib)
print(cib2)
-- (nba == nil) -> Need to add dira to the a
-- (a == nba) -> Already connected
-- (a ~= nba) -> Need to connect a and nbas
if (cia2 == nil)
then
connsa[cia] = connsa[cia] + math.pow(2,dira)
elseif (a ~= cia2)
then
-- We take the v size of selected cable
local v = math.fmod(math.floor(connsa[cia]/16),2)
connsa[cia] = math.fmod(connsa[cia],16) + math.fmod(connsa[cia2],16) + v*16
table.remove(connsa,cia2)
end
if (cib2 == nil)
then
connsb[cib] = connsb[cib] + math.pow(2,3-dira)
elseif (b ~= cib2)
then
-- We take the v size of selected cable
local v = math.fmod(math.floor(connsb[cib]/16),2)
connsb[cib] = math.fmod(connsb[cib],16) + math.fmod(connsb[cib2],16) + v*16
table.remove(connsb,cib2)
end
table.sort(connsa)
table.sort(connsb)
return {table.getkey1(logikraft.cablesconn,connsa),table.getkey1(logikraft.cablesconn,connsb)}
end
function logikraft.disconnectInCable(name,a)
local conns = table.copy(logikraft.cablesconn[name])
local cindex = logikraft.cablesnbconn[name][a]