Some cleaning

This commit is contained in:
Jean-Patrick Guerrero 2021-10-19 05:54:51 +02:00
parent 43b20b317e
commit caba7f3599
5 changed files with 39 additions and 29 deletions

View File

@ -21,3 +21,8 @@ globals = {
"sfinv", "sfinv",
"unified_inventory", "unified_inventory",
} }
exclude_files = {
"tests/test_custom_recipes.lua",
"tests/test_tabs.lua",
}

View File

@ -1,4 +1,4 @@
local fmt, insert = string.format, table.insert local fmt, insert, copy, pairs, ipairs = string.format, table.insert, table.copy, pairs, ipairs
local wood_types = { local wood_types = {
"acacia_wood", "aspen_wood", "junglewood", "pine_wood", "acacia_wood", "aspen_wood", "junglewood", "pine_wood",
@ -262,7 +262,7 @@ local moreblocks_nodes = {
"ice", "ice",
} }
local colors_moreblocks = table.copy(colors) local colors_moreblocks = copy(colors)
insert(colors_moreblocks, "white") insert(colors_moreblocks, "white")
local moreblocks_mods = { local moreblocks_mods = {

View File

@ -1,4 +1,3 @@
local modpath = core.get_modpath "i3"
local damage_enabled = core.settings:get_bool "enable_damage" local damage_enabled = core.settings:get_bool "enable_damage"
local reg_items = core.registered_items local reg_items = core.registered_items
@ -20,14 +19,10 @@ local min, max, floor, ceil = math.min, math.max, math.floor, math.ceil
local clr, ESC, check_privs, translate = local clr, ESC, check_privs, translate =
core.colorize, core.formspec_escape, core.check_player_privs, core.get_translated_string core.colorize, core.formspec_escape, core.check_player_privs, core.get_translated_string
local model_aliases = dofile(modpath .. "/etc/model_aliases.lua") local model_aliases = i3.files.model_alias()
local PNG, styles, fs_elements = dofile(modpath .. "/etc/styles.lua") local PNG, styles, fs_elements = i3.files.styles()
local _, _, is_group, extract_groups, item_has_groups = unpack(i3.files.common().progressive)
local _, _, is_group, extract_groups, item_has_groups = local groups_to_items, compression_active, compressible, true_str, is_fav = unpack(i3.files.common().gui)
unpack(dofile(modpath .. "/etc/common.lua").progressive)
local groups_to_items, compression_active, compressible, true_str, is_fav =
unpack(dofile(modpath .. "/etc/common.lua").gui)
local S = i3.S local S = i3.S

View File

@ -1,14 +1,12 @@
local POLL_FREQ = 0.25 local POLL_FREQ = 0.25
local HUD_TIMER_MAX = 1.5 local HUD_TIMER_MAX = 1.5
local set_fs = i3.set_fs
local modpath = core.get_modpath "i3"
local search, table_merge, is_group, extract_groups, item_has_groups, apply_recipe_filters = local search, table_merge, is_group, extract_groups, item_has_groups, apply_recipe_filters =
unpack(dofile(modpath .. "/etc/common.lua").progressive) unpack(i3.files.common().progressive)
local singleplayer = core.is_singleplayer() local singleplayer = core.is_singleplayer()
local fmt, after = string.format, core.after local fmt, after, pairs = string.format, core.after, pairs
local set_fs = i3.set_fs
local function array_diff(t1, t2) local function array_diff(t1, t2)
local hash = {} local hash = {}
@ -204,8 +202,7 @@ local function show_hud_success(player, data)
end end
player:hud_change(data.hud.text, "text", player:hud_change(data.hud.text, "text",
fmt("%u new recipe%s unlocked!", fmt("%u new recipe%s unlocked!", data.discovered, data.discovered > 1 and "s" or ""))
data.discovered, data.discovered > 1 and "s" or ""))
elseif data.show_hud == false then elseif data.show_hud == false then
if data.hud_timer >= HUD_TIMER_MAX then if data.hud_timer >= HUD_TIMER_MAX then

View File

@ -1,3 +1,9 @@
local modpath = core.get_modpath "i3"
local function lf(path)
return loadfile(modpath .. path)
end
i3 = { i3 = {
modules = {}, modules = {},
@ -39,9 +45,18 @@ i3 = {
search_filters = {}, search_filters = {},
craft_types = {}, craft_types = {},
tabs = {}, tabs = {},
files = {
common = lf("/etc/common.lua"),
compress = lf("/etc/compress.lua"),
groups = lf("/etc/groups.lua"),
gui = lf("/etc/gui.lua"),
model_alias = lf("/etc/model_aliases.lua"),
progressive = lf("/etc/progressive.lua"),
styles = lf("/etc/styles.lua"),
}
} }
local modpath = core.get_modpath "i3"
local http = core.request_http_api() local http = core.request_http_api()
local storage = core.get_mod_storage() local storage = core.get_mod_storage()
@ -49,16 +64,16 @@ i3.S = core.get_translator "i3"
local S, slz, dslz = i3.S, core.serialize, core.deserialize local S, slz, dslz = i3.S, core.serialize, core.deserialize
i3.data = dslz(storage:get_string "data") or {} i3.data = dslz(storage:get_string "data") or {}
i3.compress_groups, i3.compressed = dofile(modpath .. "/etc/compress.lua") i3.compress_groups, i3.compressed = i3.files.compress()
i3.group_stereotypes, i3.group_names = dofile(modpath .. "/etc/groups.lua") i3.group_stereotypes, i3.group_names = i3.files.groups()
local is_str, show_item, reset_compression = unpack(dofile(modpath .. "/etc/common.lua").init) local is_str, show_item, reset_compression = unpack(i3.files.common().init)
local groups_to_items, _, compressible, true_str, is_fav = unpack(dofile(modpath .. "/etc/common.lua").gui) local groups_to_items, _, compressible, true_str, is_fav = unpack(i3.files.common().gui)
local search, table_merge, is_group, extract_groups, item_has_groups, apply_recipe_filters = local search, table_merge, is_group, extract_groups, item_has_groups, apply_recipe_filters =
unpack(dofile(modpath .. "/etc/common.lua").progressive) unpack(i3.files.common().progressive)
local make_fs, get_inventory_fs = dofile(modpath .. "/etc/gui.lua") local make_fs, get_inventory_fs = i3.files.gui()
local progressive_mode = core.settings:get_bool "i3_progressive_mode" local progressive_mode = core.settings:get_bool "i3_progressive_mode"
@ -82,9 +97,7 @@ local fmt, find, gmatch, match, sub, split, upper, lower =
string.sub, string.split, string.upper, string.lower string.sub, string.split, string.upper, string.lower
local min, ceil, random = math.min, math.ceil, math.random local min, ceil, random = math.min, math.ceil, math.random
local pairs, ipairs, next, type, tonum = pairs, ipairs, next, type, tonumber
local pairs, ipairs, next, type, tonum =
pairs, ipairs, next, type, tonumber
local vec_new, vec_add, vec_mul, vec_eq, vec_round = local vec_new, vec_add, vec_mul, vec_eq, vec_round =
vector.new, vector.add, vector.multiply, vector.equals, vector.round vector.new, vector.add, vector.multiply, vector.equals, vector.round
@ -1618,7 +1631,7 @@ core.register_on_player_hpchange(function(player, hpchange)
end) end)
if progressive_mode then if progressive_mode then
dofile(modpath .. "/etc/progressive.lua") i3.files.progressive()
end end
local bag_recipes = { local bag_recipes = {