Move and document the pos string functions
This commit is contained in:
parent
8a5e787ad3
commit
9d487fbfa6
@ -6,5 +6,4 @@ dofile(minetest.get_modpath("lzr_laser").."/elements.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/blocks_util.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/blocks.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/physics.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/triggers.lua")
|
||||
dofile(minetest.get_modpath("lzr_laser").."/tools.lua")
|
||||
|
@ -1,31 +0,0 @@
|
||||
-- Helper functions for the Trigger System, senders and receivers.
|
||||
|
||||
|
||||
lzr_laser.pos_string_to_positions = function(pos_str)
|
||||
local strs = string.split(pos_str, ";")
|
||||
local posses = {}
|
||||
if strs then
|
||||
for s=1, #strs do
|
||||
local stpos = minetest.string_to_pos(strs[s])
|
||||
if not stpos then
|
||||
minetest.log("error", "[lzr_laser] Invalid pos_string syntax of node at "..minetest.pos_to_string(stpos)..": "..tostring(pos_str))
|
||||
return {}
|
||||
end
|
||||
table.insert(posses, stpos)
|
||||
end
|
||||
end
|
||||
return posses
|
||||
end
|
||||
|
||||
lzr_laser.positions_to_pos_string = function(positions)
|
||||
local to_str = ""
|
||||
for p=1, #positions do
|
||||
to_str = to_str .. minetest.pos_to_string(positions[p])
|
||||
if p < #positions then
|
||||
to_str = to_str .. ";"
|
||||
end
|
||||
end
|
||||
return to_str
|
||||
end
|
||||
|
||||
|
@ -252,3 +252,37 @@ function lzr_laser.is_laser_block_active(nodename)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Convert a 'pos string' to a list of positions.
|
||||
-- A 'pos string' is a string containing of positions,
|
||||
-- each in the `minetest.pos_to_string` format, and each
|
||||
-- position is separated by a semicolon.
|
||||
lzr_laser.pos_string_to_positions = function(pos_str)
|
||||
local strs = string.split(pos_str, ";")
|
||||
local posses = {}
|
||||
if strs then
|
||||
for s=1, #strs do
|
||||
local stpos = minetest.string_to_pos(strs[s])
|
||||
if not stpos then
|
||||
minetest.log("error", "[lzr_laser] Invalid pos_string syntax of node at "..minetest.pos_to_string(stpos)..": "..tostring(pos_str))
|
||||
return {}
|
||||
end
|
||||
table.insert(posses, stpos)
|
||||
end
|
||||
end
|
||||
return posses
|
||||
end
|
||||
|
||||
-- Convert a list of positions to a 'pos string'.
|
||||
-- See `lzr_laser.pos_string_to_positions` for a definition
|
||||
-- of 'pos string'.
|
||||
lzr_laser.positions_to_pos_string = function(positions)
|
||||
local to_str = ""
|
||||
for p=1, #positions do
|
||||
to_str = to_str .. minetest.pos_to_string(positions[p])
|
||||
if p < #positions then
|
||||
to_str = to_str .. ";"
|
||||
end
|
||||
end
|
||||
return to_str
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user