BaseUI: Clearing the context is now an optional parameter & edit /list command. close #33

This commit is contained in:
Van
2026-03-02 19:54:22 +03:00
parent 1a6086190e
commit 692105abfa
3 changed files with 28 additions and 14 deletions

View File

@@ -10,18 +10,26 @@ local BaseUI = {
contex = {}
}
---@param name string
---@param name string The name of the formspec that will be shown to the player. It is recommended that the name be unique.
---@param getFormSpecString fun(self:BaseUI,playerName:string,...):string
function BaseUI:new(name, getFormSpecString)
---@param clearContex boolean? Whether to clear the context stored for a player when that player closes the form. Default `true`.
function BaseUI:new(name, getFormSpecString, clearContex)
if clearContex == nil then
clearContex = true
end
---@type BaseUI
local instance = getInstance(self, {})
instance.name = name
instance.getFormSpecString = getFormSpecString
-- Ensure that when the form is closed, the context is cleared.
instance:registerOnFormQuit(function(player)
instance:clearContex(player)
end)
if clearContex then
core.log(name)
-- Ensure that when the form is closed, the context is cleared.
instance:registerOnFormQuit(function(player)
instance:clearContex(player)
end)
end
return instance
end