CraftSystem: first working version #31

Merged
varttist merged 27 commits from craft-system into main 2026-02-18 19:30:39 +00:00
Showing only changes of commit c70bf96734 - Show all commits

View File

@@ -3,17 +3,20 @@ local getInstance = Class.getInstance
---@class BaseUI
---Context for transferring data between displaying
---the form spec to the player and handling callbacks.
---@field name string
---@field contex table<string, table>
---@field name string
---@field getFormSpecString fun(self:BaseUI,playerName:string,...):string
---@field contex table<string, table>
local BaseUI = {
contex = {}
}
---@param name string
function BaseUI:new(name)
---@param name string
---@param getFormSpecString fun(self:BaseUI,playerName:string,...):string
function BaseUI:new(name, getFormSpecString)
---@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)
@@ -103,4 +106,17 @@ function BaseUI:registerOnFormFieldActionMatch( fieldNamePattern, callback)
Smc.registerOnFormFieldActionMatch(self.name, fieldNamePattern, callback)
end
---Shows the player the FormSpec registered by the instance of this UI.
---@param playerName string
function BaseUI:showForm(playerName, ...)
core.show_formspec(playerName, self.name, self:getFormSpecString(playerName, ...))
end
---Close the player the FormSpec registered by the instance of this UI.
---@param playerName string
function BaseUI:closeForm(playerName)
core.close_formspec(playerName, self.name)
end
return BaseUI