diff options
author | cheapie <no-email-for-you@example.com> | 2025-04-11 18:14:38 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2025-04-11 18:24:24 -0500 |
commit | 8746da03e3ebb32ff79e5a24e1ed92534e90092a (patch) | |
tree | 530e0258d6a868e68342c33d4f82e241950763e2 | |
parent | 46ff5fc78061554c30cfa2a3416e70f41a4437b1 (diff) | |
download | celevator-8746da03e3ebb32ff79e5a24e1ed92534e90092a.tar celevator-8746da03e3ebb32ff79e5a24e1ed92534e90092a.tar.gz celevator-8746da03e3ebb32ff79e5a24e1ed92534e90092a.tar.bz2 celevator-8746da03e3ebb32ff79e5a24e1ed92534e90092a.tar.xz celevator-8746da03e3ebb32ff79e5a24e1ed92534e90092a.zip |
Add extra checks to prevent and detect invalid floor tables
-rw-r--r-- | controllerfw.lua | 20 | ||||
-rw-r--r-- | dispatcherfw.lua | 23 |
2 files changed, 41 insertions, 2 deletions
diff --git a/controllerfw.lua b/controllerfw.lua index 2b29db2..1850a1e 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -235,6 +235,24 @@ if mem.params and not mem.params.secoverrideusers then mem.params.secoverrideuse if mem.params and mem.params.swingcallwhennotswing == nil then mem.params.swingcallwhennotswing = true end if not mem.editinguser then mem.editinguser = 1 end +if mem.params and #mem.params.floornames < 2 then + mem.params.floornames = {"1","2","3"} + mem.params.floorheights = {5,5,5} + mem.carstate = "bfdemand" + if mem.doorstate == "closed" then + drivecmd({ + command = "setmaxvel", + maxvel = mem.params.contractspeed, + }) + drivecmd({command = "resetpos"}) + interrupt(0.1,"checkdrive") + mem.carmotion = true + juststarted = true + else + close() + end +end + if event.type == "program" then mem.carstate = "uninit" mem.editingfloor = 1 @@ -344,7 +362,7 @@ elseif event.type == "ui" then elseif event.fields.add then table.insert(mem.params.floorheights,5) table.insert(mem.params.floornames,tostring(#mem.params.floornames+1)) - elseif event.fields.remove then + elseif event.fields.remove and #mem.params.floornames > 2 then table.remove(mem.params.floorheights,mem.editingfloor) table.remove(mem.params.floornames,mem.editingfloor) mem.editingfloor = math.max(1,mem.editingfloor-1) diff --git a/dispatcherfw.lua b/dispatcherfw.lua index 25ad4f8..9b0a23b 100644 --- a/dispatcherfw.lua +++ b/dispatcherfw.lua @@ -300,6 +300,27 @@ local function fs(element) mem.formspec = mem.formspec..element end +if mem.params and #mem.params.floornames < 2 then + mem.params.floorheights = {5,5,5} + mem.params.floornames = {"1","2","3"} + for _,carid in ipairs(mem.params.carids) do + local floornames = {} + local floorheights = {} + for i=1,#mem.params.floornames,1 do + if mem.params.floorsserved[carid][i] then + table.insert(floornames,mem.params.floornames[i]) + table.insert(floorheights,mem.params.floorheights[i]) + elseif #floornames > 0 then + floorheights[#floorheights] = floorheights[#floorheights]+mem.params.floorheights[i] + end + end + send(carid,"newfloortable",{ + floornames = floornames, + floorheights = floorheights, + }) + end +end + if event.type == "program" then mem.carstatus = {} mem.screenstate = "oobe_welcome" @@ -367,7 +388,7 @@ elseif event.type == "ui" then elseif event.fields.add then table.insert(mem.params.floorheights,5) table.insert(mem.params.floornames,tostring(#mem.params.floornames+1)) - elseif event.fields.remove then + elseif event.fields.remove and #mem.params.floornames > 2 then table.remove(mem.params.floorheights,mem.editingfloor) table.remove(mem.params.floornames,mem.editingfloor) mem.editingfloor = math.max(1,mem.editingfloor-1) |