mirror of
https://github.com/pandorabox-io/banners.git
synced 2025-01-08 17:10:32 +01:00
add recoverable per player history with saved colour
This commit is contained in:
parent
dc9867f359
commit
b99d10cba5
26
init.lua
26
init.lua
@ -2,7 +2,7 @@ local MP = core.get_modpath("banners") .. "/"
|
|||||||
dofile(MP .. "smartfs.lua")
|
dofile(MP .. "smartfs.lua")
|
||||||
|
|
||||||
banners = {
|
banners = {
|
||||||
version = 20241128.1419
|
version = 20241128.1507
|
||||||
}
|
}
|
||||||
|
|
||||||
banners.masks = {
|
banners.masks = {
|
||||||
@ -37,6 +37,9 @@ banners.masks = {
|
|||||||
-- memory bloat.
|
-- memory bloat.
|
||||||
banners.max_undo_levels = 256
|
banners.max_undo_levels = 256
|
||||||
|
|
||||||
|
-- cache of player histories
|
||||||
|
local histories = {}
|
||||||
|
|
||||||
banners.colors = {
|
banners.colors = {
|
||||||
"black", "cyan", "green", "white",
|
"black", "cyan", "green", "white",
|
||||||
"blue", "darkblue", "red", "yellow",
|
"blue", "darkblue", "red", "yellow",
|
||||||
@ -66,10 +69,16 @@ banners.creation_form_func = function(state)
|
|||||||
self:update_preview(transform_string)
|
self:update_preview(transform_string)
|
||||||
self:update_player_inv(transform_string)
|
self:update_player_inv(transform_string)
|
||||||
end
|
end
|
||||||
-- initialize with empty banner
|
if histories[state.player] then
|
||||||
state.banner = banners.Banner:new(nil)
|
-- initialize with saved history
|
||||||
state.banner:push_transform(banners.base_transform)
|
state.banner = histories[state.player]
|
||||||
state.current_color = "bg_white.png"
|
else
|
||||||
|
-- initialize with empty banner
|
||||||
|
state.banner = banners.Banner:new(nil)
|
||||||
|
state.banner:push_transform(banners.base_transform)
|
||||||
|
histories[state.player] = state.banner
|
||||||
|
end
|
||||||
|
state.current_color = state.banner.color
|
||||||
state:size(20, 10)
|
state:size(20, 10)
|
||||||
state:image(3, 0.4, 4, 2, "banner_preview", nil)
|
state:image(3, 0.4, 4, 2, "banner_preview", nil)
|
||||||
state:image(2.4, 0.8, 0.7, 0.7, "color_indicator", state.current_color)
|
state:image(2.4, 0.8, 0.7, 0.7, "color_indicator", state.current_color)
|
||||||
@ -96,6 +105,7 @@ banners.creation_form_func = function(state)
|
|||||||
b:click(function(self, state2)
|
b:click(function(self, state2)
|
||||||
state2.current_color = "bg_" .. self.name .. ".png"
|
state2.current_color = "bg_" .. self.name .. ".png"
|
||||||
state2:get("color_indicator"):setImage(state2.current_color)
|
state2:get("color_indicator"):setImage(state2.current_color)
|
||||||
|
state2.banner.color = state2.current_color
|
||||||
-- todo: update masks or something
|
-- todo: update masks or something
|
||||||
end)
|
end)
|
||||||
x = x + 1
|
x = x + 1
|
||||||
@ -134,7 +144,7 @@ banners.creation_form = smartfs.create("banners:banner_creation",
|
|||||||
banners.Banner = {}
|
banners.Banner = {}
|
||||||
|
|
||||||
function banners.Banner:new(banner)
|
function banners.Banner:new(banner)
|
||||||
banner = banner or { transforms = {} }
|
banner = banner or { color = "bg_black.png", transforms = {} }
|
||||||
setmetatable(banner, self)
|
setmetatable(banner, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
return banner
|
return banner
|
||||||
@ -261,6 +271,10 @@ core.register_entity("banners:banner_ent", {
|
|||||||
on_activate = banners.banner_on_activate,
|
on_activate = banners.banner_on_activate,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
core.register_on_leaveplayer(function(player)
|
||||||
|
histories[player:get_player_name()] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
if core.get_modpath("factions") then
|
if core.get_modpath("factions") then
|
||||||
dofile(MP .. "factions.lua")
|
dofile(MP .. "factions.lua")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user