From ae679a14d42cb2fe3d1eb01509d8d4e70524a4ab Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Wed, 27 Nov 2024 22:54:39 +0100 Subject: [PATCH] luacheck cleanups - unused arguments - shaddowed vars - var redeclarations - some whitespace involved in above lines --- factions.lua | 11 +++++++---- init.lua | 47 +++++++++++++++++++++++-------------------- smartfs.lua | 56 +++++++++++++++++++++++++++------------------------- 3 files changed, 62 insertions(+), 52 deletions(-) diff --git a/factions.lua b/factions.lua index fbb453a..aab0cf1 100644 --- a/factions.lua +++ b/factions.lua @@ -182,8 +182,9 @@ core.register_node("banners:death_banner", { on_destruct = function(pos) banners.banner_on_destruct(pos) end, - on_dig = function(pos, n, p) - if core.is_protected(pos, p:get_player_name()) then + -- (pos, node, player) + on_dig = function(pos, _, player) + if core.is_protected(pos, player:get_player_name()) then return end local meta = core.get_meta(pos) @@ -199,7 +200,8 @@ core.register_node("banners:death_banner", { end, }) -banners.after_powerbanner_placed = function(pos, player, itemstack, pointed_thing) +-- (pos, player, itemstack, pointed_thing) +banners.after_powerbanner_placed = function(pos, player, _, pointed_thing) core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing) local faction = factions.players[player:get_player_name()] if not faction then @@ -213,7 +215,8 @@ banners.after_powerbanner_placed = function(pos, player, itemstack, pointed_thin core.add_entity(pos, "banners:banner_ent") end -banners.after_deathbanner_placed = function(pos, player, itemstack, pointed_thing) +-- (pos, player, itemstack, pointed_thing) +banners.after_deathbanner_placed = function(pos, player, _, pointed_thing) core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing) local attacking_faction = factions.players[player:get_player_name()] if attacking_faction then diff --git a/init.lua b/init.lua index 8be2917..c894622 100644 --- a/init.lua +++ b/init.lua @@ -66,26 +66,26 @@ banners.creation_form_func = function(state) state:update_all() -- color indicator -- undo button - state:button(0.5, 0.3, 2, 1, "undo", "Undo"):click(function(self, state) - if #state.banner.transforms > 1 then - state.banner:pop_transform() - state:update_all() + state:button(0.5, 0.3, 2, 1, "undo", "Undo"):click(function(_, state2) + if #state2.banner.transforms > 1 then + state2.banner:pop_transform() + state2:update_all() end end) -- delete button - state:button(0.5, 1.3, 2, 1, "delete", "Delete"):click(function(self, state) - state.banner.transforms = {banners.base_transform} - state:update_all() + state:button(0.5, 1.3, 2, 1, "delete", "Delete"):click(function(_, state2) + state2.banner.transforms = { banners.base_transform } + state2:update_all() end) -- add banners colors local x = 7 local y = .3 for i in ipairs(banners.colors) do local b = state:button(x, y, 1, 1, banners.colors[i], "") - b:click(function(self, state) - state.current_color = "bg_"..self.name..".png" - state:update_preview() b:setImage("bg_" .. banners.colors[i] .. ".png") + b:click(function(self, state2) + state2.current_color = "bg_" .. self.name .. ".png" + state2:update_preview() -- todo: update masks or something end) x = x + 1 @@ -95,16 +95,17 @@ banners.creation_form_func = function(state) end end -- add banners buttons - local x = 1 - local y = 3 + x = 1 + y = 3 for i in ipairs(banners.masks) do local b = state:button(x, y, 2, 1, banners.masks[i], "") - b:click(function(self, state) - state.banner:push_transform({texture=state.current_color, mask=self.name..".png"}) - state:update_all() - end - ) b:setImage(banners.masks[i] .. ".png") + b:click(function(self, state2) + state2.banner:push_transform({ + texture = state2.current_color, + mask = self.name .. ".png" + }) + state2:update_all() end) x = x + 2 if x > 17.5 then @@ -146,7 +147,8 @@ function banners.Banner.get_transform_string(self) end -- helper function for determining the flag's direction -banners.determine_flag_direction = function(pos, pointed_thing) +-- (pos, pointed_thing) +banners.determine_flag_direction = function(_, pointed_thing) local above = pointed_thing.above local under = pointed_thing.under local dir = { @@ -157,7 +159,8 @@ banners.determine_flag_direction = function(pos, pointed_thing) return core.dir_to_wallmounted(dir) end -banners.banner_on_use = function(itemstack, player, pointed_thing) +-- (itemstack, player, pointed_thing) +banners.banner_on_use = function(_, player) if player.is_player then banners.creation_form:show(player:get_player_name()) end @@ -178,7 +181,8 @@ banners.banner_on_dig = function(pos, node, player) core.remove_node(pos) end -banners.banner_on_destruct = function(pos, node, player) +-- (pos, node, player) +banners.banner_on_destruct = function(pos) local objects = core.get_objects_inside_radius(pos, 0.5) for _, v in ipairs(objects) do local e = v:get_luaentity() @@ -188,7 +192,8 @@ banners.banner_on_destruct = function(pos, node, player) end end -banners.banner_after_place = function (pos, player, itemstack, pointed_thing) +-- (pos, player, itemstack, pointed_thing) +banners.banner_after_place = function(pos, _, itemstack, pointed_thing) core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing) core.get_meta(pos):set_string("banner", itemstack:get_meta():get_string("")) core.add_entity(pos, "banners:banner_ent") diff --git a/smartfs.lua b/smartfs.lua index f992468..8ddb3c7 100644 --- a/smartfs.lua +++ b/smartfs.lua @@ -12,7 +12,7 @@ smartfs = { } -- the smartfs() function -function smartfs.__call(self, name) +function smartfs.__call(_, name) return smartfs._fdef[name] end @@ -75,7 +75,8 @@ function smartfs.add_to_inventory(form, icon, title) image = icon, }) unified_inventory.register_page(form.name, { - get_formspec = function(player, formspec) + -- (player, formspec) + get_formspec = function(player) local name = player:get_player_name() local opened = smartfs._show_(form, name, nil, true) return { formspec = opened:_getFS_(false) } @@ -120,7 +121,7 @@ function smartfs._makeState_(form, player, params, is_inv) if self._size and size then res = "size[" .. self._size.w .. "," .. self._size.h .. "]" end - for key,val in pairs(self._ele) do + for _, val in pairs(self._ele) do res = res .. val:build() end return res @@ -139,15 +140,15 @@ function smartfs._makeState_(form, player, params, is_inv) core.show_formspec(player, form.name, res) end end, - load = function(self,file) - local file = io.open(file, "r") + load = function(self, file_name) + local file = io.open(file_name, "r") if file then local table = core.deserialize(file:read("*all")) if type(table) == "table" then if table.size then self._size = table.size end - for key,val in pairs(table.ele) do + for _, val in pairs(table.ele) do self:element(val.type, val) end return true @@ -155,7 +156,7 @@ function smartfs._makeState_(form, player, params, is_inv) end return false end, - save = function(self,file) + save = function(self, file_name) local res = { ele = {} } if self._size then @@ -166,7 +167,7 @@ function smartfs._makeState_(form, player, params, is_inv) res.ele[key] = val.data end - local file = io.open(file, "w") + local file = io.open(file_name, "w") if file then file:write(core.serialize(res)) file:close() @@ -288,8 +289,8 @@ function smartfs._makeState_(form, player, params, is_inv) name = data.name, root = self, data = data, - remove = function(self) - self.root._ele[self.name] = nil + remove = function(self2) + self2.root._ele[self2.name] = nil end } @@ -333,7 +334,7 @@ local function _sfs_recieve_(state, name, fields) state._ele[key].data.value = val end end - for key,val in pairs(state._ele) do + for _, val in pairs(state._ele) do if val.submit then if val:submit(fields) == true then return true @@ -401,7 +402,8 @@ smartfs.element("button", { end end end, - submit = function(self,fields,state) + -- (self, fields, state) + submit = function(self, fields) if fields[self.name] and self._click then self:_click(self.root) end @@ -413,13 +415,13 @@ smartfs.element("button", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setSize = function(self, w, h) self.data.size = { w = w, h = h } end, - getSize = function(self,x,y) + getSize = function(self) return self.data.size end, onClick = function(self, func) @@ -471,13 +473,13 @@ smartfs.element("toggle", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setSize = function(self, w, h) self.data.size = { w = w, h = h } end, - getSize = function(self,x,y) + getSize = function(self) return self.data.size end, setId = function(self, id) @@ -501,7 +503,7 @@ smartfs.element("label", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setText = function(self, text) @@ -542,13 +544,13 @@ smartfs.element("field", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setSize = function(self, w, h) self.data.size = { w = w, h = h } end, - getSize = function(self,x,y) + getSize = function(self) return self.data.size end, setText = function(self, text) @@ -576,13 +578,13 @@ smartfs.element("image", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setSize = function(self, w, h) self.data.size = { w = w, h = h } end, - getSize = function(self,x,y) + getSize = function(self) return self.data.size end, setImage = function(self, text) @@ -616,13 +618,13 @@ smartfs.element("checkbox", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setSize = function(self, w, h) self.data.size = { w = w, h = h } end, - getSize = function(self,x,y) + getSize = function(self) return self.data.size end, setText = function(self, text) @@ -675,13 +677,13 @@ smartfs.element("list", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setSize = function(self, w, h) self.data.size = { w = w, h = h } end, - getSize = function(self,x,y) + getSize = function(self) return self.data.size end, addItem = function(self, item) @@ -719,13 +721,13 @@ smartfs.element("inventory", { setPosition = function(self, x, y) self.data.pos = { x = x, y = y } end, - getPosition = function(self,x,y) + getPosition = function(self) return self.data.pos end, setSize = function(self, w, h) self.data.size = { w = w, h = h } end, - getSize = function(self,x,y) + getSize = function(self) return self.data.size end, -- available inventory locations