Varous fixes on multiple stomp registration.

This commit is contained in:
Karamel 2017-08-30 14:12:50 +02:00
parent 9b692a233c
commit ea8cd66edc

@ -32,8 +32,8 @@ function poschangelib.get_footprint_node_name(source_node_name, mod_name)
-- current_modname is the caller mod, not always poschangelib
mod_name = minetest.get_current_modname()
end
node_mod_name = string.sub(source_node_name, 1, string.find(source_node_name, ':'))
if node_mode_name == mod_name then
local node_mod_name = string.sub(source_node_name, 1, string.find(source_node_name, ':'))
if node_mod_name == mod_name then
return source_node_name .. '_with_footprint'
else
return mod_name .. ':' .. string.gsub(source_node_name, ':', '__') .. '_with_footprint'
@ -126,7 +126,7 @@ function poschangelib.register_footprints(node_name, stomp_desc)
-- Register all nodes from the table
local names = {}
for i, name in pairs(node_name) do
names[#names] = poschangelib.register_footprints(name, stomp_desc)
table.insert(names, poschangelib.register_footprints(name, stomp_desc))
end
return names
end
@ -137,14 +137,16 @@ function poschangelib.register_footprints(node_name, stomp_desc)
return
end
local stomped_node_name = poschangelib.get_footprint_node_name(node_name)
stomp_desc.dest_node_name = stomped_node_name
stomp_desc_defaults(node_name, stomp_desc)
-- Use a copy of stomp desc to keep it unchanged outside the function
local local_stomp_desc = table_copy(stomp_desc)
local_stomp_desc.dest_node_name = stomped_node_name
stomp_desc_defaults(node_name, local_stomp_desc)
local stomped_node_desc = table_copy(desc)
stomped_node_desc.description = desc.description .. ' With Footprint'
-- Add footprint on top of the node texture
local footprint_texture = 'poschangelib_footprint.png'
if stomp_desc.footprint_texture then
footprint_texture = stomp_desc.footprint_texture
if local_stomp_desc.footprint_texture then
footprint_texture = local_stomp_desc.footprint_texture
end
if type(desc.tiles[1]) == 'table' then
-- Replace top texture
@ -155,7 +157,7 @@ function poschangelib.register_footprints(node_name, stomp_desc)
stomped_node_desc.tiles[2] = desc.tiles[1]
end
-- Revert timer
if stomp_desc.duration_min then
if local_stomp_desc.duration_min then
if not desc.on_timer then
stomped_node_desc.on_timer = function(pos, elapsed)
poschangelib.change_node(pos, stomped_node_name, node_name)
@ -164,10 +166,10 @@ function poschangelib.register_footprints(node_name, stomp_desc)
if desc.on_construct then
stomped_node_desc.on_construct = function(pos)
desc.on_construct(pos)
minetest.get_node_timer(pos):start(math.random(stomp_desc.duration_min, stomp_desc.duration_max))
minetest.get_node_timer(pos):start(math.random(local_stomp_desc.duration_min, local_stomp_desc.duration_max))
end
else
stomped_node_desc.on_construct = function(pos) minetest.get_node_timer(pos):start(math.random(stomp_desc.duration_min, stomp_desc.duration_max)) end
stomped_node_desc.on_construct = function(pos) minetest.get_node_timer(pos):start(math.random(local_stomp_desc.duration_min, local_stomp_desc.duration_max)) end
end
end
-- Drop the original node when dug
@ -176,9 +178,9 @@ function poschangelib.register_footprints(node_name, stomp_desc)
end
-- Register
minetest.register_node(stomped_node_name, stomped_node_desc)
poschangelib.register_stomp(node_name, stomped_node_name, stomp_desc)
poschangelib.register_stomp(node_name, stomped_node_name, local_stomp_desc)
-- Stomp to itself to reset the timer on restomp
poschangelib.register_stomp(stomped_node_name, stomped_node_name, stomp_desc)
poschangelib.register_stomp(stomped_node_name, stomped_node_name, local_stomp_desc)
return stomped_node_name
end
@ -201,22 +203,23 @@ function poschangelib.register_stomp(source_node_name, stomp_node_name, stomp_de
if not stomps[source_node_name] then
stomps[source_node_name] = {}
end
stomp_desc.dest_node_name = stomp_node_name
stomp_desc_defaults(source_node_name, stomp_desc)
local local_stomp_desc = table_copy(stomp_desc)
local_stomp_desc.dest_node_name = stomp_node_name
stomp_desc_defaults(source_node_name, local_stomp_desc)
-- Insert in stomps
local inserted = false
local i = 1
-- insert while keeping ascending priority order
while i <= #stomps[source_node_name] and not inserted do
if stomps[source_node_name][i].priority > stomp_desc.priority then
table.insert(stomps[source_node_name], i, stomp_desc)
if stomps[source_node_name][i].priority > local_stomp_desc.priority then
table.insert(stomps[source_node_name], i, local_stomp_desc)
inserted = true
end
i = i + 1
end
-- not inserted: there is no other stomp for this node, insert it.
if not inserted then table.insert(stomps[source_node_name], stomp_desc) end
poschangelib.add_player_walk_listener(stomp_desc.name, walk_listener, {source_node_name})
if not inserted then table.insert(stomps[source_node_name], local_stomp_desc) end
poschangelib.add_player_walk_listener(local_stomp_desc.name, walk_listener, {source_node_name})
end
minetest.register_chatcommand('stomp', {