Minor refactoring
This commit is contained in:
36
Lua/activecountercomponent.lua
Normal file
36
Lua/activecountercomponent.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
local allItems = {}
|
||||
|
||||
Hook.Add("item.created", "activecountercomponent.init", function(item)
|
||||
if item.Prefab.Identifier == "activecountercomponent" then
|
||||
allItems[item] = true
|
||||
end
|
||||
end)
|
||||
|
||||
local signalReceived = function(signal, connection)
|
||||
local this = connection.Item
|
||||
local mem = this.Components[2]
|
||||
|
||||
if signal.value == "" then return end
|
||||
local input = tonumber(signal.value) or 1
|
||||
|
||||
if input > 0 then
|
||||
if tonumber(mem.value) >= this.Components[3].clampMax then
|
||||
mem.value = tostring(this.Components[3].clampMin)
|
||||
else
|
||||
mem.value = tostring(tonumber(mem.value) + 1)
|
||||
end
|
||||
elseif input == 0 then
|
||||
mem.value = "0"
|
||||
elseif input < 0 then
|
||||
mem.value = tostring(-input)
|
||||
end
|
||||
end
|
||||
|
||||
local think = function()
|
||||
for component, _ in pairs(allItems) do
|
||||
component.SendSignal(component.Components[2].value, "state_out")
|
||||
end
|
||||
end
|
||||
|
||||
Hook.Add("think", "activecountercomponent.think", think)
|
||||
Hook.Add("signalreceived.activecountercomponent", "activecountercomponent.signalReceived", signalReceived)
|
Reference in New Issue
Block a user