From 9a617992b4c39d8d0a15ac2124f8728ca01aaff2 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Sun, 19 Jun 2022 15:34:08 -0700 Subject: [PATCH] remove dead code, fix luacheck --- invsaw/.luacheckrc | 2 +- invsaw/api.lua | 11 +++----- invsaw/formspec.lua | 50 ------------------------------------ invsaw/inventory.lua | 16 +++++++----- invsaw/privs.lua | 4 ++- invsaw/unified_inventory.lua | 30 ---------------------- 6 files changed, 17 insertions(+), 96 deletions(-) diff --git a/invsaw/.luacheckrc b/invsaw/.luacheckrc index ce63fdd..11ce218 100644 --- a/invsaw/.luacheckrc +++ b/invsaw/.luacheckrc @@ -19,7 +19,7 @@ stds.minetest = { } } -stds.moreblocks = { +stds.invsaw = { globals = { "invsaw", }, diff --git a/invsaw/api.lua b/invsaw/api.lua index dd01e04..db7ebf3 100644 --- a/invsaw/api.lua +++ b/invsaw/api.lua @@ -1,5 +1,3 @@ -local station = stairsplus.api.station - function invsaw.has_saw_in_inventory(player) local inv = player:get_inventory() return inv:contains_item("main", invsaw.settings.saw_item) @@ -19,16 +17,13 @@ function invsaw.allow_use_saw(player) ) end -function invsaw.on_join(player) - local meta = player:get_meta() - local inv = player:get_inventory() +function invsaw.check_use_status(player) if invsaw.can_use_saw(player) then - station.initialize_metadata(meta, inv, {"legacy"}) - station.initialize_inventory(inv) + invsaw.initialize_inventory(player) else invsaw.drop_inventory(player) end end -minetest.register_on_joinplayer(invsaw.on_join) +minetest.register_on_joinplayer(invsaw.check_use_status) diff --git a/invsaw/formspec.lua b/invsaw/formspec.lua index 6614da2..2eac016 100644 --- a/invsaw/formspec.lua +++ b/invsaw/formspec.lua @@ -1,56 +1,6 @@ -local ui = unified_inventory -local get_location_string = stairsplus.util.get_location_string local station = stairsplus.api.station local circular_saw = stairsplus.api.circular_saw -local S = stairsplus.S -local F = minetest.formspec_escape - -invsaw.formspec = [[ - formspec_version[4] - size[16,15] - background9[0,0;1,1;ui_formbg_9_sliced.png;true;16] - listcolors[#00000000;#FFFFFF80;#00000000] - label[0.75,1.3;%s] - %s - list[%s;stairsplus:input;3,1;1,1;] - label[0.75,3;%s] - %s - list[%s;stairsplus:micro;3,2.5;1,1;] - label[0.75,4.3;%s] - %s - list[%s;stairsplus:recycle;3,4;1,1;] - field[0.75,6;1,1;max_offered;%s:;%i] - button[2,6;1,1;Set;%s] - %s - list[%s;stairsplus:output;5,1;8,6;] - %s - %s - list[current_player;main;4,9.5;8,4;] -]] - -function invsaw.build_formspec(meta, inv) - local inv_location = get_location_string(inv) - return invsaw.formspec:format( - F(S("Nodes")), - ui.single_slot(1.88, 0.88, true), - inv_location, - F(S("Microblocks")), - ui.single_slot(1.88, 2.38), - inv_location, - F(S("Input")), - ui.single_slot(1.88, 3.88), - inv_location, - F(S("Max")), - meta:get_int("stairsplus:max_offered"), - F(S("Set")), - ui.make_inv_img_grid(3.88, 0.88, 8, 6), - inv_location, - ui.make_inv_img_grid(3.88, 9.38, 8, 1, true), - ui.make_inv_img_grid(3.88, 10.63, 8, 3) - ) -end - function invsaw.show_formspec(player) local name = player:get_player_name() local meta = player:get_meta() diff --git a/invsaw/inventory.lua b/invsaw/inventory.lua index 7ded029..7f9a981 100644 --- a/invsaw/inventory.lua +++ b/invsaw/inventory.lua @@ -1,5 +1,13 @@ local station = stairsplus.api.station +function invsaw.initialize_inventory(player) + local meta = player:get_meta() + local inv = player:get_inventory() + + station.initialize_metadata(meta, inv, {"legacy"}) + station.initialize_inventory(inv) +end + function invsaw.drop_inventory(player) local pos = player:get_pos() local inv = player:get_inventory() @@ -24,8 +32,6 @@ local function is_stairsplus_inventory(listname) ) end -local get_location_string = stairsplus.util.get_location_string - minetest.register_allow_player_inventory_action(function(player, action, inv, info) local meta = player:get_meta() if action == "move" and is_stairsplus_inventory(info.from_list) and is_stairsplus_inventory(info.to_list) then @@ -48,16 +54,14 @@ end) minetest.register_on_player_inventory_action(function(player, action, inv, info) local meta = player:get_meta() - if action == "move" and is_stairsplus_inventory(info.from_list) and is_stairsplus_inventory(info.to_list) then - - elseif action == "move" and is_stairsplus_inventory(info.from_list) then + if action == "move" and is_stairsplus_inventory(info.from_list) and not is_stairsplus_inventory(info.to_list) then local stack = inv:get_stack(info.to_list, info.to_index) stack:set_count(info.count) station.on_inventory_take( meta, inv, info.from_list, info.from_index, stack, player ) - elseif action == "move" and is_stairsplus_inventory(info.to_list) then + elseif action == "move" and not is_stairsplus_inventory(info.from_list) and is_stairsplus_inventory(info.to_list) then local stack = inv:get_stack(info.from_list, info.from_index) station.on_inventory_put( meta, inv, info.to_list, info.to_index, stack, player diff --git a/invsaw/privs.lua b/invsaw/privs.lua index c2c237b..5a62af9 100644 --- a/invsaw/privs.lua +++ b/invsaw/privs.lua @@ -1,10 +1,12 @@ +-- luacheck: globals minetest + local creative_priv = invsaw.settings.creative_priv local priv = invsaw.settings.priv local function on_priv_change(name) local player = minetest.get_player_by_name(name) if player then - invsaw.on_join(player) + invsaw.check_use_status(player) end end diff --git a/invsaw/unified_inventory.lua b/invsaw/unified_inventory.lua index 04a31c6..762974f 100644 --- a/invsaw/unified_inventory.lua +++ b/invsaw/unified_inventory.lua @@ -8,33 +8,3 @@ ui.register_button("saw", { return invsaw.allow_use_saw(player) end, }) - --- this takes over 3 seconds on my machine O_O ---local old_get_formspec = ui.get_formspec --- ---function ui.get_formspec(player, page) --- local fs = old_get_formspec(player, page) --- if invsaw.can_use_saw(player) then --- return fs --- end --- --- local start = minetest.get_us_time() --- -- excise the button --- local pre, post = fs:match( --- "(.*)image_button%[%-?%d+%.?%d*,%-?%d+%.?%d*;%-?%d+%.?%d*,%-?%d+%.?%d*;stairsplus_saw_button.png[^%]]*](.*)" --- ) --- --- if not pre and post then --- pre, post = fs:match( --- "(.*)image%[%-?%d+%.?%d*,%-?%d+%.?%d*;%-?%d+%.?%d*,%-?%d+%.?%d*;stairsplus_saw_button.png[^%]]*](.*)" --- ) --- end --- --- if pre and post then --- fs = pre .. post --- end --- --- minetest.chat_send_player(player:get_player_name(), ("took %s"):format((minetest.get_us_time() - start) / 1000000)) --- --- return fs ---end