Set events metatable correctly

This commit is contained in:
cora 2022-11-23 23:09:10 +01:00
parent 87d5cdc439
commit d0ea7c4059

View File

@ -6,13 +6,11 @@ else disabled_events = {} end
local DBG = minetest.settings:get_bool("mcl_logging_event_api",false) local DBG = minetest.settings:get_bool("mcl_logging_event_api",false)
local active_events = {} local active_events = {}
local tpl_eventdef = { local event_tpl = {
stage = 0, stage = 0,
max_stage = 1, max_stage = 1,
percent = 100, percent = 100,
bars = {}, bars = {},
--pos = vector.zero(),
--time_start = 0,
completed = false, completed = false,
cond_start = function(event) end, --return table of positions cond_start = function(event) end, --return table of positions
on_step = function(event) end, on_step = function(event) end,
@ -49,7 +47,7 @@ local function start_event(p,e)
mcl_log("[mcl_events] Event started: "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos))) mcl_log("[mcl_events] Event started: "..e.readable_name.." at "..minetest.pos_to_string(vector.round(p.pos)))
local idx = #active_events + 1 local idx = #active_events + 1
active_events[idx] = table.copy(e) active_events[idx] = table.copy(e)
setmetatable(active_events[idx],e) setmetatable(active_events[idx],{__index = event_tpl})
for k,v in pairs(p) do active_events[idx][k] = v end for k,v in pairs(p) do active_events[idx][k] = v end
active_events[idx].stage = 0 active_events[idx].stage = 0
active_events[idx].percent = 100 active_events[idx].percent = 100