Implements restart lbm

This commit is contained in:
AliasAlreadyTaken 2024-07-10 02:43:53 +02:00
parent 0e40a09d60
commit b313d17439
4 changed files with 66 additions and 27 deletions

36
api.lua
View File

@ -117,16 +117,8 @@ local function add_stage(p_stage)
end
-- Add to lbm_nodenames
if ((stage.restart == false) or (stage.restart == nil)) then
--[[ TODO: Make add and delete into a function:
for i=#yl_api_nodestages.lbm_nodenames,1,-1 do
if (yl_api_nodestages.lbm_nodenames[i] == modname .. ":" .. nodename) then
table.remove(yl_api_nodestages.lbm_nodenames, i)
break
end
end
table.insert(yl_api_nodestages.lbm_nodenames, stage.stage_name)
]]--
if ((stage.restart == true) or (stage.restart == nil)) then
yl_api_nodestages.lbm_add_to_restart(stage.stage_name)
end
target_def._stage = stage
@ -208,9 +200,11 @@ local function overwrite_stage(p_stage)
end
end
-- Remove from lbm_nodenames
yl_api_nodestages.lbm_remove_from_restart(stage.stage_name)
-- Add to lbm_nodenames
if ((stage.restart == false) or (stage.restart == nil)) then
table.insert(yl_api_nodestages.lbm_nodenames, stage.stage_name)
if ((stage.restart == true) or (stage.restart == nil)) then
yl_api_nodestages.lbm_add_to_restart(stage.stage_name)
end
-- Assign the new values
@ -275,15 +269,10 @@ local function rollback_stage(modname, nodename)
end
-- Remove current from lbm_names
for i=#yl_api_nodestages.lbm_nodenames,1,-1 do
if (yl_api_nodestages.lbm_nodenames[i] == modname .. ":" .. nodename) then
table.remove(yl_api_nodestages.lbm_nodenames, i)
break
end
end
yl_api_nodestages.lbm_remove_from_restart(modname .. ":" .. nodename)
-- Add to lbm_nodenames
if ((previous.stage.restart == false) or (previous.stage.restart == nil)) then
table.insert(yl_api_nodestages.lbm_nodenames, previous.stage.stage_name)
if ((previous.stage.restart == true) or (previous.stage.restart == nil)) then
yl_api_nodestages.lbm_add_to_restart(previous.stage.stage_name)
end
def._stage = previous.stage
@ -327,12 +316,7 @@ local function delete_stage(modname, nodename)
end
-- Remove current from lbm_names
for i=#yl_api_nodestages.lbm_nodenames,1,-1 do
if (yl_api_nodestages.lbm_nodenames[i] == modname .. ":" .. nodename) then
table.remove(yl_api_nodestages.lbm_nodenames, i)
break
end
end
yl_api_nodestages.lbm_remove_from_restart(modname .. ":" .. nodename)
def._stage = nil
def.on_timer = nil

View File

@ -13,3 +13,4 @@ function yl_api_nodestages.log(text) return log(text) end
dofile(yl_api_nodestages.modpath .. "internal_nodefunctions.lua")
dofile(yl_api_nodestages.modpath .. "internal_validation.lua")
dofile(yl_api_nodestages.modpath .. "internal_lbm.lua")

54
internal_lbm.lua Normal file
View File

@ -0,0 +1,54 @@
-- lbm_remove_from_restart
--
local function lbm_remove_from_restart(target)
for i=#yl_api_nodestages.lbm_nodenames,1,-1 do
if (yl_api_nodestages.lbm_nodenames[i] == target) then
table.remove(yl_api_nodestages.lbm_nodenames, i)
return true
end
end
return false
end
function yl_api_nodestages.lbm_remove_from_restart(target)
return lbm_remove_from_restart(target)
end
-- lbm_add_to_restart
--
local function lbm_add_to_restart(target)
local found = false
for _, nodename in ipairs(yl_api_nodestages.lbm_nodenames) do
if (nodename == target) then
found = true
end
end
if (found == false) then
table.insert(yl_api_nodestages.lbm_nodenames, target)
return true
end
return false
end
function yl_api_nodestages.lbm_add_to_restart(target)
return lbm_add_to_restart(target)
end
-- lbm_action
--
local function lbm_action(pos, node, _dtime_s)
local t = minetest.get_node_timer(pos)
if t:is_started() == false then
local stage = minetest.registered_nodes[node.name]._stage
if (stage and stage.duration and (type(stage.duration) == "number") and (stage.duration > 0)) then
t:start(stage.duration)
end
end
end
function yl_api_nodestages.lbm_action(pos, node, dtime_s)
return lbm_action(pos, node, dtime_s)
end

View File

@ -1,5 +1,5 @@
local function action(pos, node, dtime_s)
return yl_api_nodestages.lbm_action(pos, node, dtime_s)
end
local def = {