@@ -17,7 +17,6 @@ require("console")
1717require (" errorhandler" )
1818require (" extensions.love" )
1919require (' ranks' )
20- require (' stats' )
2120
2221local log = require (" log" )
2322local melee = require (" melee" )
@@ -28,6 +27,8 @@ local notification = require("notification")
2827local overlay = require (" overlay" )
2928local music = require (" music" )
3029
30+ local json = require (" serializer.json" )
31+ local web = require (" web" )
3132local color = require (" util.color" )
3233local gui = require (" gui" )
3334local web = require (" web" )
@@ -94,6 +95,41 @@ local opponentName = ""
9495local opponentRank = " "
9596local 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\n query 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+
97133local portless_title = " "
98134function 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
0 commit comments