Some cleaning

This commit is contained in:
Jean-Patrick Guerrero 2021-10-25 20:31:20 +02:00
parent 2d9e4ee474
commit 980adeb71f
8 changed files with 42 additions and 62 deletions

View File

@ -9,9 +9,9 @@ local true_str, true_table, is_str, is_func, is_table, clean_name =
function i3.register_craft_type(name, def) function i3.register_craft_type(name, def)
if not true_str(name) then if not true_str(name) then
return err "i3.register_craft_type: name missing" return err "i3.register_craft_type: name missing"
end elseif not true_table(def) then
return err "i3.register_craft_type: definition missing"
if not is_str(def.description) then elseif not is_str(def.description) then
def.description = "" def.description = ""
end end
@ -173,17 +173,11 @@ end
function i3.new_tab(def) function i3.new_tab(def)
if not true_table(def) then if not true_table(def) then
return err "i3.new_tab: tab definition missing" return err "i3.new_tab: tab definition missing"
end elseif not true_str(def.name) then
if not true_str(def.name) then
return err "i3.new_tab: tab name missing" return err "i3.new_tab: tab name missing"
end elseif not true_str(def.description) then
if not true_str(def.description) then
return err "i3.new_tab: description missing" return err "i3.new_tab: description missing"
end elseif #i3.tabs == 6 then
if #i3.tabs == 6 then
return err(fmt("i3.new_tab: cannot add '%s' tab. Limit reached (6).", def.name)) return err(fmt("i3.new_tab: cannot add '%s' tab. Limit reached (6).", def.name))
end end
@ -235,13 +229,9 @@ end
function i3.override_tab(tabname, newdef) function i3.override_tab(tabname, newdef)
if not true_table(newdef) then if not true_table(newdef) then
return err "i3.override_tab: tab definition missing" return err "i3.override_tab: tab definition missing"
end elseif not true_str(newdef.name) then
if not true_str(newdef.name) then
return err "i3.override_tab: tab name missing" return err "i3.override_tab: tab name missing"
end elseif not true_str(newdef.description) then
if not true_str(newdef.description) then
return err "i3.override_tab: description missing" return err "i3.override_tab: description missing"
end end
@ -279,17 +269,11 @@ end)
function i3.compress(item, def) function i3.compress(item, def)
if not true_str(item) then if not true_str(item) then
return err "i3.compress: item name missing" return err "i3.compress: item name missing"
end elseif not true_table(def) then
if not true_table(def) then
return err "i3.compress: replace definition missing" return err "i3.compress: replace definition missing"
end elseif not true_str(def.replace) then
if not true_str(def.replace) then
return err "i3.compress: replace string missing" return err "i3.compress: replace string missing"
end elseif not is_table(def.by) then
if not is_table(def.by) then
return err "i3.compress: replace substrings missing" return err "i3.compress: replace substrings missing"
end end
@ -305,5 +289,3 @@ function i3.compress(item, def)
i3.compressed[it] = true i3.compressed[it] = true
end end
end end
return i3.set_fs, i3.set_tab

View File

@ -1,4 +1,3 @@
local set_fs = i3.files.api()
local S, fmt, msg, spawn_item = i3.get("S", "fmt", "msg", "spawn_item") local S, fmt, msg, spawn_item = i3.get("S", "fmt", "msg", "spawn_item")
local function init_backpack(player) local function init_backpack(player)
@ -28,7 +27,7 @@ local function init_backpack(player)
data.bag_size = minetest.get_item_group(stackname, "bag") data.bag_size = minetest.get_item_group(stackname, "bag")
inv:set_size("main", i3.BAG_SIZES[data.bag_size]) inv:set_size("main", i3.BAG_SIZES[data.bag_size])
set_fs(player) i3.set_fs(player)
end, end,
on_take = function() on_take = function()
@ -44,7 +43,7 @@ local function init_backpack(player)
data.bag_size = nil data.bag_size = nil
inv:set_size("main", i3.INV_SIZE) inv:set_size("main", i3.INV_SIZE)
set_fs(player) i3.set_fs(player)
end, end,
}) })

View File

@ -316,4 +316,4 @@ for _, v2 in ipairs(v) do
end end
end end
return compressed, _compressed i3.compress_groups, i3.compressed = compressed, _compressed

View File

@ -1,6 +1,6 @@
local S = i3.get("S") local S = i3.get("S")
local group_stereotypes = { i3.group_stereotypes = {
dye = "dye:white", dye = "dye:white",
wool = "wool:white", wool = "wool:white",
wood = "default:wood", wood = "default:wood",
@ -17,7 +17,7 @@ local group_stereotypes = {
mesecon_conductor_craftable = "mesecons:wire_00000000_off", mesecon_conductor_craftable = "mesecons:wire_00000000_off",
} }
local group_names = { i3.group_names = {
dye = S"Any dye", dye = S"Any dye",
coal = S"Any coal", coal = S"Any coal",
sand = S"Any sand", sand = S"Any sand",
@ -58,5 +58,3 @@ local group_names = {
["color_dark_grey,dye"] = S"Any dark grey dye", ["color_dark_grey,dye"] = S"Any dark grey dye",
["color_dark_green,dye"] = S"Any dark green dye", ["color_dark_green,dye"] = S"Any dark green dye",
} }
return group_stereotypes, group_names

View File

@ -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 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 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 = local groups_to_items, compression_active, compressible =
i3.get("groups_to_items", "compression_active", "compressible") i3.get("groups_to_items", "compression_active", "compressible")

View File

@ -1,4 +1,3 @@
local set_fs, set_tab = i3.files.api()
local _, get_inventory_fs = i3.files.gui() local _, get_inventory_fs = i3.files.gui()
local S, clr = i3.get("S", "clr") local S, clr = i3.get("S", "clr")
@ -295,7 +294,7 @@ i3.new_tab {
data.scrbar_inv = data.scrbar_inv + 1000 data.scrbar_inv = data.scrbar_inv + 1000
end end
return set_fs(player) return i3.set_fs(player)
end, end,
} }
@ -450,7 +449,7 @@ local function rcp_fields(player, data, fields)
elseif fields.key_enter_field == "filter" or fields.search then elseif fields.key_enter_field == "filter" or fields.search then
if fields.filter == "" then if fields.filter == "" then
reset_data(data) reset_data(data)
return set_fs(player) return i3.set_fs(player)
end end
local str = lower(fields.filter) 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 for f in pairs(fields) do
if sub(f, 1, 4) == "tab_" then if sub(f, 1, 4) == "tab_" then
local tabname = sub(f, 5) local tabname = sub(f, 5)
set_tab(player, tabname) i3.set_tab(player, tabname)
break break
elseif sub(f, 1, 5) == "itab_" then elseif sub(f, 1, 5) == "itab_" then
data.pagenum = 1 data.pagenum = 1
@ -563,7 +562,7 @@ core.register_on_player_receive_fields(function(player, formname, fields)
return true, tab.fields(player, data, fields) return true, tab.fields(player, data, fields)
end end
return true, set_fs(player) return true, i3.set_fs(player)
end) end)
core.register_on_player_hpchange(function(player, hpchange) 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 local hp_max = player:get_properties().hp_max
data.hp = min(hp_max, player:get_hp() + hpchange) data.hp = min(hp_max, player:get_hp() + hpchange)
set_fs(player) i3.set_fs(player)
end) end)
core.register_on_dieplayer(function(player) core.register_on_dieplayer(function(player)
@ -591,12 +590,12 @@ core.register_on_dieplayer(function(player)
inv:set_size("main", i3.INV_SIZE) inv:set_size("main", i3.INV_SIZE)
end end
set_fs(player) i3.set_fs(player)
end) end)
core.register_on_chatcommand(function(name) core.register_on_chatcommand(function(name)
local player = core.get_player_by_name(name) local player = core.get_player_by_name(name)
core.after(0, set_fs, player) core.after(0, i3.set_fs, player)
end) end)
core.register_on_priv_grant(function(name, _, priv) core.register_on_priv_grant(function(name, _, priv)
@ -606,7 +605,7 @@ core.register_on_priv_grant(function(name, _, priv)
data.favs = {} data.favs = {}
local player = core.get_player_by_name(name) local player = core.get_player_by_name(name)
core.after(0, set_fs, player) core.after(0, i3.set_fs, player)
end end
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 == "main" and info.to_list == "craft") or
(info.from_list == "craft" and info.to_list == "main") or (info.from_list == "craft" and info.to_list == "main") or
(info.from_list == "craftresult" and info.to_list == "main")) then (info.from_list == "craftresult" and info.to_list == "main")) then
set_fs(player) i3.set_fs(player)
end end
end) end)
@ -631,7 +630,7 @@ local trash = core.create_detached_inventory("i3_trash", {
local name = player:get_player_name() local name = player:get_player_name()
if not core.is_creative_enabled(name) then if not core.is_creative_enabled(name) then
set_fs(player) i3.set_fs(player)
end end
end, end,
}) })

View File

@ -1,7 +1,7 @@
local set_fs = i3.files.api()
local singleplayer = core.is_singleplayer() 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 = local is_group, extract_groups, item_has_groups, apply_recipe_filters =
i3.get("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 data.current_itab = 1
search(data) search(data)
set_fs(player) i3.set_fs(player)
end end
end end

View File

@ -66,17 +66,18 @@ i3 = {
} }
i3.files.common() i3.files.common()
i3.files.api()
i3.files.compress()
i3.files.groups()
i3.files.inventory()
local storage = core.get_mod_storage() local storage = core.get_mod_storage()
local fmt, copy, slz, dslz = i3.get("fmt", "copy", "slz", "dslz") local fmt, copy, slz, dslz = i3.get("fmt", "copy", "slz", "dslz")
i3.data = dslz(storage:get_string "data") or {} 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_backpack = i3.files.bags()
local init_recipes = i3.files.recipes() local init_recipes = i3.files.recipes()
i3.files.inventory()
local function get_lang_code(info) local function get_lang_code(info)
return info and info.lang_code return info and info.lang_code
@ -95,7 +96,7 @@ end
if rawget(_G, "armor") then if rawget(_G, "armor") then
i3.modules.armor = true i3.modules.armor = true
armor:register_on_update(set_fs) armor:register_on_update(i3.set_fs)
end end
if rawget(_G, "skins") then if rawget(_G, "skins") then
@ -106,20 +107,20 @@ if rawget(_G, "awards") then
i3.modules.awards = true i3.modules.awards = true
core.register_on_craft(function(_, player) core.register_on_craft(function(_, player)
set_fs(player) i3.set_fs(player)
end) end)
core.register_on_dignode(function(_, _, player) core.register_on_dignode(function(_, _, player)
set_fs(player) i3.set_fs(player)
end) end)
core.register_on_placenode(function(_, _, player) core.register_on_placenode(function(_, _, player)
set_fs(player) i3.set_fs(player)
end) end)
core.register_on_chat_message(function(name) core.register_on_chat_message(function(name)
local player = core.get_player_by_name(name) local player = core.get_player_by_name(name)
set_fs(player) i3.set_fs(player)
end) end)
end end
@ -152,7 +153,7 @@ local function init_data(player, info)
data.lang_code = get_lang_code(info) data.lang_code = get_lang_code(info)
data.fs_version = info.formspec_version data.fs_version = info.formspec_version
core.after(0, set_fs, player) core.after(0, i3.set_fs, player)
end end
local function init_waypoints(player) local function init_waypoints(player)