ExperimentalGear/scripts/result.lua

413 lines
13 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 defaultJacketImage = gfx.CreateSkinImage("result/default_jacket.png", 0);
2021-07-27 21:18:13 +02:00
2021-07-28 18:50:06 +02:00
local appealCardImage = gfx.CreateSkinImage("appeal_card.png", 0);
local danBadgeImage = gfx.CreateSkinImage("dan/inf.png", 0);
local volforceBadgeImage = gfx.CreateSkinImage("volforce/10.png", 0);
2021-07-28 16:35:34 +02:00
local gradeImages = {
S = gfx.CreateSkinImage("score/S.png", 0),
AAA_P = gfx.CreateSkinImage("score/AAA+.png", 0),
AAA = gfx.CreateSkinImage("score/AAA.png", 0),
AA_P = gfx.CreateSkinImage("score/AA+.png", 0),
AA = gfx.CreateSkinImage("score/AA.png", 0),
A_P = gfx.CreateSkinImage("score/A+.png", 0),
A = gfx.CreateSkinImage("score/A.png", 0),
B = gfx.CreateSkinImage("score/B.png", 0),
C = gfx.CreateSkinImage("score/C.png", 0),
D = gfx.CreateSkinImage("score/D.png", 0),
}
2021-07-28 00:02:23 +02:00
-- ANIMS
local idolAnimation = gfx.LoadSkinAnimation('idol', 1/30, 0, false);
2021-07-27 21:18:13 +02:00
local transitionEnterScale = 0;
2021-07-28 00:02:23 +02:00
local idolAnimTransitionScale = 0;
2021-07-27 21:18:13 +02:00
local rightPanelX = 0;
local rightPanelY = 850;
2021-07-28 17:40:25 +02:00
local bottomPanelX = 0;
local bottomPanelY = 1110;
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 highScore;
2021-07-28 18:50:06 +02:00
local username = game.GetSkinSetting('username');
local earlyLateBarsStats = {
2021-07-27 23:54:17 +02:00
earlyErrors = 0,
earlyNears = 0,
criticals = 0,
lateNears = 0,
lateErrors = 0
};
local objectTypeTimingStats = {
2021-07-27 23:54:17 +02:00
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
2021-07-27 23:54:17 +02:00
function drawTimingBar(y, value, max, type)
gfx.BeginPath();
local barAlpha = math.floor(Easing.outQuad(transitionEnterScale)*255)
2021-07-27 23:54:17 +02:00
if type == 'crit' then
gfx.FillColor(253,243,24,barAlpha);
2021-07-27 23:54:17 +02:00
elseif type == 'early' then
gfx.FillColor(215,48,182,barAlpha);
2021-07-27 23:54:17 +02:00
elseif type == 'late' then
gfx.FillColor(46,211,241,barAlpha);
2021-07-27 23:54:17 +02:00
end
2021-07-27 23:57:27 +02:00
gfx.Rect(rightPanelX+696,rightPanelY+y,293*(value/max), 8);
2021-07-27 23:54:17 +02:00
gfx.Fill();
gfx.ClosePath();
end
2021-07-28 16:35:34 +02:00
function load_number_image(path)
local images = {}
for i = 0, 9 do
images[i + 1] = gfx.CreateSkinImage(string.format("%s/%d.png", path, i), 0)
end
return images
end
function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern)
scale = scale or 1;
kern = kern or 1;
local tw, th = gfx.ImageSize(images[1])
tw = tw * scale;
th = th * scale;
x = x + (tw * (digits - 1)) / 2
y = y - th / 2
for i = 1, digits do
local mul = 10 ^ (i - 1)
local digit = math.floor(num / mul) % 10
local a = alpha
if is_dim and num < mul then
a = 0.4
end
gfx.BeginPath()
gfx.ImageRect(x, y, tw, th, images[digit + 1], a, 0)
x = x - (tw * kern)
end
end
2021-07-28 00:02:23 +02:00
local drawIdol = function (deltaTime)
local idolAnimTickRes = gfx.TickAnimation(idolAnimation, deltaTime);
if idolAnimTickRes == 1 then
gfx.GlobalAlpha(idolAnimTransitionScale);
idolAnimTransitionScale = idolAnimTransitionScale + 1/60;
if (idolAnimTransitionScale > 1) then
idolAnimTransitionScale = 1;
end
gfx.ImageRect(0, 0, desw, desh, idolAnimation, 1, 0);
2021-07-28 00:02:23 +02:00
gfx.GlobalAlpha(1);
end
end
2021-07-27 21:18:13 +02:00
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);
2021-07-27 23:54:17 +02:00
gfx.ImageRect(rightPanelX, rightPanelY, tw, th, rightPanelImage,
Easing.outQuad(transitionEnterScale), 0);
end
2021-07-27 21:18:13 +02:00
2021-07-28 16:35:34 +02:00
local scoreNumber = load_number_image("score_num");
2021-07-27 23:54:17 +02:00
local drawRightPanelContent = function()
-- Draw song name and artist
gfx.FontSize(28)
2021-07-27 23:54:17 +02:00
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);
2021-07-27 23:54:17 +02:00
2021-07-28 16:35:34 +02:00
-- Draw score
draw_number(rightPanelX+580, rightPanelY+192, 1.0, math.floor(result.score / 10000), 4, scoreNumber, true, 0.42, 1.12)
draw_number(rightPanelX+768, rightPanelY+202, 1.0, result.score, 4, scoreNumber, true, 0.25, 1.12)
-- Draw grade
local gradeImageKey = string.gsub(result.grade, '+', '_P');
local gradeImage = gradeImages[gradeImageKey] or gradeImages.D
gfx.BeginPath();
gfx.ImageRect(rightPanelX+890, rightPanelY+130, 85, 85, gradeImage, 1, 0);
-- Draw best score
gfx.FontSize(20)
2021-07-27 23:54:17 +02:00
gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE)
gfx.LoadSkinFont('Digital-Serial-Bold.ttf')
local highScoreScore = 0;
if highScore then
highScoreScore = highScore.score
end
local highScoreDelta = result.score - highScoreScore
local deltaPrefix = '-'
if highScoreDelta > 0 then
deltaPrefix = '+'
end
highScoreDelta = math.abs(highScoreDelta);
gfx.Text(string.format("%08d", highScoreScore), rightPanelX + 962, rightPanelY + 239);
gfx.Text(deltaPrefix .. string.format("%08d", highScoreDelta), rightPanelX + 962, rightPanelY + 259);
2021-07-28 17:22:25 +02:00
-- Draw gauge status
gfx.FontSize(24)
gfx.Text(math.floor(result.gauge * 100) .. '%', rightPanelX + 984, rightPanelY + 295);
-- Draw err/early/critical/late/err texts
2021-07-27 23:54:17 +02:00
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);
2021-07-27 23:54:17 +02:00
-- Draw hit timing bars
local totalHits = earlyLateBarsStats.earlyErrors +
earlyLateBarsStats.earlyNears +
earlyLateBarsStats.criticals +
earlyLateBarsStats.lateNears +
earlyLateBarsStats.lateErrors
gfx.Save()
drawTimingBar(365, earlyLateBarsStats.earlyErrors, totalHits, 'early')
drawTimingBar(396, earlyLateBarsStats.earlyNears, totalHits, 'early')
drawTimingBar(427, earlyLateBarsStats.criticals, totalHits, 'crit')
drawTimingBar(458, earlyLateBarsStats.lateNears, totalHits, 'late')
drawTimingBar(489, earlyLateBarsStats.lateErrors, totalHits, 'late')
gfx.Restore()
-- Draw hit stats based on objects
-- CHIP
2021-07-27 23:54:17 +02:00
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);
-- Draw max combo
gfx.Text(result.maxCombo, rightPanelX + 371, rightPanelY + 466);
2021-07-27 21:18:13 +02:00
end
2021-07-27 23:54:17 +02:00
local drawBottomPanel = function()
2021-07-27 21:18:13 +02:00
gfx.BeginPath();
local tw, th = gfx.ImageSize(bottomPanelImage);
2021-07-28 17:40:25 +02:00
gfx.ImageRect(bottomPanelX, bottomPanelY, tw, th,
2021-07-27 23:54:17 +02:00
bottomPanelImage, Easing.outQuad(transitionEnterScale), 0);
2021-07-27 21:18:13 +02:00
end
2021-07-28 17:40:25 +02:00
local drawBottomPanelContent = function ()
2021-07-28 18:50:06 +02:00
-- Draw appeal card
gfx.BeginPath();
gfx.ImageRect(bottomPanelX+58, bottomPanelY+277, 103, 132, appealCardImage, 1, 0);
-- Draw description
gfx.FontSize(22)
gfx.LoadSkinFont('Digital-Serial-Bold.ttf')
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.Text('Hellooooooo', bottomPanelX+190, bottomPanelY+282);
-- Draw username
gfx.FontSize(28)
gfx.Text(username, bottomPanelX+190, bottomPanelY+314);
-- Draw dan badge
gfx.BeginPath();
gfx.ImageRect(bottomPanelX+187, bottomPanelY+362, 107, 29, danBadgeImage, 1, 0);
2021-07-28 17:40:25 +02:00
2021-07-28 18:50:06 +02:00
-- Draw volforce badge
gfx.BeginPath();
gfx.ImageRect(bottomPanelX+310, bottomPanelY+355, 42, 42, volforceBadgeImage, 1, 0);
-- Draw volforce label
gfx.FontSize(11)
gfx.Text('VOLFORCE', bottomPanelX+357, bottomPanelY+369);
gfx.FontSize(18)
gfx.Text('20.148', bottomPanelX+357, bottomPanelY+385);
2021-07-28 17:40:25 +02:00
end
2021-07-27 21:18:13 +02:00
local drawJacketPanel = function()
gfx.BeginPath();
local tw, th = gfx.ImageSize(jacketPanelImage);
2021-07-27 23:54:17 +02:00
gfx.ImageRect(jacketPanelX, jacketPanelY, tw, th, jacketPanelImage,
Easing.outQuad(transitionEnterScale), 0);
2021-07-27 21:18:13 +02:00
end
2021-07-27 23:54:17 +02:00
local drawJacketPanelContent = function()
gfx.BeginPath();
gfx.ImageRect(jacketPanelX + 12, jacketPanelY + 26, 273, 273, jacketImage or defaultJacketImage,
2021-07-27 23:54:17 +02:00
Easing.outQuad(transitionEnterScale), 0);
2021-07-27 21:18:13 +02:00
end
local tickTransitions = function(deltaTime)
if transitionEnterScale < 1 then
2021-07-28 17:40:40 +02:00
transitionEnterScale = transitionEnterScale + deltaTime / 10 -- transition should last for 1s
2021-07-27 21:18:13 +02:00
else
transitionEnterScale = 1
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
2021-07-27 23:54:17 +02:00
rightPanelX = 0 +
(RIGHT_PANEL_TRANSTION_ENTER_OFFSET *
(1 - Easing.outQuad(transitionEnterScale)))
2021-07-28 17:40:25 +02:00
bottomPanelY = 1110 + (BOTTOM_PANEL_TRANSTION_ENTER_OFFSET *
(1 - Easing.outQuad(transitionEnterScale)))
2021-07-27 23:54:17 +02:00
jacketPanelX = 40 + (JACKET_PANEL_TRANSTION_ENTER_OFFSET *
(1 - Easing.outQuad(transitionEnterScale)))
2021-07-27 21:18:13 +02:00
end
2021-07-27 23:54:17 +02:00
result_set = function()
2021-07-27 21:18:13 +02:00
if result.jacketPath ~= nil and result.jacketPath ~= "" then
jacketImage = gfx.CreateImage(result.jacketPath, 0)
end
highScore = result.highScores[1];
-- 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
2021-07-27 23:54:17 +02:00
objectTypeTimingStats.chip.errors =
objectTypeTimingStats.chip.errors + 1;
if hitStat.delta < 0 then
2021-07-27 23:54:17 +02:00
earlyLateBarsStats.earlyErrors =
earlyLateBarsStats.earlyErrors + 1;
else
2021-07-27 23:54:17 +02:00
earlyLateBarsStats.lateErrors =
earlyLateBarsStats.lateErrors + 1;
end
elseif hitStat.rating == 1 then
2021-07-27 23:54:17 +02:00
objectTypeTimingStats.chip.nears =
objectTypeTimingStats.chip.nears + 1;
if hitStat.delta < 0 then
2021-07-27 23:54:17 +02:00
earlyLateBarsStats.earlyNears =
earlyLateBarsStats.earlyNears + 1;
else
earlyLateBarsStats.lateNears = earlyLateBarsStats.lateNears + 1;
end
else
2021-07-27 23:54:17 +02:00
objectTypeTimingStats.chip.criticals =
objectTypeTimingStats.chip.criticals + 1;
end
2021-07-25 20:10:06 +02:00
end
2021-07-27 23:54:17 +02:00
-- misses on LONGs or LAZERs are automatically late errors
-- so we add errors that are not ealy or late to late errors
2021-07-27 23:54:17 +02:00
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);
2021-07-28 00:02:23 +02:00
drawIdol(deltaTime)
2021-07-27 21:18:13 +02:00
drawTopBar()
2021-07-28 18:50:06 +02:00
2021-07-27 21:18:13 +02:00
drawBottomPanel()
2021-07-28 18:50:06 +02:00
drawBottomPanelContent()
2021-07-27 21:18:13 +02:00
drawRightPanel()
drawRightPanelContent()
2021-07-28 18:50:06 +02:00
2021-07-27 21:18:13 +02:00
drawJacketPanel()
drawJacketPanelContent()
handleSfx()
-- debug
gfx.FontSize(18)
2021-07-27 23:54:17 +02:00
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();
gfx.BeginPath();
2021-07-27 21:18:13 +02:00
end