Files
pulse/mods/ToneAPI.pulse/mod/scripts/vscripts/pulse-common-func.gnut
T
2023-10-23 20:19:30 +02:00

95 lines
3.1 KiB
Plaintext

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
void function pulsePrefixSet() //Sets our prefix
{
pulsePrefix = format("\x1b[38;2;%i;%i;%im[PULSE]\x1b[0m", 255, 178, 102)
}
void function pulsePrintt(string content) //Prints whatever we want printed with given prefix (by standard [PULSE]).
{
printt(format("%s " + content, pulsePrefix))
}
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
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)
foreach (var key in DecodedJSON) {
table dData = DecodedJSON[key]
pulseDataStruct data = {
dataType = requestedDataType,
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 {
pulsePrintt(format("%s, %s is unreachable.", response.statusCode, givenURL))
pulseLockStats()
}
}
void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure) : (givenURL)
{
pulsePrintt(format("Something went wrong, %s is unreachable", givenURL))
pulseLockStats()
}
foreach (key, value in parameterTable)
{
requestTable[string(key)] <- [string(value)]
}
return NSHttpGet(givenURL, requestTable, onSuccess, onFailure)
}
void function pulseLockStats()
{
loebSetLockedButton(Localize("#MENU_TITLE_STATS"), true)
}
string function HammerToMeterString(float value)
{
return value > 0 && int((1.905 * value ))/100 > 0 ? string(int((1.905 * value ) )/100) + "m" : "0";
}