techpack/tubelib/states.lua

90 lines
2.2 KiB
Lua
Raw Normal View History

2018-03-10 22:14:57 +01:00
--[[
Tube Library
============
Copyright (C) 2017-2020 Joachim Stolberg
2018-03-10 22:14:57 +01:00
AGPL v3
2018-03-10 22:14:57 +01:00
See LICENSE.txt for more information
states.lua:
A state model for tubelib nodes.
]]--
--
2018-12-22 16:58:11 +01:00
-- Tubelib machine states
2018-03-10 22:14:57 +01:00
--
2018-12-22 16:58:11 +01:00
tubelib.STOPPED = 1 -- not operational/turned off
tubelib.RUNNING = 2 -- in normal operation/turned on
tubelib.STANDBY = 3 -- nothing to do (e.g. no input items), or blocked anyhow (output jammed),
-- or node (world) not loaded
tubelib.FAULT = 4 -- any fault state (e.g. no fuel), which can be fixed by the player
tubelib.BLOCKED = 5 -- a pushing node is blocked due to a full destination inventory
tubelib.DEFECT = 6 -- a defect (broken), which has to be repaired by the player
2018-03-10 22:14:57 +01:00
tubelib.StatesImg = {
"tubelib_inv_button_off.png",
"tubelib_inv_button_on.png",
"tubelib_inv_button_standby.png",
2018-12-22 16:58:11 +01:00
"tubelib_inv_button_error.png",
"tubelib_inv_button_warning.png",
2018-12-22 16:58:11 +01:00
"tubelib_inv_button_off.png",
2018-03-10 22:14:57 +01:00
}
2018-03-10 22:14:57 +01:00
-- Return state button image for the node inventory
function tubelib.state_button(state)
2018-12-22 16:58:11 +01:00
if state and state < 7 and state > 0 then
2018-03-10 22:14:57 +01:00
return tubelib.StatesImg[state]
end
2018-12-22 16:58:11 +01:00
return "tubelib_inv_button_off.png"
2018-03-10 22:14:57 +01:00
end
-- State string based on button states
2018-12-22 16:58:11 +01:00
tubelib.StateStrings = {"stopped", "running", "standby", "fault", "blocked", "defect"}
2018-03-10 22:14:57 +01:00
2018-12-22 16:58:11 +01:00
2018-03-10 22:14:57 +01:00
--
2018-12-22 16:58:11 +01:00
-- 'running' variable States (deprecated)
2018-03-10 22:14:57 +01:00
--
tubelib.STATE_RUNNING = 1 -- in normal operation
tubelib.STATE_STOPPED = 0 -- not operational
tubelib.STATE_STANDBY = -1 -- nothing to do
tubelib.STATE_BLOCKED = -2 -- pushing node is blocked due to a full inventory
tubelib.STATE_FAULT = -3 -- any fault state, which has to be fixed by the player
-- Return machine state based on the running counter
function tubelib.state(running)
if running > 0 then
return tubelib.RUNNING
elseif running == 0 then
return tubelib.STOPPED
elseif running == -1 then
return tubelib.STANDBY
elseif running == -2 then
return tubelib.BLOCKED
else
2019-02-10 13:28:17 +01:00
return tubelib.STOPPED
2018-03-10 22:14:57 +01:00
end
end
-- Return state string based on the running counter
function tubelib.statestring(running)
if running > 0 then
return "running"
elseif running == 0 then
return "stopped"
elseif running == -1 then
return "standby"
elseif running == -2 then
return "blocked"
else
return "fault"
end
end