ExperimentalGear/scripts/result.lua

251 lines
7.3 KiB
Lua
Raw Normal View History

2021-07-27 21:18:13 +02:00
local Easing = require('common.easings');
local resx, resy = game.GetResolution()
2021-07-27 20:00:02 +02:00
local desw = 1080
local desh = 1920
2021-07-25 20:10:06 +02:00
2021-07-27 20:00:02 +02:00
local bgSfxPlayed = false;
2021-07-25 20:10:06 +02:00
local backgroundImage = gfx.CreateSkinImage("bg.png", 0);
2021-07-27 21:18:13 +02:00
local topBarImage = gfx.CreateSkinImage("result/top_bar.png", 0);
local jacketPanelImage = gfx.CreateSkinImage("result/panels/jacket.png", 0);
local rightPanelImage = gfx.CreateSkinImage("result/panels/right.png", 0);
local bottomPanelImage = gfx.CreateSkinImage("result/panels/bottom.png", 0);
2021-07-27 21:18:13 +02:00
local jacketImage = gfx.CreateSkinImage("result/default_jacket.png", 0);
2021-07-27 21:18:13 +02:00
local transitionEnterScale = 0;
local rightPanelX = 0;
local rightPanelY = 850;
2021-07-27 21:18:13 +02:00
local jacketPanelX = 0;
local jacketPanelY = 820;
local JACKET_PANEL_TRANSTION_ENTER_OFFSET = -128;
local RIGHT_PANEL_TRANSTION_ENTER_OFFSET = 128;
local BOTTOM_PANEL_TRANSTION_ENTER_OFFSET = 128;
local earlyLateBarsStats = {
earlyErrors = 0;
earlyNears = 0;
criticals = 0;
lateNears = 0;
lateErrors = 0;
};
local objectTypeTimingStats = {
chip = {
criticals = 0,
nears = 0,
errors = 0,
},
long = {
criticals = 0,
errors = 0,
},
vol = {
criticals = 0,
errors = 0,
},
}
2021-07-27 20:00:02 +02:00
game.LoadSkinSample("result")
2021-07-25 20:10:06 +02:00
2021-07-27 20:00:02 +02:00
function resetLayoutInformation()
resx, resy = game.GetResolution()
desw = 1080
desh = 1920
scale = resx / desw
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
local handleSfx = function()
2021-07-27 20:00:02 +02:00
if not bgSfxPlayed then
2021-07-25 20:10:06 +02:00
game.PlaySample("result", true)
2021-07-27 20:00:02 +02:00
bgSfxPlayed = true
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
if game.GetButton(game.BUTTON_STA) then game.StopSample("result") end
if game.GetButton(game.BUTTON_BCK) then game.StopSample("result") end
end
local drawTopBar = function()
gfx.BeginPath();
local tw, th = gfx.ImageSize(topBarImage);
gfx.ImageRect(0, -th * (1 - Easing.outQuad(transitionEnterScale)), desw, th,
topBarImage, 1, 0);
end
local drawRightPanel = function()
gfx.BeginPath();
local tw, th = gfx.ImageSize(rightPanelImage);
gfx.ImageRect(
rightPanelX,
rightPanelY,
2021-07-27 21:18:13 +02:00
tw,
th,
rightPanelImage,
Easing.outQuad(transitionEnterScale),
0
);
end
2021-07-27 21:18:13 +02:00
local drawRightPanelContent = function ()
-- Draw song name and artist
gfx.FontSize(28)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.Text(result.realTitle, rightPanelX + 435, rightPanelY + 108);
gfx.Text(result.artist, rightPanelX + 435, rightPanelY + 143);
-- Draw err/early/critical/late/err texts
gfx.FontSize(24)
gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE)
gfx.LoadSkinFont('Digital-Serial-Bold.ttf')
gfx.Text(earlyLateBarsStats.earlyErrors, rightPanelX + 683, rightPanelY + 370);
gfx.Text(earlyLateBarsStats.earlyNears, rightPanelX + 683, rightPanelY + 401);
gfx.Text(earlyLateBarsStats.criticals, rightPanelX + 683, rightPanelY + 432);
gfx.Text(earlyLateBarsStats.lateNears, rightPanelX + 683, rightPanelY + 463);
gfx.Text(earlyLateBarsStats.lateErrors, rightPanelX + 683, rightPanelY + 494);
-- Draw hit stats based on objects
-- CHIP
gfx.Text(objectTypeTimingStats.chip.criticals, rightPanelX + 255, rightPanelY + 365);
gfx.Text(objectTypeTimingStats.chip.nears, rightPanelX + 255, rightPanelY + 395);
gfx.Text(objectTypeTimingStats.chip.errors, rightPanelX + 255, rightPanelY + 425);
-- LONG
gfx.Text('???', rightPanelX + 333, rightPanelY + 365);
gfx.Text('-', rightPanelX + 333, rightPanelY + 395);
gfx.Text('???', rightPanelX + 333, rightPanelY + 425);
-- VOL
gfx.Text('???', rightPanelX + 411, rightPanelY + 365);
gfx.Text('-', rightPanelX + 411, rightPanelY + 395);
gfx.Text('???', rightPanelX + 411, rightPanelY + 425);
2021-07-27 21:18:13 +02:00
end
local drawBottomPanel = function ()
gfx.BeginPath();
local tw, th = gfx.ImageSize(bottomPanelImage);
gfx.ImageRect(
0,
1110+(BOTTOM_PANEL_TRANSTION_ENTER_OFFSET * (1 - Easing.outQuad(transitionEnterScale))),
tw,
th,
bottomPanelImage,
Easing.outQuad(transitionEnterScale),
0
);
end
local drawJacketPanel = function()
gfx.BeginPath();
local tw, th = gfx.ImageSize(jacketPanelImage);
gfx.ImageRect(
jacketPanelX,
jacketPanelY,
tw,
th,
jacketPanelImage,
Easing.outQuad(transitionEnterScale),
0
);
end
local drawJacketPanelContent = function ()
gfx.BeginPath();
2021-07-27 21:18:13 +02:00
gfx.ImageRect(
jacketPanelX+12,
jacketPanelY+26,
273,
273,
jacketImage,
Easing.outQuad(transitionEnterScale),
0
);
end
local tickTransitions = function(deltaTime)
if transitionEnterScale < 1 then
transitionEnterScale = transitionEnterScale + deltaTime / 5
else
transitionEnterScale = 1
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
rightPanelX = 0+(RIGHT_PANEL_TRANSTION_ENTER_OFFSET * (1 - Easing.outQuad(transitionEnterScale)))
2021-07-27 21:18:13 +02:00
jacketPanelX = 40 + (JACKET_PANEL_TRANSTION_ENTER_OFFSET * (1 - Easing.outQuad(transitionEnterScale)))
end
result_set = function ()
if result.jacketPath ~= nil and result.jacketPath ~= "" then
jacketImage = gfx.CreateImage(result.jacketPath, 0)
end
-- This only counts the "CHIP" objects, not LONGs or LAZERs
for hitStatIndex = 1, #result.noteHitStats do
local hitStat = result.noteHitStats[hitStatIndex];
if (hitStat.rating == 0) then -- Miss
objectTypeTimingStats.chip.errors = objectTypeTimingStats.chip.errors + 1;
if hitStat.delta < 0 then
earlyLateBarsStats.earlyErrors = earlyLateBarsStats.earlyErrors + 1;
else
earlyLateBarsStats.lateErrors = earlyLateBarsStats.lateErrors + 1;
end
elseif hitStat.rating == 1 then
objectTypeTimingStats.chip.nears = objectTypeTimingStats.chip.nears + 1;
if hitStat.delta < 0 then
earlyLateBarsStats.earlyNears = earlyLateBarsStats.earlyNears + 1;
else
earlyLateBarsStats.lateNears = earlyLateBarsStats.lateNears + 1;
end
else
objectTypeTimingStats.chip.criticals = objectTypeTimingStats.chip.criticals + 1;
end
2021-07-25 20:10:06 +02:00
end
-- misses on LONGs or LAZERs are automatically late errors
-- so we add errors that are not ealy or late to late errors
earlyLateBarsStats.lateErrors = earlyLateBarsStats.lateErrors + (result.misses - earlyLateBarsStats.lateErrors - earlyLateBarsStats.earlyErrors)
-- criticals are same for all objects so we just copy them from results
earlyLateBarsStats.criticals = result.perfects
2021-07-27 21:18:13 +02:00
end
render = function(deltaTime, showStats)
gfx.Save();
2021-07-27 21:18:13 +02:00
resetLayoutInformation()
gfx.ResetTransform();
gfx.ResetScissor();
gfx.BeginPath()
2021-07-27 21:18:13 +02:00
gfx.Scale(scale, scale)
gfx.ImageRect(0, 0, desw, desh, backgroundImage, 1, 0);
drawTopBar()
drawBottomPanel()
drawRightPanel()
drawRightPanelContent()
2021-07-27 21:18:13 +02:00
drawJacketPanel()
drawJacketPanelContent()
handleSfx()
-- debug
gfx.FontSize(18)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)
2021-07-27 21:18:13 +02:00
gfx.Text('DELTA: ' .. deltaTime .. ' // TRANSITION_ENTER_SCALE: ' ..
transitionEnterScale .. ' // EASING_OUT_QUAD: ' ..
Easing.outQuad(transitionEnterScale), 8, 8);
2021-07-27 21:18:13 +02:00
tickTransitions(deltaTime)
gfx.Restore();
2021-07-27 21:18:13 +02:00
end