allow setting fuzzy matching pattern after mod load

This commit is contained in:
whosit 2025-04-06 08:00:27 +03:00
parent f501c89a4e
commit 26a37d3076

View File

@ -655,6 +655,29 @@ end
waypoint_compass={}
function waypoint_compass.get_coords_pattern()
return FUZZY_COORD_PATTERN
end
-- Allow changing coords pattern after mod is loaded
function waypoint_compass.set_coords_pattern(pattern)
if type(pattern) == "string" then
-- This is an attempt at "validating" the pattern. Whatever
-- lua is doing, it's not enough to just pass non-empty string
-- to trigger a invalid pattern error, or even some random
-- string. Hope is that running pattern against itself will
-- trigger whatever is wrong with it.
local status, err = pcall(string.find, pattern, pattern)
if status then
FUZZY_COORD_PATTERN = pattern
return pattern
end
return status, err
end
end
-- Basic function that can be overridable with something smarter
function waypoint_compass.teleport(player, pos)
if player and type(player) == "userdata" and minetest.is_player(player) then