ExperimentalGear/scripts/titlescreen/boot.lua

122 lines
4.0 KiB
Lua

require "common.globals"
require "common.class"
require "common.filereader"
local Display = require "scripts.graphics.display"
local Version = require "common.version"
local PageRegistry = require "api.page.pageregistry"
local Page = require "api.page.page"
local CheckUpdatePage = require "titlescreen.boot.checkupdatepage"
local ServiceField = require "api.page.servicefield"
local ListField = require "titlescreen.common.listfield"
local SelfTestField = require "titlescreen.boot.selftestfield"
---@class BootPage: Page
local BootPage = {
__name = "BootPage",
}
---Create a new BootPage instance
---@param params? BootPage # initial parameters
---@return BootPage
function BootPage.new(params)
params = params or {}
local self = CreateInstance(BootPage, params, Page)
local checkUpdatePage = PageRegistry:getOrCreatePage(CheckUpdatePage)
self._networkResult = {}
checkUpdatePage.onInvalidation = function (page_self, reason)
self:onInvalidation(reason)
end
self:addField(ServiceField.new{posX = 32, posY = 32, label = Version.long_version(), value = ""})
self:addField(ServiceField.new{posX = 64, posY = 64, label = "UNNAMED SDVX CLONE STARTUP...", value = ""})
local valueOffX = 220
self._mainIoTestField = SelfTestField.new{label = "MAIN I/O", VALUE_OFFSETX = valueOffX}
self._mainIoTestField.checkTask = function(obj)
return SelfTestStatus.OK
end
self._mainIoTestField.onStatusChange = function(_, status)
if status == SelfTestStatus.OK then
self._skinConfigTestField:activate()
end
end
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 SelfTestStatus.ERROR
end
return SelfTestStatus.OK
end
self._skinConfigTestField.onStatusChange = function(_, status)
if status == SelfTestStatus.OK then
self._networkTestField:activate()
end
end
self._networkTestField = SelfTestField.new{label = "NETWORK", VALUE_OFFSETX = valueOffX}
-- set up async network check
self._networkTestField.checkTask = function(obj)
local status = SelfTestStatus.INPROGRESS
if not IRData.Active then
return SelfTestStatus.PASS
end
while status == SelfTestStatus.INPROGRESS do
if self._networkResult.statusCode == IRData.States.Success then
status = SelfTestStatus.OK
elseif self._networkResult.statusCode then
status = SelfTestStatus.ERROR -- there's a response, but it's not success
end
coroutine.yield(status)
end
return status
end
self._networkTestField.onStatusChange = function(_, status)
if status == SelfTestStatus.INPROGRESS then
IR.Heartbeat(function(res) self._networkResult = res end) -- IR doesn't like being called in a coroutine
elseif status == SelfTestStatus.PASS or status == SelfTestStatus.OK then
if self.viewHandler then
self.viewHandler:navigate(checkUpdatePage)
self.viewHandler:get():init()
end
end
end
self._mainIoTestField:init()
self._skinConfigTestField:init()
self._networkTestField:init()
local list = ListField.new{posX = 64, posY = 96}
list:addField(self._mainIoTestField)
list:addField(self._skinConfigTestField)
list:addField(self._networkTestField)
self:addField(list)
return self
end
function BootPage:init()
self._mainIoTestField:activate()
end
---@param deltaTime number # frametime in seconds
function BootPage:drawBackground(deltaTime)
gfx.BeginPath()
gfx.FillColor(0, 0, 0)
gfx.Rect(0, 0, Display.design.width, Display.design.height)
gfx.Fill()
end
return BootPage