Add Tutorial Text API

This commit is contained in:
2026-03-10 19:12:38 -05:00
parent 5609738464
commit 487a5259fb
4 changed files with 302 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
require("GameManager/ColorStruct")
---Represents a single text entry in a tutorial text view.
---@class TutorialTextEntry
---@field Key string The unique key for this entry.
---@field Text string The display text.
---@field Duration number Duration in seconds, or -1 for infinite.
---@field Color ColorStruct The text color.
---Represents a named set of tutorial text entries.
---@class TutorialTextView
---@field Name string The view name.
---@field Entries table<string, TutorialTextEntry> Entries keyed by their text key.
---@field IsActive boolean Whether this view is currently being displayed.
TutorialTextView = {}
TutorialTextView.__index = TutorialTextView
---Creates a new Tutorial Text View.
---@param name string The view name.
---@return TutorialTextView
function TutorialTextView:New(name)
local self = setmetatable({}, TutorialTextView)
self.Name = name
self.Entries = {}
self.IsActive = false
return self
end
---Sets or updates a text entry in this view.
---@param key string The unique key for this entry.
---@param text string The display text.
---@param duration number|nil Duration in seconds, defaults to -1 (infinite).
---@param color ColorStruct|nil The text color, defaults to white.
function TutorialTextView:SetEntry(key, text, duration, color)
self.Entries[key] = {
Key = key,
Text = text,
Duration = duration or -1,
Color = color or ColorStruct:New(1, 1, 1, 1),
}
end
---Removes a text entry from this view.
---@param key string The key to remove.
function TutorialTextView:RemoveEntry(key)
self.Entries[key] = nil
end
---Removes all entries from this view.
function TutorialTextView:Clear()
self.Entries = {}
end
function TutorialTextView:Debug()
local count = 0
for _ in pairs(self.Entries) do count = count + 1 end
return string.format("TutorialTextView '%s' (%d entries)", self.Name, count)
end