Skip to content

Commit ee5ad49

Browse files
committed
delete stats file - don't know how to await so put stats callback in main - add config
1 parent 6faf828 commit ee5ad49

3 files changed

Lines changed: 66 additions & 50 deletions

File tree

source/main.lua

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require("console")
1717
require("errorhandler")
1818
require("extensions.love")
1919
require('ranks')
20-
require('stats')
2120

2221
local log = require("log")
2322
local melee = require("melee")
@@ -28,6 +27,8 @@ local notification = require("notification")
2827
local overlay = require("overlay")
2928
local music = require("music")
3029

30+
local json = require("serializer.json")
31+
local web = require("web")
3132
local color = require("util.color")
3233
local gui = require("gui")
3334
local web = require("web")
@@ -94,6 +95,41 @@ local opponentName = ""
9495
local opponentRank = ""
9596
local opponentElo = 0
9697

98+
function grabUserStats(userCode, isOpponent)
99+
-- userCode: 'xxx#123'
100+
local body = json.encode({
101+
operationName = "AccountManagementPageQuery",
102+
variables = {
103+
cc = string.format("%s", userCode),
104+
uid = string.format("%s", userCode)
105+
},
106+
query = "fragment userProfilePage on User {\n fbUid\n displayName\n connectCode {\n code\n __typename\n }\n status\n activeSubscription {\n level\n hasGiftSub\n __typename\n }\n rankedNetplayProfile {\n id\n ratingOrdinal\n ratingUpdateCount\n wins\n losses\n dailyGlobalPlacement\n dailyRegionalPlacement\n continent\n characters {\n id\n character\n gameCount\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery AccountManagementPageQuery($cc: String!, $uid: String!) {\n getUser(fbUid: $uid) {\n ...userProfilePage\n __typename\n }\n getConnectCode(code: $cc) {\n user {\n ...userProfilePage\n __typename\n }\n __typename\n }\n}\n"
107+
})
108+
print(body)
109+
110+
local res = web.post(
111+
'https://gql-gateway-dot-slippi.uc.r.appspot.com/graphql',
112+
body,
113+
{
114+
["Content-Type"] = "application/json",
115+
["Content-Length"] = string.len(body)
116+
},
117+
function(event)
118+
data = json.decode(event.response)
119+
if data.data and data.data.getConnectCode.user.displayName then
120+
if isOpponent then
121+
opponentElo = data.data.getConnectCode.user.rankedNetplayProfile.ratingOrdinal
122+
opponentRank = getRank(opponentElo, false)
123+
opponentName = data.data.getConnectCode.user.displayName
124+
else
125+
playerElo = data.data.getConnectCode.user.rankedNetplayProfile.ratingOrdinal
126+
playerRank = getRank(playerElo, false)
127+
playerName = data.data.getConnectCode.user.displayName
128+
end
129+
end
130+
end)
131+
end
132+
97133
local portless_title = ""
98134
function love.updateTitle(str)
99135
local title = str
@@ -186,16 +222,10 @@ memory.hook("scene.minor", "Slippi Auto Port Switcher", function(minor)
186222
opponentCode = memory.slippi.players[1].code
187223
end
188224

189-
playerStats = grabUserStats(playerCode)
190-
opponentStats = grabUserStats(opponentCode)
191-
192-
playerName = playerStats[1]
193-
playerElo = playerStats[2]
194-
playerRank = getRank(playerElo, false)
195-
196-
opponentName = opponentStats[1]
197-
opponentElo = opponentStats[2]
198-
opponentRank = getRank(opponentElo, false)
225+
if PANEL_SETTINGS:IsShowRanksEnabled() then
226+
grabUserStats(playerCode, false)
227+
grabUserStats(opponentCode, true)
228+
end
199229

200230
if minor == SCENE_VS_ONLINE_CSS or menu == SCENE_VS_ONLINE_SSS then
201231
-- Switch back to whatever controller is controlling port 1, when not in a match
@@ -405,13 +435,15 @@ function love.drawControllerOverlay()
405435
overlay.draw(controller)
406436
-- graphics.textOutline(string.format("%s %s", opponentName, opponentRank), .5, 400, 200) -- maybe add outline
407437
graphics.setColor(255, 0, 0, 255)
408-
local playerLabel = string.format("%s\n%s (%d)", playerName, playerRank, playerElo)
409-
local opponentLabel = string.format("%s\n(%d) %s", opponentName, opponentElo, opponentRank)
410-
if playerElo > 0 then
411-
graphics.print(playerLabel, 10, 200)
412-
end
413-
if opponentElo > 0 then
414-
graphics.printf(opponentLabel, 300, 200, 200, "right")
438+
if PANEL_SETTINGS:IsShowRanksEnabled() then
439+
local playerLabel = string.format("%s\n%s (%d)", playerName, playerRank, playerElo)
440+
local opponentLabel = string.format("%s\n(%d) %s", opponentName, opponentElo, opponentRank)
441+
if playerElo > 0 then
442+
graphics.print(playerLabel, 10, 200)
443+
end
444+
if opponentElo > 0 then
445+
graphics.printf(opponentLabel, 300, 200, 200, "right")
446+
end
415447
end
416448

417449
if PANEL_SETTINGS:GetDebuggingInputFlags() > 0 then

source/modules/gui/panels/settings.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ SLIPPI_OFF = 1
1212
SLIPPI_NETPLAY = 2
1313
SLIPPI_REPLAY = 3
1414

15+
SHOW_RANKED_DETAILS = 1
16+
1517
LOOPING_NONE = 0
1618
LOOPING_MENU = 1
1719
LOOPING_STAGE_TIMED = 2
@@ -115,7 +117,7 @@ function PANEL:Settings()
115117
self.SLIPPI.MODE = self.SLIPPI.RIGHT:Add("RadioPanel")
116118
self.SLIPPI.MODE:SetText("Slippi mode")
117119
self.SLIPPI.MODE:DockMargin(0,0,0,0)
118-
self.SLIPPI.MODE:Dock(DOCK_FILL)
120+
self.SLIPPI.MODE:Dock(DOCK_TOP)
119121
self.SLIPPI.MODE:SetWidth(100)
120122

121123
local off = self.SLIPPI.MODE:AddOption(SLIPPI_OFF, "Off: Other games", true)
@@ -136,6 +138,15 @@ WARNING: This tricks M'Overlay into thinking Melee is being played when an inval
136138
self.SLIPPI.MODE.OnSelectOption = function(this, num)
137139
self.SLIPPI.ICON:SetImage(num == SLIPPI_OFF and "textures/slippi.png" or "textures/slippi_filled.png")
138140
end
141+
142+
self.SLIPPI.RANKED = self.SLIPPI.RIGHT:Add("CheckBox")
143+
self.SLIPPI.RANKED:SetText("Ranked Details")
144+
self.SLIPPI.RANKED:DockMargin(0,0,0,0)
145+
self.SLIPPI.RANKED:Dock(DOCK_BOTTOM)
146+
self.SLIPPI.RANKED:SetWidth(100)
147+
self.SLIPPI.RANKED:SetTooltipParent(self.SLIPPI.RANKED)
148+
self.SLIPPI.RANKED:SetTooltipTitle("Show Ranked Details")
149+
self.SLIPPI.RANKED:SetTooltipBody("[[Shows player and opponent slippi.gg leaderboard elo and league ranks]]")
139150

140151
self.MELEE.MUSIC = self.MELEE.LEFT:Add("CheckBox")
141152
self.MELEE.MUSIC:SetText("Enable music")
@@ -531,6 +542,10 @@ function PANEL:GetSlippiMode()
531542
return self.SLIPPI.MODE:GetOption()
532543
end
533544

545+
function PANEL:IsShowRanksEnabled()
546+
return self.SLIPPI.RANKED:IsToggled()
547+
end
548+
534549
function PANEL:IsSlippiNetplay()
535550
return self.SLIPPI.MODE:GetOption() == SLIPPI_NETPLAY
536551
end

source/modules/stats.lua

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)