mirror of
https://files.creativekara.fr/git/poschangelib.git
synced 2024-08-18 20:34:12 +02:00
Fix multiple listener not being called with the same trigger.
This commit is contained in:
parent
4cc361ea41
commit
90bcb40a93
20
init.lua
20
init.lua
@ -20,11 +20,11 @@ end
|
|||||||
-- more than once per loop (player) if they are registered for more than one event
|
-- more than once per loop (player) if they are registered for more than one event
|
||||||
-- (for example triggered on walk on multiple groups)
|
-- (for example triggered on walk on multiple groups)
|
||||||
local triggered_listeners = {}
|
local triggered_listeners = {}
|
||||||
local function set_listener_triggered(name, pos)
|
local function set_listener_triggered(listener_name, pos)
|
||||||
if not triggered_listeners.name then
|
if not triggered_listeners[listener_name] then
|
||||||
triggered_listeners.name = {}
|
triggered_listeners[listener_name] = {}
|
||||||
end
|
end
|
||||||
table.insert(triggered_listeners.name, pos)
|
table.insert(triggered_listeners[listener_name], pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Internal utility to create an empty table on first registration.
|
--- Internal utility to create an empty table on first registration.
|
||||||
@ -39,10 +39,10 @@ local function get_subtable_or_create(mothertable, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Check if a listener can be triggered
|
--- Check if a listener can be triggered
|
||||||
local function is_callable(name, pos)
|
local function is_callable(listener_name, pos)
|
||||||
-- Check if not aleady called
|
-- Check if not aleady called
|
||||||
if triggered_listeners.name then
|
if triggered_listeners[listener_name] then
|
||||||
for _, trigg_pos in ipairs(triggered_listeners.name) do
|
for _, trigg_pos in ipairs(triggered_listeners[listener_name]) do
|
||||||
if vector.equals(trigg_pos, pos) then
|
if vector.equals(trigg_pos, pos) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -148,10 +148,10 @@ end
|
|||||||
--- Trigger a walk listener by it's name.
|
--- Trigger a walk listener by it's name.
|
||||||
-- Never called directly, use trigger_player_walk_listener_by_* functions
|
-- Never called directly, use trigger_player_walk_listener_by_* functions
|
||||||
local function trigger_player_walk_listeners(trigger_name, player, pos, node, node_def, trigger_meta)
|
local function trigger_player_walk_listeners(trigger_name, player, pos, node, node_def, trigger_meta)
|
||||||
for name, callback in pairs(walk_listeners[trigger_name]) do
|
for listener_name, callback in pairs(walk_listeners[trigger_name]) do
|
||||||
if is_callable(name, pos) then
|
if is_callable(listener_name, pos) then
|
||||||
callback(player, pos, node, node_def, trigger_meta)
|
callback(player, pos, node, node_def, trigger_meta)
|
||||||
set_listener_triggered(trigger_name, pos)
|
set_listener_triggered(listener_name, pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user