remove dead code, fix luacheck

This commit is contained in:
flux 2022-06-19 15:34:08 -07:00
parent 5990d7c6a4
commit 9a617992b4
6 changed files with 17 additions and 96 deletions

View File

@ -19,7 +19,7 @@ stds.minetest = {
}
}
stds.moreblocks = {
stds.invsaw = {
globals = {
"invsaw",
},

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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