Compare commits
No commits in common. "b907e06c5f1f368df2002dfb85384d408b598e19" and "ef8b8910b085cf80bbdb51b0593c9c9afcd46897" have entirely different histories.
b907e06c5f
...
ef8b8910b0
@ -37,20 +37,6 @@ logikraft.components = {
|
|||||||
left = {nil,nil,nil,nil,nil,"in_3","in_2","in_1"},
|
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"}
|
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"}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,11 @@
|
|||||||
|
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}
|
||||||
|
})
|
||||||
86
circuits.lua
86
circuits.lua
@ -60,17 +60,13 @@ local function collapseConnectionsStep(connz)
|
|||||||
do
|
do
|
||||||
if k<l
|
if k<l
|
||||||
then
|
then
|
||||||
local match = table.findMatch1(conna.conn,connb.conn)
|
local match = table.findMatch1(conna,connb)
|
||||||
if match
|
if match
|
||||||
then
|
then
|
||||||
-- we add connb\m[2] to conna\m[1], and then we remove connb
|
-- we add connb\m[2] to conna\m[1], and then we remove connbç
|
||||||
table.remove(conna.conn,match[1])
|
table.remove(conna,match[1])
|
||||||
for i,x in pairs(connb.conn) do
|
for i,x in pairs(connb) do
|
||||||
if i ~= match[2] then table.insert(conna.conn,x) end
|
if i ~= match[2] then table.insert(conna,x) end
|
||||||
end
|
|
||||||
-- And we merge the node lists
|
|
||||||
for i,x in ipairs(connb.nodes) do
|
|
||||||
table.insert(conna.nodes,x)
|
|
||||||
end
|
end
|
||||||
table.remove(connz,l)
|
table.remove(connz,l)
|
||||||
return true
|
return true
|
||||||
@ -93,6 +89,7 @@ function logikraft.compileCircuit(poz)
|
|||||||
for i,pos in ipairs(poz)
|
for i,pos in ipairs(poz)
|
||||||
do
|
do
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
print("Analyzing "..node.name)
|
||||||
if logikraft.cablenodes[node.name]
|
if logikraft.cablenodes[node.name]
|
||||||
then
|
then
|
||||||
-- It is a cable
|
-- It is a cable
|
||||||
@ -110,9 +107,7 @@ function logikraft.compileCircuit(poz)
|
|||||||
then table.insert(newconn,{x=pos.x,y=pos.y,z=pos.z,d=0}) end
|
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
|
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
|
then table.insert(newconn,{x=pos.x,y=pos.y,z=pos.z,d=1}) end
|
||||||
local pos2 = table.copy(pos)
|
table.insert(connections,newconn)
|
||||||
pos2.conn = j
|
|
||||||
table.insert(connections,{nodes = {pos2},conn = newconn})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif logikraft.componentnodes[node.name]
|
elseif logikraft.componentnodes[node.name]
|
||||||
@ -122,7 +117,7 @@ function logikraft.compileCircuit(poz)
|
|||||||
if cpblock.x == 1 and cpblock.y == 1
|
if cpblock.x == 1 and cpblock.y == 1
|
||||||
then
|
then
|
||||||
local component = logikraft.components[cpblock.name]
|
local component = logikraft.components[cpblock.name]
|
||||||
local cp = {type = cpblock.name, ports = {}, pos = pos}
|
local cp = {type = cpblock.name, ports = {}}
|
||||||
-- Left
|
-- Left
|
||||||
if component.ports.left
|
if component.ports.left
|
||||||
then
|
then
|
||||||
@ -167,77 +162,14 @@ function logikraft.compileCircuit(poz)
|
|||||||
end
|
end
|
||||||
end
|
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)
|
table.insert(components,cp)
|
||||||
-- We do everything in the 0 0 block, we ignore the others
|
-- We do everything in the 0 0 block, we ignore the others
|
||||||
end
|
end
|
||||||
-- else we just ignore
|
-- else we just ignore
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
logikraft.collapseConnections(connections)
|
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
|
|
||||||
|
|
||||||
-- We remove inputs and outputs, as we only store ports
|
|
||||||
local inputs = {}
|
|
||||||
local outputs = {}
|
|
||||||
local cleanedComponents = {}
|
|
||||||
for i,cmp in ipairs(components)
|
|
||||||
do
|
|
||||||
local name = cmp.name or cmp.type.."_unknown_"..tostring(i)
|
|
||||||
if cmp.type == "input"
|
|
||||||
then
|
|
||||||
inputs[name] = {
|
|
||||||
conn = cmp.ports["out"],
|
|
||||||
pos = cmp.pos
|
|
||||||
}
|
|
||||||
elseif cmp.type == "output"
|
|
||||||
then
|
|
||||||
outputs[name] = {
|
|
||||||
conn = cmp.ports["in"],
|
|
||||||
pos = cmp.pos
|
|
||||||
}
|
|
||||||
else
|
|
||||||
table.insert(cleanedComponents,cmp)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
print("Discovered:")
|
print("Discovered:")
|
||||||
--[[
|
print(dump(components))
|
||||||
print(dump(cleanedComponents))
|
|
||||||
print(dump(inputs))
|
|
||||||
print(dump(outputs))
|
|
||||||
print(dump(connections))
|
print(dump(connections))
|
||||||
--]]
|
|
||||||
return {components = cleanedComponents, inputs=inputs, outputs=outputs, connections = connections}
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function logikraft.compute(circuit,inz)
|
|
||||||
local out = {outX = inz["in1"]}
|
|
||||||
return out
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -38,84 +38,3 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function posToStr(pos)
|
|
||||||
return pos.x..";"..pos.y..";"..pos.z
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getCircuitFormspec(inz,outz)
|
|
||||||
local formspec = {
|
|
||||||
"formspec_version[4]",
|
|
||||||
"size[9,",tostring(2.625+(table.length(inz)*0.5)+(table.length(outz)*0.5)),"]",
|
|
||||||
"label[0.375,0.5;", minetest.formspec_escape("Inputs"), "]"
|
|
||||||
}
|
|
||||||
local y = 1.0
|
|
||||||
for name,x in pairs(inz)
|
|
||||||
do
|
|
||||||
if x == 0
|
|
||||||
then table.insert(formspec,"button[0.375,"..tostring(y-0.25)..";0.5,0.5;input_"..name..";OFF]")
|
|
||||||
else table.insert(formspec,"button[0.375,"..tostring(y-0.25)..";0.5,0.5;input_"..name..";ON]")
|
|
||||||
end
|
|
||||||
table.insert(formspec,"label[1.0,"..tostring(y)..";"..minetest.formspec_escape(name).."]")
|
|
||||||
y = y + 0.5
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(formspec,"label[0.375,"..tostring(y)..";".. minetest.formspec_escape("Outputs").. "]")
|
|
||||||
y = y + 0.5
|
|
||||||
|
|
||||||
for name,x in pairs(outz)
|
|
||||||
do
|
|
||||||
table.insert(formspec,"style_type[label;bold,font_size=12px]")
|
|
||||||
if x == 0
|
|
||||||
then table.insert(formspec,"label[0.375,"..tostring(y)..";OFF]")
|
|
||||||
else table.insert(formspec,"label[0.375,"..tostring(y)..";ON]")
|
|
||||||
end
|
|
||||||
table.insert(formspec,"style_type[label;normal,font_size=10px]")
|
|
||||||
table.insert(formspec,"label[1.0,"..tostring(y)..";"..minetest.formspec_escape(name).."]")
|
|
||||||
y = y + 0.5
|
|
||||||
end
|
|
||||||
table.insert(formspec,"button_exit[3,"..tostring(y-0.15)..";3,1;commit;OK]")
|
|
||||||
|
|
||||||
return table.concat(formspec,"")
|
|
||||||
end
|
|
||||||
|
|
||||||
function logikraft.showCircuitFormspec(playername,pos)
|
|
||||||
local poz = logikraft.discoverBlocks(pos)
|
|
||||||
local circuit = logikraft.compileCircuit(poz)
|
|
||||||
|
|
||||||
local cn = posToStr(pos).."_"..playername
|
|
||||||
if not _contexts[cn]
|
|
||||||
then
|
|
||||||
_contexts[cn] = {}
|
|
||||||
for name,x in pairs(circuit.inputs)
|
|
||||||
do _contexts[cn][name] = 0 end
|
|
||||||
end
|
|
||||||
print(dump(_contexts[cn]))
|
|
||||||
local formspec = getCircuitFormspec(_contexts[cn],logikraft.compute(circuit,_contexts[cn]))
|
|
||||||
_contexts[playername] = pos
|
|
||||||
minetest.show_formspec(playername, "logikraft:circuitFormSpec", formspec)
|
|
||||||
end
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
if formname ~= "logikraft:circuitFormSpec" then return end
|
|
||||||
|
|
||||||
local pname = player:get_player_name()
|
|
||||||
if _contexts[pname]
|
|
||||||
then
|
|
||||||
local cn = posToStr(_contexts[pname]).."_"..pname
|
|
||||||
-- We update the clicked field
|
|
||||||
for f,x in pairs(fields)
|
|
||||||
do
|
|
||||||
if string.startsWith(f,"input_")
|
|
||||||
then
|
|
||||||
print("ploup")
|
|
||||||
local v = (x == "OFF") and 1 or 0
|
|
||||||
_contexts[cn][string.without(f,"input_")] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not fields.commit
|
|
||||||
then logikraft.showCircuitFormspec(pname,_contexts[pname])
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.chat_send_player(pname, "Could not get pos data from formspec")
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|||||||
13
items.lua
13
items.lua
@ -140,18 +140,15 @@ minetest.register_craftitem("logikraft:editor", {
|
|||||||
then
|
then
|
||||||
local index = logikraft.lookingAtNbIndex(user,pointed_thing.under)
|
local index = logikraft.lookingAtNbIndex(user,pointed_thing.under)
|
||||||
minetest.chat_send_all("Looking at nodeblock "..tostring(index))
|
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]
|
elseif logikraft.componentnodes[node.name]
|
||||||
then
|
then
|
||||||
minetest.chat_send_all("Looking at component "..logikraft.componentnodes[node.name].name)
|
minetest.chat_send_all("Looking at component "..logikraft.componentnodes[node.name].name)
|
||||||
elseif node.name == "logikraft:circuitBlock"
|
elseif node.name == "logikraft:inputBlock"
|
||||||
then
|
then
|
||||||
logikraft.showCircuitFormspec(user:get_player_name(), pointed_thing.under)
|
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
|
end
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 606 B After Width: | Height: | Size: 606 B |
|
Before Width: | Height: | Size: 636 B After Width: | Height: | Size: 636 B |
14
utils.lua
14
utils.lua
@ -30,26 +30,12 @@ function table.getkey1(arr,x)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function table.length(arr)
|
|
||||||
local c = 0
|
|
||||||
for k,v in pairs(arr)
|
|
||||||
do
|
|
||||||
c = c + 1
|
|
||||||
end
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
function string.startsWith(str,ex)
|
function string.startsWith(str,ex)
|
||||||
return string.sub(str,1,string.len(ex)) == ex
|
return string.sub(str,1,string.len(ex)) == ex
|
||||||
end
|
end
|
||||||
function string.without(str,ex)
|
function string.without(str,ex)
|
||||||
return string.sub(str,string.len(ex)+1,-1)
|
return string.sub(str,string.len(ex)+1,-1)
|
||||||
end
|
end
|
||||||
function string.endsWith(str,ex)
|
|
||||||
return string.sub(str,-1-string.len(ex),-1) == ex
|
|
||||||
end
|
|
||||||
function string.without2(str,ex,ex2)
|
|
||||||
return string.sub(str,string.len(ex)+1,-1-string.len(ex2))
|
|
||||||
end
|
|
||||||
function table.equals1(arr1,arr2)
|
function table.equals1(arr1,arr2)
|
||||||
for i,v in pairs(arr1)
|
for i,v in pairs(arr1)
|
||||||
do
|
do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user