mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 23:33:44 +01:00
sl_controller: report correct state when asked.
LUA Controller now correctly responds to state requests, returning 'running' or 'stopped' according to its operational status. Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
This commit is contained in:
parent
42d01b2142
commit
a7173e046d
@ -116,8 +116,8 @@ sl_controller.register_function("get_ms_time", {
|
|||||||
|
|
||||||
|
|
||||||
local function formspec0(meta)
|
local function formspec0(meta)
|
||||||
local running = meta:get_int("state") == tubelib.RUNNING
|
local state = meta:get_int("state") == tubelib.RUNNING
|
||||||
local cmnd = running and "stop;Stop" or "start;Start"
|
local cmnd = state and "stop;Stop" or "start;Start"
|
||||||
local init = meta:get_string("init")
|
local init = meta:get_string("init")
|
||||||
init = minetest.formspec_escape(init)
|
init = minetest.formspec_escape(init)
|
||||||
return "size[4,3]"..
|
return "size[4,3]"..
|
||||||
@ -129,8 +129,8 @@ local function formspec0(meta)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function formspec1(meta)
|
local function formspec1(meta)
|
||||||
local running = meta:get_int("state") == tubelib.RUNNING
|
local state = meta:get_int("state") == tubelib.RUNNING
|
||||||
local cmnd = running and "stop;Stop" or "start;Start"
|
local cmnd = state and "stop;Stop" or "start;Start"
|
||||||
local init = meta:get_string("init")
|
local init = meta:get_string("init")
|
||||||
init = minetest.formspec_escape(init)
|
init = minetest.formspec_escape(init)
|
||||||
return "size[10,8]"..
|
return "size[10,8]"..
|
||||||
@ -146,8 +146,8 @@ local function formspec1(meta)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function formspec2(meta)
|
local function formspec2(meta)
|
||||||
local running = meta:get_int("state") == tubelib.RUNNING
|
local state = meta:get_int("state") == tubelib.RUNNING
|
||||||
local cmnd = running and "stop;Stop" or "start;Start"
|
local cmnd = state and "stop;Stop" or "start;Start"
|
||||||
local loop = meta:get_string("loop")
|
local loop = meta:get_string("loop")
|
||||||
loop = minetest.formspec_escape(loop)
|
loop = minetest.formspec_escape(loop)
|
||||||
return "size[10,8]"..
|
return "size[10,8]"..
|
||||||
@ -163,8 +163,8 @@ local function formspec2(meta)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function formspec3(meta)
|
local function formspec3(meta)
|
||||||
local running = meta:get_int("state") == tubelib.RUNNING
|
local state = meta:get_int("state") == tubelib.RUNNING
|
||||||
local cmnd = running and "stop;Stop" or "start;Start"
|
local cmnd = state and "stop;Stop" or "start;Start"
|
||||||
local output = meta:get_string("output")
|
local output = meta:get_string("output")
|
||||||
output = minetest.formspec_escape(output)
|
output = minetest.formspec_escape(output)
|
||||||
return "size[10,8]"..
|
return "size[10,8]"..
|
||||||
@ -210,6 +210,7 @@ local function error(pos, err)
|
|||||||
meta:set_string("formspec", formspec3(meta))
|
meta:set_string("formspec", formspec3(meta))
|
||||||
meta:set_string("infotext", "Controller "..number..": error")
|
meta:set_string("infotext", "Controller "..number..": error")
|
||||||
meta:set_int("state", tubelib.STOPPED)
|
meta:set_int("state", tubelib.STOPPED)
|
||||||
|
meta:set_int("running", tubelib.STATE_STOPPED)
|
||||||
minetest.get_node_timer(pos):stop()
|
minetest.get_node_timer(pos):stop()
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -254,6 +255,7 @@ local function start_controller(pos)
|
|||||||
|
|
||||||
if compile(pos, meta, number) then
|
if compile(pos, meta, number) then
|
||||||
meta:set_int("state", tubelib.RUNNING)
|
meta:set_int("state", tubelib.RUNNING)
|
||||||
|
meta:set_int("running", tubelib.STATE_RUNNING)
|
||||||
minetest.get_node_timer(pos):start(1)
|
minetest.get_node_timer(pos):start(1)
|
||||||
meta:set_string("formspec", formspec3(meta))
|
meta:set_string("formspec", formspec3(meta))
|
||||||
meta:set_string("infotext", "Controller "..number..": running")
|
meta:set_string("infotext", "Controller "..number..": running")
|
||||||
@ -266,6 +268,7 @@ local function stop_controller(pos)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local number = meta:get_string("number")
|
local number = meta:get_string("number")
|
||||||
meta:set_int("state", tubelib.STOPPED)
|
meta:set_int("state", tubelib.STOPPED)
|
||||||
|
meta:set_int("running", tubelib.STATE_STOPPED)
|
||||||
minetest.get_node_timer(pos):stop()
|
minetest.get_node_timer(pos):stop()
|
||||||
meta:set_string("infotext", "Controller "..number..": stopped")
|
meta:set_string("infotext", "Controller "..number..": stopped")
|
||||||
meta:set_string("formspec", formspec2(meta))
|
meta:set_string("formspec", formspec2(meta))
|
||||||
@ -275,6 +278,7 @@ local function no_battery(pos)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local number = meta:get_string("number")
|
local number = meta:get_string("number")
|
||||||
meta:set_int("state", tubelib.STOPPED)
|
meta:set_int("state", tubelib.STOPPED)
|
||||||
|
meta:set_int("running", tubelib.STATE_STOPPED)
|
||||||
minetest.get_node_timer(pos):stop()
|
minetest.get_node_timer(pos):stop()
|
||||||
meta:set_string("infotext", "Controller "..number..": No battery")
|
meta:set_string("infotext", "Controller "..number..": No battery")
|
||||||
meta:set_string("formspec", formspec0(meta))
|
meta:set_string("formspec", formspec0(meta))
|
||||||
@ -409,6 +413,7 @@ minetest.register_node("sl_controller:controller", {
|
|||||||
meta:set_string("owner", placer:get_player_name())
|
meta:set_string("owner", placer:get_player_name())
|
||||||
meta:set_string("number", number)
|
meta:set_string("number", number)
|
||||||
meta:set_int("state", tubelib.STOPPED)
|
meta:set_int("state", tubelib.STOPPED)
|
||||||
|
meta:set_int("running", tubelib.STATE_STOPPED)
|
||||||
meta:set_string("init", "-- called only once")
|
meta:set_string("init", "-- called only once")
|
||||||
meta:set_string("loop", "-- called every second")
|
meta:set_string("loop", "-- called every second")
|
||||||
meta:set_string("notes", "For your notes / snippets")
|
meta:set_string("notes", "For your notes / snippets")
|
||||||
@ -480,8 +485,8 @@ tubelib.register_node("sl_controller:controller", {}, {
|
|||||||
elseif topic == "off" then
|
elseif topic == "off" then
|
||||||
set_input(pos, number, payload, topic)
|
set_input(pos, number, payload, topic)
|
||||||
elseif topic == "state" then
|
elseif topic == "state" then
|
||||||
local state = meta:get_int("state")
|
local running = meta:get_int("running") or tubelib.STATE_STOPPED
|
||||||
return tubelib.statestring(state)
|
return tubelib.statestring(running)
|
||||||
else
|
else
|
||||||
return "unsupported"
|
return "unsupported"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user