mirror of
https://github.com/pandorabox-io/banners.git
synced 2025-01-08 00:50:32 +01:00
minimize metadata size
also changed banners.max_transformations to banners.max_undo_levels and lowered the value substantially.
This commit is contained in:
parent
3d22f9b76b
commit
7e3a84eaac
38
init.lua
38
init.lua
@ -29,15 +29,11 @@ banners.masks = {
|
|||||||
"star_chevron", "checkered_8_4", "checkered_16_8"
|
"star_chevron", "checkered_8_4", "checkered_16_8"
|
||||||
}
|
}
|
||||||
|
|
||||||
-- The amount of transformations needs to be capped somewhere
|
-- It is now unlikely for the server to crash from too long
|
||||||
-- to avoid crashing server.
|
-- history since we now trim out garbage when converting to
|
||||||
-- It doesn't make sense to have any one mask multiple times
|
-- metadata. This limit is now just to avoid run-time
|
||||||
-- but users normally don't follow strict logic when being
|
-- memory bloat.
|
||||||
-- creative, so we give them plenty of space to work with.
|
banners.max_undo_levels = 256
|
||||||
-- A better approach would be to strip duplicates and to
|
|
||||||
-- drop all previous masks if a full background is dropped
|
|
||||||
-- on top of other masks.
|
|
||||||
banners.max_transformations = #banners.masks * #banners.masks
|
|
||||||
|
|
||||||
banners.colors = {
|
banners.colors = {
|
||||||
"black", "cyan", "green", "white",
|
"black", "cyan", "green", "white",
|
||||||
@ -143,7 +139,7 @@ function banners.Banner:new(banner)
|
|||||||
end
|
end
|
||||||
function banners.Banner.push_transform(self, transform)
|
function banners.Banner.push_transform(self, transform)
|
||||||
table.insert(self.transforms, transform)
|
table.insert(self.transforms, transform)
|
||||||
if #self.transforms > banners.max_transformations then
|
if #self.transforms > banners.max_undo_levels then
|
||||||
table.remove(self.transforms, 1)
|
table.remove(self.transforms, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -152,10 +148,24 @@ function banners.Banner.pop_transform(self)
|
|||||||
end
|
end
|
||||||
function banners.Banner.get_transform_string(self)
|
function banners.Banner.get_transform_string(self)
|
||||||
local final = {}
|
local final = {}
|
||||||
for _, transform in ipairs(self.transforms) do
|
local used = {}
|
||||||
table.insert(final, "(" .. transform.texture
|
local transform
|
||||||
.. "^[mask:" .. transform.mask .. "^[makealpha:0,0,0)")
|
-- work backwards to keep resulting data small
|
||||||
end
|
local i = #self.transforms
|
||||||
|
repeat
|
||||||
|
transform = self.transforms[i]
|
||||||
|
-- same mask can be trimmed out only using most recent
|
||||||
|
if not used[transform.mask] then
|
||||||
|
used[transform.mask] = true
|
||||||
|
table.insert(final, 1, "(" .. transform.texture
|
||||||
|
.. "^[mask:" .. transform.mask .. "^[makealpha:0,0,0)")
|
||||||
|
-- anything before a background is fully covered
|
||||||
|
if "mask_background.png" == transform.mask then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
i = i - 1
|
||||||
|
until i == 0
|
||||||
local ret = table.concat(final, "^")
|
local ret = table.concat(final, "^")
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user