diff --git a/mod.json b/mod.json index ee14667..248814a 100644 --- a/mod.json +++ b/mod.json @@ -27,11 +27,15 @@ ], "Scripts": [ { - "Path": "pulse.gnut", - "RunOn": "UI", - "UICallback": { - "After": "pulseInit" - } + "Path":"pulse-common-func.gnut", + "RunOn":"UI" + }, + { + "Path": "pulse.gnut", + "RunOn": "UI", + "UICallback": { + "After": "pulseInit" + } } ] } diff --git a/mod/scripts/vscripts/pulse-common-func.gnut b/mod/scripts/vscripts/pulse-common-func.gnut new file mode 100644 index 0000000..95afc27 --- /dev/null +++ b/mod/scripts/vscripts/pulse-common-func.gnut @@ -0,0 +1,42 @@ +globalize_all_functions + + +void function pulsePrintt (string content) +{ + printt(format("%s " + content, pulsePrefix)) +} + +table function pulseGetCurrentVersionAsTable +{ + table result = ["MajorVersion" = GetConVarString("MajorVersion"), "MinorVersion" = GetConVarString("MinorVersion"), "PatchVersion" = GetConVarString("PatchVersion")] + return result +} + +string function pulseFormatAsVersion(table Version) +{ + return format("v%s.%s.%s", Version["MajorVersion"], Version["MinorVersion"], Version["PatchVersion"]) +} + +bool function pulseIsUpToDate(string givenURL) +{ + bool result = false + HttpRequest versionreq + versionreq.method = HttpRequestMethod.GET + versionreq.url = givenURL + void functionref (HttpRequestResponse) onSuccess = void function(HttpRequestResponse response) + { + table DecodedJSON = DecodeJSON(response.body) + if (pulseFormatAsVersion(DecodedJSON) == pulseFormatAsVersion(pulseGetCurrentVersionAsTable())) + { + result = true + } else { + result = false + } + } + void functionref (HttpRequestFailure) onFailure = void function(HttpRequestFailure failure) + { + pulsePrintt("Something went wrong while getting latest version.") + } + NSHttpRequest(versionreq, onSuccess, onFailure) + return result +} \ No newline at end of file diff --git a/version.json b/version.json index d3c0ffc..d2cae6f 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "Major": "2", - "Minor": "0", - "Patch": "0" + "MajorVersion": "2", + "MinorVersion": "0", + "PatchVersion": "0" } \ No newline at end of file