Add non-active counter & flip-flop components
This commit is contained in:
@@ -19,6 +19,25 @@
|
||||
</ConnectionPanel>
|
||||
</Item>
|
||||
|
||||
<Item name="Active Flip-Flop Component" identifier="activeflipflopcomponent" category="Electrical" scale="0.5" impactsoundtag="impact_metal_light">
|
||||
<InventoryIcon texture="luacomp_inv.png" sourcerect="0,0,64,52" origin="0.5,0.5" />
|
||||
<Sprite texture="luacomp_sprite.png" depth="0.8" sourcerect="0,0,32,32" origin="0.5,0.5" />
|
||||
<Body width="32" height="24" density="30" />
|
||||
<Holdable selectkey="Select" pickkey="Use" aimpos="65,-10" handle1="0,0" attachable="true" aimable="true" PickingTime="5.0" slots="Any,RightHand,LeftHand" msg="ItemMsgDetachWrench">
|
||||
<RequiredItem items="wrench" type="Equipped" />
|
||||
<StatusEffect type="Always" target="This" stackable="false">
|
||||
<LuaHook name="activeflipflopcomponent.update" />
|
||||
</StatusEffect>
|
||||
</Holdable>
|
||||
<MemoryComponent canbeselected="false" MaxValueLength="1" AllowInGameEditing="false" Value="0" />
|
||||
<ConnectionPanel selectkey="Action" canbeselected="true" msg="ItemMsgRewireScrewdriver" hudpriority="10">
|
||||
<GuiFrame relativesize="0.2,0.32" minsize="400,350" maxsize="480,420" anchor="Center" style="ConnectionPanel" />
|
||||
<RequiredItem items="screwdriver" type="Equipped" />
|
||||
<input name="input" displayname="connection.input" />
|
||||
<output name="state_out" displayname="connection.state_out" />
|
||||
</ConnectionPanel>
|
||||
</Item>
|
||||
|
||||
<Item name="Counter Component" identifier="countercomponent" category="Electrical" Tags="smallitem,logic" maxstacksize="8" scale="0.5" impactsoundtag="impact_metal_light">
|
||||
<InventoryIcon texture="luacomp_inv.png" sourcerect="0,0,64,52" origin="0.5,0.5" />
|
||||
<Sprite texture="luacomp_sprite.png" depth="0.8" sourcerect="0,0,32,32" origin="0.5,0.5" />
|
||||
@@ -39,6 +58,26 @@
|
||||
</ConnectionPanel>
|
||||
</Item>
|
||||
|
||||
<Item name="Active Counter Component" identifier="activecountercomponent" category="Electrical" Tags="smallitem,logic" maxstacksize="8" scale="0.5" impactsoundtag="impact_metal_light">
|
||||
<InventoryIcon texture="luacomp_inv.png" sourcerect="0,0,64,52" origin="0.5,0.5" />
|
||||
<Sprite texture="luacomp_sprite.png" depth="0.8" sourcerect="0,0,32,32" origin="0.5,0.5" />
|
||||
<Body width="32" height="24" density="30" />
|
||||
<Holdable selectkey="Select" pickkey="Use" aimpos="65,-10" handle1="0,0" attachable="true" aimable="true" PickingTime="5.0" slots="Any,RightHand,LeftHand" msg="ItemMsgDetachWrench">
|
||||
<RequiredItem items="wrench" type="Equipped" />
|
||||
<StatusEffect type="Always" target="This" stackable="false">
|
||||
<LuaHook name="activecountercomponent.update" />
|
||||
</StatusEffect>
|
||||
</Holdable>
|
||||
<MemoryComponent canbeselected="false" MaxValueLength="200" AllowInGameEditing="false" Value="0" />
|
||||
<AdderComponent canbeselected="false" ClampMin="0" ClampMax="100" />
|
||||
<ConnectionPanel selectkey="Action" canbeselected="true" msg="ItemMsgRewireScrewdriver" hudpriority="10">
|
||||
<GuiFrame relativesize="0.2,0.32" minsize="400,350" maxsize="480,420" anchor="Center" style="ConnectionPanel" />
|
||||
<RequiredItem items="screwdriver" type="Equipped" />
|
||||
<input name="input" displayname="connection.input" />
|
||||
<output name="state_out" displayname="connection.state_out" />
|
||||
</ConnectionPanel>
|
||||
</Item>
|
||||
|
||||
<item name="Reactor Controller Component" identifier="reactorcontrollercomponent" category="Electrical" Tags="smallitem,logic" maxstacksize="8" scale="0.5" impactsoundtag="impact_metal_light">
|
||||
<InventoryIcon texture="luacomp_inv.png" sourcerect="0,0,64,52" origin="0.5,0.5" />
|
||||
<Sprite texture="luacomp_sprite.png" depth="0.8" sourcerect="0,0,32,32" origin="0.5,0.5" />
|
||||
|
@@ -1,6 +1,8 @@
|
||||
local moduleNames = {
|
||||
"flipflopcomponent",
|
||||
-- "activeflipflopcomponent",
|
||||
"countercomponent",
|
||||
-- "activecountercomponent",
|
||||
"reactorcontrollercomponent",
|
||||
}
|
||||
|
||||
|
36
Lua/activecountercomponen.lua
Normal file
36
Lua/activecountercomponen.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)
|
32
Lua/activeflipflopcomponent.lua
Normal file
32
Lua/activeflipflopcomponent.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local allItems = {}
|
||||
|
||||
Hook.Add("item.created", "activeflipflopcomponent.init", function(item)
|
||||
if item.Prefab.Identifier == "activeflipflopcomponent" 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 == 1 then
|
||||
if mem.value == "0" then mem.value = "1" else mem.value = "0" end
|
||||
elseif input == 0 then
|
||||
mem.value = "0"
|
||||
elseif input == -1 then
|
||||
mem.value = "1"
|
||||
end
|
||||
end
|
||||
|
||||
local think = function()
|
||||
for component, _ in pairs(allItems) do
|
||||
component.SendSignal(component.Components[2].value, "state_out")
|
||||
end
|
||||
end
|
||||
|
||||
Hook.Add("think", "activeflipflopcomponent.think", think)
|
||||
Hook.Add("signalreceived.activeflipflopcomponent", "activeflipflopcomponent.signalReceived", signalReceived)
|
@@ -1,11 +1,3 @@
|
||||
local allItems = {}
|
||||
|
||||
Hook.Add("item.created", "countercomponent.init", function(item)
|
||||
if item.Prefab.Identifier == "countercomponent" then
|
||||
allItems[item] = true
|
||||
end
|
||||
end)
|
||||
|
||||
local signalReceived = function(signal, connection)
|
||||
local this = connection.Item
|
||||
local mem = this.Components[2]
|
||||
@@ -24,13 +16,8 @@ local signalReceived = function(signal, connection)
|
||||
elseif input < 0 then
|
||||
mem.value = tostring(-input)
|
||||
end
|
||||
|
||||
this.SendSignal(mem.value, "state_out")
|
||||
end
|
||||
|
||||
local think = function()
|
||||
for component, _ in pairs(allItems) do
|
||||
component.SendSignal(component.Components[2].value, "state_out")
|
||||
end
|
||||
end
|
||||
|
||||
Hook.Add("think", "countercomponent.think", think)
|
||||
Hook.Add("signalreceived.countercomponent", "countercomponent.signalReceived", signalReceived)
|
||||
|
@@ -1,11 +1,3 @@
|
||||
local allItems = {}
|
||||
|
||||
Hook.Add("item.created", "flipflopcomponent.init", function(item)
|
||||
if item.Prefab.Identifier == "flipflopcomponent" then
|
||||
allItems[item] = true
|
||||
end
|
||||
end)
|
||||
|
||||
local signalReceived = function(signal, connection)
|
||||
local this = connection.Item
|
||||
local mem = this.Components[2]
|
||||
@@ -20,13 +12,8 @@ local signalReceived = function(signal, connection)
|
||||
elseif input == -1 then
|
||||
mem.value = "1"
|
||||
end
|
||||
|
||||
this.sendSignal(mem.value, "state_out")
|
||||
end
|
||||
|
||||
local think = function()
|
||||
for component, _ in pairs(allItems) do
|
||||
component.SendSignal(component.Components[2].value, "state_out")
|
||||
end
|
||||
end
|
||||
|
||||
Hook.Add("think", "flipflopcomponent.think", think)
|
||||
Hook.Add("signalreceived.flipflopcomponent", "flipflopcomponent.signalReceived", signalReceived)
|
||||
|
@@ -3,9 +3,15 @@
|
||||
<entityname.flipflopcomponent>Flip-Flop Component</entityname.flipflopcomponent>
|
||||
<entitydescription.flipflopcomponent>Switches state when receiving 1, forces state to X when receiving -X.</entitydescription.flipflopcomponent>
|
||||
|
||||
<entityname.flipflopcomponent>Active Flip-Flop Component</entityname.flipflopcomponent>
|
||||
<entitydescription.flipflopcomponent>Switches state when receiving 1, forces state to X when receiving -X. Sends a signal constantly.</entitydescription.flipflopcomponent>
|
||||
|
||||
<entityname.countercomponent>Counter Component</entityname.countercomponent>\
|
||||
<entitydescription.countercomponent>Counts up to ClampMax when receiving 1, resets to ClampMin when reached, forces state to X when receiving -X.</entitydescription.countercomponent>
|
||||
|
||||
<entityname.activecountercomponent>Active Counter Component</entityname.activecountercomponent>\
|
||||
<entitydescription.activecountercomponent>Counts up to ClampMax when receiving 1, resets to ClampMin when reached, forces state to X when receiving -X. Sends a signal constantly.</entitydescription.activecountercomponent>
|
||||
|
||||
<entityname.reactorcontrollercomponent>Reactor Controller Component</entityname.reactorcontrollercomponent>
|
||||
<entitydescription.reactorcontrollercomponent>Automatically sets a reactor's Fission Rate and Turbine Output.</entitydescription.reactorcontrollercomponent>
|
||||
</infotexts>
|
||||
|
@@ -6,6 +6,8 @@
|
||||
<Other file="%ModDir%/Items/luacomp_inv.png" />
|
||||
<Other file="%ModDir%/Items/luacomp_sprite.png" />
|
||||
<Other file="%ModDir%/Lua/flipflopcomponent.lua" />
|
||||
<Other file="%ModDir%/Lua/activeflipflopcomponent.lua" />
|
||||
<Other file="%ModDir%/Lua/countercomponent.lua" />
|
||||
<Other file="%ModDir%/Lua/activecountercomponent.lua" />
|
||||
<Other file="%ModDir%/Lua/reactorcontrollercomponent.lua" />
|
||||
</contentpackage>
|
||||
|
Reference in New Issue
Block a user