From 84ab278d927f8424988c9e751b938a6f50b41857 Mon Sep 17 00:00:00 2001 From: okvdai <108829133+okvdai@users.noreply.github.com> Date: Fri, 2 Jun 2023 14:48:40 +0200 Subject: [PATCH] Update nut files to work with refactor --- mod/scripts/vscripts/pulse-common-func.gnut | 33 ++++++++++++++----- mod/scripts/vscripts/pulse.gnut | 11 ++++--- mod/scripts/vscripts/ui/menu_stats_maps.nut | 18 +++++----- .../vscripts/ui/menu_stats_overview.nut | 28 ++++++++-------- mod/scripts/vscripts/ui/menu_stats_time.nut | 10 +++--- mod/scripts/vscripts/ui/menu_stats_titans.nut | 2 +- .../vscripts/ui/menu_stats_utility.nut | 10 +++--- .../vscripts/ui/menu_stats_weapons.nut | 6 ++-- 8 files changed, 66 insertions(+), 52 deletions(-) diff --git a/mod/scripts/vscripts/pulse-common-func.gnut b/mod/scripts/vscripts/pulse-common-func.gnut index 6bf7d12..e64229f 100644 --- a/mod/scripts/vscripts/pulse-common-func.gnut +++ b/mod/scripts/vscripts/pulse-common-func.gnut @@ -13,17 +13,23 @@ void function pulsePrintt(string content) //Prints whatever we want printed with printt(format("%s " + content, pulsePrefix)) } -bool function pulseRequestData(string givenURL, table parameterTable) //Gets data from API (see ToneURL within mod.json) and puts it into one table for processing. +bool function pulseRequestData(string givenURL, table parameterTable, string tablepath) //Gets data from API (see ToneURL within mod.json) and puts it into one table for processing. { table > params foreach (parameter in paramTable) { params[parameter] <- [paramTable(parameter)] } - void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) + void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (params, tablepath) { table DecodedJSON = DecodeJSON(response.body) - pulseData += DecodedJSON + if (params["map"]) + { + table map[params["map"]] <- DecodedJSON + pulseData[tablepath] <- map + } else { + pulseData[tablepath] <- DecodedJSON + } } void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure) { @@ -32,16 +38,25 @@ bool function pulseRequestData(string givenURL, table parameterTable) //Gets dat return NSHttpGet(givenURL, params, onSuccess, onFailure) } -int function pulseParse(string parameter, string key, string value) +int function pulseParse(string parameter, string key, string value, string opt = "none") { - if (key == "maps") { + if (key == "maps") + { parameter = parameter.slice(3) } - if (key in pulseData) { + if (key in pulseData) + { table keyandvalTable = expect table(pulseData[key]) - if (parameter in keyandvalTable) { - table valTable = expect table(keyandvalTable[parameter]) - return expect int(valTable[value]) + if (parameter in keyandvalTable) + { + table valTable = expect table(keyandvalTable[parameter]) + if (opt == "none") + { + return expect int(valTable[value]) + } else { + actualValTable = expect table(valTable[value]) + return expect int(actualValTable[opt]) + } } } return 0 diff --git a/mod/scripts/vscripts/pulse.gnut b/mod/scripts/vscripts/pulse.gnut index e3538de..fa965bd 100644 --- a/mod/scripts/vscripts/pulse.gnut +++ b/mod/scripts/vscripts/pulse.gnut @@ -16,12 +16,13 @@ void function pulseGetData() { string URL = GetConVarString("ToneURL") array URLpath = ["/weapons", "/weapons", "/gamemodes", "/gamemodes", "/maps"] - pulseRequestData(URL + URLpath[1], ["uid" = NSGetLocalPlayerUID()]) - pulseRequestData(URL + URLpath[2], ["uid" = "!" + NSGetLocalPlayerUID()]) - pulseRequestData(URL + URLpath[3], ["uid" = NSGetLocalPlayerUID()]) + array tablepath = ["weaponsLocal", "weaponsGlobal", "gamemodesAll", "gamemodesSeparated", "maps"] + pulseRequestData(URL + URLpath[1], ["uid" = NSGetLocalPlayerUID()], tablepath[1]) + pulseRequestData(URL + URLpath[2], ["uid" = "!" + NSGetLocalPlayerUID()], tablepath[2]) + pulseRequestData(URL + URLpath[3], ["uid" = NSGetLocalPlayerUID()], tablepath[3]) foreach (map in file.allMaps) { - pulseRequestData(URL + URLpath[4], ["uid" = NSGetLocalPlayerUID(), "map" = map.slice(3)]) + pulseRequestData(URL + URLpath[4], ["uid" = NSGetLocalPlayerUID(), "map" = map.slice(3)], tablepath[4]) } - pulseRequestData(URL + URLpath[5], ["uid" = NSGetLocalPlayerUID()]) + pulseRequestData(URL + URLpath[5], ["uid" = NSGetLocalPlayerUID()], tablepath[5]) } \ No newline at end of file diff --git a/mod/scripts/vscripts/ui/menu_stats_maps.nut b/mod/scripts/vscripts/ui/menu_stats_maps.nut index 49d72b4..67d1d7f 100644 --- a/mod/scripts/vscripts/ui/menu_stats_maps.nut +++ b/mod/scripts/vscripts/ui/menu_stats_maps.nut @@ -140,8 +140,6 @@ void function UpdateStatsForMap( string mapName ) Hud_SetText( Hud_GetChild( file.menu, "WeaponName" ), GetMapDisplayName( mapName ) ) - fetchGamemodeStatsFromToneAPI(mapName) - // Image var imageElem = Hud_GetRui( Hud_GetChild( file.menu, "WeaponImageLarge" ) ) RuiSetImage( imageElem, "basicImage", GetMapImageForMapName( mapName ) ) @@ -155,16 +153,16 @@ void function UpdateStatsForMap( string mapName ) //SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat3" ), Localize( "#STATS_GAMES_PLAYED" ), gamesPlayed ) SetStatsLabelValue( file.menu, "KillsLabel0", "KILLS ON MAP" ) - SetStatsLabelValue( file.menu, "KillsValue0", getFromToneAPI(mapName, "maps", "kills") ) + SetStatsLabelValue( file.menu, "KillsValue0", pulseParse(mapName, "maps", "kills") ) SetStatsLabelValue( file.menu, "KillsLabel1", "DEATHS ON MAP" ) - SetStatsLabelValue( file.menu, "KillsValue1", getFromToneAPI(mapName, "maps", "deaths") ) + SetStatsLabelValue( file.menu, "KillsValue1", pulseParse(mapName, "maps", "deaths") ) SetStatsLabelValue( file.menu, "KillsLabel2", "TOTAL SHOT DISTANCE" ) - SetStatsLabelValue( file.menu, "KillsValue2", string(int((1.905 * float(getFromToneAPI(mapName, "maps", "total_distance") ) ) )/100) + "m" ) + SetStatsLabelValue( file.menu, "KillsValue2", string(int((1.905 * float(pulseParse(mapName, "maps", "total_distance") ) ) )/100) + "m" ) SetStatsLabelValue( file.menu, "KillsLabel3", "MAXIMUM SHOT DISTANCE" ) - SetStatsLabelValue( file.menu, "KillsValue3", string(int((1.905 * float(getFromToneAPI(mapName, "maps", "max_distance") ) ) )/100) + "m" ) + SetStatsLabelValue( file.menu, "KillsValue3", string(int((1.905 * float(pulseParse(mapName, "maps", "max_distance") ) ) )/100) + "m" ) SetStatsLabelValue( file.menu, "KillsLabel4", "--" ) SetStatsLabelValue( file.menu, "KillsValue4", "--" ) @@ -193,10 +191,10 @@ void function UpdateStatsForMap( string mapName ) for ( int modeId = 0; modeId < enumCount; modeId++ ) { string modeName = PersistenceGetEnumItemNameForIndex( "gameModes", modeId ) - if ( mapName in globalToneAPIGamemodeMapData && modeName in globalToneAPIGamemodeMapData[mapName] ) + if ( mapName in pulseData && modeName in pulseData[mapName] ) { float modePlayedTime = 0 - modePlayedTime = float(globalToneAPIGamemodeMapData[mapName][modeName]) + modePlayedTime = float(pulseParse(mapName, "gamemodesSeparated", modeName, "kills")) if ( modePlayedTime > 0 ) { AddPieChartEntry( modes, GameMode_GetName( modeName ), modePlayedTime, GetGameModeDisplayColor( modeName ) ) } @@ -204,10 +202,10 @@ void function UpdateStatsForMap( string mapName ) } foreach (string key, array value in customGamemodeList) { - if ( mapName in globalToneAPIGamemodeMapData && key in globalToneAPIGamemodeMapData[mapName]) + if ( mapName in pulseData && key in pulseData[mapName]) { float modePlayedTime = 0 - modePlayedTime = float(globalToneAPIGamemodeMapData[mapName][key]) + modePlayedTime = float(pulseParse(mapName, "gamemodesSeparated", modeName, "kills")) if ( modePlayedTime > 0 ) { AddPieChartEntry( modes, customGamemodeNames[key], modePlayedTime, value) } diff --git a/mod/scripts/vscripts/ui/menu_stats_overview.nut b/mod/scripts/vscripts/ui/menu_stats_overview.nut index 4d3d9d8..43810b2 100644 --- a/mod/scripts/vscripts/ui/menu_stats_overview.nut +++ b/mod/scripts/vscripts/ui/menu_stats_overview.nut @@ -52,7 +52,7 @@ void function GetTitanKills( string titanName ) foreach ( weaponRef in file.titanStatLoadout[ titanName ]) { - titanKillData[weaponRef] <- getFromToneAPI(weaponRef, "weaponsLocal", "kills") + titanKillData[weaponRef] <- pulseParse(weaponRef, "weaponsLocal", "kills") } } @@ -332,7 +332,7 @@ function UpdateViewStatsOverviewMenu() if (key in titanKillData) { continue } else { - killsAsPilot += getFromToneAPI(string(key), "weaponsLocal", "kills") + killsAsPilot += pulseParse(string(key), "weaponsLocal", "kills") } } @@ -407,27 +407,27 @@ function UpdateViewStatsOverviewMenu() Hud_SetText( GetElem( file.menu, "KillsAsPilotValue0" ), string( killsAsPilot ) ) Hud_SetText( GetElem( file.menu, "KillsAsPilotValue1" ), string( GetPlayerStatInt( player, "kills_stats", "titanKillsAsPilot" ) ) ) Hud_SetText( GetElem( file.menu, "KillsAsPilotValue2" ), string( GetPlayerStatInt( player, "kills_stats", "totalNPC" ) ) ) - Hud_SetText( GetElem( file.menu, "KillsAsPilotValue3" ), string( getFromToneAPI("pilot_emptyhanded", "weaponsLocal", "kills") ) ) - Hud_SetText( GetElem( file.menu, "KillsAsPilotValue4" ), string( getFromToneAPI("human_execution", "weaponsLocal", "kills") ) ) + Hud_SetText( GetElem( file.menu, "KillsAsPilotValue3" ), string( pulseParse("pilot_emptyhanded", "weaponsLocal", "kills") ) ) + Hud_SetText( GetElem( file.menu, "KillsAsPilotValue4" ), string( pulseParse("human_execution", "weaponsLocal", "kills") ) ) // Hud_SetText( GetElem( file.menu, "KillsAsPilotValue5" ), string( GetPlayerStatInt( player, "kills_stats", "titanFallKill" ) ) ) var titanMeleeKills = 0 - titanMeleeKills += getFromToneAPI("titan_punch_ion", "weaponsLocal", "kills") - titanMeleeKills += getFromToneAPI("titan_punch_scorch", "weaponsLocal", "kills") - titanMeleeKills += getFromToneAPI("titan_punch_northstar", "weaponsLocal", "kills") - titanMeleeKills += getFromToneAPI("titan_sword", "weaponsLocal", "kills") - titanMeleeKills += getFromToneAPI("titan_punch_tone", "weaponsLocal", "kills") - titanMeleeKills += getFromToneAPI("titan_punch_legion", "weaponsLocal", "kills") - titanMeleeKills += getFromToneAPI("titan_punch_vanguard", "weaponsLocal", "kills") - titanMeleeKills += getFromToneAPI("auto_titan_melee", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("titan_punch_ion", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("titan_punch_scorch", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("titan_punch_northstar", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("titan_sword", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("titan_punch_tone", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("titan_punch_legion", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("titan_punch_vanguard", "weaponsLocal", "kills") + titanMeleeKills += pulseParse("auto_titan_melee", "weaponsLocal", "kills") - var titanExecutions = getFromToneAPI("titan_execution", "weaponsLocal", "kills") + var titanExecutions = pulseParse("titan_execution", "weaponsLocal", "kills") Hud_SetText( GetElem( file.menu, "KillsAsTitanValue0" ), string( killsAsTitan ) ) Hud_SetText( GetElem( file.menu, "KillsAsTitanValue1" ), string( GetPlayerStatInt( player, "kills_stats", "titanKillsAsTitan" ) ) ) Hud_SetText( GetElem( file.menu, "KillsAsTitanValue2" ), string( titanExecutions ) ) Hud_SetText( GetElem( file.menu, "KillsAsTitanValue3" ), string( titanMeleeKills ) ) - Hud_SetText( GetElem( file.menu, "KillsAsTitanValue4" ), string( getFromToneAPI("damagedef_titan_step", "weaponsLocal", "kills") ) ) + Hud_SetText( GetElem( file.menu, "KillsAsTitanValue4" ), string( pulseParse("damagedef_titan_step", "weaponsLocal", "kills") ) ) } function PlotKDPointsOnGraph( menu, graphIndex, values, dottedAverage ) diff --git a/mod/scripts/vscripts/ui/menu_stats_time.nut b/mod/scripts/vscripts/ui/menu_stats_time.nut index 3030481..157e4bd 100644 --- a/mod/scripts/vscripts/ui/menu_stats_time.nut +++ b/mod/scripts/vscripts/ui/menu_stats_time.nut @@ -49,7 +49,7 @@ float function GetTitanKills( string titanName) float weaponKills = 0 foreach ( weaponRef in file.titanStatLoadout[ titanName ]) { - weaponKills += float(getFromToneAPI(weaponRef, "weaponsLocal", "kills")) + weaponKills += float(pulseParse(weaponRef, "weaponsLocal", "kills")) } return weaponKills } @@ -160,10 +160,10 @@ void function UpdateViewStatsTimeMenu() for ( int modeId = 0; modeId < enumCount; modeId++ ) { string modeName = PersistenceGetEnumItemNameForIndex( "gameModes", modeId ) - if ( getFromToneAPI(modeName, "gamemodes", "kills") != 0 ) + if ( pulseParse(modeName, "gamemodes", "kills") != 0 ) { float modePlayedTime = 0 - modePlayedTime = float(getFromToneAPI(modeName, "gamemodes", "kills")) + modePlayedTime = float(pulseParse(modeName, "gamemodes", "kills")) if ( modePlayedTime > 0 ) { AddPieChartEntry( modes, GameMode_GetName( modeName ), modePlayedTime, GetGameModeDisplayColor( modeName ) ) } @@ -171,10 +171,10 @@ void function UpdateViewStatsTimeMenu() } foreach (string key, array value in customGamemodeList) { - if ( getFromToneAPI(key, "gamemodes", "kills") != 0 ) + if ( pulseParse(key, "gamemodes", "kills") != 0 ) { float modePlayedTime = 0 - modePlayedTime = float(getFromToneAPI(key, "gamemodes", "kills")) + modePlayedTime = float(pulseParse(key, "gamemodes", "kills")) if ( modePlayedTime > 0 ) { AddPieChartEntry( modes, customGamemodeNames[key], modePlayedTime, value) } diff --git a/mod/scripts/vscripts/ui/menu_stats_titans.nut b/mod/scripts/vscripts/ui/menu_stats_titans.nut index e9cd6f8..f401e10 100644 --- a/mod/scripts/vscripts/ui/menu_stats_titans.nut +++ b/mod/scripts/vscripts/ui/menu_stats_titans.nut @@ -175,7 +175,7 @@ void function UpdateStatsForTitan( string titanRef, int loadoutIndex ) int aiKills foreach ( weaponRef in file.titanStatLoadout[ titanRef ] ) { - totalKills += getFromToneAPI(weaponRef, "weaponsLocal", "kills") + totalKills += pulseParse(weaponRef, "weaponsLocal", "kills") pilotKills += GetPlayerStatInt( player, "weapon_kill_stats", "pilots", weaponRef ) titanKills += GetPlayerStatInt( player, "weapon_kill_stats", "titansTotal", weaponRef ) aiKills += GetPlayerStatInt( player, "weapon_kill_stats", "ai", weaponRef ) diff --git a/mod/scripts/vscripts/ui/menu_stats_utility.nut b/mod/scripts/vscripts/ui/menu_stats_utility.nut index 29be870..c53e458 100644 --- a/mod/scripts/vscripts/ui/menu_stats_utility.nut +++ b/mod/scripts/vscripts/ui/menu_stats_utility.nut @@ -338,7 +338,7 @@ table function GetOverviewWeaponData() if ( !PersistenceEnumValueIsValid( "loadoutWeaponsAndAbilities", weaponName ) ) continue - int val = getFromToneAPI(weaponName, "weaponsLocal", "kills") + int val = pulseParse(weaponName, "weaponsLocal", "kills") if ( val > Table[ "most_kills" ].val ) { Table[ "most_kills" ].ref = weaponName @@ -346,7 +346,7 @@ table function GetOverviewWeaponData() Table[ "most_kills" ].val = val } - int nval = getFromToneAPI(weaponName, "weaponsLocal", "deaths") + int nval = pulseParse(weaponName, "weaponsLocal", "deaths") if ( nval > Table[ "nemesis_weapon" ].val ) { Table[ "nemesis_weapon" ].ref = weaponName @@ -357,9 +357,9 @@ table function GetOverviewWeaponData() float kdval = 0 float kval = 0 float dval = 0 - if( getFromToneAPI(weaponName, "weaponsLocal", "kills") != 0 && getFromToneAPI(weaponName, "weaponsLocal", "deaths_while_equipped") != 0){ - kval = float(getFromToneAPI(weaponName, "weaponsLocal", "kills")) - dval = float(getFromToneAPI(weaponName, "weaponsLocal", "deaths_while_equipped")) + if( pulseParse(weaponName, "weaponsLocal", "kills") != 0 && pulseParse(weaponName, "weaponsLocal", "deaths_while_equipped") != 0){ + kval = float(pulseParse(weaponName, "weaponsLocal", "kills")) + dval = float(pulseParse(weaponName, "weaponsLocal", "deaths_while_equipped")) if (kval / dval > kdval){ kdval = kval / dval } diff --git a/mod/scripts/vscripts/ui/menu_stats_weapons.nut b/mod/scripts/vscripts/ui/menu_stats_weapons.nut index 6fcc252..4b4c95a 100644 --- a/mod/scripts/vscripts/ui/menu_stats_weapons.nut +++ b/mod/scripts/vscripts/ui/menu_stats_weapons.nut @@ -180,8 +180,8 @@ void function UpdateStatsForWeapon( string weaponRef ) } // Total Kills Stats - SetStatsLabelValue( file.menu, "KillsValue0", getFromToneAPI(weaponRef, "weaponsLocal", "kills") ) //Total kills - SetStatsLabelValue( file.menu, "KillsValue1", getFromToneAPI(weaponRef, "weaponsLocal", "kills") ) //Pilots + SetStatsLabelValue( file.menu, "KillsValue0", pulseParse(weaponRef, "weaponsLocal", "kills") ) //Total kills + SetStatsLabelValue( file.menu, "KillsValue1", pulseParse(weaponRef, "weaponsLocal", "kills") ) //Pilots SetStatsLabelValue( file.menu, "KillsValue2", GetPlayerStatInt( player, "weapon_kill_stats", "titansTotal", weaponRef ) ) //Titans - SetStatsLabelValue( file.menu, "KillsValue3", getFromToneAPI(weaponRef, "weaponsLocal", "deaths_while_equipped")) // Deaths with weapon + SetStatsLabelValue( file.menu, "KillsValue3", pulseParse(weaponRef, "weaponsLocal", "deaths_while_equipped")) // Deaths with weapon }