mirror of
https://github.com/minetest-mods/i3.git
synced 2024-11-13 06:10:21 +01:00
Some cleaning
This commit is contained in:
parent
2d9e4ee474
commit
980adeb71f
40
etc/api.lua
40
etc/api.lua
|
@ -9,9 +9,9 @@ local true_str, true_table, is_str, is_func, is_table, clean_name =
|
|||
function i3.register_craft_type(name, def)
|
||||
if not true_str(name) then
|
||||
return err "i3.register_craft_type: name missing"
|
||||
end
|
||||
|
||||
if not is_str(def.description) then
|
||||
elseif not true_table(def) then
|
||||
return err "i3.register_craft_type: definition missing"
|
||||
elseif not is_str(def.description) then
|
||||
def.description = ""
|
||||
end
|
||||
|
||||
|
@ -173,17 +173,11 @@ end
|
|||
function i3.new_tab(def)
|
||||
if not true_table(def) then
|
||||
return err "i3.new_tab: tab definition missing"
|
||||
end
|
||||
|
||||
if not true_str(def.name) then
|
||||
elseif not true_str(def.name) then
|
||||
return err "i3.new_tab: tab name missing"
|
||||
end
|
||||
|
||||
if not true_str(def.description) then
|
||||
elseif not true_str(def.description) then
|
||||
return err "i3.new_tab: description missing"
|
||||
end
|
||||
|
||||
if #i3.tabs == 6 then
|
||||
elseif #i3.tabs == 6 then
|
||||
return err(fmt("i3.new_tab: cannot add '%s' tab. Limit reached (6).", def.name))
|
||||
end
|
||||
|
||||
|
@ -235,13 +229,9 @@ end
|
|||
function i3.override_tab(tabname, newdef)
|
||||
if not true_table(newdef) then
|
||||
return err "i3.override_tab: tab definition missing"
|
||||
end
|
||||
|
||||
if not true_str(newdef.name) then
|
||||
elseif not true_str(newdef.name) then
|
||||
return err "i3.override_tab: tab name missing"
|
||||
end
|
||||
|
||||
if not true_str(newdef.description) then
|
||||
elseif not true_str(newdef.description) then
|
||||
return err "i3.override_tab: description missing"
|
||||
end
|
||||
|
||||
|
@ -279,17 +269,11 @@ end)
|
|||
function i3.compress(item, def)
|
||||
if not true_str(item) then
|
||||
return err "i3.compress: item name missing"
|
||||
end
|
||||
|
||||
if not true_table(def) then
|
||||
elseif not true_table(def) then
|
||||
return err "i3.compress: replace definition missing"
|
||||
end
|
||||
|
||||
if not true_str(def.replace) then
|
||||
elseif not true_str(def.replace) then
|
||||
return err "i3.compress: replace string missing"
|
||||
end
|
||||
|
||||
if not is_table(def.by) then
|
||||
elseif not is_table(def.by) then
|
||||
return err "i3.compress: replace substrings missing"
|
||||
end
|
||||
|
||||
|
@ -305,5 +289,3 @@ function i3.compress(item, def)
|
|||
i3.compressed[it] = true
|
||||
end
|
||||
end
|
||||
|
||||
return i3.set_fs, i3.set_tab
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
local set_fs = i3.files.api()
|
||||
local S, fmt, msg, spawn_item = i3.get("S", "fmt", "msg", "spawn_item")
|
||||
|
||||
local function init_backpack(player)
|
||||
|
@ -28,7 +27,7 @@ local function init_backpack(player)
|
|||
data.bag_size = minetest.get_item_group(stackname, "bag")
|
||||
|
||||
inv:set_size("main", i3.BAG_SIZES[data.bag_size])
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end,
|
||||
|
||||
on_take = function()
|
||||
|
@ -44,7 +43,7 @@ local function init_backpack(player)
|
|||
data.bag_size = nil
|
||||
|
||||
inv:set_size("main", i3.INV_SIZE)
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
@ -316,4 +316,4 @@ for _, v2 in ipairs(v) do
|
|||
end
|
||||
end
|
||||
|
||||
return compressed, _compressed
|
||||
i3.compress_groups, i3.compressed = compressed, _compressed
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local S = i3.get("S")
|
||||
|
||||
local group_stereotypes = {
|
||||
i3.group_stereotypes = {
|
||||
dye = "dye:white",
|
||||
wool = "wool:white",
|
||||
wood = "default:wood",
|
||||
|
@ -17,7 +17,7 @@ local group_stereotypes = {
|
|||
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
|
||||
}
|
||||
|
||||
local group_names = {
|
||||
i3.group_names = {
|
||||
dye = S"Any dye",
|
||||
coal = S"Any coal",
|
||||
sand = S"Any sand",
|
||||
|
@ -58,5 +58,3 @@ local group_names = {
|
|||
["color_dark_grey,dye"] = S"Any dark grey dye",
|
||||
["color_dark_green,dye"] = S"Any dark green dye",
|
||||
}
|
||||
|
||||
return group_stereotypes, group_names
|
||||
|
|
|
@ -11,7 +11,8 @@ local reg_items, reg_tools, reg_entities = i3.get("reg_items", "reg_tools", "reg
|
|||
local maxn, sort, concat, copy, insert, remove = i3.get("maxn", "sort", "concat", "copy", "insert", "remove")
|
||||
|
||||
local true_str, is_fav, is_num = i3.get("true_str", "is_fav", "is_num")
|
||||
local is_group, extract_groups, item_has_groups = i3.get("is_group", "extract_groups", "item_has_groups")
|
||||
local is_group, extract_groups, item_has_groups =
|
||||
i3.get("is_group", "extract_groups", "item_has_groups")
|
||||
local groups_to_items, compression_active, compressible =
|
||||
i3.get("groups_to_items", "compression_active", "compressible")
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
local set_fs, set_tab = i3.files.api()
|
||||
local _, get_inventory_fs = i3.files.gui()
|
||||
|
||||
local S, clr = i3.get("S", "clr")
|
||||
|
@ -295,7 +294,7 @@ i3.new_tab {
|
|||
data.scrbar_inv = data.scrbar_inv + 1000
|
||||
end
|
||||
|
||||
return set_fs(player)
|
||||
return i3.set_fs(player)
|
||||
end,
|
||||
}
|
||||
|
||||
|
@ -450,7 +449,7 @@ local function rcp_fields(player, data, fields)
|
|||
elseif fields.key_enter_field == "filter" or fields.search then
|
||||
if fields.filter == "" then
|
||||
reset_data(data)
|
||||
return set_fs(player)
|
||||
return i3.set_fs(player)
|
||||
end
|
||||
|
||||
local str = lower(fields.filter)
|
||||
|
@ -546,7 +545,7 @@ core.register_on_player_receive_fields(function(player, formname, fields)
|
|||
for f in pairs(fields) do
|
||||
if sub(f, 1, 4) == "tab_" then
|
||||
local tabname = sub(f, 5)
|
||||
set_tab(player, tabname)
|
||||
i3.set_tab(player, tabname)
|
||||
break
|
||||
elseif sub(f, 1, 5) == "itab_" then
|
||||
data.pagenum = 1
|
||||
|
@ -563,7 +562,7 @@ core.register_on_player_receive_fields(function(player, formname, fields)
|
|||
return true, tab.fields(player, data, fields)
|
||||
end
|
||||
|
||||
return true, set_fs(player)
|
||||
return true, i3.set_fs(player)
|
||||
end)
|
||||
|
||||
core.register_on_player_hpchange(function(player, hpchange)
|
||||
|
@ -574,7 +573,7 @@ core.register_on_player_hpchange(function(player, hpchange)
|
|||
local hp_max = player:get_properties().hp_max
|
||||
data.hp = min(hp_max, player:get_hp() + hpchange)
|
||||
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end)
|
||||
|
||||
core.register_on_dieplayer(function(player)
|
||||
|
@ -591,12 +590,12 @@ core.register_on_dieplayer(function(player)
|
|||
inv:set_size("main", i3.INV_SIZE)
|
||||
end
|
||||
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end)
|
||||
|
||||
core.register_on_chatcommand(function(name)
|
||||
local player = core.get_player_by_name(name)
|
||||
core.after(0, set_fs, player)
|
||||
core.after(0, i3.set_fs, player)
|
||||
end)
|
||||
|
||||
core.register_on_priv_grant(function(name, _, priv)
|
||||
|
@ -606,7 +605,7 @@ core.register_on_priv_grant(function(name, _, priv)
|
|||
data.favs = {}
|
||||
|
||||
local player = core.get_player_by_name(name)
|
||||
core.after(0, set_fs, player)
|
||||
core.after(0, i3.set_fs, player)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -617,7 +616,7 @@ core.register_on_player_inventory_action(function(player, _, _, info)
|
|||
((info.from_list == "main" and info.to_list == "craft") or
|
||||
(info.from_list == "craft" and info.to_list == "main") or
|
||||
(info.from_list == "craftresult" and info.to_list == "main")) then
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -631,7 +630,7 @@ local trash = core.create_detached_inventory("i3_trash", {
|
|||
local name = player:get_player_name()
|
||||
|
||||
if not core.is_creative_enabled(name) then
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local set_fs = i3.files.api()
|
||||
local singleplayer = core.is_singleplayer()
|
||||
|
||||
local fmt, search, table_merge, array_diff = i3.get("fmt", "search", "table_merge", "array_diff")
|
||||
local fmt, search, table_merge, array_diff =
|
||||
i3.get("fmt", "search", "table_merge", "array_diff")
|
||||
local is_group, extract_groups, item_has_groups, apply_recipe_filters =
|
||||
i3.get("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters")
|
||||
|
||||
|
@ -225,7 +225,7 @@ local function poll_new_items()
|
|||
data.current_itab = 1
|
||||
|
||||
search(data)
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
21
init.lua
21
init.lua
|
@ -66,17 +66,18 @@ i3 = {
|
|||
}
|
||||
|
||||
i3.files.common()
|
||||
i3.files.api()
|
||||
i3.files.compress()
|
||||
i3.files.groups()
|
||||
i3.files.inventory()
|
||||
|
||||
local storage = core.get_mod_storage()
|
||||
local fmt, copy, slz, dslz = i3.get("fmt", "copy", "slz", "dslz")
|
||||
|
||||
i3.data = dslz(storage:get_string "data") or {}
|
||||
i3.compress_groups, i3.compressed = i3.files.compress()
|
||||
i3.group_stereotypes, i3.group_names = i3.files.groups()
|
||||
|
||||
local set_fs = i3.files.api()
|
||||
local init_backpack = i3.files.bags()
|
||||
local init_recipes = i3.files.recipes()
|
||||
i3.files.inventory()
|
||||
|
||||
local function get_lang_code(info)
|
||||
return info and info.lang_code
|
||||
|
@ -95,7 +96,7 @@ end
|
|||
|
||||
if rawget(_G, "armor") then
|
||||
i3.modules.armor = true
|
||||
armor:register_on_update(set_fs)
|
||||
armor:register_on_update(i3.set_fs)
|
||||
end
|
||||
|
||||
if rawget(_G, "skins") then
|
||||
|
@ -106,20 +107,20 @@ if rawget(_G, "awards") then
|
|||
i3.modules.awards = true
|
||||
|
||||
core.register_on_craft(function(_, player)
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end)
|
||||
|
||||
core.register_on_dignode(function(_, _, player)
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end)
|
||||
|
||||
core.register_on_placenode(function(_, _, player)
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end)
|
||||
|
||||
core.register_on_chat_message(function(name)
|
||||
local player = core.get_player_by_name(name)
|
||||
set_fs(player)
|
||||
i3.set_fs(player)
|
||||
end)
|
||||
end
|
||||
|
||||
|
@ -152,7 +153,7 @@ local function init_data(player, info)
|
|||
data.lang_code = get_lang_code(info)
|
||||
data.fs_version = info.formspec_version
|
||||
|
||||
core.after(0, set_fs, player)
|
||||
core.after(0, i3.set_fs, player)
|
||||
end
|
||||
|
||||
local function init_waypoints(player)
|
||||
|
|
Loading…
Reference in New Issue
Block a user