From 5735e67c2f78f24ecc4477b3fe7c564fe52389d5 Mon Sep 17 00:00:00 2001 From: okvdai <108829133+okvdai@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:06:32 +0200 Subject: [PATCH] Copy getFromToneAPI to common file as pulseParse --- mod/scripts/vscripts/pulse-common-func.gnut | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mod/scripts/vscripts/pulse-common-func.gnut b/mod/scripts/vscripts/pulse-common-func.gnut index f739707..f291ef0 100644 --- a/mod/scripts/vscripts/pulse-common-func.gnut +++ b/mod/scripts/vscripts/pulse-common-func.gnut @@ -45,7 +45,7 @@ bool function pulseIsUpToDate(string givenURL) //Compares version contained in o return result } -bool function pulseRequestData(string givenURL, table parameterTable) //Gets all data from API (see ToneURL within mod.json) and puts it into one table for processing. +bool function pulseRequestData(string givenURL, table parameterTable) //Gets data from API (see ToneURL within mod.json) and puts it into one table for processing. { table > params foreach (parameter in paramTable) @@ -62,4 +62,19 @@ bool function pulseRequestData(string givenURL, table parameterTable) //Gets all pulsePrintt("Something went wrong while getting data.") } return NSHttpGet(givenURL, params, onSuccess, onFailure) +} + +int function pulseParse(string parameter, string key, string value) +{ + if (key == "maps") { + parameter = parameter.slice(3) + } + 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]) + } + } + return 0 } \ No newline at end of file