code cleanup

instead of implementing __tostring, set __name
use variable name 'params' instead of 'o'
use 'self' for indicating instance instead of 'this'
move private members under self instead of params
set doc type of 'params' as the object created (helps IDE autocomplete)
This commit is contained in:
Hersi 2022-05-06 01:02:30 +02:00
parent be9a1f9408
commit e68fcd5bfe
28 changed files with 253 additions and 248 deletions

View File

@ -8,19 +8,21 @@ local exclusiveAudioSample = nil
---@field exclusive boolean
---@field loop boolean
---@field playing boolean
local AudioSample = {}
local AudioSample = {
__name = "AudioSample"
}
---Create new AudioSample instance
---@param o AudioSample
---@param params AudioSample
---@return AudioSample
function AudioSample.new(o)
assert(o.path, "AudioSample.new() did not receive path to audio sample")
o.exclusive = o.exclusive or false
o.loop = o.loop or false
function AudioSample.new(params)
assert(params.path, "AudioSample.new() did not receive path to audio sample")
params.exclusive = params.exclusive or false
params.loop = params.loop or false
game.LoadSkinSample(o.path)
game.LoadSkinSample(params.path)
return CreateInstance(AudioSample, o)
return CreateInstance(AudioSample, params)
end
function AudioSample:play()

View File

@ -4,24 +4,24 @@ local Field = require("api.page.field")
---@class ContainerField: Field
---@field content Field[]
local ContainerField = {
__tostring = function() return "ContainerField" end,
__name = "ContainerField"
}
---Create a new ContainerField instance
---@param o? table # initial parameters
---@param params? ContainerField # initial parameters
---@return ContainerField
function ContainerField.new(o)
o = o or {}
function ContainerField.new(params)
params = params or {}
--set instance members
o.content = o.content or {}
params.content = params.content or {}
local this = CreateInstance(ContainerField, o, Field)
local self = CreateInstance(ContainerField, params, Field)
this:refreshFields()
self:refreshFields()
return this
return self
end
---Add content to container

View File

@ -7,24 +7,24 @@ require("common.class")
---@field aabbW number
---@field aabbH number
local Field = {
__tostring = function() return "Field" end,
__name = "Field"
}
---Create a new Field instance
---@param o? table # initial parameters
---@param params? Field # initial parameters
---@return Field
function Field.new(o)
o = o or {}
function Field.new(params)
params = params or {}
--set instance members
o.parent = o.parent or nil
o.posX = o.posX or 0
o.posY = o.posY or 0
o.aabbW = o.aabbW or 0
o.aabbH = o.aabbH or 0
params.parent = params.parent or nil
params.posX = params.posX or 0
params.posY = params.posY or 0
params.aabbW = params.aabbW or 0
params.aabbH = params.aabbH or 0
return CreateInstance(Field, o)
return CreateInstance(Field, params)
end
---Get the containing top-level parent page

View File

@ -4,18 +4,18 @@ local Field = require("api.page.field")
---@class LinkField: Field
---@field link Page
local LinkField = {
__tostring = function() return "LinkField" end
__name = "LinkField"
}
---Create a new LinkField instance
---@param o? table # initial parameters
---@param params? LinkField # initial parameters
---@return LinkField
function LinkField.new(o)
o = o or {}
function LinkField.new(params)
params = params or {}
o.link = o.link or nil
params.link = params.link or nil
return CreateInstance(LinkField, o, Field)
return CreateInstance(LinkField, params, Field)
end
---@param button integer # options are under the `game` table prefixed with `BUTTON`

View File

@ -5,11 +5,11 @@ require("common.class")
---@field content Field[]
---@field viewHandler nil|PageView
local Page = {
__tostring = function() return "Page" end,
__name = "Page",
}
---Create a new Page instance
---@param params? table # initial parameters
---@param params? Page # initial parameters
---@return Page
function Page.new(params)
params = params or {}

View File

@ -3,7 +3,7 @@ require("common.class")
---@class PageView
---@field pageStack Page[]
local PageView = {
__tostring = function() return "PageView" end
__name = "PageView"
}
local function pushStack(t, o)
@ -17,7 +17,7 @@ end
---Create a new PageView instance
---@return PageView
function PageView.new()
local self = CreateInstance(PageView, {})
local self = CreateInstance(PageView)
self.pageStack = {}
return self
end

View File

@ -12,11 +12,11 @@ end
---Create polimorphic class
---@generic BaseT, T
---@param cls T # class metatable
---@param o? table # initial parameters
---@param params? table # initial parameters
---@param ... BaseT # base class metatables (if any)
---@return T # class instance
function CreateInstance(cls, o, ...)
o = o or {}
function CreateInstance(cls, params, ...)
params = params or {}
local nargs = select("#", ...)
local vargs = { select(1, ...) }
cls.__index = cls
@ -24,14 +24,14 @@ function CreateInstance(cls, o, ...)
-- single inheritance
local base = vargs[1]
setmetatable(cls, {__index = base})
o = base.new(o)
params = base.new(params)
elseif nargs > 1 then
-- multiple inheritance (note: slow(er) member lookup)
setmetatable(cls, {__index = function(t, k) return search(k, vargs) end})
for _, base in ipairs(vargs) do
o = base.new(o)
params = base.new(params)
end
end
setmetatable(o, cls)
return o
setmetatable(params, cls)
return params
end

View File

@ -8,26 +8,27 @@ local SplashScreen = require "titlescreen.splash"
---@class BootScreen : Screen
---@field bootpage BootPage
local BootScreen = {
__tostring = function() return "BootScreen" end
__name = "BootScreen"
}
---Create a new BootScreen instance
---@param o? BootScreen
---@param params? BootScreen
---@return BootScreen
function BootScreen.new(o)
o = o or {}
function BootScreen.new(params)
params = params or {}
o.bootpage = o.bootpage or BootPage.new()
params.bootpage = params.bootpage or BootPage.new()
return CreateInstance(BootScreen, o, Screen)
return CreateInstance(BootScreen, params, Screen)
end
function BootScreen:init()
Screen.init(self)
self.pageview:replace(self.bootpage)
end
function BootScreen:deactivate()
self.onDeactivation({reason = "deactivation", hint = tostring(SplashScreen)})
self.onDeactivation({reason = "deactivation", hint = SplashScreen.__name})
end
return BootScreen

View File

@ -6,27 +6,28 @@ local ServiceField = require("titlescreen.components.servicefield")
---@field onUpdateAvailable nil|fun(url: string, version: string)
---@field _timer number
local CheckUpdateField = {
__tostring = function() return "CheckUpdateField" end,
__name = "CheckUpdateField",
PROGRESS_FREQ = 3, -- seconds
CHECK_UPDATE_TIMEOUT = 5, -- seconds
}
---Create a new CheckUpdateField instance
---@param o? table # initial parameters
---@param params? CheckUpdateField # initial parameters
---@return CheckUpdateField
function CheckUpdateField.new(o)
o = o or {}
function CheckUpdateField.new(params)
params = params or {}
o._timer = o._timer or 0
o.onUpdateAvailable = o.onUpdateAvailable or nil
params.onUpdateAvailable = params.onUpdateAvailable or nil
local this = CreateInstance(CheckUpdateField, o, ServiceField)
local self = CreateInstance(CheckUpdateField, params, ServiceField)
this._url = nil
this._version = nil
this._onUpdateAvailableFired = false
self._timer = 0
return this
self._url = nil
self._version = nil
self._onUpdateAvailableFired = false
return self
end
function CheckUpdateField:drawLabel(deltaTime)

View File

@ -4,21 +4,21 @@ local ServiceField = require("titlescreen.components.servicefield")
---@class ColorGradientField: ServiceField
local ColorGradientField = {
__tostring = function() return "ColorGradientField" end,
__name = "ColorGradientField",
GRADIENT_X_OFFSET = 128,
GRADIENT_WIDTH = 576,
GRADIENT_STEPS = 32
}
---Create a new ColorGradientField instance
---@param o? table # initial parameters
---@param params? ColorGradientField # initial parameters
---@return ColorGradientField
function ColorGradientField.new(o)
o = o or {}
function ColorGradientField.new(params)
params = params or {}
o.value = o.value or {0, 0, 0, 255}
params.value = params.value or {0, 0, 0, 255}
return CreateInstance(ColorGradientField, o, ServiceField)
return CreateInstance(ColorGradientField, params, ServiceField)
end
---@param obj? any # message object for the field

View File

@ -5,7 +5,7 @@ local ContainerField = require("api.page.containerfield")
---@field _symbolMargin number
---@field _symbolSize number
local DialogField = {
__tostring = function() return "ContainerField" end,
__name = "ContainerField",
BGCOLOR = {0, 0, 0, 255}, --{r, g, b, a}
DEFAULT_WIDTH = 400,
DEFAULT_HEIGHT = 200,
@ -35,20 +35,20 @@ local DialogField = {
---Create a new DialogField instance
---
---Inherits from ContainerField
---@param o ContainerField
---@param params? DialogField # initial parameters
---@return DialogField
function DialogField.new(o)
o = o or {}
function DialogField.new(params)
params = params or {}
o.aabbW = o.aabbW or DialogField.DEFAULT_WIDTH
o.aabbH = o.aabbH or DialogField.DEFAULT_HEIGHT
params.aabbW = params.aabbW or DialogField.DEFAULT_WIDTH
params.aabbH = params.aabbH or DialogField.DEFAULT_HEIGHT
local this = CreateInstance(DialogField, o, ContainerField)
local self = CreateInstance(DialogField, params, ContainerField)
this._symbolMargin = 8
this._symbolSize = 48
self._symbolMargin = 8
self._symbolSize = 48
return this
return self
end
---Draw the dialog symbol

View File

@ -4,18 +4,18 @@ local ServiceField = require("titlescreen.components.servicefield")
---@class InputButtonField: ServiceField
---@field button integer
local InputButtonField = {
__tostring = function() return "InputButtonField" end,
__name = "InputButtonField"
}
---Create a new InputButtonField instance
---@param o? table # initial parameters
---@param params? InputButtonField # initial parameters
---@return InputButtonField
function InputButtonField.new(o)
o = o or {}
function InputButtonField.new(params)
params = params or {}
o.button = o.button or nil
params.button = params.button or nil
return CreateInstance(InputButtonField, o, ServiceField)
return CreateInstance(InputButtonField, params, ServiceField)
end
---@param obj? any # message object for the field

View File

@ -5,7 +5,7 @@ local ServiceField = require("titlescreen.components.servicefield")
---@class InputKnobField: ServiceField
---@field knob integer
local InputKnobField = {
__tostring = function() return "InputKnobField" end,
__name = "InputKnobField",
SLIDER_SIZE = {200, 16}, --{w, h}
SLIDER_BGCOLOR = {255, 0, 0, 255},
SLIDER_FRAME_COLOR = ServiceField.FONT_COLOR,
@ -16,14 +16,14 @@ local InputKnobField = {
}
---Create a new InputKnobField instance
---@param o? table # initial parameters
---@param params? InputKnobField # initial parameters
---@return InputKnobField
function InputKnobField.new(o)
o = o or {}
function InputKnobField.new(params)
params = params or {}
o.knob = o.knob or nil
params.knob = params.knob or nil
return CreateInstance(InputKnobField, o, ServiceField)
return CreateInstance(InputKnobField, params, ServiceField)
end
---@param obj? any # message object for the field

View File

@ -7,29 +7,29 @@ local ServiceField = require("titlescreen.components.servicefield")
---@field locked boolean
---@field PADDING number[]
local ListField = {
__tostring = function() return "ListField" end,
__name = "ListField",
MARGIN = {0, 0, 0, 0}, --{left, top, right, bottom}
PADDING = {0, 0, 0, 0}, --{left, top, right, bottom}
}
---Create a new ListField instance
---@param o? table # initial parameters
---@param params? ListField # initial parameters
---@return ListField
function ListField.new(o)
o = o or {}
function ListField.new(params)
params = params or {}
--set instance members
o.selectedIndex = o.selectedIndex or 1
o.locked = o.locked or false
params.selectedIndex = params.selectedIndex or 1
params.locked = params.locked or false
local this = CreateInstance(ListField, o, ContainerField, ServiceField)
local self = CreateInstance(ListField, params, ContainerField, ServiceField)
local minW = this.MARGIN[1] + this.PADDING[1] + this.PADDING[3] + this.MARGIN[3]
local minH = this.MARGIN[2] + this.PADDING[2] + this.PADDING[4] + this.MARGIN[4]
this.aabbW = math.max(this.aabbW, minW)
this.aabbH = math.max(this.aabbH, minH)
local minW = self.MARGIN[1] + self.PADDING[1] + self.PADDING[3] + self.MARGIN[3]
local minH = self.MARGIN[2] + self.PADDING[2] + self.PADDING[4] + self.MARGIN[4]
self.aabbW = math.max(self.aabbW, minW)
self.aabbH = math.max(self.aabbH, minH)
return this
return self
end
---@param obj? any # message object for the field

View File

@ -23,7 +23,7 @@ end
---@field _thread thread
---@field _timer number
local SelfTestField = {
__tostring = function () return "SelfTestField" end,
__name = "SelfTestField",
COLOR_INPROGRESS = {255, 255, 255, 255},
COLOR_OK = {0, 255, 0, 255},
COLOR_PASS = {255, 255, 0, 255},
@ -32,20 +32,23 @@ local SelfTestField = {
}
---Create a new SelfTestField instance
---@param o? table
---@param params? SelfTestField
---@return SelfTestField
function SelfTestField.new(o)
o = o or {}
function SelfTestField.new(params)
params = params or {}
o.status = o.status or SelfTestStatusEnum.IDLE
o._timer = 0
o._thread = nil
params.status = params.status or SelfTestStatusEnum.IDLE
assert((not o.onStatusChange) or (o.checkTask and o.onStatusChange),
assert((not params.onStatusChange) or (params.checkTask and params.onStatusChange),
"Failed to construct SelfTestField, checkTask is mandatory when onStatusChange is defined!\n" .. debug.traceback()
)
return CreateInstance(SelfTestField, o, ServiceField)
local self = CreateInstance(SelfTestField, params, ServiceField)
self._timer = 0
self._thread = nil
return self
end
function SelfTestField:_closeThread()

View File

@ -22,7 +22,7 @@ ServiceFieldState = {
---@field MARGIN number[] # {left, top, right, bottom}
---@field VALUE_OFFSETX number
local ServiceField = {
__tostring = function() return "ServiceField" end,
__name = "ServiceField",
FONT_SIZE = 24,
FONT_FACE = "dfmarugoth.ttf",
FONT_COLOR = {255, 255, 255, 255},
@ -33,29 +33,29 @@ local ServiceField = {
}
---Create a new ServiceField instance
---@param o? table # initial parameters
---@param params? ServiceField # initial parameters
---@return ServiceField
function ServiceField.new(o)
o = o or {}
function ServiceField.new(params)
params = params or {}
local h = ServiceField.FONT_SIZE + ServiceField.MARGIN[2] + ServiceField.MARGIN[4]
o.aabbH = o.aabbH or h
o.aabbW = o.aabbW or Dim.design.width --:shrug:
params.aabbH = params.aabbH or h
params.aabbW = params.aabbW or Dim.design.width --:shrug:
o.label = o.label or "<UNDEFINED>"
o.value = o.value or nil
o.footer = o.footer or nil
params.label = params.label or "<UNDEFINED>"
params.value = params.value or nil
params.footer = params.footer or nil
o._state = ServiceFieldState.INACTIVE
local self = CreateInstance(ServiceField, params, Field)
local this = CreateInstance(ServiceField, o, Field)
self._state = ServiceFieldState.INACTIVE
if this.aabbH < h then
this.aabbH = h
if self.aabbH < h then
self.aabbH = h
end
return this
return self
end
---@param obj? any # message object for the field

View File

@ -4,16 +4,16 @@ local ServiceField = require("titlescreen.components.servicefield")
---@class ServiceLinkField: LinkField, ServiceField
local ServiceLinkField = {
__tostring = function() return "ServiceLinkField" end,
__name = "ServiceLinkField",
}
---Create a new ServiceLinkField instance
---@param o? table # initial parameters
---@param params? ServiceLinkField # initial parameters
---@return ServiceLinkField
function ServiceLinkField.new(o)
o = o or {}
function ServiceLinkField.new(params)
params = params or {}
return CreateInstance(ServiceLinkField, o, ServiceField, LinkField)
return CreateInstance(ServiceLinkField, params, ServiceField, LinkField)
end
---@param deltaTime number # frametime in seconds

View File

@ -4,7 +4,7 @@ local ServiceField = require("titlescreen.components.servicefield")
---@class UpdateField: ServiceField
---@field _timer number
local UpdateField = {
__tostring = function() return "UpdateField" end,
__name = "UpdateField",
UPDATE_FLICKER_TIME = 0.5,
UPDATE_FLICKER_COLORS = {
{255, 0, 0, 255},
@ -13,14 +13,16 @@ local UpdateField = {
}
---Create a new UpdateField instance
---@param o? table # initial parameters
---@param params? UpdateField # initial parameters
---@return UpdateField
function UpdateField.new(o)
o = o or {}
function UpdateField.new(params)
params = params or {}
o._timer = 0
local self = CreateInstance(UpdateField, params, ServiceField)
return CreateInstance(UpdateField, o, ServiceField)
self._timer = 0
return self
end
---@param obj? any # message object for the field

View File

@ -10,50 +10,50 @@ local SelfTestField = require("titlescreen.components.selftestfield")
---@class BootPage: Page
local BootPage = {
__tostring = function() return "BootPage" end,
__name = "BootPage",
}
---Create a new BootPage instance
---@param o? table # initial parameters
---@param params? BootPage # initial parameters
---@return BootPage
function BootPage.new(o)
o = o or {}
function BootPage.new(params)
params = params or {}
local this = CreateInstance(BootPage, o, Page)
local self = CreateInstance(BootPage, params, Page)
this._networkResult = {}
self._networkResult = {}
this:addField(ServiceField.new{posX = 32, posY = 32, label = Version.getLongVersion(), value = ""})
this:addField(ServiceField.new{posX = 64, posY = 64, label = "UNNAMED SDVX CLONE STARTUP...", value = ""})
self:addField(ServiceField.new{posX = 32, posY = 32, label = Version.getLongVersion(), value = ""})
self:addField(ServiceField.new{posX = 64, posY = 64, label = "UNNAMED SDVX CLONE STARTUP...", value = ""})
local valueOffX = 220
this._mainIoTestField = SelfTestField.new{label = "MAIN I/O", VALUE_OFFSETX = valueOffX}
this._mainIoTestField.checkTask = function(obj)
self._mainIoTestField = SelfTestField.new{label = "MAIN I/O", VALUE_OFFSETX = valueOffX}
self._mainIoTestField.checkTask = function(obj)
return SelfTestStatusEnum.OK
end
this._mainIoTestField.onStatusChange = function(status)
self._mainIoTestField.onStatusChange = function(status)
if status == SelfTestStatusEnum.OK then
this._skinConfigTestField:activate()
self._skinConfigTestField:activate()
end
end
this._skinConfigTestField = SelfTestField.new{label = "SKIN CONFIG", VALUE_OFFSETX = valueOffX}
this._skinConfigTestField.checkTask = function(obj)
self._skinConfigTestField = SelfTestField.new{label = "SKIN CONFIG", VALUE_OFFSETX = valueOffX}
self._skinConfigTestField.checkTask = function(obj)
local crewpath = "skins/" .. game.GetSkin() .. "/textures/crew/anim/" .. game.GetSkinSetting("single_idol")
if not IsDir(crewpath) then
return SelfTestStatusEnum.ERROR
end
return SelfTestStatusEnum.OK
end
this._skinConfigTestField.onStatusChange = function(status)
self._skinConfigTestField.onStatusChange = function(status)
if status == SelfTestStatusEnum.OK then
this._networkTestField:activate()
self._networkTestField:activate()
end
end
this._networkTestField = SelfTestField.new{label = "NETWORK", VALUE_OFFSETX = valueOffX}
self._networkTestField = SelfTestField.new{label = "NETWORK", VALUE_OFFSETX = valueOffX}
-- set up async network check
this._networkTestField.checkTask = function(obj)
self._networkTestField.checkTask = function(obj)
local status = SelfTestStatusEnum.INPROGRESS
if not IRData.Active then
@ -61,9 +61,9 @@ function BootPage.new(o)
end
while status == SelfTestStatusEnum.INPROGRESS do
if this._networkResult.statusCode == IRData.States.Success then
if self._networkResult.statusCode == IRData.States.Success then
status = SelfTestStatusEnum.OK
elseif this._networkResult.statusCode then
elseif self._networkResult.statusCode then
status = SelfTestStatusEnum.ERROR -- there's a response, but it's not success
end
@ -72,23 +72,23 @@ function BootPage.new(o)
return status
end
this._networkTestField.onStatusChange = function(status)
self._networkTestField.onStatusChange = function(status)
if status == SelfTestStatusEnum.INPROGRESS then
IR.Heartbeat(function(res) this._networkResult = res end) -- IR doesn't like being called in a coroutine
IR.Heartbeat(function(res) self._networkResult = res end) -- IR doesn't like being called in a coroutine
elseif status == SelfTestStatusEnum.PASS or status == SelfTestStatusEnum.OK then
if this.viewHandler then
this.viewHandler:navigate(CheckUpdatePage.new())
if self.viewHandler then
self.viewHandler:navigate(CheckUpdatePage.new())
end
end
end
local list = ListField.new{posX = 64, posY = 96}
list:addField(this._mainIoTestField)
list:addField(this._skinConfigTestField)
list:addField(this._networkTestField)
this:addField(list)
list:addField(self._mainIoTestField)
list:addField(self._skinConfigTestField)
list:addField(self._networkTestField)
self:addField(list)
return this
return self
end
---@param deltaTime number # frametime in seconds

View File

@ -7,20 +7,20 @@ local DialogField = require("titlescreen.components.dialogfield")
---@class CheckUpdatePage: Page
---@field _focusedField CheckUpdateField
local CheckUpdatePage = {
__tostring = function() return "CheckUpdatePage" end,
__name = "CheckUpdatePage",
}
---Create a new CheckUpdatePage instance
---@param o? table # initial parameters
---@param params? CheckUpdatePage # initial parameters
---@return CheckUpdatePage
function CheckUpdatePage.new(o)
local this = CreateInstance(CheckUpdatePage, o, Page)
function CheckUpdatePage.new(params)
local self = CreateInstance(CheckUpdatePage, params, Page)
local width = DialogField.DEFAULT_WIDTH
local height = DialogField.DEFAULT_HEIGHT
local posX = (Dim.design.width - width) / 2
local posY = (Dim.design.height - height) / 2
this._updateDialogField = DialogField.new{
self._updateDialogField = DialogField.new{
posX = posX,
posY = posY,
aabbW = width,
@ -44,37 +44,37 @@ function CheckUpdatePage.new(o)
}
}
}
this._updateDialogField.handleButtonInput = function (self, button)
if not this.viewHandler then
self._updateDialogField.handleButtonInput = function (_, button)
if not self.viewHandler then
return false
end
if button == game.BUTTON_BCK then
this.viewHandler:clear() -- Cancel update, close screen
self.viewHandler:clear() -- Cancel update, close screen
return true
elseif button == game.BUTTON_STA then
-- NOTE: this is a huge ass hack, please rethink
local MainMenuPage = require("titlescreen.pages.service.mainmenupage")
local VersionInfoPage = require("titlescreen.pages.service.versioninfopage")
this.viewHandler:replace(MainMenuPage.new())
this.viewHandler:navigate(VersionInfoPage.new())
self.viewHandler:replace(MainMenuPage.new())
self.viewHandler:navigate(VersionInfoPage.new())
return true
end
return false
end
this._checkUpdateField = CheckUpdateField.new{posX = 32, posY = 64, label = "update check"}
this._checkUpdateField.onUpdateAvailable = function(url, version)
this:addField(this._updateDialogField)
this._focusedField = this._updateDialogField
self._checkUpdateField = CheckUpdateField.new{posX = 32, posY = 64, label = "update check"}
self._checkUpdateField.onUpdateAvailable = function(url, version)
self:addField(self._updateDialogField)
self._focusedField = self._updateDialogField
end
this:addField(this._checkUpdateField)
self:addField(self._checkUpdateField)
this._focusedField = this._checkUpdateField
self._focusedField = self._checkUpdateField
return this
return self
end
function CheckUpdatePage:handleButtonInput(button)

View File

@ -14,7 +14,7 @@ local crew = game.GetSkinSetting("single_idol")
---@class ModeSelectPage: Page
---@field _idolAnimationState AnimationState
local ModeSelectPage = {
__tostring = function () return "ModeSelectPage" end,
__name = "ModeSelectPage",
images = {
selectorBgImage = gfx.CreateSkinImage("titlescreen/selector_bg.png", 0),
selectorArrowsImage = gfx.CreateSkinImage("titlescreen/selector_arrows.png", 0),
@ -41,8 +41,8 @@ local ModeSelectPage = {
}
}
function ModeSelectPage.new(o)
local self = CreateInstance(ModeSelectPage, o, Page)
function ModeSelectPage.new(params)
local self = CreateInstance(ModeSelectPage, params, Page)
return self
end

View File

@ -5,7 +5,7 @@ local ColorGradientField = require("titlescreen.components.colorgradientfield")
---@class ColorCheckPage: ServicePage
local ColorCheckPage = {
__tostring = function() return "ColorCheckPage" end,
__name = "ColorCheckPage",
PADDING = {56, 120, 0, 56}, --{left, top, right, bottom}
@ -19,18 +19,18 @@ local ColorCheckPage = {
}
---Create a new ColorCheckPage instance
---@param o? table # initial parameters
---@param params? ColorCheckPage # initial parameters
---@return ColorCheckPage
function ColorCheckPage.new(o)
o = o or {}
function ColorCheckPage.new(params)
params = params or {}
o.title = o.title or "COLOR CHECK"
o.footer = o.footer or {
params.title = params.title or "COLOR CHECK"
params.footer = params.footer or {
"START BUTTON = EXIT",
"BACK BUTTON = EXIT"
}
local this = CreateInstance(ColorCheckPage, o, ServicePage)
local self = CreateInstance(ColorCheckPage, params, ServicePage)
local height = ColorCheckPage.GRADIENT_SPACING
local list = ListField.new()
@ -43,10 +43,10 @@ function ColorCheckPage.new(o)
list:addField(ColorGradientField.new{label = "WHITE", value = {255, 255, 255, 255}, aabbH = height})
list:refreshFields()
this:addField(list)
this:refreshFields()
self:addField(list)
self:refreshFields()
return this
return self
end
---@param button integer # options are under the `game` table prefixed with `BUTTON`

View File

@ -6,19 +6,19 @@ local ListField = require("titlescreen.components.listfield")
---@class InputCheckPage: ServicePage
local InputCheckPage = {
__tostring = function() return "InputCheckPage" end,
__name = "InputCheckPage",
}
---Create a new InputCheckPage instance
---@param o? table # initial parameters
---@param params? InputCheckPage # initial parameters
---@return InputCheckPage
function InputCheckPage.new(o)
o = o or {}
function InputCheckPage.new(params)
params = params or {}
o.title = o.title or "INPUT CHECK"
o.footer = o.footer or "BACK BUTTON = EXIT"
params.title = params.title or "INPUT CHECK"
params.footer = params.footer or "BACK BUTTON = EXIT"
local this = CreateInstance(InputCheckPage, o, ServicePage)
local self = CreateInstance(InputCheckPage, params, ServicePage)
local list = ListField.new()
list:addField(InputButtonField.new{label="START BUTTON", button=game.BUTTON_STA})
@ -32,10 +32,10 @@ function InputCheckPage.new(o)
list:addField(InputKnobField.new{label="ANALOG VOLUME R", knob=1})
list:refreshFields()
this:addField(list)
this:refreshFields()
self:addField(list)
self:refreshFields()
return this
return self
end
---@param button integer # options are under the `game` table prefixed with `BUTTON`

View File

@ -9,18 +9,18 @@ local ListField = require("titlescreen.components.listfield")
---@class MainMenuPage: ServicePage
local MainMenuPage = {
__tostring = function() return "MainMenuPage" end,
__name = "MainMenuPage",
}
---Create a new MainMenuPage instance
---@param o? table # initial parameters
---@param params? MainMenuPage # initial parameters
---@return MainMenuPage
function MainMenuPage.new(o)
o = o or {}
function MainMenuPage.new(params)
params = params or {}
o.title = o.title or "MAIN MENU"
params.title = params.title or "MAIN MENU"
local this = CreateInstance(MainMenuPage, o, ServicePage)
local self = CreateInstance(MainMenuPage, params, ServicePage)
local list = ListField.new()
list:addField(ServiceLinkField.new{label = "INPUT CHECK", link = InputCheckPage.new()})
@ -29,10 +29,10 @@ function MainMenuPage.new(o)
list:addField(ServiceLinkField.new{label = "VERSION INFORMATION", link = VersionInfoPage.new()})
list:refreshFields()
this:addField(list)
this:refreshFields()
self:addField(list)
self:refreshFields()
return this
return self
end
return MainMenuPage

View File

@ -4,7 +4,7 @@ local ServicePage = require("titlescreen.pages.service.servicepage")
---@class ScreenCheckPage: ServicePage
local ScreenCheckPage = {
__tostring = function() return "ScreenCheckPage" end,
__name = "ScreenCheckPage",
BG_COLOR = {255, 255, 255, 255},
STROKE_COLOR = {255, 0, 0, 255},
@ -17,18 +17,18 @@ local ScreenCheckPage = {
}
---Create a new ScreenCheckPage instance
---@param o? table # initial parameters
---@param params? ScreenCheckPage # initial parameters
---@return ScreenCheckPage
function ScreenCheckPage.new(o)
o = o or {}
function ScreenCheckPage.new(params)
params = params or {}
o.title = o.title or "SCREEN CHECK"
o.footer = o.footer or {
params.title = params.title or "SCREEN CHECK"
params.footer = params.footer or {
"START BUTTON = EXIT",
"BACK BUTTON = EXIT"
}
return CreateInstance(ScreenCheckPage, o, ServicePage)
return CreateInstance(ScreenCheckPage, params, ServicePage)
end
---@param button integer # options are under the `game` table prefixed with `BUTTON`

View File

@ -17,7 +17,7 @@ local ServiceField = require("titlescreen.components.servicefield")
---@field FOOTER string|string[]
---@field FOOTER_SPACING number
local ServicePage = {
__tostring = function() return "ServicePage" end,
__name = "ServicePage",
FONT_SIZE = ServiceField.FONT_SIZE,
FONT_FACE = ServiceField.FONT_FACE,
FONT_COLOR = ServiceField.FONT_COLOR, --{r, g, b, a}
@ -34,16 +34,16 @@ local ServicePage = {
}
---Create a new ServicePage instance
---@param o? table # initial parameters
---@param params? ServicePage # initial parameters
---@return ServicePage
function ServicePage.new(o)
o = o or {}
function ServicePage.new(params)
params = params or {}
o.title = o.title or ""
o.selectedIndex = o.selectedIndex or 1
o.footer = o.footer or ServicePage.FOOTER
params.title = params.title or ""
params.selectedIndex = params.selectedIndex or 1
params.footer = params.footer or ServicePage.FOOTER
return CreateInstance(ServicePage, o, Page)
return CreateInstance(ServicePage, params, Page)
end
---Refresh content values

View File

@ -14,23 +14,23 @@ end
---@class VersionInfoPage: ServicePage
local VersionInfoPage = {
__tostring = function() return "VersionInfoPage" end,
__name = "VersionInfoPage",
}
---Create a new VersionInfoPage instance
---@param o? table # initial parameters
---@param params? VersionInfoPage # initial parameters
---@return VersionInfoPage
function VersionInfoPage.new(o)
o = o or {}
function VersionInfoPage.new(params)
params = params or {}
o.title = o.title or "SYSTEM INFORMATION"
o.footer = o.footer or {
params.title = params.title or "SYSTEM INFORMATION"
params.footer = params.footer or {
"START BUTTON = UPDATE",
"BACK BUTTON = EXIT"
}
o.selectedIndex = o.selectedIndex or 1
params.selectedIndex = params.selectedIndex or 1
local this = CreateInstance(VersionInfoPage, o, ServicePage)
local self = CreateInstance(VersionInfoPage, params, ServicePage)
local logStr = ReadGameFile("log_usc-game.exe.txt") or ReadGameFile("log_usc-game.txt")
@ -45,10 +45,10 @@ function VersionInfoPage.new(o)
list:addField(ServiceField.new{label = "GL VENDOR", value = getGameLogValue("OpenGL Vendor", logStr)})
list:refreshFields()
this:addField(list)
this:refreshFields()
self:addField(list)
self:refreshFields()
return this
return self
end
---@param button integer # options are under the `game` table prefixed with `BUTTON`

View File

@ -6,19 +6,19 @@ local PageView = require "api.page.pageview"
---@class Screen
---@field pageview PageView
local Screen = {
__tostring = function() return "Screen" end
__name = "Screen"
}
---Create a new Screen instance
---@param o? Screen
---@param params? Screen
---@return Screen
function Screen.new(o)
local self = CreateInstance(Screen, o)
function Screen.new(params)
local self = CreateInstance(Screen, params)
self.pageview = PageView.new()
return self
end
---Initialize screen, override to push new page into pageview
---Initialize screen
function Screen:init()
end
@ -63,10 +63,6 @@ end
---@param deltaTime number # frametime in seconds
function Screen:render(deltaTime)
if not self.pageview:get() then
self:deactivate()
end
self.pageview:render(deltaTime)
end