Initial move of utils wea → wea_c

Here we go...!
This commit is contained in:
Starbeamrainbowlabs 2022-09-18 16:45:08 +01:00
parent 2b88fa867e
commit 58a7629ea1
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
59 changed files with 66 additions and 66 deletions

@ -9,35 +9,6 @@ worldeditadditions = {}
local wea = worldeditadditions local wea = worldeditadditions
wea.modpath = minetest.get_modpath("worldeditadditions") wea.modpath = minetest.get_modpath("worldeditadditions")
wea.Set = dofile(wea.modpath.."/utils/set.lua")
wea.Vector3 = dofile(wea.modpath.."/utils/vector3.lua")
wea.Mesh, wea.Face = dofile(wea.modpath.."/utils/mesh.lua")
wea.Queue = dofile(wea.modpath.."/utils/queue.lua")
wea.LRU = dofile(wea.modpath.."/utils/lru.lua")
wea.inspect = dofile(wea.modpath.."/utils/inspect.lua")
-- I/O compatibility layer
wea.io = dofile(wea.modpath.."/utils/io.lua")
wea.bit = dofile(wea.modpath.."/utils/bit.lua")
wea.terrain = dofile(wea.modpath.."/utils/terrain/init.lua")
dofile(wea.modpath.."/utils/vector.lua")
dofile(wea.modpath.."/utils/strings/init.lua")
dofile(wea.modpath.."/utils/format/init.lua")
dofile(wea.modpath.."/utils/parse/init.lua")
dofile(wea.modpath.."/utils/tables/init.lua")
dofile(wea.modpath.."/utils/numbers.lua")
dofile(wea.modpath.."/utils/nodes.lua")
dofile(wea.modpath.."/utils/node_identification.lua")
dofile(wea.modpath.."/utils/raycast_adv.lua") -- For the farwand
dofile(wea.modpath.."/utils/player.lua") -- Player info functions
dofile(wea.modpath.."/lib/compat/saplingnames.lua") dofile(wea.modpath.."/lib/compat/saplingnames.lua")
dofile(wea.modpath.."/lib/floodfill.lua") dofile(wea.modpath.."/lib/floodfill.lua")

@ -1,17 +0,0 @@
-- TODO: This is duplicated from worldeditadditions/utils. We should consider moving worldeditadditions/utils to worldeditadditions_core. Perhaps also we could move the definition of the worldeditadditions namespace to worldeditadditions_core too?
--- Formats (usually large) numbers as human-readable strings.
-- Ported from PHP: https://github.com/sbrl/Pepperminty-Wiki/blob/0a81c940c5803856db250b29f54658476bc81e21/core/05-functions.php#L67
-- @param n number The number to format.
-- @param decimals number The number of decimal places to show.
-- @return string A formatted string that represents the given input number.
local function human_size(n, decimals)
local sizes = { "", "K", "M", "G", "T", "P", "E", "Y", "Z" }
local factor = math.floor((#tostring(n) - 1) / 3)
local multiplier = 10^(decimals or 0)
local result = math.floor(0.5 + (n / (1000 ^ factor)) * multiplier) / multiplier
return result .. sizes[factor+1]
end
return human_size

@ -1,7 +1,7 @@
-- WARNING: safe_region MUST NOT be imported more than once, as it defines chat commands. If you want to import it again elsewhere, check first that multiple dofile() calls don't execute a file more than once. -- WARNING: safe_region MUST NOT be imported more than once, as it defines chat commands. If you want to import it again elsewhere, check first that multiple dofile() calls don't execute a file more than once.
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local safe_region = dofile(wea_c.modpath.."/core/safe_region.lua") local safe_region = dofile(wea_c.modpath.."/core/safe_region.lua")
local human_size = dofile(wea_c.modpath.."/core/lib/human_size.lua") local human_size = wea_c.format.human_size
-- TODO: Reimplement worldedit.player_notify(player_name, msg_text) -- TODO: Reimplement worldedit.player_notify(player_name, msg_text)

@ -22,9 +22,44 @@ worldeditadditions_core = {
safe_region_limit_default = 100000, safe_region_limit_default = 100000,
} }
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
wea_c.EventEmitter = dofile(modpath.."/core/lib/EventEmitter.lua") wea_c.EventEmitter = dofile(modpath.."/utils/EventEmitter.lua")
wea_c.pos = dofile(modpath.."/core/pos.lua")
wea_c.Set = dofile(wea_c.modpath.."/utils/set.lua")
wea_c.Vector3 = dofile(wea_c.modpath.."/utils/vector3.lua")
wea_c.Mesh, wea_c.Face = dofile(wea_c.modpath.."/utils/mesh.lua")
wea_c.Queue = dofile(wea_c.modpath.."/utils/queue.lua")
wea_c.LRU = dofile(wea_c.modpath.."/utils/lru.lua")
wea_c.inspect = dofile(wea_c.modpath.."/utils/inspect.lua")
-- I/O compatibility layer
wea_c.io = dofile(wea_c.modpath.."/utils/io.lua")
wea_c.bit = dofile(wea_c.modpath.."/utils/bit.lua")
wea_c.terrain = dofile(wea_c.modpath.."/utils/terrain/init.lua")
dofile(wea_c.modpath.."/utils/vector.lua")
dofile(wea_c.modpath.."/utils/strings/init.lua")
dofile(wea_c.modpath.."/utils/format/init.lua")
dofile(wea_c.modpath.."/utils/parse/init.lua")
dofile(wea_c.modpath.."/utils/tables/init.lua")
dofile(wea_c.modpath.."/utils/numbers.lua")
dofile(wea_c.modpath.."/utils/nodes.lua")
dofile(wea_c.modpath.."/utils/node_identification.lua")
dofile(wea_c.modpath.."/utils/raycast_adv.lua") -- For the farwand
dofile(wea_c.modpath.."/utils/player.lua") -- Player info functions
wea_c.pos = dofile(modpath.."/core/pos.lua")
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")

@ -1,21 +1,21 @@
local wea = worldeditadditions local wea_c = worldeditadditions_core
local v3 = worldeditadditions.Vector3 local v3 = worldeditadditions_core.Vector3
--- Returns the player's position (at leg level). --- Returns the player's position (at leg level).
-- @param name string The name of the player to return facing direction of. -- @param name string The name of the player to return facing direction of.
-- @return vector Returns position. -- @return vector Returns position.
function worldeditadditions.player_vector(name) function wea_c.player_vector(name)
return minetest.get_player_by_name(name):get_pos() return minetest.get_player_by_name(name):get_pos()
end end
--- Returns the player's facing info including relative DIRs. --- Returns the player's facing info including relative DIRs.
-- @param name string The name of the player to return facing direction of. -- @param name string The name of the player to return facing direction of.
-- @returns table(vector3+) xyz raw values and {axis,sign} tables for facing direction and relative direction keys (front, back, left, right, up, down). -- @returns table(vector3+) xyz raw values and {axis,sign} tables for facing direction and relative direction keys (front, back, left, right, up, down).
function worldeditadditions.player_dir(name) function wea_c.player_dir(name)
local dir = v3.clone(minetest.get_player_by_name(name):get_look_dir()) local dir = v3.clone(minetest.get_player_by_name(name):get_look_dir())
local abs = dir:abs() local abs = dir:abs()
-- Facing info -- Facing info
if abs.x > abs.z then dir.facing = {axis="x",sign=wea.getsign(dir.x)} if abs.x > abs.z then dir.facing = {axis="x",sign=wea_c.getsign(dir.x)}
else dir.facing = {axis="z",sign=wea.getsign(dir.z)} end else dir.facing = {axis="z",sign=wea_c.getsign(dir.z)} end
-- Set front and back -- Set front and back
dir.front = dir.facing dir.front = dir.facing
dir.back = {axis=dir.facing.axis,sign=dir.facing.sign*-1} dir.back = {axis=dir.facing.axis,sign=dir.facing.sign*-1}
@ -29,16 +29,16 @@ function worldeditadditions.player_dir(name)
return dir return dir
end end
-- /lua print(worldeditadditions.vector.tostring(minetest.get_player_by_name(myname):get_look_dir())) -- /lua print(wea_c.vector.tostring(minetest.get_player_by_name(myname):get_look_dir()))
--- DEPRECATED ================================================================= --- DEPRECATED =================================================================
-- TODO: Refactor commands that use the following functions to use player_dir then delete these functions -- TODO: Refactor commands that use the following functions to use player_dir then delete these functions
--- Returns the player's facing direction on the horizontal axes only. --- Returns the player's facing direction on the horizontal axes only.
-- @deprecated Use worldeditadditions.player_dir instead. -- @deprecated Use wea_c.player_dir instead.
-- @param name string The name of the player to return facing direction of. -- @param name string The name of the player to return facing direction of.
-- @return string,int Returns axis name and sign multiplier. -- @return string,int Returns axis name and sign multiplier.
function worldeditadditions.player_axis2d(name) function wea_c.player_axis2d(name)
-- minetest.get_player_by_name("singleplayer"): -- minetest.get_player_by_name("singleplayer"):
local dir = minetest.get_player_by_name(name):get_look_dir() local dir = minetest.get_player_by_name(name):get_look_dir()
local x, z= math.abs(dir.x), math.abs(dir.z) local x, z= math.abs(dir.x), math.abs(dir.z)
@ -47,24 +47,24 @@ function worldeditadditions.player_axis2d(name)
end end
--- Returns the axis and sign of the axis to the left of the input axis. --- Returns the axis and sign of the axis to the left of the input axis.
-- @deprecated Use worldeditadditions.player_dir instead. -- @deprecated Use wea_c.player_dir instead.
-- @param axis string x or z. -- @param axis string x or z.
-- @param sign int Sign multiplier. -- @param sign int Sign multiplier.
-- @return string,int Returns axis name and sign multiplier. -- @return string,int Returns axis name and sign multiplier.
function worldeditadditions.axis_left(axis,sign) function wea_c.axis_left(axis,sign)
if not axis:match("[xz]") then return false, "Error: Not a horizontal axis!" if not axis:match("[xz]") then return false, "Error: Not a horizontal axis!"
elseif axis == "x" then return true, "z", sign elseif axis == "x" then return true, "z", sign
else return true, "x", -sign end else return true, "x", -sign end
end end
--- Dehumanize Direction: translates up, down, left, right, front, into xyz based on player orientation. --- Dehumanize Direction: translates up, down, left, right, front, into xyz based on player orientation.
-- @deprecated Use worldeditadditions.player_dir instead. -- @deprecated Use wea_c.player_dir instead.
-- @param name string The name of the player to return facing direction of. -- @param name string The name of the player to return facing direction of.
-- @param dir string Relative direction to translate. -- @param dir string Relative direction to translate.
-- @return string Returns axis name and sign multiplier. -- @return string Returns axis name and sign multiplier.
function worldeditadditions.dir_to_xyz(name, dir) function wea_c.dir_to_xyz(name, dir)
local axfac, drfac = worldeditadditions.player_axis2d(name) local axfac, drfac = wea_c.player_axis2d(name)
local _, axlft, drlft = worldeditadditions.axis_left(axfac,drfac) local _, axlft, drlft = wea_c.axis_left(axfac,drfac)
if dir:match("front") or dir:match("back") then if dir:match("front") or dir:match("back") then
return axfac, dir:match("front") and drfac or -drfac return axfac, dir:match("front") and drfac or -drfac
elseif dir:match("left") or dir:match("right") then elseif dir:match("left") or dir:match("right") then

@ -1,10 +1,10 @@
local wea_c = worldeditadditions_core
--- Raycasts to find a node in the direction the given player is looking. --- Raycasts to find a node in the direction the given player is looking.
-- @param player Player The player object to raycast from. -- @param player Player The player object to raycast from.
-- @param maxdist number The maximum distance to raycast. -- @param maxdist number The maximum distance to raycast.
-- @param skip_liquid bool Whether to skip liquids when raycasting. -- @param skip_liquid bool Whether to skip liquids when raycasting.
-- @return position, number nil if nothing was found (or unloaded chunks were hit), or the position as an {x, y, z} table and the node id if something was found. -- @return position, number nil if nothing was found (or unloaded chunks were hit), or the position as an {x, y, z} table and the node id if something was found.
function worldeditadditions.raycast(player, maxdist, skip_liquid) function wea_c.raycast(player, maxdist, skip_liquid)
if maxdist == nil then maxdist = 100 end if maxdist == nil then maxdist = 100 end
if skip_liquid == nil then skip_liquid = false end if skip_liquid == nil then skip_liquid = false end
local look_dir = player:get_look_dir() local look_dir = player:get_look_dir()

@ -1,11 +1,13 @@
worldeditadditions.vector = {} worldeditadditions.vector = {}
-- @deprecated Use Vector3 instead.
function worldeditadditions.vector.tostring(v) function worldeditadditions.vector.tostring(v)
if not v then return "(nil)" end if not v then return "(nil)" end
return "(" .. v.x ..", " .. v.y ..", " .. v.z ..")" return "(" .. v.x ..", " .. v.y ..", " .. v.z ..")"
end end
--- Calculates the length squared of the given vector. --- Calculates the length squared of the given vector.
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- @param v Vector The vector to operate on
-- @return number The length of the given vector squared -- @return number The length of the given vector squared
function worldeditadditions.vector.lengthsquared(v) function worldeditadditions.vector.lengthsquared(v)
@ -16,6 +18,7 @@ end
--- Normalises the given vector such that its length is 1. --- Normalises the given vector such that its length is 1.
-- Also known as calculating the unit vector. -- Also known as calculating the unit vector.
-- This method does *not* mutate. -- This method does *not* mutate.
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to calculate from. -- @param v Vector The vector to calculate from.
-- @return Vector A new normalised vector. -- @return Vector A new normalised vector.
function worldeditadditions.vector.normalize(v) function worldeditadditions.vector.normalize(v)
@ -33,6 +36,7 @@ end
--- Rounds the values in a vector down. --- Rounds the values in a vector down.
-- Warning: This MUTATES the given vector! -- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- @param v Vector The vector to operate on
function worldeditadditions.vector.floor(v) function worldeditadditions.vector.floor(v)
if v.x then v.x = math.floor(v.x) end if v.x then v.x = math.floor(v.x) end
@ -44,6 +48,7 @@ end
--- Rounds the values in a vector up. --- Rounds the values in a vector up.
-- Warning: This MUTATES the given vector! -- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- @param v Vector The vector to operate on
function worldeditadditions.vector.ceil(v) function worldeditadditions.vector.ceil(v)
if v.x then v.x = math.ceil(v.x) end if v.x then v.x = math.ceil(v.x) end
@ -55,6 +60,7 @@ end
--- Sets the values in a vector to their absolute values. --- Sets the values in a vector to their absolute values.
-- Warning: This MUTATES the given vector! -- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on -- @param v Vector The vector to operate on
function worldeditadditions.vector.abs(v) function worldeditadditions.vector.abs(v)
if v.x then v.x = math.abs(v.x) end if v.x then v.x = math.abs(v.x) end
@ -65,6 +71,7 @@ function worldeditadditions.vector.abs(v)
end end
--- Determines if the target point is contained within the defined worldedit region. --- Determines if the target point is contained within the defined worldedit region.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to check. -- @param target Vector The target vector to check.
@ -80,6 +87,7 @@ function worldeditadditions.vector.is_contained(pos1, pos2, target)
end end
--- Expands the defined region to include the given point. --- Expands the defined region to include the given point.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to include. -- @param target Vector The target vector to include.
@ -98,6 +106,7 @@ function worldeditadditions.vector.expand_region(pos1, pos2, target)
end end
--- Returns the mean (average) of 2 positions to give you the centre. --- Returns the mean (average) of 2 positions to give you the centre.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @param target Vector Centre coordinates. -- @param target Vector Centre coordinates.
@ -106,6 +115,7 @@ function worldeditadditions.vector.mean(pos1, pos2)
end end
--- Returns a vector of the min values of 2 positions. --- Returns a vector of the min values of 2 positions.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @return Vector Min values from input vectors. -- @return Vector Min values from input vectors.
@ -114,6 +124,7 @@ function worldeditadditions.vector.min(pos1, pos2)
end end
--- Returns a vector of the max values of 2 positions. --- Returns a vector of the max values of 2 positions.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region. -- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region. -- @param pos2 Vector pos2 of the defined region.
-- @return Vector Max values from input vectors. -- @return Vector Max values from input vectors.