Complete refactor #8
This commit is contained in:
@@ -3,16 +3,7 @@ global function GetStatsFromToneAPI
|
||||
global function getFromToneAPI
|
||||
global function fetchGamemodeStatsFromToneAPI
|
||||
|
||||
global table globalToneAPIKillData = {}
|
||||
global table globalToneAPIDeathData = {}
|
||||
global table globalToneAPIDWEData = {}
|
||||
global table globalToneAPIMapDeathData = {}
|
||||
global table globalToneAPIMapDistData = {}
|
||||
global table globalToneAPIMapKillData = {}
|
||||
global table globalToneAPIMapMDistData = {}
|
||||
global table globalToneAPIGamemodeData = {}
|
||||
global table globalToneAPIAllPlayerKillData = {}
|
||||
global table globalToneAPIAllPlayerDeathData = {}
|
||||
global table pulseData = {}
|
||||
global table< table > globalToneAPIGamemodeMapData = {}
|
||||
|
||||
string prefix = "default"
|
||||
@@ -51,35 +42,23 @@ void function pulseInit()
|
||||
void function GetStatsFromToneAPI()
|
||||
{
|
||||
string UID = NSGetLocalPlayerUID()
|
||||
array <string> allHttpRequests = ["/weapons", "/weapons", "/maps", "/gamemodes"]
|
||||
array <string> allHttpRequests = ["/weapons", "/weapons", "/gamemodes", "/maps"]
|
||||
array <string> allHttpParameters = [UID, "!" + UID, UID, UID]
|
||||
array <string> keyValues = ["weaponsLocal", "weaponsGlobal", "gamemodes", "maps"]
|
||||
for (int i; i < allHttpRequests.len(); i++) {
|
||||
HttpRequest getStats
|
||||
getStats.method = HttpRequestMethod.GET
|
||||
getStats.url = HTTPrequestURL + allHttpRequests[i]
|
||||
getStats.queryParameters["player"] <- [allHttpParameters[i]]
|
||||
void functionref(HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (i, allHttpRequests)
|
||||
void functionref(HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (i, allHttpRequests, keyValues)
|
||||
{
|
||||
table DecodedJSON = DecodeJSON(response.body)
|
||||
table keyandvalues = {}
|
||||
foreach (var key, var value in DecodedJSON) {
|
||||
table test = expect table(value)
|
||||
switch (i) {
|
||||
case 0:
|
||||
globalToneAPIKillData[string(key)] <- test.kills
|
||||
globalToneAPIDeathData[string(key)] <- test.deaths
|
||||
globalToneAPIDWEData[string(key)] <- test.deaths_while_equipped
|
||||
case 1:
|
||||
globalToneAPIAllPlayerKillData[string(key)] <- test.kills
|
||||
globalToneAPIAllPlayerDeathData[string(key)] <- test.deaths
|
||||
case 2:
|
||||
globalToneAPIMapKillData[string(key)] <- test.kills
|
||||
globalToneAPIMapDeathData[string(key)] <- test.deaths
|
||||
globalToneAPIMapDistData[string(key)] <- test.total_distance
|
||||
globalToneAPIMapMDistData[string(key)] <- test.max_distance
|
||||
case 3:
|
||||
globalToneAPIGamemodeData[string(key)] <- test.kills
|
||||
table values = expect table(value)
|
||||
keyandvalues[string(key)] <- values
|
||||
}
|
||||
}
|
||||
pulseData[keyValues[i]] <- keyandvalues
|
||||
print(prefix + "has succeeded in getting stats for " + allHttpRequests[i].slice(1))
|
||||
}
|
||||
void functionref(HttpRequestFailure) onFailure = void function(HttpRequestFailure failure) : (i, allHttpRequests)
|
||||
@@ -122,13 +101,19 @@ void function fetchGamemodeStatsFromToneAPI(string mapName)
|
||||
NSHttpRequest(getMapGamemodeStats, onSuccess, onFailure)
|
||||
}
|
||||
|
||||
int function getFromToneAPI(string parameter, table data){
|
||||
int function getFromToneAPI(string parameter, string key, string value){
|
||||
|
||||
if (file.allMaps.find(parameter) != -1) {
|
||||
if (key == "maps") {
|
||||
parameter = parameter.slice(3)
|
||||
}
|
||||
if (parameter in data) {
|
||||
return expect int(data[parameter])
|
||||
if (key in pulseData) {
|
||||
table keyandvalTable = expect table(pulseData[key])
|
||||
// look to array keyValues for possible values for key
|
||||
if (parameter in keyandvalTable) {
|
||||
table valTable = expect table(keyandvalTable[parameter])
|
||||
return expect int(valTable[value])
|
||||
// possible values for parameter: kills, deaths, deaths_while_equipped, total_distance, max_distance
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -155,16 +155,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, globalToneAPIMapKillData) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue0", getFromToneAPI(mapName, "maps", "kills") )
|
||||
|
||||
SetStatsLabelValue( file.menu, "KillsLabel1", "DEATHS ON MAP" )
|
||||
SetStatsLabelValue( file.menu, "KillsValue1", getFromToneAPI(mapName, globalToneAPIMapDeathData) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue1", getFromToneAPI(mapName, "maps", "deaths") )
|
||||
|
||||
SetStatsLabelValue( file.menu, "KillsLabel2", "TOTAL SHOT DISTANCE" )
|
||||
SetStatsLabelValue( file.menu, "KillsValue2", string(int((1.905 * float(getFromToneAPI(mapName, globalToneAPIMapDistData) ) ) )/100) + "m" )
|
||||
SetStatsLabelValue( file.menu, "KillsValue2", string(int((1.905 * float(getFromToneAPI(mapName, "maps", "total_distance") ) ) )/100) + "m" )
|
||||
|
||||
SetStatsLabelValue( file.menu, "KillsLabel3", "MAXIMUM SHOT DISTANCE" )
|
||||
SetStatsLabelValue( file.menu, "KillsValue3", string(int((1.905 * float(getFromToneAPI(mapName, globalToneAPIMapMDistData) ) ) )/100) + "m" )
|
||||
SetStatsLabelValue( file.menu, "KillsValue3", string(int((1.905 * float(getFromToneAPI(mapName, "maps", "max_distance") ) ) )/100) + "m" )
|
||||
|
||||
SetStatsLabelValue( file.menu, "KillsLabel4", "--" )
|
||||
SetStatsLabelValue( file.menu, "KillsValue4", "--" )
|
||||
|
||||
@@ -6,11 +6,13 @@ struct
|
||||
{
|
||||
var menu
|
||||
array<ItemDisplayData> allTitans
|
||||
array<ItemDisplayData> allPilotWeapons
|
||||
table<string, array<string> > titanStatLoadout
|
||||
} file
|
||||
|
||||
const MAX_DOTS_ON_GRAPH = 10
|
||||
table <string, int> titanKillData = {}
|
||||
table <string, int> pilotKillData = {}
|
||||
|
||||
const IMAGE_TITAN_STRYDER = $"ui/menu/personal_stats/ps_titan_icon_stryder"
|
||||
const IMAGE_TITAN_ATLAS = $"ui/menu/personal_stats/ps_titan_icon_atlas"
|
||||
@@ -34,7 +36,7 @@ void function GetTitanKills( string titanName )
|
||||
{
|
||||
file.allTitans = GetVisibleItemsOfType( eItemTypes.TITAN )
|
||||
var dataTable = GetDataTable( $"datatable/titan_properties.rpak" )
|
||||
|
||||
|
||||
foreach ( titan in file.allTitans )
|
||||
{
|
||||
file.titanStatLoadout[ titan.ref ] <- []
|
||||
@@ -50,10 +52,19 @@ void function GetTitanKills( string titanName )
|
||||
|
||||
foreach ( weaponRef in file.titanStatLoadout[ titanName ])
|
||||
{
|
||||
titanKillData[weaponRef] <- getFromToneAPI(weaponRef, globalToneAPIKillData)
|
||||
titanKillData[weaponRef] <- getFromToneAPI(weaponRef, "weaponsLocal", "kills")
|
||||
}
|
||||
}
|
||||
|
||||
void function GetAllPilotWeapons()
|
||||
{
|
||||
file.allPilotWeapons = GetVisibleItemsOfType( eItemTypes.PILOT_PRIMARY)
|
||||
file.allPilotWeapons.extend(GetVisibleItemsOfType( eItemTypes.PILOT_SECONDARY) )
|
||||
file.allPilotWeapons.extend(GetVisibleItemsOfType( eItemTypes.PILOT_ORDNANCE) )
|
||||
file.allPilotWeapons.extend( GetVisibleItemsOfType( eItemTypes.PILOT_SPECIAL ) )
|
||||
}
|
||||
|
||||
|
||||
void function OnStatsOverview_Open()
|
||||
{
|
||||
UI_SetPresentationType( ePresentationType.NO_MODELS )
|
||||
@@ -288,40 +299,45 @@ function UpdateViewStatsOverviewMenu()
|
||||
//#########################
|
||||
|
||||
// Lifetime
|
||||
|
||||
table playerweaponData = expect table(pulseData["weaponsLocal"])
|
||||
table globalweaponData = expect table(pulseData["weaponsGlobal"])
|
||||
var totalPilotKills = 0
|
||||
|
||||
foreach (var key, var value in globalToneAPIKillData) {
|
||||
totalPilotKills += value
|
||||
|
||||
foreach (var key, var value in playerweaponData) {
|
||||
table values = expect table(value)
|
||||
totalPilotKills += values["kills"]
|
||||
}
|
||||
|
||||
var totalGlobalKills = 0
|
||||
foreach (var key, var value in globalToneAPIAllPlayerKillData) {
|
||||
totalGlobalKills += value
|
||||
}
|
||||
|
||||
var totalGlobalDeaths = 0
|
||||
foreach (var key, var value in globalToneAPIAllPlayerDeathData) {
|
||||
totalGlobalDeaths += value
|
||||
foreach (var key, var value in globalweaponData) {
|
||||
table values = expect table(value)
|
||||
totalGlobalKills += values["kills"]
|
||||
}
|
||||
|
||||
var totalPilotDeaths = 0
|
||||
|
||||
foreach (var key, var value in globalToneAPIDeathData) {
|
||||
totalPilotDeaths += value
|
||||
foreach (var key, var value in playerweaponData) {
|
||||
table values = expect table(value)
|
||||
totalPilotDeaths += values["deaths"]
|
||||
}
|
||||
|
||||
var totalGlobalDeaths = 0
|
||||
foreach (var key, var value in globalweaponData) {
|
||||
table values = expect table(value)
|
||||
totalGlobalDeaths += values["deaths"]
|
||||
}
|
||||
|
||||
|
||||
var killsAsPilot = 0
|
||||
foreach (var key, var value in globalToneAPIKillData) {
|
||||
foreach (var key, var value in playerweaponData) {
|
||||
if (key in titanKillData) {
|
||||
continue
|
||||
} else {
|
||||
killsAsPilot += getFromToneAPI(string(key), globalToneAPIKillData)
|
||||
killsAsPilot += getFromToneAPI(string(key), "weaponsLocal", "kills")
|
||||
}
|
||||
}
|
||||
|
||||
var killsAsTitan = 0
|
||||
foreach (var key, var value in globalToneAPIKillData) {
|
||||
foreach (var key, var value in playerweaponData) {
|
||||
if (key in titanKillData) {
|
||||
killsAsTitan += titanKillData[string(key)]
|
||||
}
|
||||
@@ -391,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", globalToneAPIKillData) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue4" ), string( getFromToneAPI("human_execution", globalToneAPIKillData) ) )
|
||||
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, "KillsAsPilotValue5" ), string( GetPlayerStatInt( player, "kills_stats", "titanFallKill" ) ) )
|
||||
|
||||
var titanMeleeKills = 0
|
||||
titanMeleeKills += getFromToneAPI("titan_punch_ion", globalToneAPIKillData)
|
||||
titanMeleeKills += getFromToneAPI("titan_punch_scorch", globalToneAPIKillData)
|
||||
titanMeleeKills += getFromToneAPI("titan_punch_northstar", globalToneAPIKillData)
|
||||
titanMeleeKills += getFromToneAPI("titan_sword", globalToneAPIKillData)
|
||||
titanMeleeKills += getFromToneAPI("titan_punch_tone", globalToneAPIKillData)
|
||||
titanMeleeKills += getFromToneAPI("titan_punch_legion", globalToneAPIKillData)
|
||||
titanMeleeKills += getFromToneAPI("titan_punch_vanguard", globalToneAPIKillData)
|
||||
titanMeleeKills += getFromToneAPI("auto_titan_melee", globalToneAPIKillData)
|
||||
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")
|
||||
|
||||
var titanExecutions = getFromToneAPI("titan_execution", globalToneAPIKillData)
|
||||
var titanExecutions = getFromToneAPI("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", globalToneAPIKillData) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue4" ), string( getFromToneAPI("damagedef_titan_step", "weaponsLocal", "kills") ) )
|
||||
}
|
||||
|
||||
function PlotKDPointsOnGraph( menu, graphIndex, values, dottedAverage )
|
||||
|
||||
@@ -49,7 +49,7 @@ float function GetTitanKills( string titanName)
|
||||
float weaponKills = 0
|
||||
foreach ( weaponRef in file.titanStatLoadout[ titanName ])
|
||||
{
|
||||
weaponKills += float(getFromToneAPI(weaponRef, globalToneAPIKillData))
|
||||
weaponKills += float(getFromToneAPI(weaponRef, "weaponsLocal", "kills"))
|
||||
}
|
||||
return weaponKills
|
||||
}
|
||||
@@ -79,11 +79,13 @@ void function UpdateViewStatsTimeMenu()
|
||||
//#########################################
|
||||
// Time By Class Pie Chart
|
||||
//#########################################
|
||||
|
||||
|
||||
var totalPilotKills = 0
|
||||
|
||||
foreach (var key, var value in globalToneAPIKillData) {
|
||||
totalPilotKills += value
|
||||
table playerweaponData = expect table(pulseData["weaponsLocal"])
|
||||
|
||||
foreach (var key, var value in playerweaponData) {
|
||||
table values = expect table(value)
|
||||
totalPilotKills += values["kills"]
|
||||
}
|
||||
float hoursAsPilot = float(totalPilotKills)
|
||||
float hoursAsTitan = killsAsTitan
|
||||
@@ -153,10 +155,10 @@ void function UpdateViewStatsTimeMenu()
|
||||
for ( int modeId = 0; modeId < enumCount; modeId++ )
|
||||
{
|
||||
string modeName = PersistenceGetEnumItemNameForIndex( "gameModes", modeId )
|
||||
if ( modeName in globalToneAPIGamemodeData )
|
||||
if ( getFromToneAPI(modeName, "gamemodes", "kills") != 0 )
|
||||
{
|
||||
float modePlayedTime = 0
|
||||
modePlayedTime = float(globalToneAPIGamemodeData[modeName])
|
||||
modePlayedTime = float(getFromToneAPI(modeName, "gamemodes", "kills"))
|
||||
if ( modePlayedTime > 0 ) {
|
||||
AddPieChartEntry( modes, GameMode_GetName( modeName ), modePlayedTime, GetGameModeDisplayColor( modeName ) )
|
||||
}
|
||||
@@ -164,10 +166,10 @@ void function UpdateViewStatsTimeMenu()
|
||||
}
|
||||
foreach (string key, array<int> value in customGamemodeList)
|
||||
{
|
||||
if ( key in globalToneAPIGamemodeData)
|
||||
if ( getFromToneAPI(key, "gamemodes", "kills") != 0 )
|
||||
{
|
||||
float modePlayedTime = 0
|
||||
modePlayedTime = float(globalToneAPIGamemodeData[key])
|
||||
modePlayedTime = float(getFromToneAPI(key, "gamemodes", "kills"))
|
||||
if ( modePlayedTime > 0 ) {
|
||||
AddPieChartEntry( modes, key, modePlayedTime, value)
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ void function UpdateStatsForTitan( string titanRef, int loadoutIndex )
|
||||
int aiKills
|
||||
foreach ( weaponRef in file.titanStatLoadout[ titanRef ] )
|
||||
{
|
||||
totalKills += getFromToneAPI(weaponRef, globalToneAPIKillData)
|
||||
totalKills += getFromToneAPI(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 )
|
||||
|
||||
@@ -338,7 +338,7 @@ table<string, table> function GetOverviewWeaponData()
|
||||
if ( !PersistenceEnumValueIsValid( "loadoutWeaponsAndAbilities", weaponName ) )
|
||||
continue
|
||||
|
||||
int val = getFromToneAPI(weaponName, globalToneAPIKillData)
|
||||
int val = getFromToneAPI(weaponName, "weaponsLocal", "kills")
|
||||
if ( val > Table[ "most_kills" ].val )
|
||||
{
|
||||
Table[ "most_kills" ].ref = weaponName
|
||||
@@ -346,7 +346,7 @@ table<string, table> function GetOverviewWeaponData()
|
||||
Table[ "most_kills" ].val = val
|
||||
}
|
||||
|
||||
int nval = getFromToneAPI(weaponName, globalToneAPIDeathData)
|
||||
int nval = getFromToneAPI(weaponName, "weaponsLocal", "deaths")
|
||||
if ( nval > Table[ "nemesis_weapon" ].val )
|
||||
{
|
||||
Table[ "nemesis_weapon" ].ref = weaponName
|
||||
@@ -357,9 +357,9 @@ table<string, table> function GetOverviewWeaponData()
|
||||
float kdval = 0
|
||||
float kval = 0
|
||||
float dval = 0
|
||||
if( getFromToneAPI(weaponName, globalToneAPIKillData) != 0 && getFromToneAPI(weaponName, globalToneAPIDWEData) != 0){
|
||||
kval = float(getFromToneAPI(weaponName, globalToneAPIKillData))
|
||||
dval = float(getFromToneAPI(weaponName, globalToneAPIDWEData))
|
||||
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 (kval / dval > kdval){
|
||||
kdval = kval / dval
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ void function UpdateStatsForWeapon( string weaponRef )
|
||||
}
|
||||
|
||||
// Total Kills Stats
|
||||
SetStatsLabelValue( file.menu, "KillsValue0", getFromToneAPI(weaponRef, globalToneAPIKillData) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue1", getFromToneAPI(weaponRef, globalToneAPIKillData) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue2", GetPlayerStatInt( player, "weapon_kill_stats", "titansTotal", weaponRef ) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue3", getFromToneAPI(weaponRef, globalToneAPIDWEData))
|
||||
SetStatsLabelValue( file.menu, "KillsValue0", getFromToneAPI(weaponRef, "weaponsLocal", "kills") ) //Total kills
|
||||
SetStatsLabelValue( file.menu, "KillsValue1", getFromToneAPI(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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user