Skip to content

Commit

Permalink
totd map submissions work with optional dep of mapinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Whitacre committed Aug 28, 2024
1 parent 2e846a6 commit c30143c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugin/info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ author = "DanOnTheMoon"
category = "Race"
version = "0.0.2"
siteid = 610

[script]
optional_dependencies = ["mapinfo"]
10 changes: 10 additions & 0 deletions plugin/src/API.as
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,21 @@ void SubmitMapPB() {
const string accountId = App.MenuManager.MenuCustom_CurrentManiaApp.LocalUser.WebServicesUserId;
const string displayName = App.MenuManager.MenuCustom_CurrentManiaApp.LocalUser.Name;
const uint pb = App.MenuManager.MenuCustom_CurrentManiaApp.ScoreMgr.Map_GetRecord_v2(App.UserManagerScript.Users[0].Id, uid, "PersonalBest", "", "TimeAttack", "");
auto currentMapInfo = MapInfo::GetCurrentMapInfo();

if (pb > 2147483647) {
error("submitting map pb failed after " + (Time::Now - start) + "ms: pb is not set or too large");
submitting = false;
return;
}

Json::Value mapData = Json::Object();
mapData["mapUid"] = uid;
mapData["authorTime"] = author;
mapData["name"] = mapName;
if (currentMapInfo.LoadedWasTOTD) {
mapData["totdDate"] = currentMapInfo.TOTDDate.Split(" ")[0];
}

Net::HttpRequest@ req = Net::HttpPost(S_ApiUrl + "/maps?api-key=" + S_ApiKey, Json::Write(mapData), "application/json");
while (!req.Finished())
Expand Down
4 changes: 4 additions & 0 deletions plugin/src/MedalWindow.as
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ void MedalWindow() {

UI::Separator();

#if DEPENDENCY_MAPINFO
UI::BeginDisabled(submitting);
if (UI::Button(" Submit" + (submitting ? "ing..." : "") + " PB")) {
trace("submitting...");
startnew(SubmitMapPB);
}
UI::EndDisabled();
#else
UI::Text("Install Map Info to submit times.");
#endif
}
}
UI::End();
Expand Down

0 comments on commit c30143c

Please sign in to comment.