mirror of
https://github.com/pandorabox-io/banners.git
synced 2025-04-20 03:10:22 +02:00
refactor: reusable transformation string creation
unfortunately the git diff is a bit messy on this one. Nothing changed with: - banners.Banner - banners.Banner:new - banners.Banner:push_transform - banners.Banner:pop_transform content of banners.Banner:get_transform_string was moved to banners.transform_table_to_string with very few changes
This commit is contained in:
parent
2fea87dbde
commit
1c5b11609b
53
init.lua
53
init.lua
@ -144,31 +144,20 @@ end
|
|||||||
banners.creation_form = smartfs.create("banners:banner_creation",
|
banners.creation_form = smartfs.create("banners:banner_creation",
|
||||||
banners.creation_form_func)
|
banners.creation_form_func)
|
||||||
|
|
||||||
|
|
||||||
-- banner definition
|
|
||||||
banners.Banner = {}
|
|
||||||
|
|
||||||
function banners.Banner:new(banner)
|
|
||||||
banner = banner or { color = "bg_black.png", transforms = {} }
|
|
||||||
setmetatable(banner, self)
|
|
||||||
self.__index = self
|
|
||||||
return banner
|
|
||||||
end
|
|
||||||
table.insert(self.transforms, transform)
|
|
||||||
if #self.transforms > banners.max_undo_levels then
|
|
||||||
table.remove(self.transforms, 1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.remove(self.transforms)
|
|
||||||
end
|
function banners.transform_table_to_string(transforms)
|
||||||
local final = {}
|
local final = {}
|
||||||
local used = {}
|
local used = {}
|
||||||
local transform
|
local transform
|
||||||
-- work backwards to keep resulting data small
|
-- work backwards to keep resulting data small
|
||||||
local i = #self.transforms
|
local i = #transforms
|
||||||
|
if 0 == i then return "" end
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
transform = self.transforms[i]
|
transform = transforms[i]
|
||||||
-- same mask can be trimmed out only using most recent
|
-- duplicate mask can be trimmed out only use most recent
|
||||||
if not used[transform.mask] then
|
if not used[transform.mask] then
|
||||||
used[transform.mask] = true
|
used[transform.mask] = true
|
||||||
table.insert(final, 1, "(" .. transform.texture
|
table.insert(final, 1, "(" .. transform.texture
|
||||||
@ -180,11 +169,35 @@ end
|
|||||||
end
|
end
|
||||||
i = i - 1
|
i = i - 1
|
||||||
until i == 0
|
until i == 0
|
||||||
local ret = table.concat(final, "^")
|
return table.concat(final, "^")
|
||||||
return ret
|
end
|
||||||
|
|
||||||
|
-- banner definition
|
||||||
|
banners.Banner = {}
|
||||||
|
|
||||||
|
function banners.Banner:new(banner)
|
||||||
|
p('new')
|
||||||
|
banner = banner or { color = "bg_pink.png", transforms = {} }
|
||||||
|
setmetatable(banner, self)
|
||||||
|
self.__index = self
|
||||||
|
return banner
|
||||||
|
end
|
||||||
|
|
||||||
function banners.Banner:push_transform(transform)
|
function banners.Banner:push_transform(transform)
|
||||||
|
table.insert(self.transforms, transform)
|
||||||
|
if #self.transforms > banners.max_undo_levels then
|
||||||
|
table.remove(self.transforms, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function banners.Banner:pop_transform()
|
function banners.Banner:pop_transform()
|
||||||
|
table.remove(self.transforms)
|
||||||
|
end
|
||||||
|
|
||||||
function banners.Banner:get_transform_string()
|
function banners.Banner:get_transform_string()
|
||||||
|
return banners.transform_table_to_string(self.transforms)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- helper function for determining the flag's direction
|
-- helper function for determining the flag's direction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user