bug fixes for oop changes
This commit is contained in:
parent
58133caa95
commit
8323cd065d
@ -8,6 +8,9 @@ datablock fxDTSBrickData(LogicGate_Button_Data : LogicGate_Switch_Data){
|
|||||||
|
|
||||||
numLogicPorts = 2;
|
numLogicPorts = 2;
|
||||||
|
|
||||||
|
logicInit = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/switch-init.lua" );
|
||||||
|
logicInput = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/switch-input.lua");
|
||||||
|
|
||||||
logicPortType[0] = 0;
|
logicPortType[0] = 0;
|
||||||
logicPortPos[0] = "0 1 0";
|
logicPortPos[0] = "0 1 0";
|
||||||
logicPortDir[0] = "1";
|
logicPortDir[0] = "1";
|
||||||
|
6
bricks/inputs/switch-init.lua
Normal file
6
bricks/inputs/switch-init.lua
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
return function(gate)
|
||||||
|
Gate.initdata(gate)
|
||||||
|
local gatedata = Gate.getdata(gate)
|
||||||
|
gatedata.switchstate = false
|
||||||
|
end
|
@ -14,7 +14,7 @@ datablock fxDTSBrickData(LogicGate_Switch_Data)
|
|||||||
isLogicGate = 1;
|
isLogicGate = 1;
|
||||||
isLogicInput = 1;
|
isLogicInput = 1;
|
||||||
|
|
||||||
logicInit = "return function(gate) Gate.initdata(gate) local gatedata = Gate.getdata(gate) gatedata.switchstate = false end";
|
logicInit = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/switch-init.lua" );
|
||||||
logicInput = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/switch-input.lua");
|
logicInput = lualogic_readfile($LuaLogic::Path @ "bricks/inputs/switch-input.lua");
|
||||||
|
|
||||||
numLogicPorts = 2;
|
numLogicPorts = 2;
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
|
||||||
return function(gate)
|
return function(gate)
|
||||||
gate.lastTickChanged = 0
|
Gate.initdata(gate)
|
||||||
gate.listenState = "wait"
|
local gatedata = Gate.getdata(gate)
|
||||||
gate.bitsReceived = 0
|
|
||||||
gate.valReceived = 0
|
gatedata.lastTickChanged = 0
|
||||||
|
gatedata.listenState = "wait"
|
||||||
|
gatedata.bitsReceived = 0
|
||||||
|
gatedata.valReceived = 0
|
||||||
end
|
end
|
||||||
|
@ -1,27 +1,29 @@
|
|||||||
|
|
||||||
local function getBit(gate, val)
|
local function getBit(gate, val)
|
||||||
|
local gatedata = Gate.getdata(gate)
|
||||||
|
|
||||||
--print("get bit", val)
|
--print("get bit", val)
|
||||||
if gate.listenState=="wait" then
|
if gatedata.listenState=="wait" then
|
||||||
if val==1 then
|
if val==1 then
|
||||||
gate.listenState = "getbits"
|
gatedata.listenState = "getbits"
|
||||||
gate.bitsReceived = 0
|
gatedata.bitsReceived = 0
|
||||||
--print("", "state = listen")
|
--print("", "state = listen")
|
||||||
end
|
end
|
||||||
elseif gate.listenState=="getbits" then
|
elseif gatedata.listenState=="getbits" then
|
||||||
gate.valReceived = gate.valReceived + math.pow(2, textbrick2_bitsNeeded-1-gate.bitsReceived)*val
|
gatedata.valReceived = gatedata.valReceived + math.pow(2, textbrick2_bitsNeeded-1-gatedata.bitsReceived)*val
|
||||||
gate.bitsReceived = gate.bitsReceived+1
|
gatedata.bitsReceived = gatedata.bitsReceived+1
|
||||||
|
|
||||||
--print("", "append", gate.bitsReceived-1, val)
|
--print("", "append", gatedata.bitsReceived-1, val)
|
||||||
|
|
||||||
if gate.bitsReceived==textbrick2_bitsNeeded then
|
if gatedata.bitsReceived==textbrick2_bitsNeeded then
|
||||||
|
|
||||||
gate.listenState = "terminate"
|
gatedata.listenState = "terminate"
|
||||||
end
|
end
|
||||||
elseif gate.listenState=="terminate" then
|
elseif gatedata.listenState=="terminate" then
|
||||||
if val==1 then
|
if val==1 then
|
||||||
--print("", "terminate")
|
--print("", "terminate")
|
||||||
|
|
||||||
local printid = gate.valReceived
|
local printid = gatedata.valReceived
|
||||||
local printname = textbrick2_idxToPrint[printid]
|
local printname = textbrick2_idxToPrint[printid]
|
||||||
|
|
||||||
Gate.cb(gate, printname)
|
Gate.cb(gate, printname)
|
||||||
@ -29,29 +31,31 @@ local function getBit(gate, val)
|
|||||||
--print("", "set print", string.format("%02x", printid), printname)
|
--print("", "set print", string.format("%02x", printid), printname)
|
||||||
end
|
end
|
||||||
|
|
||||||
gate.listenState = "wait"
|
gatedata.listenState = "wait"
|
||||||
|
|
||||||
gate.bitsReceived = 0
|
gatedata.bitsReceived = 0
|
||||||
gate.valReceived = 0
|
gatedata.valReceived = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function changeTo(gate, val)
|
local function changeTo(gate, val)
|
||||||
|
local gatedata = Gate.getdata(gate)
|
||||||
|
|
||||||
local tick = Gate.gettick(gate)
|
local tick = Gate.gettick(gate)
|
||||||
local ticks = tick-gate.lastTickChanged
|
local ticks = tick-gatedata.lastTickChanged
|
||||||
|
|
||||||
local bits = math.min(ticks, 10)
|
local bits = math.min(ticks, 10)
|
||||||
for i = 1, bits do
|
for i = 1, bits do
|
||||||
getBit(gate, val)
|
getBit(gate, val)
|
||||||
end
|
end
|
||||||
|
|
||||||
gate.lastTickChanged = tick
|
gatedata.lastTickChanged = tick
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(gate)
|
return function(gate)
|
||||||
if Gate.getportisrising(gate, 1) then
|
if Gate.getportisrising(gate, 1) then
|
||||||
changeTo(gate, 0)
|
changeTo(gate, 0)
|
||||||
elseif Gate.getportisfalling(gate, 2) then
|
elseif Gate.getportisfalling(gate, 1) then
|
||||||
changeTo(gate, 1)
|
changeTo(gate, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
|
|
||||||
-- 2020-03-30
|
|
||||||
-- Requirement change: The gate's output will now depend only on the event, and not carry the input at all
|
|
||||||
|
|
||||||
return function(gate, argv)
|
return function(gate, argv)
|
||||||
gate.ports[2]:setstate(toboolean(argv[1]))
|
Gate.setportstate(gate, 2, toboolean(argv[1]))
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user