mirror of
https://github.com/pandorabox-io/banners.git
synced 2025-01-06 16:10:32 +01:00
luacheck cleanups
- unused arguments - shaddowed vars - var redeclarations - some whitespace involved in above lines
This commit is contained in:
parent
8d6b2f264f
commit
ae679a14d4
11
factions.lua
11
factions.lua
@ -182,8 +182,9 @@ core.register_node("banners:death_banner", {
|
|||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
banners.banner_on_destruct(pos)
|
banners.banner_on_destruct(pos)
|
||||||
end,
|
end,
|
||||||
on_dig = function(pos, n, p)
|
-- (pos, node, player)
|
||||||
if core.is_protected(pos, p:get_player_name()) then
|
on_dig = function(pos, _, player)
|
||||||
|
if core.is_protected(pos, player:get_player_name()) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
@ -199,7 +200,8 @@ core.register_node("banners:death_banner", {
|
|||||||
end,
|
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)
|
core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
|
||||||
local faction = factions.players[player:get_player_name()]
|
local faction = factions.players[player:get_player_name()]
|
||||||
if not faction then
|
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")
|
core.add_entity(pos, "banners:banner_ent")
|
||||||
end
|
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)
|
core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
|
||||||
local attacking_faction = factions.players[player:get_player_name()]
|
local attacking_faction = factions.players[player:get_player_name()]
|
||||||
if attacking_faction then
|
if attacking_faction then
|
||||||
|
47
init.lua
47
init.lua
@ -66,26 +66,26 @@ banners.creation_form_func = function(state)
|
|||||||
state:update_all()
|
state:update_all()
|
||||||
-- color indicator
|
-- color indicator
|
||||||
-- undo button
|
-- undo button
|
||||||
state:button(0.5, 0.3, 2, 1, "undo", "Undo"):click(function(self, state)
|
state:button(0.5, 0.3, 2, 1, "undo", "Undo"):click(function(_, state2)
|
||||||
if #state.banner.transforms > 1 then
|
if #state2.banner.transforms > 1 then
|
||||||
state.banner:pop_transform()
|
state2.banner:pop_transform()
|
||||||
state:update_all()
|
state2:update_all()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
-- delete button
|
-- delete button
|
||||||
state:button(0.5, 1.3, 2, 1, "delete", "Delete"):click(function(self, state)
|
state:button(0.5, 1.3, 2, 1, "delete", "Delete"):click(function(_, state2)
|
||||||
state.banner.transforms = {banners.base_transform}
|
state2.banner.transforms = { banners.base_transform }
|
||||||
state:update_all()
|
state2:update_all()
|
||||||
end)
|
end)
|
||||||
-- add banners colors
|
-- add banners colors
|
||||||
local x = 7
|
local x = 7
|
||||||
local y = .3
|
local y = .3
|
||||||
for i in ipairs(banners.colors) do
|
for i in ipairs(banners.colors) do
|
||||||
local b = state:button(x, y, 1, 1, banners.colors[i], "")
|
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: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
|
-- todo: update masks or something
|
||||||
end)
|
end)
|
||||||
x = x + 1
|
x = x + 1
|
||||||
@ -95,16 +95,17 @@ banners.creation_form_func = function(state)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- add banners buttons
|
-- add banners buttons
|
||||||
local x = 1
|
x = 1
|
||||||
local y = 3
|
y = 3
|
||||||
for i in ipairs(banners.masks) do
|
for i in ipairs(banners.masks) do
|
||||||
local b = state:button(x, y, 2, 1, banners.masks[i], "")
|
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: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)
|
end)
|
||||||
x = x + 2
|
x = x + 2
|
||||||
if x > 17.5 then
|
if x > 17.5 then
|
||||||
@ -146,7 +147,8 @@ function banners.Banner.get_transform_string(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- helper function for determining the flag's direction
|
-- 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 above = pointed_thing.above
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
local dir = {
|
local dir = {
|
||||||
@ -157,7 +159,8 @@ banners.determine_flag_direction = function(pos, pointed_thing)
|
|||||||
return core.dir_to_wallmounted(dir)
|
return core.dir_to_wallmounted(dir)
|
||||||
end
|
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
|
if player.is_player then
|
||||||
banners.creation_form:show(player:get_player_name())
|
banners.creation_form:show(player:get_player_name())
|
||||||
end
|
end
|
||||||
@ -178,7 +181,8 @@ banners.banner_on_dig = function(pos, node, player)
|
|||||||
core.remove_node(pos)
|
core.remove_node(pos)
|
||||||
end
|
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)
|
local objects = core.get_objects_inside_radius(pos, 0.5)
|
||||||
for _, v in ipairs(objects) do
|
for _, v in ipairs(objects) do
|
||||||
local e = v:get_luaentity()
|
local e = v:get_luaentity()
|
||||||
@ -188,7 +192,8 @@ banners.banner_on_destruct = function(pos, node, player)
|
|||||||
end
|
end
|
||||||
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_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
|
||||||
core.get_meta(pos):set_string("banner", itemstack:get_meta():get_string(""))
|
core.get_meta(pos):set_string("banner", itemstack:get_meta():get_string(""))
|
||||||
core.add_entity(pos, "banners:banner_ent")
|
core.add_entity(pos, "banners:banner_ent")
|
||||||
|
56
smartfs.lua
56
smartfs.lua
@ -12,7 +12,7 @@ smartfs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- the smartfs() function
|
-- the smartfs() function
|
||||||
function smartfs.__call(self, name)
|
function smartfs.__call(_, name)
|
||||||
return smartfs._fdef[name]
|
return smartfs._fdef[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -75,7 +75,8 @@ function smartfs.add_to_inventory(form, icon, title)
|
|||||||
image = icon,
|
image = icon,
|
||||||
})
|
})
|
||||||
unified_inventory.register_page(form.name, {
|
unified_inventory.register_page(form.name, {
|
||||||
get_formspec = function(player, formspec)
|
-- (player, formspec)
|
||||||
|
get_formspec = function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local opened = smartfs._show_(form, name, nil, true)
|
local opened = smartfs._show_(form, name, nil, true)
|
||||||
return { formspec = opened:_getFS_(false) }
|
return { formspec = opened:_getFS_(false) }
|
||||||
@ -120,7 +121,7 @@ function smartfs._makeState_(form, player, params, is_inv)
|
|||||||
if self._size and size then
|
if self._size and size then
|
||||||
res = "size[" .. self._size.w .. "," .. self._size.h .. "]"
|
res = "size[" .. self._size.w .. "," .. self._size.h .. "]"
|
||||||
end
|
end
|
||||||
for key,val in pairs(self._ele) do
|
for _, val in pairs(self._ele) do
|
||||||
res = res .. val:build()
|
res = res .. val:build()
|
||||||
end
|
end
|
||||||
return res
|
return res
|
||||||
@ -139,15 +140,15 @@ function smartfs._makeState_(form, player, params, is_inv)
|
|||||||
core.show_formspec(player, form.name, res)
|
core.show_formspec(player, form.name, res)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
load = function(self,file)
|
load = function(self, file_name)
|
||||||
local file = io.open(file, "r")
|
local file = io.open(file_name, "r")
|
||||||
if file then
|
if file then
|
||||||
local table = core.deserialize(file:read("*all"))
|
local table = core.deserialize(file:read("*all"))
|
||||||
if type(table) == "table" then
|
if type(table) == "table" then
|
||||||
if table.size then
|
if table.size then
|
||||||
self._size = table.size
|
self._size = table.size
|
||||||
end
|
end
|
||||||
for key,val in pairs(table.ele) do
|
for _, val in pairs(table.ele) do
|
||||||
self:element(val.type, val)
|
self:element(val.type, val)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -155,7 +156,7 @@ function smartfs._makeState_(form, player, params, is_inv)
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
save = function(self,file)
|
save = function(self, file_name)
|
||||||
local res = { ele = {} }
|
local res = { ele = {} }
|
||||||
|
|
||||||
if self._size then
|
if self._size then
|
||||||
@ -166,7 +167,7 @@ function smartfs._makeState_(form, player, params, is_inv)
|
|||||||
res.ele[key] = val.data
|
res.ele[key] = val.data
|
||||||
end
|
end
|
||||||
|
|
||||||
local file = io.open(file, "w")
|
local file = io.open(file_name, "w")
|
||||||
if file then
|
if file then
|
||||||
file:write(core.serialize(res))
|
file:write(core.serialize(res))
|
||||||
file:close()
|
file:close()
|
||||||
@ -288,8 +289,8 @@ function smartfs._makeState_(form, player, params, is_inv)
|
|||||||
name = data.name,
|
name = data.name,
|
||||||
root = self,
|
root = self,
|
||||||
data = data,
|
data = data,
|
||||||
remove = function(self)
|
remove = function(self2)
|
||||||
self.root._ele[self.name] = nil
|
self2.root._ele[self2.name] = nil
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +334,7 @@ local function _sfs_recieve_(state, name, fields)
|
|||||||
state._ele[key].data.value = val
|
state._ele[key].data.value = val
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for key,val in pairs(state._ele) do
|
for _, val in pairs(state._ele) do
|
||||||
if val.submit then
|
if val.submit then
|
||||||
if val:submit(fields) == true then
|
if val:submit(fields) == true then
|
||||||
return true
|
return true
|
||||||
@ -401,7 +402,8 @@ smartfs.element("button", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
submit = function(self,fields,state)
|
-- (self, fields, state)
|
||||||
|
submit = function(self, fields)
|
||||||
if fields[self.name] and self._click then
|
if fields[self.name] and self._click then
|
||||||
self:_click(self.root)
|
self:_click(self.root)
|
||||||
end
|
end
|
||||||
@ -413,13 +415,13 @@ smartfs.element("button", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
self.data.size = { w = w, h = h }
|
self.data.size = { w = w, h = h }
|
||||||
end,
|
end,
|
||||||
getSize = function(self,x,y)
|
getSize = function(self)
|
||||||
return self.data.size
|
return self.data.size
|
||||||
end,
|
end,
|
||||||
onClick = function(self, func)
|
onClick = function(self, func)
|
||||||
@ -471,13 +473,13 @@ smartfs.element("toggle", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
self.data.size = { w = w, h = h }
|
self.data.size = { w = w, h = h }
|
||||||
end,
|
end,
|
||||||
getSize = function(self,x,y)
|
getSize = function(self)
|
||||||
return self.data.size
|
return self.data.size
|
||||||
end,
|
end,
|
||||||
setId = function(self, id)
|
setId = function(self, id)
|
||||||
@ -501,7 +503,7 @@ smartfs.element("label", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setText = function(self, text)
|
setText = function(self, text)
|
||||||
@ -542,13 +544,13 @@ smartfs.element("field", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
self.data.size = { w = w, h = h }
|
self.data.size = { w = w, h = h }
|
||||||
end,
|
end,
|
||||||
getSize = function(self,x,y)
|
getSize = function(self)
|
||||||
return self.data.size
|
return self.data.size
|
||||||
end,
|
end,
|
||||||
setText = function(self, text)
|
setText = function(self, text)
|
||||||
@ -576,13 +578,13 @@ smartfs.element("image", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
self.data.size = { w = w, h = h }
|
self.data.size = { w = w, h = h }
|
||||||
end,
|
end,
|
||||||
getSize = function(self,x,y)
|
getSize = function(self)
|
||||||
return self.data.size
|
return self.data.size
|
||||||
end,
|
end,
|
||||||
setImage = function(self, text)
|
setImage = function(self, text)
|
||||||
@ -616,13 +618,13 @@ smartfs.element("checkbox", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
self.data.size = { w = w, h = h }
|
self.data.size = { w = w, h = h }
|
||||||
end,
|
end,
|
||||||
getSize = function(self,x,y)
|
getSize = function(self)
|
||||||
return self.data.size
|
return self.data.size
|
||||||
end,
|
end,
|
||||||
setText = function(self, text)
|
setText = function(self, text)
|
||||||
@ -675,13 +677,13 @@ smartfs.element("list", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
self.data.size = { w = w, h = h }
|
self.data.size = { w = w, h = h }
|
||||||
end,
|
end,
|
||||||
getSize = function(self,x,y)
|
getSize = function(self)
|
||||||
return self.data.size
|
return self.data.size
|
||||||
end,
|
end,
|
||||||
addItem = function(self, item)
|
addItem = function(self, item)
|
||||||
@ -719,13 +721,13 @@ smartfs.element("inventory", {
|
|||||||
setPosition = function(self, x, y)
|
setPosition = function(self, x, y)
|
||||||
self.data.pos = { x = x, y = y }
|
self.data.pos = { x = x, y = y }
|
||||||
end,
|
end,
|
||||||
getPosition = function(self,x,y)
|
getPosition = function(self)
|
||||||
return self.data.pos
|
return self.data.pos
|
||||||
end,
|
end,
|
||||||
setSize = function(self, w, h)
|
setSize = function(self, w, h)
|
||||||
self.data.size = { w = w, h = h }
|
self.data.size = { w = w, h = h }
|
||||||
end,
|
end,
|
||||||
getSize = function(self,x,y)
|
getSize = function(self)
|
||||||
return self.data.size
|
return self.data.size
|
||||||
end,
|
end,
|
||||||
-- available inventory locations
|
-- available inventory locations
|
||||||
|
Loading…
Reference in New Issue
Block a user