bug fixes for oop changes
This commit is contained in:
		| @@ -8,6 +8,9 @@ datablock fxDTSBrickData(LogicGate_Button_Data : LogicGate_Switch_Data){ | ||||
| 	 | ||||
| 	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; | ||||
| 	logicPortPos[0] = "0 1 0"; | ||||
| 	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; | ||||
| 	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"); | ||||
| 	 | ||||
| 	numLogicPorts = 2; | ||||
|   | ||||
| @@ -1,7 +1,10 @@ | ||||
|  | ||||
| return function(gate) | ||||
| 	gate.lastTickChanged = 0 | ||||
| 	gate.listenState = "wait" | ||||
| 	gate.bitsReceived = 0 | ||||
| 	gate.valReceived = 0 | ||||
| 	Gate.initdata(gate) | ||||
| 	local gatedata = Gate.getdata(gate) | ||||
| 	 | ||||
| 	gatedata.lastTickChanged = 0 | ||||
| 	gatedata.listenState = "wait" | ||||
| 	gatedata.bitsReceived = 0 | ||||
| 	gatedata.valReceived = 0 | ||||
| end | ||||
|   | ||||
| @@ -1,27 +1,29 @@ | ||||
|  | ||||
| local function getBit(gate, val) | ||||
| 	local gatedata = Gate.getdata(gate) | ||||
| 	 | ||||
| 	--print("get bit", val) | ||||
| 	if gate.listenState=="wait" then | ||||
| 	if gatedata.listenState=="wait" then | ||||
| 		if val==1 then | ||||
| 			gate.listenState = "getbits" | ||||
| 			gate.bitsReceived = 0 | ||||
| 			gatedata.listenState = "getbits" | ||||
| 			gatedata.bitsReceived = 0 | ||||
| 			--print("", "state = listen") | ||||
| 		end | ||||
| 	elseif gate.listenState=="getbits" then | ||||
| 		gate.valReceived = gate.valReceived + math.pow(2, textbrick2_bitsNeeded-1-gate.bitsReceived)*val | ||||
| 		gate.bitsReceived = gate.bitsReceived+1 | ||||
| 	elseif gatedata.listenState=="getbits" then | ||||
| 		gatedata.valReceived = gatedata.valReceived + math.pow(2, textbrick2_bitsNeeded-1-gatedata.bitsReceived)*val | ||||
| 		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 | ||||
| 	elseif gate.listenState=="terminate" then | ||||
| 	elseif gatedata.listenState=="terminate" then | ||||
| 		if val==1 then | ||||
| 			--print("", "terminate") | ||||
| 			 | ||||
| 			local printid = gate.valReceived | ||||
| 			local printid = gatedata.valReceived | ||||
| 			local printname = textbrick2_idxToPrint[printid] | ||||
| 			 | ||||
| 			Gate.cb(gate, printname) | ||||
| @@ -29,29 +31,31 @@ local function getBit(gate, val) | ||||
| 			--print("", "set print", string.format("%02x", printid), printname) | ||||
| 		end | ||||
| 		 | ||||
| 		gate.listenState = "wait" | ||||
| 		gatedata.listenState = "wait" | ||||
| 		 | ||||
| 		gate.bitsReceived = 0 | ||||
| 		gate.valReceived = 0 | ||||
| 		gatedata.bitsReceived = 0 | ||||
| 		gatedata.valReceived = 0 | ||||
| 	end | ||||
| end | ||||
|  | ||||
| local function changeTo(gate, val) | ||||
| 	local gatedata = Gate.getdata(gate) | ||||
| 	 | ||||
| 	local tick = Gate.gettick(gate) | ||||
| 	local ticks = tick-gate.lastTickChanged | ||||
| 	local ticks = tick-gatedata.lastTickChanged | ||||
| 	 | ||||
| 	local bits = math.min(ticks, 10) | ||||
| 	for i = 1, bits do | ||||
| 		getBit(gate, val) | ||||
| 	end | ||||
| 	 | ||||
| 	gate.lastTickChanged = tick | ||||
| 	gatedata.lastTickChanged = tick | ||||
| end | ||||
|  | ||||
| return function(gate) | ||||
| 	if Gate.getportisrising(gate, 1) then | ||||
| 		changeTo(gate, 0) | ||||
| 	elseif Gate.getportisfalling(gate, 2) then | ||||
| 	elseif Gate.getportisfalling(gate, 1) then | ||||
| 		changeTo(gate, 1) | ||||
| 	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) | ||||
| 	gate.ports[2]:setstate(toboolean(argv[1])) | ||||
| 	Gate.setportstate(gate, 2, toboolean(argv[1])) | ||||
| end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Redo
					Redo