Update nut files to work with refactor

This commit is contained in:
okvdai
2023-06-02 14:48:40 +02:00
parent c41173ad13
commit 84ab278d92
8 changed files with 66 additions and 52 deletions
+22 -7
View File
@@ -13,17 +13,23 @@ void function pulsePrintt(string content) //Prints whatever we want printed with
printt(format("%s " + content, pulsePrefix)) 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<string, array<string> > params table<string, array<string> > params
foreach (parameter in paramTable) foreach (parameter in paramTable)
{ {
params[parameter] <- [paramTable(parameter)] 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) 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) 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) 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) parameter = parameter.slice(3)
} }
if (key in pulseData) { if (key in pulseData)
{
table keyandvalTable = expect table(pulseData[key]) table keyandvalTable = expect table(pulseData[key])
if (parameter in keyandvalTable) { if (parameter in keyandvalTable)
{
table valTable = expect table(keyandvalTable[parameter]) table valTable = expect table(keyandvalTable[parameter])
if (opt == "none")
{
return expect int(valTable[value]) return expect int(valTable[value])
} else {
actualValTable = expect table(valTable[value])
return expect int(actualValTable[opt])
}
} }
} }
return 0 return 0
+6 -5
View File
@@ -16,12 +16,13 @@ void function pulseGetData()
{ {
string URL = GetConVarString("ToneURL") string URL = GetConVarString("ToneURL")
array URLpath = ["/weapons", "/weapons", "/gamemodes", "/gamemodes", "/maps"] array URLpath = ["/weapons", "/weapons", "/gamemodes", "/gamemodes", "/maps"]
pulseRequestData(URL + URLpath[1], ["uid" = NSGetLocalPlayerUID()]) array tablepath = ["weaponsLocal", "weaponsGlobal", "gamemodesAll", "gamemodesSeparated", "maps"]
pulseRequestData(URL + URLpath[2], ["uid" = "!" + NSGetLocalPlayerUID()]) pulseRequestData(URL + URLpath[1], ["uid" = NSGetLocalPlayerUID()], tablepath[1])
pulseRequestData(URL + URLpath[3], ["uid" = NSGetLocalPlayerUID()]) pulseRequestData(URL + URLpath[2], ["uid" = "!" + NSGetLocalPlayerUID()], tablepath[2])
pulseRequestData(URL + URLpath[3], ["uid" = NSGetLocalPlayerUID()], tablepath[3])
foreach (map in file.allMaps) 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])
} }
+8 -10
View File
@@ -140,8 +140,6 @@ void function UpdateStatsForMap( string mapName )
Hud_SetText( Hud_GetChild( file.menu, "WeaponName" ), GetMapDisplayName( mapName ) ) Hud_SetText( Hud_GetChild( file.menu, "WeaponName" ), GetMapDisplayName( mapName ) )
fetchGamemodeStatsFromToneAPI(mapName)
// Image // Image
var imageElem = Hud_GetRui( Hud_GetChild( file.menu, "WeaponImageLarge" ) ) var imageElem = Hud_GetRui( Hud_GetChild( file.menu, "WeaponImageLarge" ) )
RuiSetImage( imageElem, "basicImage", GetMapImageForMapName( mapName ) ) 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 ) //SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat3" ), Localize( "#STATS_GAMES_PLAYED" ), gamesPlayed )
SetStatsLabelValue( file.menu, "KillsLabel0", "KILLS ON MAP" ) 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, "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, "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, "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, "KillsLabel4", "--" )
SetStatsLabelValue( file.menu, "KillsValue4", "--" ) SetStatsLabelValue( file.menu, "KillsValue4", "--" )
@@ -193,10 +191,10 @@ void function UpdateStatsForMap( string mapName )
for ( int modeId = 0; modeId < enumCount; modeId++ ) for ( int modeId = 0; modeId < enumCount; modeId++ )
{ {
string modeName = PersistenceGetEnumItemNameForIndex( "gameModes", 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 float modePlayedTime = 0
modePlayedTime = float(globalToneAPIGamemodeMapData[mapName][modeName]) modePlayedTime = float(pulseParse(mapName, "gamemodesSeparated", modeName, "kills"))
if ( modePlayedTime > 0 ) { if ( modePlayedTime > 0 ) {
AddPieChartEntry( modes, GameMode_GetName( modeName ), modePlayedTime, GetGameModeDisplayColor( modeName ) ) AddPieChartEntry( modes, GameMode_GetName( modeName ), modePlayedTime, GetGameModeDisplayColor( modeName ) )
} }
@@ -204,10 +202,10 @@ void function UpdateStatsForMap( string mapName )
} }
foreach (string key, array<int> value in customGamemodeList) foreach (string key, array<int> value in customGamemodeList)
{ {
if ( mapName in globalToneAPIGamemodeMapData && key in globalToneAPIGamemodeMapData[mapName]) if ( mapName in pulseData && key in pulseData[mapName])
{ {
float modePlayedTime = 0 float modePlayedTime = 0
modePlayedTime = float(globalToneAPIGamemodeMapData[mapName][key]) modePlayedTime = float(pulseParse(mapName, "gamemodesSeparated", modeName, "kills"))
if ( modePlayedTime > 0 ) { if ( modePlayedTime > 0 ) {
AddPieChartEntry( modes, customGamemodeNames[key], modePlayedTime, value) AddPieChartEntry( modes, customGamemodeNames[key], modePlayedTime, value)
} }
+14 -14
View File
@@ -52,7 +52,7 @@ void function GetTitanKills( string titanName )
foreach ( weaponRef in file.titanStatLoadout[ 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) { if (key in titanKillData) {
continue continue
} else { } 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, "KillsAsPilotValue0" ), string( killsAsPilot ) )
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue1" ), string( GetPlayerStatInt( player, "kills_stats", "titanKillsAsPilot" ) ) ) 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, "KillsAsPilotValue2" ), string( GetPlayerStatInt( player, "kills_stats", "totalNPC" ) ) )
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue3" ), string( getFromToneAPI("pilot_emptyhanded", "weaponsLocal", "kills") ) ) Hud_SetText( GetElem( file.menu, "KillsAsPilotValue3" ), string( pulseParse("pilot_emptyhanded", "weaponsLocal", "kills") ) )
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue4" ), string( getFromToneAPI("human_execution", "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" ) ) ) // Hud_SetText( GetElem( file.menu, "KillsAsPilotValue5" ), string( GetPlayerStatInt( player, "kills_stats", "titanFallKill" ) ) )
var titanMeleeKills = 0 var titanMeleeKills = 0
titanMeleeKills += getFromToneAPI("titan_punch_ion", "weaponsLocal", "kills") titanMeleeKills += pulseParse("titan_punch_ion", "weaponsLocal", "kills")
titanMeleeKills += getFromToneAPI("titan_punch_scorch", "weaponsLocal", "kills") titanMeleeKills += pulseParse("titan_punch_scorch", "weaponsLocal", "kills")
titanMeleeKills += getFromToneAPI("titan_punch_northstar", "weaponsLocal", "kills") titanMeleeKills += pulseParse("titan_punch_northstar", "weaponsLocal", "kills")
titanMeleeKills += getFromToneAPI("titan_sword", "weaponsLocal", "kills") titanMeleeKills += pulseParse("titan_sword", "weaponsLocal", "kills")
titanMeleeKills += getFromToneAPI("titan_punch_tone", "weaponsLocal", "kills") titanMeleeKills += pulseParse("titan_punch_tone", "weaponsLocal", "kills")
titanMeleeKills += getFromToneAPI("titan_punch_legion", "weaponsLocal", "kills") titanMeleeKills += pulseParse("titan_punch_legion", "weaponsLocal", "kills")
titanMeleeKills += getFromToneAPI("titan_punch_vanguard", "weaponsLocal", "kills") titanMeleeKills += pulseParse("titan_punch_vanguard", "weaponsLocal", "kills")
titanMeleeKills += getFromToneAPI("auto_titan_melee", "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, "KillsAsTitanValue0" ), string( killsAsTitan ) )
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue1" ), string( GetPlayerStatInt( player, "kills_stats", "titanKillsAsTitan" ) ) ) 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, "KillsAsTitanValue2" ), string( titanExecutions ) )
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue3" ), string( titanMeleeKills ) ) 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 ) function PlotKDPointsOnGraph( menu, graphIndex, values, dottedAverage )
+5 -5
View File
@@ -49,7 +49,7 @@ float function GetTitanKills( string titanName)
float weaponKills = 0 float weaponKills = 0
foreach ( weaponRef in file.titanStatLoadout[ titanName ]) foreach ( weaponRef in file.titanStatLoadout[ titanName ])
{ {
weaponKills += float(getFromToneAPI(weaponRef, "weaponsLocal", "kills")) weaponKills += float(pulseParse(weaponRef, "weaponsLocal", "kills"))
} }
return weaponKills return weaponKills
} }
@@ -160,10 +160,10 @@ void function UpdateViewStatsTimeMenu()
for ( int modeId = 0; modeId < enumCount; modeId++ ) for ( int modeId = 0; modeId < enumCount; modeId++ )
{ {
string modeName = PersistenceGetEnumItemNameForIndex( "gameModes", modeId ) string modeName = PersistenceGetEnumItemNameForIndex( "gameModes", modeId )
if ( getFromToneAPI(modeName, "gamemodes", "kills") != 0 ) if ( pulseParse(modeName, "gamemodes", "kills") != 0 )
{ {
float modePlayedTime = 0 float modePlayedTime = 0
modePlayedTime = float(getFromToneAPI(modeName, "gamemodes", "kills")) modePlayedTime = float(pulseParse(modeName, "gamemodes", "kills"))
if ( modePlayedTime > 0 ) { if ( modePlayedTime > 0 ) {
AddPieChartEntry( modes, GameMode_GetName( modeName ), modePlayedTime, GetGameModeDisplayColor( modeName ) ) AddPieChartEntry( modes, GameMode_GetName( modeName ), modePlayedTime, GetGameModeDisplayColor( modeName ) )
} }
@@ -171,10 +171,10 @@ void function UpdateViewStatsTimeMenu()
} }
foreach (string key, array<int> value in customGamemodeList) foreach (string key, array<int> value in customGamemodeList)
{ {
if ( getFromToneAPI(key, "gamemodes", "kills") != 0 ) if ( pulseParse(key, "gamemodes", "kills") != 0 )
{ {
float modePlayedTime = 0 float modePlayedTime = 0
modePlayedTime = float(getFromToneAPI(key, "gamemodes", "kills")) modePlayedTime = float(pulseParse(key, "gamemodes", "kills"))
if ( modePlayedTime > 0 ) { if ( modePlayedTime > 0 ) {
AddPieChartEntry( modes, customGamemodeNames[key], modePlayedTime, value) AddPieChartEntry( modes, customGamemodeNames[key], modePlayedTime, value)
} }
@@ -175,7 +175,7 @@ void function UpdateStatsForTitan( string titanRef, int loadoutIndex )
int aiKills int aiKills
foreach ( weaponRef in file.titanStatLoadout[ titanRef ] ) foreach ( weaponRef in file.titanStatLoadout[ titanRef ] )
{ {
totalKills += getFromToneAPI(weaponRef, "weaponsLocal", "kills") totalKills += pulseParse(weaponRef, "weaponsLocal", "kills")
pilotKills += GetPlayerStatInt( player, "weapon_kill_stats", "pilots", weaponRef ) pilotKills += GetPlayerStatInt( player, "weapon_kill_stats", "pilots", weaponRef )
titanKills += GetPlayerStatInt( player, "weapon_kill_stats", "titansTotal", weaponRef ) titanKills += GetPlayerStatInt( player, "weapon_kill_stats", "titansTotal", weaponRef )
aiKills += GetPlayerStatInt( player, "weapon_kill_stats", "ai", weaponRef ) aiKills += GetPlayerStatInt( player, "weapon_kill_stats", "ai", weaponRef )
@@ -338,7 +338,7 @@ table<string, table> function GetOverviewWeaponData()
if ( !PersistenceEnumValueIsValid( "loadoutWeaponsAndAbilities", weaponName ) ) if ( !PersistenceEnumValueIsValid( "loadoutWeaponsAndAbilities", weaponName ) )
continue continue
int val = getFromToneAPI(weaponName, "weaponsLocal", "kills") int val = pulseParse(weaponName, "weaponsLocal", "kills")
if ( val > Table[ "most_kills" ].val ) if ( val > Table[ "most_kills" ].val )
{ {
Table[ "most_kills" ].ref = weaponName Table[ "most_kills" ].ref = weaponName
@@ -346,7 +346,7 @@ table<string, table> function GetOverviewWeaponData()
Table[ "most_kills" ].val = val Table[ "most_kills" ].val = val
} }
int nval = getFromToneAPI(weaponName, "weaponsLocal", "deaths") int nval = pulseParse(weaponName, "weaponsLocal", "deaths")
if ( nval > Table[ "nemesis_weapon" ].val ) if ( nval > Table[ "nemesis_weapon" ].val )
{ {
Table[ "nemesis_weapon" ].ref = weaponName Table[ "nemesis_weapon" ].ref = weaponName
@@ -357,9 +357,9 @@ table<string, table> function GetOverviewWeaponData()
float kdval = 0 float kdval = 0
float kval = 0 float kval = 0
float dval = 0 float dval = 0
if( getFromToneAPI(weaponName, "weaponsLocal", "kills") != 0 && getFromToneAPI(weaponName, "weaponsLocal", "deaths_while_equipped") != 0){ if( pulseParse(weaponName, "weaponsLocal", "kills") != 0 && pulseParse(weaponName, "weaponsLocal", "deaths_while_equipped") != 0){
kval = float(getFromToneAPI(weaponName, "weaponsLocal", "kills")) kval = float(pulseParse(weaponName, "weaponsLocal", "kills"))
dval = float(getFromToneAPI(weaponName, "weaponsLocal", "deaths_while_equipped")) dval = float(pulseParse(weaponName, "weaponsLocal", "deaths_while_equipped"))
if (kval / dval > kdval){ if (kval / dval > kdval){
kdval = kval / dval kdval = kval / dval
} }
@@ -180,8 +180,8 @@ void function UpdateStatsForWeapon( string weaponRef )
} }
// Total Kills Stats // Total Kills Stats
SetStatsLabelValue( file.menu, "KillsValue0", getFromToneAPI(weaponRef, "weaponsLocal", "kills") ) //Total kills SetStatsLabelValue( file.menu, "KillsValue0", pulseParse(weaponRef, "weaponsLocal", "kills") ) //Total kills
SetStatsLabelValue( file.menu, "KillsValue1", getFromToneAPI(weaponRef, "weaponsLocal", "kills") ) //Pilots SetStatsLabelValue( file.menu, "KillsValue1", pulseParse(weaponRef, "weaponsLocal", "kills") ) //Pilots
SetStatsLabelValue( file.menu, "KillsValue2", GetPlayerStatInt( player, "weapon_kill_stats", "titansTotal", weaponRef ) ) //Titans 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
} }