Added setPowerState event to EventGate brick

This commit is contained in:
Auios 2019-04-17 00:59:15 -04:00
parent bde7781d04
commit cc7e3a90e9
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,9 @@
--[[
2019-04-17
Ideally the gate should ignore event set power if its input is connected to a wiregroup.
However I don't know how to do that right now so I'm going to leave it for later
]]
return function(gate, argv)
gate.ports[2]:setstate(toboolean(argv[1]))
end

View File

@ -1,6 +1,7 @@
registerInputEvent("fxDTSBrick", "onPowerChange", "Self fxDTSBrick", 0); registerInputEvent("fxDTSBrick", "onPowerChange", "Self fxDTSBrick", 0);
registerInputEvent("fxDTSBrick", "onPowerOn", "Self fxDTSBrick", 0); registerInputEvent("fxDTSBrick", "onPowerOn", "Self fxDTSBrick", 0);
registerInputEvent("fxDTSBrick", "onPowerOff", "Self fxDTSBrick", 0); registerInputEvent("fxDTSBrick", "onPowerOff", "Self fxDTSBrick", 0);
registerOutputEvent("fxDTSBrick", "setPowerState", "bool 0");
function fxDTSBrick::onPowerChange(%this) function fxDTSBrick::onPowerChange(%this)
{ {
@ -20,6 +21,12 @@ function fxDTSBrick::onPowerOff(%this)
%this.processInputEvent("onPowerOff"); %this.processInputEvent("onPowerOff");
} }
function fxDTSBrick::setPowerState(%this, %state, %client)
{
if(%this.getDatablock().isLogicEventGate)
lualogic_sendinput(%this, 1, %state);
}
datablock fxDTSBrickData(LogicGate_EventGate_Data : brick1x1fData) datablock fxDTSBrickData(LogicGate_EventGate_Data : brick1x1fData)
{ {
logicUpdate = "return function(gate) gate:cb(bool_to_int[gate.ports[1].state]) end"; logicUpdate = "return function(gate) gate:cb(bool_to_int[gate.ports[1].state]) end";
@ -36,7 +43,9 @@ datablock fxDTSBrickData(LogicGate_EventGate_Data : brick1x1fData)
isLogic = true; isLogic = true;
isLogicGate = true; isLogicGate = true;
isLogicEventGate = true;
logicInput = lualogic_readfile($LuaLogic::Path @ "bricks/special/EventGate-input.lua" );
logicUpdate = lualogic_readfile($LuaLogic::Path @ "bricks/special/EventGate-update.lua"); logicUpdate = lualogic_readfile($LuaLogic::Path @ "bricks/special/EventGate-update.lua");
numLogicPorts = 2; numLogicPorts = 2;