From f984f5d7b7932b0336ffe14e321350bc2295b22d Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 16 May 2022 23:32:40 +0100 Subject: [PATCH] Begin rewriting worldeditadditions_core We should be able to make things a lot cleaner and more robust. --- .../core/integrations/noworldedit.lua | 8 +++ .../core/integrations/worldedit.lua | 15 +++++ .../core/register_command.lua | 58 +++++++++++++++++++ worldeditadditions_core/init.lua | 27 ++++++--- worldeditadditions_core/register/init.lua | 14 ----- worldeditadditions_core/worldedit/init.lua | 5 -- 6 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 worldeditadditions_core/core/integrations/noworldedit.lua create mode 100644 worldeditadditions_core/core/integrations/worldedit.lua create mode 100644 worldeditadditions_core/core/register_command.lua delete mode 100644 worldeditadditions_core/register/init.lua delete mode 100644 worldeditadditions_core/worldedit/init.lua diff --git a/worldeditadditions_core/core/integrations/noworldedit.lua b/worldeditadditions_core/core/integrations/noworldedit.lua new file mode 100644 index 0000000..1fd0810 --- /dev/null +++ b/worldeditadditions_core/core/integrations/noworldedit.lua @@ -0,0 +1,8 @@ +local wea_c = worldeditadditions_core + +--- WorldEdit shim just in case WorldEdit doesn't exist. +-- Eventually this will go away. +worldedit = { + -- Note that you want worldeditadditions_core.registered_commands, and not worldedit.registered_commands! This table is not guaranteed to contain all command definitions in the future, whereas worldedit command definitions are guaranteed to be imported into this worldeditadditions_core.registered_commands. + registered_commands = { } +} diff --git a/worldeditadditions_core/core/integrations/worldedit.lua b/worldeditadditions_core/core/integrations/worldedit.lua new file mode 100644 index 0000000..23913ac --- /dev/null +++ b/worldeditadditions_core/core/integrations/worldedit.lua @@ -0,0 +1,15 @@ +local wea_c = worldeditadditions_core + + +for name,definition in pairs(worldedit.registered_commands) do + -- This check should not be needed since worldeditadditions_commands + -- depends on this mod (so it will overwrite any worldedit definitions, + -- since worldedit is loaded first), but it's here just in case + if not wea_c.registered_commands[name] then + -- The Minetest chat command should already be imported here, so we + -- just need to import worldedit chat command definition here + wea_c.registered_commands[name] = definition + else + minetest.log("info", "Skipping registration of worldedit command "..name..", as it's already a registered worldeditadditions command") + end +end diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua new file mode 100644 index 0000000..509ea86 --- /dev/null +++ b/worldeditadditions_core/core/register_command.lua @@ -0,0 +1,58 @@ +-- ██████ ███████ ██████ ██ ███████ ████████ ███████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ █████ ██ ███ ██ ███████ ██ █████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ + +-- WorldEditAdditions chat command registration + +local function log_error(cmdname, error_message) + minetest.log("error", "register_command("..cmdname..") error: "..error_message) +end + +local function register_command(cmdname, options) + --- + -- 1: Validation + --- + if type(options.params) ~= "string" then + log_error(cmdname, "The params option is not a string.") + return false + end + if type(options.description) ~= "string" then + log_error(cmdname, "The description option is not a string.") + return false + end + if type(options.parse) ~= "string" then + log_error(cmdname, "The parse option is not a function.") + return false + end + if type(options.nodes_needed) ~= "string" then + log_error(cmdname, "The nodes_needed option is not a function.") + return false + end + if type(options.func) ~= "string" then + log_error(cmdname, "The func option is not a function.") + return false + end + + + --- + -- 2: Normalisation + --- + if not options.privs then options.privs = {} end + if not options.require_pos then options.require_pos = 0 end + + + --- + -- 3: Registration + --- + minetest.register_chatcommand("/"..cmdname, { + params = options.params, + description = options.description, + privs = options.privs, + func = function(player_name, paramtext) + -- TODO: Fill this in + end + + }) +end diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index e4e22ad..b34c1d6 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -5,14 +5,25 @@ -- @license Mozilla Public License, 2.0 -- @author Starbeamrainbowlabs and VorTechnix -worldeditadditions_core = {} +local temp = true +if temp then return end +-- This mod isn't finished yet, so it will not be executed for now. + + +local modpath = minetest.get_modpath("worldeditadditions_core") + +worldeditadditions_core = { + modpath = modpath, + registered_commands = {}, + register_command = dofile(modpath.."/core/register_command.lua") +} + + local we_c = worldeditadditions_core -we_c.modpath = minetest.get_modpath("worldeditadditions_core") - -- Initialise WorldEdit stuff if the WorldEdit mod is not present -if not minetest.get_modpath("worldedit") then - dofile(we_c.modpath.."/worldedit/init.lua") -end - -dofile(we_c.modpath.."/register/init.lua") +if minetest.global_exists("bonemeal") then + dofile(we_c.modpath.."/core/integrations/worldedit.lua") +else + dofile(we_c.modpath.."/core/integrations/noworldedit.lua") +end) diff --git a/worldeditadditions_core/register/init.lua b/worldeditadditions_core/register/init.lua deleted file mode 100644 index ff1fc86..0000000 --- a/worldeditadditions_core/register/init.lua +++ /dev/null @@ -1,14 +0,0 @@ --- ██████ ███████ ██████ ██ ███████ ████████ ███████ ██████ --- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ██████ █████ ██ ███ ██ ███████ ██ █████ ██████ --- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ --- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ - --- WorldEditAdditions Register/Overwrite Functions - -local we_cm = worldeditadditions_core.modpath .. "/register/" - -dofile(we_cm.."check.lua") -dofile(we_cm.."handler.lua") --- dofile(we_cm.."register.lua") --- dofile(we_cm.."override.lua") diff --git a/worldeditadditions_core/worldedit/init.lua b/worldeditadditions_core/worldedit/init.lua deleted file mode 100644 index f43eb44..0000000 --- a/worldeditadditions_core/worldedit/init.lua +++ /dev/null @@ -1,5 +0,0 @@ ---- WorldEdit shim just in case WorldEdit doesn't exist - -worldedit = { - registered_commands = { } -}