2022-03-04 04:06:19 +01:00
|
|
|
local Common = require("common.util")
|
|
|
|
|
|
|
|
local splashScreen = require('titlescreen.splash')
|
|
|
|
local titleScreen = require('titlescreen.title')
|
|
|
|
local modeSelectScreen = require('titlescreen.mode_select')
|
|
|
|
local serviceScreen = require('titlescreen.service')
|
2021-12-19 23:16:19 +01:00
|
|
|
|
|
|
|
local screens = {
|
|
|
|
splash = {
|
|
|
|
screen = splashScreen
|
|
|
|
},
|
2021-12-21 19:39:34 +01:00
|
|
|
title = {
|
|
|
|
screen = titleScreen
|
|
|
|
},
|
2021-12-19 23:16:19 +01:00
|
|
|
mode_select = {
|
|
|
|
screen = modeSelectScreen
|
2021-12-20 00:39:38 +01:00
|
|
|
},
|
|
|
|
service = {
|
|
|
|
screen = serviceScreen
|
2021-08-15 23:07:40 +02:00
|
|
|
}
|
2021-12-19 23:16:19 +01:00
|
|
|
}
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2022-03-04 04:06:19 +01:00
|
|
|
local url, version = game.UpdateAvailable()
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2022-03-04 04:06:19 +01:00
|
|
|
local currentScreen = (
|
|
|
|
url and screens.service or ( -- if update available, show service screen,
|
|
|
|
game.GetSkinSetting("animations_skipIntro") and screens.title or screens.splash -- else show splash screen, if skipIntro is not set.
|
|
|
|
)
|
|
|
|
)
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2022-03-12 15:17:20 +01:00
|
|
|
local function deltaKnob(delta)
|
2021-08-15 23:07:40 +02:00
|
|
|
if math.abs(delta) > 1.5 * math.pi then
|
2022-03-04 04:06:19 +01:00
|
|
|
return delta + 2 * math.pi * Common.sign(delta) * -1
|
2021-08-15 23:07:40 +02:00
|
|
|
end
|
|
|
|
return delta
|
2021-07-25 20:10:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local lastKnobs = nil
|
|
|
|
local knobProgress = 0
|
2022-03-12 15:17:20 +01:00
|
|
|
local function handle_controller()
|
2021-12-19 23:16:19 +01:00
|
|
|
if (not currentScreen.screen.onKnobsChange) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-08-15 23:07:40 +02:00
|
|
|
if lastKnobs == nil then
|
|
|
|
lastKnobs = {game.GetKnob(0), game.GetKnob(1)}
|
|
|
|
else
|
|
|
|
local newKnobs = {game.GetKnob(0), game.GetKnob(1)}
|
|
|
|
|
2022-03-04 04:06:19 +01:00
|
|
|
knobProgress = knobProgress - deltaKnob(lastKnobs[1] - newKnobs[1]) * 1.2
|
|
|
|
knobProgress = knobProgress - deltaKnob(lastKnobs[2] - newKnobs[2]) * 1.2
|
2021-08-15 23:07:40 +02:00
|
|
|
|
|
|
|
lastKnobs = newKnobs
|
|
|
|
|
|
|
|
if math.abs(knobProgress) > 1 then
|
2021-12-19 23:16:19 +01:00
|
|
|
if (knobProgress < 0) then
|
|
|
|
-- Negative
|
|
|
|
currentScreen.screen.onKnobsChange(-1)
|
|
|
|
else
|
|
|
|
-- Positive
|
|
|
|
currentScreen.screen.onKnobsChange(1)
|
2021-08-15 23:07:40 +02:00
|
|
|
end
|
2022-03-04 04:06:19 +01:00
|
|
|
knobProgress = knobProgress - Common.roundToZero(knobProgress)
|
2021-08-15 23:07:40 +02:00
|
|
|
end
|
|
|
|
end
|
2021-07-25 20:10:06 +02:00
|
|
|
end
|
2022-03-12 15:17:20 +01:00
|
|
|
|
|
|
|
local function handleScreenResponse(res)
|
|
|
|
if (res.eventType == 'switch') then
|
|
|
|
if (not screens[res.toScreen]) then
|
|
|
|
game.Log('Undefined screen ' .. res.toScreen, game.LOGGER_ERROR)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
currentScreen = screens[res.toScreen]
|
2022-04-03 01:35:41 +02:00
|
|
|
if currentScreen.screen.reset then
|
|
|
|
currentScreen.screen.reset()
|
|
|
|
end
|
2022-03-12 15:17:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function render(deltaTime)
|
|
|
|
handle_controller()
|
|
|
|
|
|
|
|
local res = currentScreen.screen.render(deltaTime)
|
|
|
|
if res then
|
|
|
|
handleScreenResponse(res)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function mouse_pressed(button)
|
|
|
|
if (currentScreen.screen.onMousePressed) then
|
|
|
|
currentScreen.screen.onMousePressed(button)
|
|
|
|
end
|
2022-03-27 03:54:02 +02:00
|
|
|
return 0
|
2022-03-12 15:17:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function button_pressed(button)
|
|
|
|
if (currentScreen.screen.onButtonPressed) then
|
|
|
|
currentScreen.screen.onButtonPressed(button)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|