Support alias export
This commit is contained in:
parent
9d558bf66e
commit
af20777daf
12
README.md
12
README.md
@ -23,15 +23,23 @@ You will get a folder in your worldpath containing a skeletal mod:
|
||||
|
||||
You will need to provide your own `init.lua`, `mod.conf` and other infrastructure, but the exported definitions are kept in a separate file so you can safely overwrite it later (e.g. if you add definitions) without destroying your custom logic.
|
||||
|
||||
`exported.lua` takes a register_item-like function as a file-level parameter. This function will receive a single parameter with the definition table; it does NOT get an item name. There is a `_raw_name` key inside the definition from which you will need to derive your own name in a manner you deem appropriate (you have an opportunity to customize before registration here).
|
||||
`exported.lua` takes a register_item-like function as a file-level parameter.
|
||||
|
||||
- This function will receive a single parameter with the definition table; it does NOT get an item name.
|
||||
- There is a `_raw_name` key inside the definition from which you will need to derive your own name in a manner you deem appropriate (you have an opportunity to customize before registration here).
|
||||
- Aliases are exported using the same format, but they will only have an `_alias_to` that will point to the _raw_name of the node the alias is pointing to.
|
||||
|
||||
Example:
|
||||
```lua
|
||||
local modname = minetest.get_current_modname()
|
||||
loadfile(minetest.get_modpath(modname) .. "/exported.lua")(function(def)
|
||||
local myname = modname .. ":" .. def._raw_name:gsub(":", "__")
|
||||
if def._alias_to then
|
||||
local myalias = modname .. ":" .. def._alias_to:gsub(":", "__")
|
||||
return minetest.register_alias(myname, myalias)
|
||||
end
|
||||
def._raw_name = nil
|
||||
minetest.register_item(myname, def)
|
||||
return minetest.register_item(myname, def)
|
||||
end)
|
||||
```
|
||||
|
||||
|
2
TODO
2
TODO
@ -1,7 +1,5 @@
|
||||
------------------------------------------------------------------------
|
||||
|
||||
- Support aliases
|
||||
|
||||
- Handle tables with mixed key types, e.g. some strings, some numbers.
|
||||
- Right now it crashes trying to sort keys when it can't compare them.
|
||||
- Possible approaches:
|
||||
|
@ -81,6 +81,11 @@ do
|
||||
configdb.items[k] = setto
|
||||
end
|
||||
end
|
||||
for k in pairs(minetest.registered_aliases) do
|
||||
if string_match(k, param) then
|
||||
configdb.items[k] = setto
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not ok then return false, string_gsub(err, ".*:%d+:%s*", "") end
|
||||
return save_export_report()
|
||||
|
@ -93,7 +93,7 @@ local function exportall()
|
||||
local skipped = {}
|
||||
do
|
||||
local props = configdb.props or nodekeys
|
||||
for k, v in pairs(minetest.registered_items) do
|
||||
local function process(k, v)
|
||||
if not blocked[k] and configdb.items[k] then
|
||||
local t = {}
|
||||
for k2, v2 in pairs(nodekeys) do
|
||||
@ -102,6 +102,7 @@ local function exportall()
|
||||
end
|
||||
end
|
||||
t._raw_name = k
|
||||
t._alias_to = v._alias_to
|
||||
if custom then
|
||||
local r = custom(t, k, v)
|
||||
if r == false then
|
||||
@ -118,6 +119,18 @@ local function exportall()
|
||||
filtered[k] = t
|
||||
end
|
||||
end
|
||||
for k, v in pairs(minetest.registered_items) do
|
||||
process(k, v)
|
||||
end
|
||||
for k, v in pairs(minetest.registered_aliases) do
|
||||
local def = minetest.registered_items[v]
|
||||
if def then
|
||||
process(k, {_alias_to = v})
|
||||
if not filtered[v] then
|
||||
process(v, def)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local missing_defs = {}
|
||||
for k in pairs(configdb.items) do
|
||||
|
Loading…
x
Reference in New Issue
Block a user