1
0
mirror of https://github.com/pandorabox-io/banners.git synced 2025-01-08 00:50:32 +01:00

avoid duplicate code

save some lines and some extra method calls.
This commit is contained in:
Luke aka SwissalpS 2024-11-27 23:08:26 +01:00
parent 7ff3dd0311
commit c8af7c71e5
2 changed files with 28 additions and 48 deletions

View File

@ -1,4 +1,5 @@
dofile(minetest.get_modpath("banners").."/smartfs.lua") local MP = core.get_modpath("banners") .. "/"
dofile(MP .. "smartfs.lua")
banners = {} banners = {}
@ -236,11 +237,11 @@ core.register_entity("banners:banner_ent", {
on_activate = banners.banner_on_activate, on_activate = banners.banner_on_activate,
}) })
dofile(minetest.get_modpath("banners").."/factions.lua")
if core.get_modpath("factions") then if core.get_modpath("factions") then
dofile(MP .. "factions.lua")
end end
dofile(minetest.get_modpath("banners").."/items.lua") dofile(MP .. "items.lua")
dofile(minetest.get_modpath("banners").."/nodes.lua") dofile(MP .. "nodes.lua")
dofile(minetest.get_modpath("banners").."/crafts.lua") dofile(MP .. "crafts.lua")

View File

@ -377,29 +377,21 @@ end)
smartfs.element("button", { smartfs.element("button", {
build = function(self) build = function(self)
local common_prefix = self.data.pos.x .. "," .. self.data.pos.y
.. ";" .. self.data.size.w .. "," ..self.data.size.h
local common_sufix = ";" .. self.name
.. ";" .. self.data.value
.. "]"
if self.data.img then if self.data.img then
return "image_button[" return "image_button["
.. self.data.pos.x .. "," .. self.data.pos.y .. common_prefix
.. ";" .. self.data.size.w .. "," ..self.data.size.h
.. ";" .. self.data.img .. ";" .. self.data.img
.. ";" .. self.name .. common_sufix
.. ";" .. self.data.value
.. "]"
else else
if self.data.closes then if self.data.closes then
return "button_exit[" return "button_exit[" .. common_prefix .. common_sufix
.. self.data.pos.x .. "," .. self.data.pos.y
.. ";" .. self.data.size.w .. "," ..self.data.size.h
.. ";" .. self.name
.. ";" .. self.data.value
.. "]"
else else
return "button[" return "button[" .. common_prefix .. common_sufix
.. self.data.pos.x .. "," .. self.data.pos.y
.. ";" .. self.data.size.w .. "," .. self.data.size.h
.. ";" .. self.name
.. ";" .. self.data.value
.. "]"
end end
end end
end, end,
@ -517,27 +509,22 @@ smartfs.element("label", {
smartfs.element("field", { smartfs.element("field", {
build = function(self) build = function(self)
local common = self.data.pos.x .. "," .. self.data.pos.y
.. ";" .. self.data.size.w .. "," .. self.data.size.h
.. ";" .. self.name
.. ";" .. self.data.label
if self.data.ml then if self.data.ml then
return "textarea[" return "textarea["
.. self.data.pos.x .. "," .. self.data.pos.y .. common
.. ";" .. self.data.size.w .. "," .. self.data.size.h
.. ";" .. self.name
.. ";" .. self.data.label
.. ";" .. self.data.value .. ";" .. self.data.value
.. "]" .. "]"
elseif self.data.pwd then elseif self.data.pwd then
return "pwdfield[" return "pwdfield["
.. self.data.pos.x .. "," .. self.data.pos.y .. common
.. ";" .. self.data.size.w .. "," .. self.data.size.h
.. ";" .. self.name
.. ";" .. self.data.label
.. "]" .. "]"
else else
return "field[" return "field["
.. self.data.pos.x .. "," .. self.data.pos.y .. common
.. ";" .. self.data.size.w .. "," .. self.data.size.h
.. ";" .. self.name
.. ";" .. self.data.label
.. ";" .. self.data.value .. ";" .. self.data.value
.. "]" .. "]"
end end
@ -598,22 +585,14 @@ smartfs.element("image", {
smartfs.element("checkbox", { smartfs.element("checkbox", {
build = function(self) build = function(self)
local out = "checkbox["
.. self.data.pos.x .. "," .. self.data.pos.y
.. ";" .. self.name
.. ";" .. self.data.label
if self.data.value then if self.data.value then
return "checkbox[".. return out .. ";true]"
self.data.pos.x..","..self.data.pos.y..
";"..
self.name..
";"..
self.data.label..
";true]"
else else
return "checkbox[".. return out .. ";false]"
self.data.pos.x..","..self.data.pos.y..
";"..
self.name..
";"..
self.data.label..
";false]"
end end
end, end,
setPosition = function(self, x, y) setPosition = function(self, x, y)