Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for Champion and Warrior medals #50

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
103 changes: 103 additions & 0 deletions AdditionalMedals.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
bool get_IsChampionMedalsActive() {
#if DEPENDENCY_CHAMPIONMEDALS
auto plugin = Meta::GetPluginFromID("ChampionMedals");
if (plugin !is null) {
return plugin.Enabled;
}
return false;
#else
return false;
#endif
}

bool get_IsWarriorMedalsActive() {
#if DEPENDENCY_WARRIORMEDALS
auto plugin = Meta::GetPluginFromID("WarriorMedals");
if (plugin !is null) {
return plugin.Enabled;
}
return false;
#else
return false;
#endif
}

bool get_ShowChampionMedals() {
return enableChampionMedals && IsChampionMedalsActive;
}

bool get_ShowWarriorMedals() {
return enableWarriorMedals && IsWarriorMedalsActive;
}

[Setting category="Display Text" name="Champion Text" if="get_IsChampionMedalsActive"]
string championText = "Champion";

[Setting category="Display Text" name="Warrior Text" if="get_IsWarriorMedalsActive"]
string warriorText = "Warrior";

[Setting category="Additional Medals" name="Enable Champion Medals" if="get_IsChampionMedalsActive"]
bool enableChampionMedals = true;

[Setting category="Additional Medals" name="Enable Warrior Medals" if="get_IsWarriorMedalsActive"]
bool enableWarriorMedals = true;

int GetChampionMedalsTime() {
#if DEPENDENCY_CHAMPIONMEDALS
if (!IsChampionMedalsActive) {
return -1;
}
return ChampionMedals::GetCMTime();
#else
return -1;
#endif
}

int GetWarriorMedalsTime() {
#if DEPENDENCY_WARRIORMEDALS
if (!IsWarriorMedalsActive) {
return -1;
}
return WarriorMedals::GetWMTime();
#else
return -1;
#endif
}

uint additionalMedalCoroNonce = 0;

void WaitForAdditionalMedalsTimes(const string &in mapUid) {
#if TMNEXT
// wait a few frames before checking for additional medals
yield(5);
auto myNonce = ++additionalMedalCoroNonce;
while (myNonce == additionalMedalCoroNonce && mapUid == currentMapUid) {
// set this to false if any time is < 0
bool haveAllTimes = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you be checking if you have all times? Or should you have separate checks for if you have the Champion time and the warrior time? It feels to have it be the same check when one could not be there.


if (champion.time < 0 && ShowChampionMedals) {
champion.time = GetChampionMedalsTime();
haveAllTimes = haveAllTimes && champion.time >= 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (champion.time == 0) {
 champion.hidden = true;
}

You should add in this check for champion medals because they can also not exist at times like warrior medals.
According to https://openplanet.dev/plugin/championmedals

New Champion medals are added 7 days after the release of a new seasonal campaign, and 1 hour after the release of a new TOTD

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this comes up a bit on my test version of this plugin+PR

trace("Champion time: " + champion.time);
}

if (warrior.time < 0 && ShowWarriorMedals) {
warrior.time = GetWarriorMedalsTime();
haveAllTimes = haveAllTimes && warrior.time >= 0;
// warrior medal returns 0 if it does not exist
if (warrior.time == 0) {
warrior.hidden = true;
}
trace("Warrior time: " + warrior.time);
}

UpdatePBMedalLabel();
if (haveAllTimes) {
break;
}

yield(5);
}
trace("Additional medals times loaded");
#endif
}
Loading