diff --git a/scripts/gameplay.lua b/scripts/gameplay.lua index d61bb1c..df84628 100644 --- a/scripts/gameplay.lua +++ b/scripts/gameplay.lua @@ -13,10 +13,14 @@ local LaserAlert = require('gameplay.laser_alert') local TrackEnd = require('gameplay.track_end') +local json = require "json" + local resx, resy = game.GetResolution() local desw, desh; local scale; +local users = nil + local maxChain = 0; local chain = 0; local score = 0; @@ -38,7 +42,7 @@ function render(deltaTime) resetLayoutInformation(); gfx.Scale(scale, scale); - Banner.render(deltaTime); + Banner.render(deltaTime, users); UserPanel.render(deltaTime, score, gameplay.scoreReplays[1]); SongPanel.render(deltaTime, @@ -129,3 +133,25 @@ function practice_end(playCount, successCount) end + +function init_tcp() + Tcp.SetTopicHandler("game.scoreboard", function(data) + users = {} + for i, u in ipairs(data.users) do + table.insert(users, u) + end + end) +end + +-- Update the users in the scoreboard +function score_callback(response) + if response.status ~= 200 then + error() + return + end + local jsondata = json.decode(response.text) + users = {} + for i, u in ipairs(jsondata.users) do + table.insert(users, u) + end +end diff --git a/scripts/gameplay/banner.lua b/scripts/gameplay/banner.lua index cd95a1c..400c5c9 100644 --- a/scripts/gameplay/banner.lua +++ b/scripts/gameplay/banner.lua @@ -4,8 +4,36 @@ local bannerBaseImage = gfx.CreateSkinImage("gameplay/banner/base.png", 0) local BANNER_W = 1080; local BANNER_H = 368; +local drawScoreboard = function (users) + if (users == nil) then + return + end -local render = function (deltaTime) + gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE) + gfx.FontSize(32) + + local x = 16; + local y = 500; + + gfx.LoadSkinFont("Digital-Serial-Bold.ttf") + + for i, u in ipairs(users) do + local y = y + 40; + + gfx.FontSize(26) + gfx.Text(u.name, x, y) + + gfx.FontSize(26) + gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE) + gfx.Text(string.format("%04d", math.floor(u.score/10000)), x+128, y) + + local lastFourDigits = ((u.score / 10000) - math.floor(u.score / 10000))*10000 + gfx.FontSize(22) + gfx.Text(string.format("%04d", math.floor(lastFourDigits)), x+186, y+1) + end +end + +local render = function (deltaTime, users) local resx, resy = game.GetResolution(); if (resx > resy) then return @@ -25,6 +53,8 @@ local render = function (deltaTime) 1, 0 ); + + drawScoreboard(users); end return {