Rework MapValidator + add human readable format

This commit is contained in:
Beu 2024-02-18 18:00:52 +01:00
parent 652bd5fe1a
commit 55c5952258
6 changed files with 185 additions and 114 deletions

View File

@ -0,0 +1,30 @@
#if MP4
CGameCtnEditorFree@ getEditor() {
return cast<CGameCtnEditorFree>(GetApp().Editor);
}
CGameCtnChallenge@ getMap() {
return cast<CGameCtnChallenge>(GetApp().RootMap);;
}
uint getAuthorTime(CGameCtnChallenge@ _Map) {
return _Map.TMObjective_AuthorTime;
}
void setAuthorTime(CGameCtnChallenge@ _Map, uint _AuthorTime) {
_Map.TMObjective_AuthorTime = _AuthorTime;
// Remove the map UID, the game will generate it again when saving
_Map.IdName = "";
}
void setValidationStatus(CGameCtnEditorFree@ _Editor) {
CGameEditorPluginMapMapType@ pluginmaptype = cast<CGameEditorPluginMapMapType>(_Editor.PluginMapType);
if (pluginmaptype is null) return;
pluginmaptype.ValidationStatus = CGameEditorPluginMapMapType::EValidationStatus::Validated;
}
string GetWarning() {
return "";
}
#endif

View File

@ -0,0 +1,27 @@
#if TMNEXT
CGameCtnEditorFree@ getEditor() {
return cast<CGameCtnEditorFree>(GetApp().Editor);
}
CGameCtnChallenge@ getMap() {
return cast<CGameCtnChallenge>(GetApp().RootMap);;
}
uint getAuthorTime(CGameCtnChallenge@ _Map) {
return _Map.TMObjective_AuthorTime;
}
void setAuthorTime(CGameCtnChallenge@ _Map, uint _AuthorTime) {
_Map.TMObjective_AuthorTime = _AuthorTime;
}
void setValidationStatus(CGameCtnEditorFree@ _Editor) {
CGameEditorPluginMapMapType@ pluginmaptype = cast<CGameEditorPluginMapMapType>(_Editor.PluginMapType);
if (pluginmaptype is null) return;
pluginmaptype.ValidationStatus = CGameEditorPluginMapMapType::EValidationStatus::Validated;
}
string GetWarning() {
return "";
}
#endif

View File

@ -0,0 +1,30 @@
#if TURBO
CGameCtnEditorFree@ getEditor() {
return cast<CGameCtnEditorFree>(GetApp().Editor);
}
CGameCtnChallenge@ getMap() {
return cast<CGameCtnChallenge>(GetApp().Challenge);
}
uint getAuthorTime(CGameCtnChallenge@ _Map) {
return _Map.TMObjective_AuthorTime;
}
void setAuthorTime(CGameCtnChallenge@ _Map, uint _AuthorTime) {
_Map.TMObjective_AuthorTime = _AuthorTime;
// Remove the map UID, the game will generate it again when saving
_Map.IdName = "";
}
void setValidationStatus(CGameCtnEditorFree@ _Editor) {
CGameCtnEditorPluginMapType@ pluginmaptype = cast<CGameCtnEditorPluginMapType>(_Editor.EditorMapType);
if (pluginmaptype is null) return;
pluginmaptype.ValidationStatus = CGameCtnEditorPluginMapType::EValidationStatus::Validated;
}
string GetWarning() {
return "Note: your map must have a start and a finish\n(or a multilap + 1CP) to be validated with the plugin";
}
#endif

View File

@ -0,0 +1,32 @@
#if UNITED
CTrackManiaEditor@ getEditor() {
return cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor);
}
CGameCtnChallenge@ getMap() {
return cast<CGameCtnChallenge>(GetApp().Challenge);
}
uint getAuthorTime(CGameCtnChallenge@ _Map) {
return _Map.ChallengeParameters.AuthorTime;
}
void setAuthorTime(CGameCtnChallenge@ _Map, uint _AuthorTime) {
_Map.ChallengeParameters.AuthorTime = _AuthorTime;
_Map.ChallengeParameters.AuthorScore = _AuthorTime;
_Map.ChallengeParameters.GoldTime = Math::Floor((1000 + _AuthorTime + _AuthorTime * 0.06)/1000)*1000;
_Map.ChallengeParameters.SilverTime = Math::Floor((1000 + _AuthorTime + _AuthorTime * 0.2)/1000)*1000;
_Map.ChallengeParameters.BronzeTime = Math::Floor((1000 + _AuthorTime + _AuthorTime * 0.5)/1000)*1000;
// Remove the map UID, the game will generate it again when saving
_Map.IdName = "";
}
void setValidationStatus(CTrackManiaEditor@ _Editor) {
return; // doesn't exists in UNITED
}
string GetWarning() {
return "Note: for an unknown reason, it happens that the times of\nthe medals are not updated, I invite you to check by yourself";
}
#endif

View File

@ -1,128 +1,81 @@
// Based on the Moski plugin which is also based on the Miss plugin :) // Based on the Moski plugin which is also based on the Miss plugin :)
bool menu_visibility = false; bool G_MenuVisibility = false;
int author_time; string G_AuthorTimeText = "0:00:00.000";
void Main() {} void Main() {}
void validate(int author_time) {
// Get editor var
#if UNITED
CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor);
#else
CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor);
#endif
// Get map & pluginmaptype if possible
#if TURBO
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
CGameCtnEditorPluginMapType@ pluginmaptype = cast<CGameCtnEditorPluginMapType>(editor.EditorMapType);
#elif UNITED
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
auto pluginmaptype == null;
#else
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap);
CGameEditorPluginMapMapType@ pluginmaptype = cast<CGameEditorPluginMapMapType>(editor.PluginMapType);
#endif
if (editor is null) {
return;
}
if (pluginmaptype !is null) {
#if TURBO
pluginmaptype.ValidationStatus = CGameCtnEditorPluginMapType::EValidationStatus::Validated;
#else
pluginmaptype.ValidationStatus = CGameEditorPluginMapMapType::EValidationStatus::Validated;
#endif
}
if (map !is null) {
#if UNITED
map.ChallengeParameters.AuthorTime = author_time;
map.ChallengeParameters.AuthorScore = author_time;
map.ChallengeParameters.GoldTime = Math::Floor((1000 + author_time + author_time * 0.06)/1000)*1000;
map.ChallengeParameters.SilverTime = Math::Floor((1000 + author_time + author_time * 0.2)/1000)*1000;
map.ChallengeParameters.BronzeTime = Math::Floor((1000 + author_time + author_time * 0.5)/1000)*1000;
#else
map.TMObjective_AuthorTime = author_time;
#endif
#if !TMNEXT
map.IdName = ""; // Remove the map UID, the game will generate it again when saving
#endif
}
}
void Render() { void Render() {
if (!menu_visibility) { auto editor = getEditor();
if (editor is null) {
G_MenuVisibility = false;
return;
}
auto map = getMap();
if (map is null) {
G_MenuVisibility = false;
return; return;
} }
#if UNITED if (!G_MenuVisibility) {
CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor); // Store the last Author Time when hidden
#else uint CurrentAuthorTime = getAuthorTime(map);
CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor); if (CurrentAuthorTime < 4294967295) {
#endif G_AuthorTimeText = Time::Format(CurrentAuthorTime);
}
#if TMNEXT || MP4
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap);
#else
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
#endif
if (map is null || editor is null) {
menu_visibility = false;
return; return;
} }
if (UI::Begin("\\$cf9" + Icons::Flag + "\\$z Map Validator###MapValidator", menu_visibility, UI::WindowFlags::NoResize | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoCollapse)){
author_time = UI::InputInt("Author time in ms", author_time ,1);
if (author_time < 0) author_time = 0; if (UI::Begin("\\$cf9" + Icons::Flag + "\\$z Map Validator###MapValidator", G_MenuVisibility, UI::WindowFlags::NoResize | UI::WindowFlags::AlwaysAutoResize | UI::WindowFlags::NoCollapse)){
UI::SetNextItemWidth(100.0);
if (UI::Button("Validate")) { G_AuthorTimeText = UI::InputText("###AuthorTimeText", G_AuthorTimeText);
validate(author_time);
menu_visibility = false;
}
// Convert time in ms to humain readable time
string display_time = Text::Format('%02d',(author_time / 1000 / 60) % 60) + ":" + Text::Format('%02d',(author_time / 1000) % 60) + "." + Text::Format('%03d',author_time % 1000);
if (Math::Floor(author_time / 1000 / 60 / 60) > 0) {
display_time = Text::Format('%d',author_time / 1000 / 60 / 60) + ":" + display_time;
}
UI::SameLine(); UI::SameLine();
UI::Text("with " + display_time + " of author time");
#if TURBO UI::BeginDisabled(!IsValidAuthorTime(G_AuthorTimeText));
UI::Text("Note: your map must have a start and a finish\n(or a multilap + 1CP) to be validated with the plugin"); if (UI::Button("Validate")) {
#elif UNITED setAuthorTime(map, Time::ParseRelativeTime(G_AuthorTimeText));
UI::Text("Note: for an unknown reason, it happens that the times of\nthe medals are not updated, I invite you to check by yourself"); setValidationStatus(editor);
#endif G_MenuVisibility = false;
}
UI::EndDisabled();
string warning = GetWarning();
if (warning != "") {
UI::SameLine();
UI::Text("\\$fa2" + Icons::Info);
if (UI::IsItemHovered()) {
UI::BeginTooltip();
UI::Text(warning);
UI::EndTooltip();
}
}
UI::End(); UI::End();
} }
} }
void RenderMenu() { void RenderMenu() {
#if UNITED auto editor = getEditor();
CTrackManiaEditor@ editor = cast<CTrackManiaEditor>(cast<CTrackMania>(GetApp()).Editor); if (editor is null) return;
#else
CGameCtnEditorFree@ editor = cast<CGameCtnEditorFree>(GetApp().Editor);
#endif
#if TMNEXT || MP4 auto map = getMap();
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().RootMap); if (map is null) return;
#else
CGameCtnChallenge@ map = cast<CGameCtnChallenge>(GetApp().Challenge);
#endif
if (map is null || editor is null) { if(UI::MenuItem("\\$cf9" + Icons::Flag + "\\$z Map Validator", "", G_MenuVisibility)) {
return; G_MenuVisibility = !G_MenuVisibility;
}
if(UI::MenuItem("\\$cf9" + Icons::Flag + "\\$z Map Validator", "", menu_visibility)) {
menu_visibility = !menu_visibility;
} }
} }
bool IsValidAuthorTime(string _AuthorTimeText) {
if (!Regex::IsMatch(_AuthorTimeText, '[\\d\\.:]+')) {
return false;
}
if (!Regex::IsMatch(_AuthorTimeText, '^((\\d+):)?(\\d|[0-5]\\d):(\\d|[0-5]\\d)\\.\\d{3}$')) {
return false;
}
return true;
}

View File

@ -1,9 +1,8 @@
[meta] [meta]
name = "Map Validator" name = "Map Validator"
author = "Beu" author = "Beu"
category = "Map Editor" category = "Map Editor"
siteid = 91
siteid = 91 version = "1.7"
version = "1.6" blocks = [ "Plugin_MapValidator" ]
blocks = [ "Plugin_MapValidator" ]