Added more components
@ -29,7 +29,7 @@ function logikraft.registerComponent(name,cmp)
|
|||||||
((y==h) and (cables.top and cables.top[x] and "component_port.png" or "component.png") or "component.png"), -- z+
|
((y==h) and (cables.top and cables.top[x] and "component_port.png" or "component.png") or "component.png"), -- z+
|
||||||
((y==1) and (cables.bottom and cables.bottom[x] and "component_port.png" or "component.png") or "component.png"), -- z-
|
((y==1) and (cables.bottom and cables.bottom[x] and "component_port.png" or "component.png") or "component.png"), -- z-
|
||||||
},
|
},
|
||||||
groups = {circuitry = 1,dig_immediate = 3},
|
groups = {circuitry = 1,dig_immediate = 3, not_in_creative_inventory = (x==1 and y==1 and 0) or 1},
|
||||||
paramtype2 = "4dir",
|
paramtype2 = "4dir",
|
||||||
inventory_image = (x == 1 and y == 1 and "component_"..name..".png") or nil,
|
inventory_image = (x == 1 and y == 1 and "component_"..name..".png") or nil,
|
||||||
drop = "logikraft:component_"..name.."_1_1",
|
drop = "logikraft:component_"..name.."_1_1",
|
||||||
|
|||||||
@ -16,6 +16,81 @@ logikraft.components = {
|
|||||||
outputs = {"out"},
|
outputs = {"out"},
|
||||||
compute = function(inz) return {out = (inz["in_1"] * inz["in_2"] == 0) and 0 or 1} end
|
compute = function(inz) return {out = (inz["in_1"] * inz["in_2"] == 0) and 0 or 1} end
|
||||||
},
|
},
|
||||||
|
["nand"] = {
|
||||||
|
width = 2,
|
||||||
|
height = 3,
|
||||||
|
ports = {
|
||||||
|
left = {"in_2",nil,"in_1"},
|
||||||
|
right = {nil,"out",nil}
|
||||||
|
},
|
||||||
|
inputs = {"in_1","in_2"},
|
||||||
|
outputs = {"out"},
|
||||||
|
compute = function(inz) return {out = (inz["in_1"] * inz["in_2"] == 0) and 1 or 0} end
|
||||||
|
},
|
||||||
|
["or"] = {
|
||||||
|
width = 2,
|
||||||
|
height = 3,
|
||||||
|
ports = {
|
||||||
|
left = {"in_2",nil,"in_1"},
|
||||||
|
right = {nil,"out",nil}
|
||||||
|
},
|
||||||
|
inputs = {"in_1","in_2"},
|
||||||
|
outputs = {"out"},
|
||||||
|
compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 0) and 0 or 1} end
|
||||||
|
},
|
||||||
|
["nor"] = {
|
||||||
|
width = 2,
|
||||||
|
height = 3,
|
||||||
|
ports = {
|
||||||
|
left = {"in_2",nil,"in_1"},
|
||||||
|
right = {nil,"out",nil}
|
||||||
|
},
|
||||||
|
inputs = {"in_1","in_2"},
|
||||||
|
outputs = {"out"},
|
||||||
|
compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 0) and 1 or 0} end
|
||||||
|
},
|
||||||
|
["xor"] = {
|
||||||
|
width = 2,
|
||||||
|
height = 3,
|
||||||
|
ports = {
|
||||||
|
left = {"in_2",nil,"in_1"},
|
||||||
|
right = {nil,"out",nil}
|
||||||
|
},
|
||||||
|
inputs = {"in_1","in_2"},
|
||||||
|
outputs = {"out"},
|
||||||
|
compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 1) and 1 or 0} end
|
||||||
|
},
|
||||||
|
["not"] = {
|
||||||
|
width = 2,
|
||||||
|
height = 1,
|
||||||
|
ports = {
|
||||||
|
left = {"in"},
|
||||||
|
right = {"out"}
|
||||||
|
},
|
||||||
|
inputs = {"in"},
|
||||||
|
outputs = {"out"},
|
||||||
|
compute = function(inz) return {out = 1 - inz["in"]} end
|
||||||
|
},
|
||||||
|
["on"] = {
|
||||||
|
width = 1,
|
||||||
|
height = 1,
|
||||||
|
ports = {
|
||||||
|
right = {"out"}
|
||||||
|
},
|
||||||
|
inputs = {},
|
||||||
|
outputs = {"out"},
|
||||||
|
compute = function(inz) return {out = 1} end
|
||||||
|
},
|
||||||
|
["off"] = {
|
||||||
|
width = 1,
|
||||||
|
height = 1,
|
||||||
|
ports = {
|
||||||
|
right = {"out"}
|
||||||
|
},
|
||||||
|
inputs = {},
|
||||||
|
outputs = {"out"},
|
||||||
|
compute = function(inz) return {out = 0} end
|
||||||
|
},
|
||||||
["switch"] = {
|
["switch"] = {
|
||||||
width = 2,
|
width = 2,
|
||||||
height = 1,
|
height = 1,
|
||||||
@ -36,7 +111,17 @@ logikraft.components = {
|
|||||||
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"}
|
||||||
},
|
},
|
||||||
inputs = {"in_1","in_2","in_3"},
|
inputs = {"in_1","in_2","in_3"},
|
||||||
outputs = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"}
|
outputs = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"},
|
||||||
|
compute = function(inz) return {
|
||||||
|
out_1 = (inz.in_1 == 0) and (inz.in_2 == 0) and (inz.in_3 == 0) and 1 or 0,
|
||||||
|
out_2 = (inz.in_1 == 1) and (inz.in_2 == 0) and (inz.in_3 == 0) and 1 or 0,
|
||||||
|
out_3 = (inz.in_1 == 0) and (inz.in_2 == 1) and (inz.in_3 == 0) and 1 or 0,
|
||||||
|
out_4 = (inz.in_1 == 1) and (inz.in_2 == 1) and (inz.in_3 == 0) and 1 or 0,
|
||||||
|
out_5 = (inz.in_1 == 0) and (inz.in_2 == 0) and (inz.in_3 == 1) and 1 or 0,
|
||||||
|
out_6 = (inz.in_1 == 1) and (inz.in_2 == 0) and (inz.in_3 == 1) and 1 or 0,
|
||||||
|
out_7 = (inz.in_1 == 0) and (inz.in_2 == 1) and (inz.in_3 == 1) and 1 or 0,
|
||||||
|
out_8 = (inz.in_1 == 1) and (inz.in_2 == 1) and (inz.in_3 == 1) and 1 or 0,
|
||||||
|
} end
|
||||||
},
|
},
|
||||||
["input"] = {
|
["input"] = {
|
||||||
width = 1,
|
width = 1,
|
||||||
|
|||||||
@ -257,6 +257,9 @@ local function computeStep(circuit,connvals,computed)
|
|||||||
if allvalue
|
if allvalue
|
||||||
then
|
then
|
||||||
local output = logikraft.components[cmp.type].compute(inputs)
|
local output = logikraft.components[cmp.type].compute(inputs)
|
||||||
|
print("Component "..cmp.type)
|
||||||
|
print(dump(inputs))
|
||||||
|
print(dump(output))
|
||||||
for name,v in pairs(output)
|
for name,v in pairs(output)
|
||||||
do
|
do
|
||||||
if cmp.ports[name] and connvals[cmp.ports[name]]
|
if cmp.ports[name] and connvals[cmp.ports[name]]
|
||||||
|
|||||||
BIN
textures/component_nand.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
textures/component_nor.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
textures/component_not.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
textures/component_off.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
textures/component_on.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
textures/component_or.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
textures/component_xor.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |