mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-21 15:03:00 +00:00
Begin rewriting worldeditadditions_core
We should be able to make things a lot cleaner and more robust.
This commit is contained in:
parent
d3119ee54a
commit
f984f5d7b7
6 changed files with 100 additions and 27 deletions
|
@ -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 = { }
|
||||
}
|
15
worldeditadditions_core/core/integrations/worldedit.lua
Normal file
15
worldeditadditions_core/core/integrations/worldedit.lua
Normal file
|
@ -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
|
58
worldeditadditions_core/core/register_command.lua
Normal file
58
worldeditadditions_core/core/register_command.lua
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
|
@ -1,5 +0,0 @@
|
|||
--- WorldEdit shim just in case WorldEdit doesn't exist
|
||||
|
||||
worldedit = {
|
||||
registered_commands = { }
|
||||
}
|
Loading…
Reference in a new issue