Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash when using random-combinator #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions UsefulCombinators_0.5.1/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---------------------------------------------------------------------------------------------------
Version: 0.5.1
Date: 2023.11.05
Info:
- Fix random-combinator error
---------------------------------------------------------------------------------------------------
Version: 0.5.0
Date: 2021.03.13
Info:
- Add support Schall Circuit Group recipe categories
---------------------------------------------------------------------------------------------------
Version: 0.4.9
Date: 2021.03.13
Info:
- Updated internal names to prevent incompatabilities with other mods
---------------------------------------------------------------------------------------------------
Version: 0.4.8
Date: 2021.03.07
Info:
- Fixed and updated for latest factorio version
---------------------------------------------------------------------------------------------------
Version: 0.4.7
Date: 2020.06.23
Info:
- Enhanced thumbnail
---------------------------------------------------------------------------------------------------
Version: 0.4.6
Date: 2020.06.22
Info:
- Updated tyo Factoio v0.18
---------------------------------------------------------------------------------------------------
Version: 0.4.5
Date: 2020.06.22
Info:
- Updated tyo Factoio v0.17
25 changes: 25 additions & 0 deletions UsefulCombinators_0.5.1/combinators/list.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
return {
"uc-and-gate-combinator",
"uc-color-combinator",
"uc-converter-combinator",
"uc-counting-combinator",
"uc-daytime-combinator",
"uc-detector-combinator",
"uc-emitter-combinator",
"uc-max-combinator",
"uc-min-combinator",
"uc-nand-gate-combinator",
"uc-nor-gate-combinator",
"uc-not-gate-combinator",
"uc-or-gate-combinator",
"uc-pollution-combinator",
"uc-power-combinator",
"uc-railway-combinator",
"uc-random-combinator",
"uc-receiver-combinator",
"uc-sensor-combinator",
"uc-statistic-combinator",
"uc-timer-combinator",
"uc-xnor-gate-combinator",
"uc-xor-gate-combinator"
}
99 changes: 99 additions & 0 deletions UsefulCombinators_0.5.1/combinators/uc-and-gate-combinator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
return {
on_click = function(player, object)
local gui = player.gui.center.uc["uc-and-gate-combinator"]
local params = object.meta.params
if gui["signal_a"].elem_value and gui["signal_a"].elem_value.name then
params[1] = {signal = gui["signal_a"].elem_value}
else
params[1] = {signal = {type = "virtual"}}
end
if gui["signal_b"].elem_value and gui["signal_b"].elem_value.name then
params[2] = {signal = gui["signal_b"].elem_value}
else
params[2] = {signal = {type = "virtual"}}
end
if gui["signal_c"].elem_value and gui["signal_c"].elem_value.name then
params[3] = {signal = gui["signal_c"].elem_value}
else
params[3] = {signal = {type = "virtual"}}
end
end,
on_key = function(player, object)
if not (player.gui.center["uc"]) then
local params = object.meta.params
local gui = player.gui.center
local uc = gui.add{type = "frame", name = "uc", caption = "AND Gate Combinator"}
local layout = uc.add{type = "table", name = "uc-and-gate-combinator", column_count = 5}
if params[1].signal and params[1].signal.name then
layout.add{type = "choose-elem-button", name = "signal_a", elem_type = "signal", signal = params[1].signal}
else
layout.add{type = "choose-elem-button", name = "signal_a", elem_type = "signal"}
end
layout.add{type = "label", caption = "AND"}
if params[2].signal and params[2].signal.name then
layout.add{type = "choose-elem-button", name = "signal_b", elem_type = "signal", signal = params[2].signal}
else
layout.add{type = "choose-elem-button", name = "signal_b", elem_type = "signal"}
end
layout.add{type = "label", caption = " = "}
if params[3].signal and params[3].signal.name then
layout.add{type = "choose-elem-button", name = "signal_c", elem_type = "signal", signal = params[3].signal}
else
layout.add{type = "choose-elem-button", name = "signal_c", elem_type = "signal"}
end
layout.add{type = "button", name = "uc-exit", caption = "Ok"}
end
end,
on_place = function(entity, item)
if item ~= nil and item.get_tag("uc_meta") ~= nil then
local tag = item.get_tag("uc_meta")
tag.meta.entity = entity
return { meta = tag.meta }
end
return {
meta = {
entity = entity,
params = {
{signal = {type = "virtual"}},
{signal = {type = "virtual"}},
{signal = {type = "virtual", name = "uc-output-signal"}}
}
}
}
end,
on_destroy = function(meta, item)
item.set_tag("uc_meta", meta)
end,
on_tick = function(object)
local control = object.meta.entity.get_or_create_control_behavior()
if control then
local params = object.meta.params
if params[3].signal then
if control.enabled then
local slots = {}
local c1,c2 = 0,0
if params[1].signal.name then
c1 = get_count(control, params[1].signal)
end
if params[2].signal.name then
c2 = get_count(control, params[2].signal)
end
if params[3].signal.name then
if (c1 > 0) and (c2 > 0) and (c1 == c2) then
table.insert(slots, {signal = params[3].signal, count = 1, index = 1})
else
table.insert(slots, {signal = params[3].signal, count = 0, index = 1})
end
end
control.parameters = slots
end
else
control.parameters = {
{
{signal = {type = "virtual", name = "uc-output-signal"}, count = 0, index = 1}
}
}
end
end
end
}
150 changes: 150 additions & 0 deletions UsefulCombinators_0.5.1/combinators/uc-color-combinator.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
return {
on_click = function(player, object)
local gui = player.gui.center
for i = 1,6 do
if gui["uc"]["uc-color-combinator"]["signal"..i].elem_value and gui["uc"]["uc-color-combinator"]["signal"..i].elem_value.name then
object.meta.params[i] = {signal = gui["uc"]["uc-color-combinator"]["signal"..i].elem_value, count = tonumber(gui["uc"]["uc-color-combinator"]["count"..i].text) or object.meta.params[i].count}
else
object.meta.params[i] = {signal = {type = "virtual"}, count = 0}
end
end
end,
on_key = function(player, object)
if not (player.gui.center["uc"]) then
local gui = player.gui.center
local params = object.meta.params
local uc = gui.add{type = "frame", name = "uc", caption = "Color Combinator"}
local layout = uc.add{type = "table", name = "uc-color-combinator", column_count = 4}
for i = 1,6 do
if i == 1 then
layout.add{type = "label", caption = "Red: (?)", tooltip = {"uc-color-combinator.red"}}
if params[i].signal and params[i].signal.name then
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal", signal = params[i].signal}
else
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal"}
end
layout.add{type = "label", caption = " = "}
layout.add{type = "textfield", name = "count"..i, style = "uc_text", text = params[i].count or 0}
elseif i == 2 then
layout.add{type = "label", caption = "Green: (?)", tooltip = {"uc-color-combinator.green"}}
if params[i].signal and params[i].signal.name then
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal", signal = params[i].signal}
else
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal"}
end
layout.add{type = "label", caption = " = "}
layout.add{type = "textfield", name = "count"..i, style = "uc_text", text = params[i].count or i}
elseif i == 3 then
layout.add{type = "label", caption = "Blue: (?)", tooltip = {"uc-color-combinator.blue"}}
if params[i].signal and params[i].signal.name then
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal", signal = params[i].signal}
else
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal"}
end
layout.add{type = "label", caption = " = "}
layout.add{type = "textfield", name = "count"..i, style = "uc_text", text = params[i].count or i}
elseif i == 4 then
layout.add{type = "label", caption = "Yellow: (?)", tooltip = {"uc-color-combinator.yellow"}}
if params[i].signal and params[i].signal.name then
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal", signal = params[i].signal}
else
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal"}
end
layout.add{type = "label", caption = " = "}
layout.add{type = "textfield", name = "count"..i, style = "uc_text", text = params[i].count or i}
elseif i == 5 then
layout.add{type = "label", caption = "Magenta: (?)", tooltip = {"uc-color-combinator.magenta"}}
if params[i].signal and params[i].signal.name then
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal", signal = params[i].signal}
else
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal"}
end
layout.add{type = "label", caption = " = "}
layout.add{type = "textfield", name = "count"..i, style = "uc_text", text = params[i].count or i}
elseif i == 6 then
layout.add{type = "label", caption = "Cyan: (?)", tooltip = {"uc-color-combinator.cyan"}}
if params[i].signal and params[i].signal.name then
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal", signal = params[i].signal}
else
layout.add{type = "choose-elem-button", name = "signal"..i, elem_type = "signal"}
end
layout.add{type = "label", caption = " = "}
layout.add{type = "textfield", name = "count"..i, style = "uc_text", text = params[i].count or i}
end
end
layout.add{type = "button", name = "uc-exit", caption = "Ok"}
end
end,
on_place = function(entity, item)
if item ~= nil and item.get_tag("uc_meta") ~= nil then
local tag = item.get_tag("uc_meta")
tag.meta.entity = entity
return { meta = tag.meta }
end
return {
meta = {
entity = entity,
params = {
{signal = {type = "virtual", name = "uc-red-signal"}, count = 1},
{signal = {type = "virtual", name = "uc-green-signal"}, count = 2},
{signal = {type = "virtual", name = "uc-blue-signal"}, count = 3},
{signal = {type = "virtual", name = "uc-yellow-signal"}, count = 4},
{signal = {type = "virtual", name = "uc-magenta-signal"}, count = 5},
{signal = {type = "virtual", name = "uc-cyan-signal"}, count = 6}
}
}
}
end,
on_destroy = function(meta, item)
item.set_tag("uc_meta", meta)
end,
on_tick = function(object)
local control = object.meta.entity.get_or_create_control_behavior()
if control then
local params = object.meta.params
if control.enabled then
local slots = {
{signal = {type = "virtual", name = "signal-red"}, count = 0, index = 1},
{signal = {type = "virtual", name = "signal-green"}, count = 0, index = 2},
{signal = {type = "virtual", name = "signal-blue"}, count = 0, index = 3},
{signal = {type = "virtual", name = "signal-yellow"}, count = 0, index = 4},
{signal = {type = "virtual", name = "signal-pink"}, count = 0, index = 5},
{signal = {type = "virtual", name = "signal-cyan"}, count = 0, index = 6}
}
for i = 1,6 do
if params[i].signal and params[i].signal.name then
local color = ""
if i == 1 then
color = "signal-red"
elseif i == 2 then
color = "signal-green"
elseif i == 3 then
color = "signal-blue"
elseif i == 4 then
color = "signal-yellow"
elseif i == 5 then
color = "signal-pink"
elseif i == 6 then
color = "signal-cyan"
end
if get_count(control, params[i].signal) == params[i].count then
table.insert(slots, {signal = {type = "virtual", name = color}, count = 1, index = i})
else
table.insert(slots, {signal = {type = "virtual", name = color}, count = 0, index = i})
end
end
end
control.parameters = slots
else
control.parameters = {
{signal = {type = "virtual", name = "signal-red"}, count = 0, index = 1},
{signal = {type = "virtual", name = "signal-green"}, count = 0, index = 2},
{signal = {type = "virtual", name = "signal-blue"}, count = 0, index = 3},
{signal = {type = "virtual", name = "signal-yellow"}, count = 0, index = 4},
{signal = {type = "virtual", name = "signal-pink"}, count = 0, index = 5},
{signal = {type = "virtual", name = "signal-cyan"}, count = 0, index = 6}
}
end
end
end
}
Loading