From 27226a0d1bee9ed8c79bdcb56ed04d9081e50c37 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Mon, 29 Nov 2021 19:15:14 +0100 Subject: [PATCH] Reduce code + Remove github workflow --- .github/workflows/luacheck.yml | 21 --------------------- README.md | 2 +- src/api.lua | 11 +++++------ src/bags.lua | 7 +++---- src/caches.lua | 13 ++++--------- src/callbacks.lua | 21 ++++++++------------- src/common.lua | 2 ++ src/compress.lua | 2 +- src/detached_inv.lua | 2 +- src/groups.lua | 2 +- src/gui.lua | 29 ++++++++++++----------------- src/hud.lua | 3 +-- src/operators.lua | 4 ++++ src/progressive.lua | 9 +++------ 14 files changed, 46 insertions(+), 82 deletions(-) delete mode 100644 .github/workflows/luacheck.yml diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml deleted file mode 100644 index 3365b97..0000000 --- a/.github/workflows/luacheck.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Luacheck - -on: [push, pull_request] - -jobs: - - luacheck: - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup ‘lua’ - uses: leafo/gh-actions-lua@v8 - with: - luaVersion: 5.1 - - name: Setup ‘luarocks’ - uses: leafo/gh-actions-luarocks@v4 - - name: Setup ‘luacheck’ - run: luarocks install luacheck - - name: Run ‘luacheck’ linter - run: luacheck . diff --git a/README.md b/README.md index 4e8ec82..e59e834 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This mod requires **Minetest 5.4+** - Progressive Mode¹ - Quick Crafting - 3D Player Model Real-Time Preview - - Isometric Area Preview + - Isometric Map Preview - Inventory Sorting (+ options: compression, reverse mode, automation, etc.) - Item List Compression (**`moreblocks`** is supported) - Item Bookmarks diff --git a/src/api.lua b/src/api.lua index 0fda2fd..f899fa7 100644 --- a/src/api.lua +++ b/src/api.lua @@ -1,11 +1,10 @@ local make_fs = i3.files.gui() -local gmatch, split = i3.get("gmatch", "split") -local S, err, fmt, reg_items = i3.get("S", "err", "fmt", "reg_items") -local sorter, sort_inventory = i3.get("sorter", "sort_inventory") -local sort, concat, copy, insert, remove = i3.get("sort", "concat", "copy", "insert", "remove") -local true_str, true_table, is_str, is_func, is_table, clean_name = - i3.get("true_str", "true_table", "is_str", "is_func", "is_table", "clean_name") +IMPORT("gmatch", "split") +IMPORT("S", "err", "fmt", "reg_items") +IMPORT("sorter", "sort_inventory") +IMPORT("sort", "concat", "copy", "insert", "remove") +IMPORT("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 diff --git a/src/bags.lua b/src/bags.lua index e7b7793..0c7fe85 100644 --- a/src/bags.lua +++ b/src/bags.lua @@ -1,8 +1,7 @@ local set_fs = i3.set_fs -local ItemStack = ItemStack -local S, ES, fmt, msg, slz, dslz = i3.get("S", "ES", "fmt", "msg", "slz", "dslz") -local get_group, play_sound, get_detached_inv, create_inventory = - i3.get("get_group", "play_sound", "get_detached_inv", "create_inventory") + +IMPORT("S", "ES", "fmt", "msg", "slz", "dslz", "ItemStack") +IMPORT("get_group", "play_sound", "get_detached_inv", "create_inventory") local function get_content(content) local t = {} diff --git a/src/caches.lua b/src/caches.lua index 4e634fe..eec94bd 100644 --- a/src/caches.lua +++ b/src/caches.lua @@ -1,14 +1,9 @@ local replacements = {fuel = {}} -local ItemStack = ItemStack -local draw_cube = core.inventorycube -local fmt, reg_items, reg_aliases, reg_nodes = i3.get("fmt", "reg_items", "reg_aliases", "reg_nodes") -local maxn, copy, insert, sort, match, sub = i3.get("maxn", "copy", "insert", "sort", "match", "sub") - -local is_group, extract_groups, item_has_groups, groups_to_items = - i3.get("is_group", "extract_groups", "item_has_groups", "groups_to_items") -local true_str, true_table, is_table, valid_item, table_merge, table_replace, rcp_eq = - i3.get("true_str", "true_table", "is_table", "valid_item", "table_merge", "table_replace", "rcp_eq") +IMPORT("maxn", "copy", "insert", "sort", "match", "sub") +IMPORT("is_group", "extract_groups", "item_has_groups", "groups_to_items") +IMPORT("fmt", "reg_items", "reg_aliases", "reg_nodes", "draw_cube", "ItemStack") +IMPORT("true_str", "true_table", "is_table", "valid_item", "table_merge", "table_replace", "rcp_eq") local function get_burntime(item) return core.get_craft_result{method = "fuel", items = {item}}.time diff --git a/src/callbacks.lua b/src/callbacks.lua index e2934be..6ee984f 100644 --- a/src/callbacks.lua +++ b/src/callbacks.lua @@ -1,19 +1,14 @@ local _, get_inventory_fs = i3.files.gui() - local set_fs = i3.set_fs -local ItemStack = ItemStack -local S, min, random = i3.get("S", "min", "random") -local reg_items, reg_aliases = i3.get("reg_items", "reg_aliases") -local fmt, find, match, sub, lower, split = i3.get("fmt", "find", "match", "sub", "lower", "split") -local vec_eq, vec_round = i3.get("vec_eq", "vec_round") -local sort, copy, insert, remove, indexof = i3.get("sort", "copy", "insert", "remove", "indexof") -local msg, is_fav, pos_to_str, str_to_pos, add_hud_waypoint, play_sound, spawn_item = - i3.get("msg", "is_fav", "pos_to_str", "str_to_pos", "add_hud_waypoint", "play_sound", "spawn_item") -local search, get_sorting_idx, sort_inventory, sort_by_category, get_recipes, get_detached_inv = - i3.get("search", "get_sorting_idx", "sort_inventory", "sort_by_category", "get_recipes", "get_detached_inv") -local valid_item, get_stack, craft_stack, clean_name, compressible, check_privs, safe_teleport = - i3.get("valid_item", "get_stack", "craft_stack", "clean_name", "compressible", "check_privs", "safe_teleport") +IMPORT("vec_eq", "vec_round") +IMPORT("reg_items", "reg_aliases") +IMPORT("S", "min", "random", "ItemStack") +IMPORT("sort", "copy", "insert", "remove", "indexof") +IMPORT("fmt", "find", "match", "sub", "lower", "split") +IMPORT("msg", "is_fav", "pos_to_str", "str_to_pos", "add_hud_waypoint", "play_sound", "spawn_item") +IMPORT("search", "get_sorting_idx", "sort_inventory", "sort_by_category", "get_recipes", "get_detached_inv") +IMPORT("valid_item", "get_stack", "craft_stack", "clean_name", "compressible", "check_privs", "safe_teleport") local function reset_data(data) data.filter = "" diff --git a/src/common.lua b/src/common.lua index 035e3e3..73af003 100644 --- a/src/common.lua +++ b/src/common.lua @@ -624,6 +624,7 @@ local _ = { msg = msg, -- Misc. functions + ItemStack = ItemStack, valid_item = valid_item, spawn_item = spawn_item, clean_name = clean_name, @@ -636,6 +637,7 @@ local _ = { slz = core.serialize, dslz = core.deserialize, ESC = core.formspec_escape, + draw_cube = core.inventorycube, get_group = core.get_item_group, pos_to_str = core.pos_to_string, str_to_pos = core.string_to_pos, diff --git a/src/compress.lua b/src/compress.lua index 4b09706..e9a8629 100644 --- a/src/compress.lua +++ b/src/compress.lua @@ -1,4 +1,4 @@ -local fmt, copy, insert = i3.get("fmt", "copy", "insert") +IMPORT("fmt", "copy", "insert") local wood_types = { "acacia_wood", "aspen_wood", "junglewood", "pine_wood", diff --git a/src/detached_inv.lua b/src/detached_inv.lua index a8513bb..ede1fec 100644 --- a/src/detached_inv.lua +++ b/src/detached_inv.lua @@ -1,5 +1,5 @@ local set_fs = i3.set_fs -local fmt, play_sound, create_inventory = i3.get("fmt", "play_sound", "create_inventory") +IMPORT("fmt", "play_sound", "create_inventory") local trash = create_inventory("i3_trash", { allow_put = function(_, _, _, stack) diff --git a/src/groups.lua b/src/groups.lua index 88a9c7f..4ffff92 100644 --- a/src/groups.lua +++ b/src/groups.lua @@ -1,4 +1,4 @@ -local S = i3.get("S") +IMPORT("S") i3.group_stereotypes = { dye = "dye:white", diff --git a/src/gui.lua b/src/gui.lua index 073bfe9..3655660 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -1,26 +1,21 @@ -local damage_enabled = core.settings:get_bool "enable_damage" +local damage_enabled = core.settings:get_bool"enable_damage" local model_aliases = i3.files.model_alias() local PNG, styles, fs_elements, colors = i3.files.styles() -local ItemStack = ItemStack +local sprintf = string.format local VoxelArea, VoxelManip = VoxelArea, VoxelManip -local S, ES, translate = i3.get("S", "ES", "translate") -local clr, ESC, check_privs = i3.get("clr", "ESC", "check_privs") -local vec_new, vec_sub, vec_round = i3.get("vec_new", "vec_sub", "vec_round") -local min, max, floor, ceil, round = i3.get("min", "max", "floor", "ceil", "round") -local sprintf, find, match, sub, upper = i3.get("fmt", "find", "match", "sub", "upper") -local reg_items, reg_tools, reg_entities = i3.get("reg_items", "reg_tools", "reg_entities") -local maxn, sort, concat, copy, insert, remove, unpack = - i3.get("maxn", "sort", "concat", "copy", "insert", "remove", "unpack") - -local true_str, is_fav, is_num, get_group, str_to_pos = - i3.get("true_str", "is_fav", "is_num", "get_group", "str_to_pos") -local groups_to_items, compression_active, compressible = - i3.get("groups_to_items", "compression_active", "compressible") -local get_sorting_idx, is_group, extract_groups, item_has_groups = - i3.get("get_sorting_idx", "is_group", "extract_groups", "item_has_groups") +IMPORT("clr", "ESC", "check_privs") +IMPORT("find", "match", "sub", "upper") +IMPORT("vec_new", "vec_sub", "vec_round") +IMPORT("S", "ES", "translate", "ItemStack") +IMPORT("min", "max", "floor", "ceil", "round") +IMPORT("reg_items", "reg_tools", "reg_entities") +IMPORT("groups_to_items", "compression_active", "compressible") +IMPORT("true_str", "is_fav", "is_num", "get_group", "str_to_pos") +IMPORT("maxn", "sort", "concat", "copy", "insert", "remove", "unpack") +IMPORT("get_sorting_idx", "is_group", "extract_groups", "item_has_groups") local function fmt(elem, ...) if not fs_elements[elem] then diff --git a/src/hud.lua b/src/hud.lua index 9bb302b..da6441d 100644 --- a/src/hud.lua +++ b/src/hud.lua @@ -1,5 +1,4 @@ -local get_player_by_name, str_to_pos, add_hud_waypoint = - i3.get("get_player_by_name", "str_to_pos", "add_hud_waypoint") +IMPORT("get_player_by_name", "str_to_pos", "add_hud_waypoint") local function init_hud(player) local name = player:get_player_name() diff --git a/src/operators.lua b/src/operators.lua index 3320fea..f1cb3cd 100644 --- a/src/operators.lua +++ b/src/operators.lua @@ -36,6 +36,10 @@ local operators = { } local function compile(data) + data = data:gsub("IMPORT%((.-)%)", function(a) + return "local " .. a:gsub("\"", "") .. " = i3.get(" .. a .. ")" + end) + for op, func in pairs(operators) do data = data:gsub("(" .. var .. "+)%s?" .. op .. "%s?(" .. var .. "*)", func) end diff --git a/src/progressive.lua b/src/progressive.lua index 7c8acde..e3a5141 100644 --- a/src/progressive.lua +++ b/src/progressive.lua @@ -1,13 +1,10 @@ local set_fs = i3.set_fs local hud_notif = i3.hud_notif - -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") - local POLL_FREQ = 0.25 +IMPORT("fmt", "search", "table_merge", "array_diff") +IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters") + local function get_filtered_items(player, data) local items, known, c = {}, 0, 0