2022-04-24 01:39:48 +02:00
|
|
|
require("common.class")
|
|
|
|
local Util = require("common.util")
|
2022-06-29 00:35:52 +02:00
|
|
|
local ServiceField = require("api.page.servicefield")
|
2022-04-24 01:39:48 +02:00
|
|
|
|
|
|
|
---@class CheckUpdateField: ServiceField
|
|
|
|
---@field onUpdateAvailable nil|fun(url: string, version: string)
|
|
|
|
---@field _timer number
|
|
|
|
local CheckUpdateField = {
|
2022-05-06 01:02:30 +02:00
|
|
|
__name = "CheckUpdateField",
|
2022-05-04 03:29:29 +02:00
|
|
|
PROGRESS_FREQ = 3, -- seconds
|
2022-04-24 15:07:52 +02:00
|
|
|
CHECK_UPDATE_TIMEOUT = 5, -- seconds
|
2022-04-24 01:39:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
---Create a new CheckUpdateField instance
|
2022-05-06 01:02:30 +02:00
|
|
|
---@param params? CheckUpdateField # initial parameters
|
2022-04-24 01:39:48 +02:00
|
|
|
---@return CheckUpdateField
|
2022-05-06 01:02:30 +02:00
|
|
|
function CheckUpdateField.new(params)
|
|
|
|
params = params or {}
|
2022-04-24 01:39:48 +02:00
|
|
|
|
2022-05-06 01:02:30 +02:00
|
|
|
params.onUpdateAvailable = params.onUpdateAvailable or nil
|
2022-04-24 01:39:48 +02:00
|
|
|
|
2022-05-06 01:02:30 +02:00
|
|
|
local self = CreateInstance(CheckUpdateField, params, ServiceField)
|
2022-04-24 01:39:48 +02:00
|
|
|
|
2022-05-06 01:02:30 +02:00
|
|
|
self._timer = 0
|
2022-04-24 01:39:48 +02:00
|
|
|
|
2022-05-06 01:02:30 +02:00
|
|
|
self._url = nil
|
|
|
|
self._version = nil
|
|
|
|
self._onUpdateAvailableFired = false
|
|
|
|
|
|
|
|
return self
|
2022-04-24 01:39:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function CheckUpdateField:drawLabel(deltaTime)
|
|
|
|
local text = self.label
|
|
|
|
local progress = math.ceil(Util.lerp(self._timer % self.PROGRESS_FREQ,
|
|
|
|
0, 0, self.PROGRESS_FREQ, 4
|
|
|
|
))
|
|
|
|
text = text .. string.rep(".", progress)
|
|
|
|
|
|
|
|
gfx.FontSize(self.FONT_SIZE)
|
|
|
|
gfx.LoadSkinFont(self.FONT_FACE)
|
|
|
|
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT | gfx.TEXT_ALIGN_TOP)
|
|
|
|
gfx.FillColor(table.unpack(self.FONT_COLOR))
|
|
|
|
gfx.Text(text, 0, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CheckUpdateField:drawValue(deltaTime)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function CheckUpdateField:tick(deltaTime)
|
2022-04-24 15:07:52 +02:00
|
|
|
if not self._onUpdateAvailableFired then
|
|
|
|
if self._timer > self.CHECK_UPDATE_TIMEOUT then
|
|
|
|
self._url, self._version = game.UpdateAvailable()
|
|
|
|
-- self._url = "" -- debug code to force onUpdateAvailable()
|
|
|
|
if self._url then
|
|
|
|
self.onUpdateAvailable(self._url, self._version)
|
|
|
|
self._onUpdateAvailableFired = true
|
|
|
|
else
|
2022-06-29 00:35:52 +02:00
|
|
|
self:getParentPage():onInvalidation() -- Exit out of bootscreen
|
2022-04-24 15:07:52 +02:00
|
|
|
end
|
2022-04-24 01:39:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
self._timer = self._timer + deltaTime
|
|
|
|
end
|
|
|
|
|
|
|
|
function CheckUpdateField:render(deltaTime)
|
|
|
|
self:tick(deltaTime)
|
|
|
|
ServiceField.render(self, deltaTime)
|
|
|
|
end
|
|
|
|
|
|
|
|
return CheckUpdateField
|