Upgraded circuit generation

This commit is contained in:
MysaaJava 2024-05-20 01:02:42 +02:00
parent ef8b8910b0
commit 0298b85323
Signed by: Mysaa
GPG Key ID: DBA23608F23F5A10
6 changed files with 62 additions and 25 deletions

View File

@ -37,6 +37,20 @@ logikraft.components = {
left = {nil,nil,nil,nil,nil,"in_3","in_2","in_1"},
right = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"}
}
},
["input"] = {
width = 1,
height = 1,
ports = {
right = {"out"}
}
},
["output"] = {
width = 1,
height = 1,
ports = {
left = {"in"}
}
}
}

View File

@ -1,11 +0,0 @@
minetest.register_node("logikraft:inputBlock", {
description = "Input Block",
tiles = {"input_block.png"},
groups = {circuitry = 1,dig_immediate = 3}
})
minetest.register_node("logikraft:outputBlock", {
description = "Output Block",
tiles = {"output_block.png"},
groups = {circuitry = 1,dig_immediate = 3}
})

View File

@ -60,13 +60,17 @@ local function collapseConnectionsStep(connz)
do
if k<l
then
local match = table.findMatch1(conna,connb)
local match = table.findMatch1(conna.conn,connb.conn)
if match
then
-- we add connb\m[2] to conna\m[1], and then we remove connbç
table.remove(conna,match[1])
for i,x in pairs(connb) do
if i ~= match[2] then table.insert(conna,x) end
-- we add connb\m[2] to conna\m[1], and then we remove connb
table.remove(conna.conn,match[1])
for i,x in pairs(connb.conn) do
if i ~= match[2] then table.insert(conna.conn,x) end
end
-- And we merge the node lists
for i,x in ipairs(connb.nodes) do
table.insert(conna.nodes,x)
end
table.remove(connz,l)
return true
@ -89,7 +93,6 @@ function logikraft.compileCircuit(poz)
for i,pos in ipairs(poz)
do
local node = minetest.get_node(pos)
print("Analyzing "..node.name)
if logikraft.cablenodes[node.name]
then
-- It is a cable
@ -107,7 +110,9 @@ function logikraft.compileCircuit(poz)
then table.insert(newconn,{x=pos.x,y=pos.y,z=pos.z,d=0}) end
if math.fmod(math.floor(c/8),2)==1
then table.insert(newconn,{x=pos.x,y=pos.y,z=pos.z,d=1}) end
table.insert(connections,newconn)
local pos2 = table.copy(pos)
pos2.conn = j
table.insert(connections,{nodes = {pos2},conn = newconn})
end
end
elseif logikraft.componentnodes[node.name]
@ -117,7 +122,7 @@ function logikraft.compileCircuit(poz)
if cpblock.x == 1 and cpblock.y == 1
then
local component = logikraft.components[cpblock.name]
local cp = {type = cpblock.name, ports = {}}
local cp = {type = cpblock.name, ports = {}, pos = pos}
-- Left
if component.ports.left
then
@ -162,14 +167,43 @@ function logikraft.compileCircuit(poz)
end
end
end
-- If we have a meta name, we save it
local meta = minetest.get_meta(pos)
if meta:get_string("logikraft:name") ~= ""
then cp.name = meta:get_string("logikraft:name")
end
table.insert(components,cp)
-- We do everything in the 0 0 block, we ignore the others
end
-- else we just ignore
end
end
logikraft.collapseConnections(connections)
-- We replace the index of the connection in the components
for k,cmp in pairs(components)
do
for pn,x in pairs(cmp.ports)
do
-- We find the connection with this port
local theconn = 0
for i,connz in ipairs(connections)
do
if table.getkey1(connz.conn,x) -- if x in connz
then theconn = i end
end
cmp.ports[pn] = theconn
end
end
-- We remove conn data from the connections, the index in now enough
for k,conn in ipairs(connections)
do
connections[k] = connections[k].nodes
end
print("Discovered:")
print(dump(components))
print(dump(connections))
return {components = components, connections = connections}
end

View File

@ -140,15 +140,15 @@ minetest.register_craftitem("logikraft:editor", {
then
local index = logikraft.lookingAtNbIndex(user,pointed_thing.under)
minetest.chat_send_all("Looking at nodeblock "..tostring(index))
elseif node.name == "logikraft:component_input_1_1"
then
logikraft.showNameFormspec(user:get_player_name(), pointed_thing.under)
elseif node.name == "logikraft:component_output_1_1"
then
logikraft.showNameFormspec(user:get_player_name(), pointed_thing.under)
elseif logikraft.componentnodes[node.name]
then
minetest.chat_send_all("Looking at component "..logikraft.componentnodes[node.name].name)
elseif node.name == "logikraft:inputBlock"
then
logikraft.showNameFormspec(user:get_player_name(), pointed_thing.under)
elseif node.name == "logikraft:outputBlock"
then
logikraft.showNameFormspec(user:get_player_name(), pointed_thing.under)
end
return itemstack

View File

Before

Width:  |  Height:  |  Size: 606 B

After

Width:  |  Height:  |  Size: 606 B

View File

Before

Width:  |  Height:  |  Size: 636 B

After

Width:  |  Height:  |  Size: 636 B