25 Commits
Author SHA1 Message Date
okvdai 47e4cd949c Begin #37 2023-10-23 20:19:30 +02:00
okvdai ca2ef84d55 Merge branch 'dev' of https://github.com/ToneAPI/pulse into dev 2023-10-23 18:32:39 +02:00
okvdai 02ba70198f Update version numbers 2023-10-13 19:04:54 +02:00
okvdai f959f7dd91 Prepare for release v2.1.0 2023-10-03 23:37:41 +02:00
okvdai 7aa6c9476f Fix stats loading only after reloading mods 2023-09-03 15:20:57 +02:00
okvdai 0f0d89c9c3 Merge pulse-loeb-component.nut into pulse-common-func.gnut 2023-09-03 15:15:33 +02:00
okvdai d56b2878a2 Update ToneURL convar 2023-09-03 14:16:16 +02:00
okvdai 5a5591d7b4 Update pulse-loeb-component.nut 2023-07-31 22:58:52 +02:00
okvdai 48c415c9ba Dependency info 2023-07-07 18:41:31 +02:00
okvdai 11ae2bac90 Integrate with loeb #35 2023-07-07 18:30:26 +02:00
okvdai f7e4588f80 Update localisation 2023-06-21 14:44:04 +02:00
okvdai b8879c3560 Update viewstats_maps.menu 2023-06-21 14:37:50 +02:00
okvdai 1c5ab1514b Average kill distance calculation, better Hammer conversion 2023-06-21 14:36:41 +02:00
okvdai c538dd44f3 Hotfixes 2023-06-20 20:25:31 +02:00
okvdai df4ee8fb0c Rename pulseSuccessBool to pulseFailure 2023-06-20 20:21:49 +02:00
okvdai ba0c4d11c7 Change request failure message 2023-06-20 20:20:55 +02:00
okvdai c1cd3a6fc7 Format code 2023-06-20 20:17:52 +02:00
okvdai a8bbd9ea39 Fix typo in english localisation 2023-06-20 20:16:17 +02:00
okvdai ff06daefae Use NsIsSuccessHttpCode() for status code checking 2023-06-20 20:15:47 +02:00
okvdai e1d5801d9a Add melee_pilot_kunai into the melee kill stat 2023-06-20 16:30:02 +02:00
okvdai d4efc94e7d Add missing comma 2023-06-19 13:42:18 +02:00
okvdai 81b1b4f928 Cleanup in menu_stats_overview.nut 2023-06-15 19:22:06 +02:00
okvdai 1d6b09537f Add status code checking to request function
"Borrowed" from the servermod
2023-06-15 19:02:54 +02:00
okvdai 4ce976cc88 Delete .gitignore 2023-05-04 20:48:07 +02:00
okvdai 687819e604 Create .gitignore 2023-05-04 20:46:03 +02:00
14 changed files with 104 additions and 1716 deletions
+11 -1
View File
@@ -73,11 +73,13 @@ Found a bug? Make an issue on GitHub [here.](https://github.com/ToneAPI/pulse/is
- Kills by Gamemode - piechart showing all kills (in percent) on chosen map by gamemode. - Kills by Gamemode - piechart showing all kills (in percent) on chosen map by gamemode.
</details> </details>
## DISCLAIMER ## DISCLAIMERS
The Tone API is NOT used by every server, view a list of supported servers [here.](https://tone.sleepycat.date/v2/client/servers) The Tone API is NOT used by every server, view a list of supported servers [here.](https://tone.sleepycat.date/v2/client/servers)
**pulse** is very much a W.I.P as of right now, features may be missing/nonfunctional. **pulse** is very much a W.I.P as of right now, features may be missing/nonfunctional.
As of v2.1.0, **pulse** requires [loeb](https://github.com/okvdai/loeb)
## CHANGELOG ## CHANGELOG
<details> <details>
@@ -97,3 +99,11 @@ The Tone API is NOT used by every server, view a list of supported servers [here
- Polish. (Northstar isn't translated into Polish, but the game supports it.) - Polish. (Northstar isn't translated into Polish, but the game supports it.)
- Locking the Stats tab, avoiding situations where you could click too fast and see no stats. Also prevents the game from showing stats when the API is unreachable. - Locking the Stats tab, avoiding situations where you could click too fast and see no stats. Also prevents the game from showing stats when the API is unreachable.
</details> </details>
<details>
<summary> pulse v2.1.0 </summary>
- Changed endpoint
- Lots of bug fixes
- Uses new experimental loeb library
</details>
+2 -2
View File
@@ -1,7 +1,7 @@
{ {
"name": "Pulse", "name": "Pulse",
"description": "Adds stats (collected by the Tone API) back to the Stats tab.", "description": "Adds stats (collected by the Tone API) back to the Stats tab.",
"version_number": "2.0.0", "version_number": "2.1.1",
"website_url": "https://github.com/ToneAPI/pulse", "website_url": "https://github.com/ToneAPI/pulse",
"dependencies": [] "dependencies": ["Okudai-loeb-1.0.1"]
} }
+2 -6
View File
@@ -1,16 +1,12 @@
{ {
"Name": "ToneAPI.pulse", "Name": "ToneAPI.pulse",
"Description": "Displays Tone API kill data in the Stats tab.", "Description": "Displays Tone API kill data in the Stats tab.",
"Version": "2.0.0", "Version": "2.1.1",
"LoadPriority": 1, "LoadPriority": 1,
"ConVars": [ "ConVars": [
{ {
"Name": "ToneURL", "Name": "ToneURL",
"DefaultValue": "https://tone.sleepycat.date/v2/client" "DefaultValue": "https://toneapi.ovh/v2/client"
},
{
"Name": "VersionURL",
"DefaultValue": "https://raw.githubusercontent.com/ToneAPI/pulse/main/version.json"
} }
], ],
"Scripts": [ "Scripts": [
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -532,7 +532,7 @@ resource/ui/menus/viewstats_pve.menu
visible 1 visible 1
font Default_23 font Default_23
labelText "--" labelText "--"
allcaps 1 allcaps 0
textAlignment center textAlignment center
fgcolor_override "255 255 255 255" fgcolor_override "255 255 255 255"
//bgcolor_override "0 255 0 100" //bgcolor_override "0 255 0 100"
@@ -1,10 +1,25 @@
globalize_all_functions globalize_all_functions
global enum ePulseDataType
{
WEAPON,
MAP,
GAMEMODE,
}
global struct pulseDataStruct
{
ePulseDataType dataType,
string dataName,
bool global,
int kills,
int deaths,
int max_distance,
int total_distance,
int deaths_while_equipped
}
global string pulsePrefix global string pulsePrefix
global bool pulseSuccessBool = true
table withMapName = {}
void function pulsePrefixSet() //Sets our prefix void function pulsePrefixSet() //Sets our prefix
{ {
pulsePrefix = format("\x1b[38;2;%i;%i;%im[PULSE]\x1b[0m", 255, 178, 102) pulsePrefix = format("\x1b[38;2;%i;%i;%im[PULSE]\x1b[0m", 255, 178, 102)
@@ -18,23 +33,49 @@ void function pulsePrintt(string content) //Prints whatever we want printed with
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. 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> > requestTable table<string, array<string> > requestTable
void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (parameterTable, requestTable, tablepath) ePulseDataType requestedDataType
if ("weapon" in parameterTable)
{
requestedDataType = ePulseDataType.WEAPON
}
else if ("map" in parameterTable)
{
requestedDataType = ePulseDataType.MAP
}
else if ("gamemode" in parameterTable)
{
requestedDataType = ePulseDataType.GAMEMODE
}
void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) : (givenURL, parameterTable, requestTable, tablepath, requestedDataType)
{
if (NSIsSuccessHttpCode(respone.StatusCode))
{ {
table DecodedJSON = DecodeJSON(response.body) table DecodedJSON = DecodeJSON(response.body)
if ("map" in parameterTable) foreach (var key in DecodedJSON) {
{ table dData = DecodedJSON[key]
string mapName = expect string(parameterTable["map"]) pulseDataStruct data = {
withMapName[mapName] <- DecodedJSON dataType = requestedDataType,
pulseData[tablepath] <- withMapName dataName = string(key),
global = tablepath.find("Global") != null ? true : false;
int kills = "kills" in dData ? dData["kills"] : 0
int deaths = "deaths" in dData ? dData["deaths"] : 0
int max_distance = "max_distance" in dData ? dData["max_distance"] : 0
int total_distance = "total_distance" in dData ? dData["total_distance"] : 0
int deaths_while_equipped = "deaths_while_equipped" in dData ? dData["deaths_while_equipped"] : 0
}
pulseData.append(data)
}
} else { } else {
pulseData[tablepath] <- DecodedJSON pulsePrintt(format("%s, %s is unreachable.", response.statusCode, givenURL))
pulseLockStats()
} }
pulseSuccessBool = false
} }
void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure) void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure) : (givenURL)
{ {
pulsePrintt("Something went wrong while getting data.") pulsePrintt(format("Something went wrong, %s is unreachable", givenURL))
pulseSuccessBool = true pulseLockStats()
} }
foreach (key, value in parameterTable) foreach (key, value in parameterTable)
{ {
@@ -43,18 +84,12 @@ bool function pulseRequestData(string givenURL, table parameterTable, string tab
return NSHttpGet(givenURL, requestTable, onSuccess, onFailure) return NSHttpGet(givenURL, requestTable, onSuccess, onFailure)
} }
int function pulseParse(...) //Returns data from our pulseData table. void function pulseLockStats()
{ {
table parser = pulseData loebSetLockedButton(Localize("#MENU_TITLE_STATS"), true)
int result = 0
for (int i; i < vargc; i++) {
if (i < expect int(vargc) - 1) {
if (expect string (vargv[i]) in parser) {
parser = expect table(parser[expect string(vargv[i])])
} else {break}
} else {
result = expect int(parser[expect string(vargv[i])])
} }
}
return result string function HammerToMeterString(float value)
{
return value > 0 && int((1.905 * value ))/100 > 0 ? string(int((1.905 * value ) )/100) + "m" : "0";
} }
@@ -1,7 +1,7 @@
global function pulseInit global function pulseInit
global function pulseGetData global function pulseGetData
global table pulseData = {} global array<pulseDataStruct> pulseData = []
struct { struct {
array<string> allMaps array<string> allMaps
@@ -12,10 +12,12 @@ void function pulseInit()
pulsePrefixSet() pulsePrefixSet()
file.allMaps = GetPrivateMatchMaps() file.allMaps = GetPrivateMatchMaps()
pulsePrintt("Initialized.") pulsePrintt("Initialized.")
AddUICallback_OnLevelInit( pulseGetData )
} }
void function pulseGetData() void function pulseGetData()
{ {
print("data getter called")
string URL = GetConVarString("ToneURL") string URL = GetConVarString("ToneURL")
array <string> URLpath = ["/weapons", "/weapons", "/gamemodes", "/gamemodes", "/maps"] array <string> URLpath = ["/weapons", "/weapons", "/gamemodes", "/gamemodes", "/maps"]
array <string> tablepath = ["weaponsLocal", "weaponsGlobal", "gamemodesAll", "gamemodesSeparated", "maps"] array <string> tablepath = ["weaponsLocal", "weaponsGlobal", "gamemodesAll", "gamemodesSeparated", "maps"]
File diff suppressed because it is too large Load Diff
@@ -159,13 +159,13 @@ void function UpdateStatsForMap( string mapName )
SetStatsLabelValue( file.menu, "KillsValue1", pulseParse("maps", mapName.slice(3), "deaths") ) SetStatsLabelValue( file.menu, "KillsValue1", pulseParse("maps", mapName.slice(3), "deaths") )
SetStatsLabelValue( file.menu, "KillsLabel2", Localize("#MAPS_TSD") ) SetStatsLabelValue( file.menu, "KillsLabel2", Localize("#MAPS_TSD") )
SetStatsLabelValue( file.menu, "KillsValue2", string(int((1.905 * float(pulseParse("maps", mapName.slice(3), "total_distance") ) ) )/100) + "m" ) SetStatsLabelValue( file.menu, "KillsValue2", HammerToMeterString(float(pulseParse("maps", mapName.slice(3), "total_distance"))))
SetStatsLabelValue( file.menu, "KillsLabel3", Localize("#MAPS_MSD") ) SetStatsLabelValue( file.menu, "KillsLabel3", Localize("#MAPS_MSD") )
SetStatsLabelValue( file.menu, "KillsValue3", string(int((1.905 * float(pulseParse("maps", mapName.slice(3), "max_distance") ) ) )/100) + "m" ) SetStatsLabelValue( file.menu, "KillsValue3", HammerToMeterString(float(pulseParse("maps", mapName.slice(3), "max_distance"))))
SetStatsLabelValue( file.menu, "KillsLabel4", "--" ) SetStatsLabelValue( file.menu, "KillsLabel4", Localize("#MAPS_ASD") )
SetStatsLabelValue( file.menu, "KillsValue4", "--" ) SetStatsLabelValue( file.menu, "KillsValue4", HammerToMeterString(float(pulseParse("maps", mapName.slice(3), "max_distance")) / float(pulseParse("maps", mapName.slice(3), "kills"))))
//var anchorElem = Hud_GetChild( file.menu, "WeaponStatsBackground" ) //var anchorElem = Hud_GetChild( file.menu, "WeaponStatsBackground" )
//printt( Hud_GetX( anchorElem ) ) //printt( Hud_GetX( anchorElem ) )
@@ -32,7 +32,7 @@ void function InitViewStatsOverviewMenu()
AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" ) AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
} }
void function GetTitanKills( string titanName ) void function GetTitanKills()
{ {
file.allTitans = GetVisibleItemsOfType( eItemTypes.TITAN ) file.allTitans = GetVisibleItemsOfType( eItemTypes.TITAN )
var dataTable = GetDataTable( $"datatable/titan_properties.rpak" ) var dataTable = GetDataTable( $"datatable/titan_properties.rpak" )
@@ -50,11 +50,14 @@ void function GetTitanKills( string titanName )
file.titanStatLoadout[ titan.ref ].append( GetDataTableString( dataTable, row, GetDataTableColumnByName( dataTable, "melee" ) ) ) file.titanStatLoadout[ titan.ref ].append( GetDataTableString( dataTable, row, GetDataTableColumnByName( dataTable, "melee" ) ) )
} }
foreach ( weaponRef in file.titanStatLoadout[ titanName ]) foreach ( titan in file.allTitans)
{
foreach ( weaponRef in file.titanStatLoadout[ titan.ref ])
{ {
titanKillData[weaponRef] <- pulseParse("weaponsLocal", weaponRef, "kills") titanKillData[weaponRef] <- pulseParse("weaponsLocal", weaponRef, "kills")
} }
} }
}
void function GetAllPilotWeapons() void function GetAllPilotWeapons()
{ {
@@ -68,15 +71,7 @@ void function GetAllPilotWeapons()
void function OnStatsOverview_Open() void function OnStatsOverview_Open()
{ {
UI_SetPresentationType( ePresentationType.NO_MODELS ) UI_SetPresentationType( ePresentationType.NO_MODELS )
GetTitanKills()
GetTitanKills("ion")
GetTitanKills("scorch")
GetTitanKills("northstar")
GetTitanKills("ronin")
GetTitanKills("tone")
GetTitanKills("legion")
GetTitanKills("vanguard")
UpdateViewStatsOverviewMenu() UpdateViewStatsOverviewMenu()
} }
@@ -301,48 +296,35 @@ function UpdateViewStatsOverviewMenu()
// Lifetime // Lifetime
table playerweaponData = expect table(pulseData["weaponsLocal"]) table playerweaponData = expect table(pulseData["weaponsLocal"])
table globalweaponData = expect table(pulseData["weaponsGlobal"]) table globalweaponData = expect table(pulseData["weaponsGlobal"])
var totalPilotKills = 0 var totalPilotKills = 0
foreach (var key, var value in playerweaponData) {
table values = expect table(value)
totalPilotKills += values["kills"]
}
var totalGlobalKills = 0
foreach (var key, var value in globalweaponData) {
table values = expect table(value)
totalGlobalKills += values["kills"]
}
var totalPilotDeaths = 0 var totalPilotDeaths = 0
foreach (var key, var value in playerweaponData) { foreach (var key, var value in playerweaponData) {
table values = expect table(value) table values = expect table(value)
totalPilotKills += values["kills"]
totalPilotDeaths += values["deaths"] totalPilotDeaths += values["deaths"]
} }
var totalGlobalKills = 0
var totalGlobalDeaths = 0 var totalGlobalDeaths = 0
foreach (var key, var value in globalweaponData) { foreach (var key, var value in globalweaponData) {
table values = expect table(value) table values = expect table(value)
totalGlobalKills += values["kills"]
totalGlobalDeaths += values["deaths"] totalGlobalDeaths += values["deaths"]
} }
var killsAsTitan = 0
var killsAsPilot = 0 var killsAsPilot = 0
foreach (var key, var value in playerweaponData) { foreach (var key, var value in playerweaponData) {
if (key in titanKillData) { if (key in titanKillData) {
continue killsAsTitan += titanKillData[string(key)]
} else { } else {
killsAsPilot += pulseParse("weaponsLocal", string(key), "kills") killsAsPilot += pulseParse("weaponsLocal", string(key), "kills")
} }
} }
var killsAsTitan = 0
foreach (var key, var value in playerweaponData) {
if (key in titanKillData) {
killsAsTitan += titanKillData[string(key)]
}
}
float kval = float(totalPilotKills) float kval = float(totalPilotKills)
float dval = float(totalPilotDeaths) float dval = float(totalPilotDeaths)
float kdval = float(int((kval / dval)*100))/100 float kdval = float(int((kval / dval)*100))/100
@@ -407,7 +389,7 @@ 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( pulseParse("weaponsLocal", "pilot_emptyhanded", "kills") ) ) Hud_SetText( GetElem( file.menu, "KillsAsPilotValue3" ), string( pulseParse("weaponsLocal", "pilot_emptyhanded", "kills") + pulseParse("weaponsLocal", "melee_pilot_kunai", "kills") ) )
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue4" ), string( pulseParse("weaponsLocal", "human_execution", "kills") ) ) Hud_SetText( GetElem( file.menu, "KillsAsPilotValue4" ), string( pulseParse("weaponsLocal", "human_execution", "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" ) ) )