Remove non-API features
Non-API features have been moved to the new HUD Plus mod. This mod will soon be renamed to HUD Library.
This commit is contained in:
parent
d880b0b460
commit
639bb08678
35
MODULES.md
35
MODULES.md
@ -1,35 +0,0 @@
|
||||
# Modules
|
||||
Modules allow HUD Plus to be divided into different parts which can be enabled or disabled using the configuration file (as documented below). We use this as an alternative to a simple modpack to prevent cluttering the list provided by `/mods` and as it allows for this mod to be distributed in another modpack. If you are considering contributing to this mod, you will likely find it worthwhile to read this short documentation on the modules API.
|
||||
|
||||
## Managing Modules
|
||||
Modules listed in the configuration file are automatically loaded at startup unless specifically disabled. For the purpose of listing and/or disabling mods, we've introduced the `modules.conf` file.
|
||||
|
||||
Each module is listed on a new line, as if setting a variable. A module can be disabled or enabled by setting this variable to `true` or `false`. If a module is set to `false` (disabled), it will not be automatically loaded. __Note:__ modules will be loaded anyway if they are not found in the configuration file at all.
|
||||
|
||||
__Example:__
|
||||
```lua
|
||||
-- Enabled:
|
||||
storage = true
|
||||
-- Disabled:
|
||||
storage = false
|
||||
```
|
||||
|
||||
A small API is provided allowing modules to be loaded from another module or from the main API. A module can be force loaded (overrides configuration), or can be loaded with the configuration in mind.
|
||||
|
||||
## Module API
|
||||
Modules are places a subdirectories of the `modules` directory. Each module must have the same name as its reference in the configuration file. Modules must have an `init.lua` file, where you can load other portions of the module with `dofile`, or use the API documented below.
|
||||
|
||||
#### `get_module_path(name)`
|
||||
__Usage:__ `hudplus.get_module_path(<module name (string)>)`
|
||||
|
||||
Returns the full path of the module or `nil` if it does not exist. This can be used to check for another module, or to easily access the path of the current module in preparation to load other files with `dofile` or the likes.
|
||||
|
||||
#### `load_module(name)`
|
||||
__Usage:__ `hudplus.load_module(<module name (string)>)`
|
||||
|
||||
Attempts to load a module. If the module path is `nil`, `nil` is returned to indicate that the module does not exist. Otherwise, a return value of `true` indicates a success or that the module has already been loaded. __Note:__ this function overrides any settings in `modules.conf`, meaning that it will be loaded even if it was disabled. For general use cases, use `require_module` instead.
|
||||
|
||||
#### `require_module(name)`
|
||||
__Usage:__ `hudplus.require_module(<module name (string)>)`
|
||||
|
||||
Passes name to `load_module` if the mod was not disabled in `modules.conf`. For further documentation, see `load_module`.
|
49
init.lua
49
init.lua
@ -32,52 +32,3 @@ minetest.register_chatcommand("hudplus", {
|
||||
|
||||
-- Load API
|
||||
dofile(modpath.."/api.lua")
|
||||
|
||||
-------------------
|
||||
----- MODULES -----
|
||||
-------------------
|
||||
|
||||
local loaded_modules = {}
|
||||
|
||||
local settings = Settings(modpath.."/modules.conf"):to_table()
|
||||
|
||||
-- [function] Get module path
|
||||
function hudplus.get_module_path(name)
|
||||
local module_path = modpath.."/modules/"..name
|
||||
|
||||
if io.open(module_path.."/init.lua") then
|
||||
return module_path
|
||||
end
|
||||
end
|
||||
|
||||
-- [function] Load module (overrides modules.conf)
|
||||
function hudplus.load_module(name)
|
||||
if loaded_modules[name] ~= false then
|
||||
local module_init = hudplus.get_module_path(name).."/init.lua"
|
||||
|
||||
if module_init then
|
||||
dofile(module_init)
|
||||
loaded_modules[name] = true
|
||||
return true
|
||||
else
|
||||
hudplus.log("Invalid module \""..name.."\". The module either does not exist "..
|
||||
"or is missing an init.lua file.", "error")
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- [function] Require module (does not override modules.conf)
|
||||
function hudplus.require_module(name)
|
||||
if settings[name] and settings[name] ~= false then
|
||||
return hudplus.load_module(name)
|
||||
end
|
||||
end
|
||||
|
||||
local modules_list = minetest.get_dir_list(modpath.."/modules", true)
|
||||
for _, d in ipairs(modules_list) do
|
||||
if settings[d] ~= "false" then
|
||||
hudplus.load_module(d)
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +0,0 @@
|
||||
-- This is a comment. The '--' signifies that this will not be
|
||||
-- loaded as a setting.
|
||||
|
||||
-- Disable modules in the form below:
|
||||
-- <module_name> = false
|
||||
-- for example:
|
||||
-- item_info = false
|
@ -1,44 +0,0 @@
|
||||
-- item_info/init.lua
|
||||
|
||||
local wield = {}
|
||||
local after = 3 -- HUD element will be hidden after this many seconds
|
||||
|
||||
hudplus.register("item_info", {
|
||||
show_on = "join",
|
||||
type = "text",
|
||||
pos = {x=0.5, y=1},
|
||||
offset = {x=0, y=-80},
|
||||
alignment = {x=0, y=0},
|
||||
number = 0xFFFFFF ,
|
||||
text = "",
|
||||
hide_after = after,
|
||||
|
||||
on_step = function(player, dtime)
|
||||
local pname = player:get_player_name()
|
||||
local wstack = player:get_wielded_item()
|
||||
local windex = player:get_wield_index()
|
||||
|
||||
local meta = wstack:get_meta()
|
||||
local desc = minetest.registered_items[wstack:get_name()].description
|
||||
if meta:get_string("description") ~= "" then
|
||||
desc = meta:get_string("description")
|
||||
end
|
||||
|
||||
local itemstring = " ("..wstack:get_name()..")"
|
||||
if wstack:get_name() == "" then itemstring = "" end
|
||||
|
||||
hudplus.hud_change(player, "item_info", "text", desc..itemstring)
|
||||
|
||||
if wield[pname] ~= windex then
|
||||
local show = hudplus.hud_get(player, "item_info", "show")
|
||||
if show == false then
|
||||
hudplus.hud_show(player, "item_info")
|
||||
end
|
||||
|
||||
-- Update timer
|
||||
hudplus.after("hide_item_info", after, function() hudplus.hud_hide(player, "item_info") end)
|
||||
end
|
||||
|
||||
wield[pname] = windex
|
||||
end,
|
||||
})
|
@ -1 +0,0 @@
|
||||
Place modules in subdirectories here.
|
@ -1,51 +0,0 @@
|
||||
-- tool_info/init.lua
|
||||
|
||||
local wield = {}
|
||||
|
||||
hudplus.register("tool_info", {
|
||||
show_on = "join",
|
||||
type = "text",
|
||||
pos = {x=0, y=1},
|
||||
offset = {x=70, y=-50},
|
||||
direction = 0,
|
||||
number = 0xFFFFFF ,
|
||||
text = "",
|
||||
|
||||
on_step = function(player, dtime)
|
||||
local pname = player:get_player_name()
|
||||
local wstack = player:get_wielded_item()
|
||||
local windex = player:get_wield_index()
|
||||
|
||||
if minetest.registered_tools[wstack:get_name()] then
|
||||
local def = minetest.registered_tools[wstack:get_name()]
|
||||
|
||||
if not def.tool_capabilities then return end
|
||||
|
||||
local meta = wstack:get_meta()
|
||||
local desc = def.description
|
||||
if meta:get_string("description") ~= "" then
|
||||
desc = meta:get_string("description")
|
||||
end
|
||||
|
||||
local damage = def.tool_capabilities.damage_groups.fleshy or 0
|
||||
local wear = math.floor(wstack:get_wear() / 65535 * 100)
|
||||
local speed = def.tool_capabilities.full_punch_interval or 1
|
||||
local drop = def.tool_capabilities.max_drop_level or 0
|
||||
|
||||
hudplus.hud_change(player, "tool_info", "text", desc.."\nWear: "..
|
||||
wear.."/100\nDamage: "..damage.."\nSpeed: "..
|
||||
speed.."\nMax Drop Level: "..drop)
|
||||
else
|
||||
hudplus.hud_hide(player, "tool_info")
|
||||
end
|
||||
|
||||
if wield[pname] ~= windex then
|
||||
local show = hudplus.hud_get(player, "tool_info", "show")
|
||||
if show == false then
|
||||
hudplus.hud_show(player, "tool_info")
|
||||
end
|
||||
end
|
||||
|
||||
wield[pname] = windex
|
||||
end,
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user