diff --git a/bricks/special/EventGate-update.lua b/bricks/special/EventGate-update.lua new file mode 100644 index 0000000..85f7128 --- /dev/null +++ b/bricks/special/EventGate-update.lua @@ -0,0 +1,4 @@ +return function(gate) + gate.ports[2]:setstate(gate.ports[1].state) + gate:cb(bool_to_int[gate.ports[1].state]) +end \ No newline at end of file diff --git a/bricks/special/EventGate.cs b/bricks/special/EventGate.cs new file mode 100644 index 0000000..0c26ffa --- /dev/null +++ b/bricks/special/EventGate.cs @@ -0,0 +1,67 @@ +registerInputEvent("fxDTSBrick", "onPowerChange", "Self fxDTSBrick", 0); +registerInputEvent("fxDTSBrick", "onPowerOn", "Self fxDTSBrick", 0); +registerInputEvent("fxDTSBrick", "onPowerOff", "Self fxDTSBrick", 0); + +function fxDTSBrick::onPowerChange(%this) +{ + $InputTarget_["Self"] = %this; + %this.processInputEvent("onPowerChange"); +} + +function fxDTSBrick::onPowerOn(%this) +{ + $InputTarget_["Self"] = %this; + %this.processInputEvent("onPowerOn"); +} + +function fxDTSBrick::onPowerOff(%this) +{ + $InputTarget_["Self"] = %this; + %this.processInputEvent("onPowerOff"); +} + +datablock fxDTSBrickData(LogicGate_EventGate_Data : brick1x1fData) +{ + logicUpdate = "return function(gate) gate:cb(bool_to_int[gate.ports[1].state]) end"; + + + + category = "Logic Bricks"; + subCategory = "Wires - Special"; + uiName = "Event Gate"; + iconName = $LuaLogic::Path @ "icons/EventGate"; + brickFile = $LuaLogic::Path @ "bricks/blb/1x1f_1i_1o.blb"; + hasPrint = 1; + printAspectRatio = "Logic"; + + isLogic = true; + isLogicGate = true; + + logicUpdate = lualogic_readfile($LuaLogic::Path @ "bricks/special/EventGate-update.lua"); + + numLogicPorts = 2; + + logicPortType[0] = 1; + logicPortPos[0] = "0 0 0"; + logicPortDir[0] = "0"; + logicPortCauseUpdate[0] = true; + logicPortUIName[0] = "Input"; + logicPortUIDesc[0] = ""; + + logicPortType[1] = 0; + logicPortPos[1] = "0 0 0"; + logicPortDir[1] = "2"; + logicPortUIName[1] = "Output"; + logicPortUIDesc[1] = ""; +}; +lualogic_registergatedefinition("LogicGate_EventGate_Data"); + +function LogicGate_EventGate_Data::LuaLogic_Callback(%this, %obj, %data) +{ + %obj.onPowerChange(); + if(%data) + %obj.onPowerOn(); + else + %obj.onPowerOff(); +} + diff --git a/icons/EventGate.png b/icons/EventGate.png new file mode 100644 index 0000000..826956c Binary files /dev/null and b/icons/EventGate.png differ diff --git a/scripts/brickdata.cs b/scripts/brickdata.cs index f122df4..3f5c46b 100644 --- a/scripts/brickdata.cs +++ b/scripts/brickdata.cs @@ -40,3 +40,6 @@ exec($LuaLogic::Path @ "bricks/bus/8BitDFlipFlop.cs"); //Memory exec($LuaLogic::Path @ "bricks/memory/DFlipFlop.cs"); exec($LuaLogic::Path @ "bricks/memory/DFlipflopGridMemory2.cs"); + +//Special +exec($LuaLogic::Path @ "bricks/special/EventGate.cs"); \ No newline at end of file