Added more components

This commit is contained in:
MysaaJava 2024-05-20 14:18:52 +02:00
parent a1177efa69
commit a5cbf1d7b2
Signed by: Mysaa
GPG Key ID: DBA23608F23F5A10
10 changed files with 90 additions and 2 deletions

View File

@ -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==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",
inventory_image = (x == 1 and y == 1 and "component_"..name..".png") or nil,
drop = "logikraft:component_"..name.."_1_1",

View File

@ -16,6 +16,81 @@ logikraft.components = {
outputs = {"out"},
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"] = {
width = 2,
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"}
},
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"] = {
width = 1,

View File

@ -257,6 +257,9 @@ local function computeStep(circuit,connvals,computed)
if allvalue
then
local output = logikraft.components[cmp.type].compute(inputs)
print("Component "..cmp.type)
print(dump(inputs))
print(dump(output))
for name,v in pairs(output)
do
if cmp.ports[name] and connvals[cmp.ports[name]]

BIN
textures/component_nand.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
textures/component_nor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
textures/component_not.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
textures/component_off.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
textures/component_on.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
textures/component_or.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
textures/component_xor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB