core: add position manager system

it doesn't save them to disk, but that would not be too difficult to add
This commit is contained in:
Starbeamrainbowlabs 2022-09-18 03:25:49 +01:00
parent fd42d96702
commit 9932852053
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,57 @@
local wea_c = worldeditadditions_core
local positions_count_limit = 999
local positions = {}
local function ensure_player(player_name)
if not positions[player_name] then
positions[player_name] = {}
end
end
--- Gets the position with the given index for the given player.
-- @param player_name string The name of the player to fetch the position for.
-- @param
local function get_pos(player_name, i)
ensure_player(player_name)
return positions[player_name][i]
end
local function get_pos1(player_name) return get_pos(player_name, 1) end
local function get_pos2(player_name) return get_pos(player_name, 2) end
local function get_pos_all(player_name)
ensure_player(player_name)
return positions[player_name]
end
local function pos_count(player_name)
ensure_player(player_name)
return #pos_count[player_name]
end
local function set_pos(player_name, i, pos)
if i > positions_count_limit then return false end
ensure_player(player_name)
positions[player_name][i] = pos
return true
end
local function set_pos_all(player_name, i, pos_list)
if #pos_list > positions_count_limit then return false end
positions[player_name] = pos_list
end
local function clear(player_name)
if positions[player_name] then
positions[player_name] = nil
end
end
return {
get = get_pos,
get1 = get_pos1,
get2 = get_pos2,
get_all = get_pos_all,
set = set_pos,
set_all = set_pos_all,
count = pos_count,
clear = clear
}

View file

@ -26,6 +26,7 @@ local wea_c = worldeditadditions_core
wea_c.register_command = dofile(modpath.."/core/register_command.lua") wea_c.register_command = dofile(modpath.."/core/register_command.lua")
wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua") wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua")
wea_c.register_alias = dofile(modpath.."/core/register_alias.lua") wea_c.register_alias = dofile(modpath.."/core/register_alias.lua")
wea_c.pos = dofile(modpath.."/core/pos.lua")
-- Initialise WorldEdit stuff if the WorldEdit mod is not present -- Initialise WorldEdit stuff if the WorldEdit mod is not present