1
0
mirror of https://github.com/pandorabox-io/banners.git synced 2025-01-06 16:10: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 = {}
@ -236,11 +237,11 @@ core.register_entity("banners:banner_ent", {
on_activate = banners.banner_on_activate,
})
dofile(minetest.get_modpath("banners").."/factions.lua")
if core.get_modpath("factions") then
dofile(MP .. "factions.lua")
end
dofile(minetest.get_modpath("banners").."/items.lua")
dofile(minetest.get_modpath("banners").."/nodes.lua")
dofile(minetest.get_modpath("banners").."/crafts.lua")
dofile(MP .. "items.lua")
dofile(MP .. "nodes.lua")
dofile(MP .. "crafts.lua")

View File

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