From 55c5952258b008f54099e53766e5596efc24579b Mon Sep 17 00:00:00 2001 From: Beu Date: Sun, 18 Feb 2024 18:00:52 +0100 Subject: [PATCH] Rework MapValidator + add human readable format --- MapValidator/Source/Games/MP4.as | 30 +++++ MapValidator/Source/Games/TMNEXT.as | 27 +++++ MapValidator/Source/Games/TURBO.as | 30 +++++ MapValidator/Source/Games/UNITED.as | 32 ++++++ MapValidator/Source/MapValidator.as | 163 ++++++++++------------------ MapValidator/info.toml | 17 ++- 6 files changed, 185 insertions(+), 114 deletions(-) create mode 100644 MapValidator/Source/Games/MP4.as create mode 100644 MapValidator/Source/Games/TMNEXT.as create mode 100644 MapValidator/Source/Games/TURBO.as create mode 100644 MapValidator/Source/Games/UNITED.as diff --git a/MapValidator/Source/Games/MP4.as b/MapValidator/Source/Games/MP4.as new file mode 100644 index 0000000..8a3ea1d --- /dev/null +++ b/MapValidator/Source/Games/MP4.as @@ -0,0 +1,30 @@ +#if MP4 +CGameCtnEditorFree@ getEditor() { + return cast(GetApp().Editor); +} + +CGameCtnChallenge@ getMap() { + return cast(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(_Editor.PluginMapType); + if (pluginmaptype is null) return; + pluginmaptype.ValidationStatus = CGameEditorPluginMapMapType::EValidationStatus::Validated; +} + +string GetWarning() { + return ""; +} +#endif \ No newline at end of file diff --git a/MapValidator/Source/Games/TMNEXT.as b/MapValidator/Source/Games/TMNEXT.as new file mode 100644 index 0000000..308c6e7 --- /dev/null +++ b/MapValidator/Source/Games/TMNEXT.as @@ -0,0 +1,27 @@ +#if TMNEXT +CGameCtnEditorFree@ getEditor() { + return cast(GetApp().Editor); +} + +CGameCtnChallenge@ getMap() { + return cast(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(_Editor.PluginMapType); + if (pluginmaptype is null) return; + pluginmaptype.ValidationStatus = CGameEditorPluginMapMapType::EValidationStatus::Validated; +} + +string GetWarning() { + return ""; +} +#endif \ No newline at end of file diff --git a/MapValidator/Source/Games/TURBO.as b/MapValidator/Source/Games/TURBO.as new file mode 100644 index 0000000..22ef957 --- /dev/null +++ b/MapValidator/Source/Games/TURBO.as @@ -0,0 +1,30 @@ +#if TURBO +CGameCtnEditorFree@ getEditor() { + return cast(GetApp().Editor); +} + +CGameCtnChallenge@ getMap() { + return cast(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(_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 \ No newline at end of file diff --git a/MapValidator/Source/Games/UNITED.as b/MapValidator/Source/Games/UNITED.as new file mode 100644 index 0000000..3151b86 --- /dev/null +++ b/MapValidator/Source/Games/UNITED.as @@ -0,0 +1,32 @@ +#if UNITED +CTrackManiaEditor@ getEditor() { + return cast(cast(GetApp()).Editor); +} + +CGameCtnChallenge@ getMap() { + return cast(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 \ No newline at end of file diff --git a/MapValidator/Source/MapValidator.as b/MapValidator/Source/MapValidator.as index 92a6843..3c4a741 100644 --- a/MapValidator/Source/MapValidator.as +++ b/MapValidator/Source/MapValidator.as @@ -1,128 +1,81 @@ // Based on the Moski plugin which is also based on the Miss plugin :) -bool menu_visibility = false; -int author_time; +bool G_MenuVisibility = false; +string G_AuthorTimeText = "0:00:00.000"; -void Main() {} - -void validate(int author_time) { - // Get editor var -#if UNITED - CTrackManiaEditor@ editor = cast(cast(GetApp()).Editor); -#else - CGameCtnEditorFree@ editor = cast(GetApp().Editor); -#endif - - // Get map & pluginmaptype if possible -#if TURBO - CGameCtnChallenge@ map = cast(GetApp().Challenge); - CGameCtnEditorPluginMapType@ pluginmaptype = cast(editor.EditorMapType); -#elif UNITED - CGameCtnChallenge@ map = cast(GetApp().Challenge); - auto pluginmaptype == null; -#else - CGameCtnChallenge@ map = cast(GetApp().RootMap); - CGameEditorPluginMapMapType@ pluginmaptype = cast(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 Main() {} 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; } -#if UNITED - CTrackManiaEditor@ editor = cast(cast(GetApp()).Editor); -#else - CGameCtnEditorFree@ editor = cast(GetApp().Editor); -#endif - -#if TMNEXT || MP4 - CGameCtnChallenge@ map = cast(GetApp().RootMap); -#else - CGameCtnChallenge@ map = cast(GetApp().Challenge); -#endif - - if (map is null || editor is null) { - menu_visibility = false; + if (!G_MenuVisibility) { + // Store the last Author Time when hidden + uint CurrentAuthorTime = getAuthorTime(map); + if (CurrentAuthorTime < 4294967295) { + G_AuthorTimeText = Time::Format(CurrentAuthorTime); + } 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::Button("Validate")) { - 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; - } + 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); + G_AuthorTimeText = UI::InputText("###AuthorTimeText", G_AuthorTimeText); UI::SameLine(); - UI::Text("with " + display_time + " of author time"); -#if TURBO - UI::Text("Note: your map must have a start and a finish\n(or a multilap + 1CP) to be validated with the plugin"); -#elif UNITED - 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"); -#endif + UI::BeginDisabled(!IsValidAuthorTime(G_AuthorTimeText)); + if (UI::Button("Validate")) { + setAuthorTime(map, Time::ParseRelativeTime(G_AuthorTimeText)); + setValidationStatus(editor); + 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(); } } - + void RenderMenu() { -#if UNITED - CTrackManiaEditor@ editor = cast(cast(GetApp()).Editor); -#else - CGameCtnEditorFree@ editor = cast(GetApp().Editor); -#endif + auto editor = getEditor(); + if (editor is null) return; -#if TMNEXT || MP4 - CGameCtnChallenge@ map = cast(GetApp().RootMap); -#else - CGameCtnChallenge@ map = cast(GetApp().Challenge); -#endif + auto map = getMap(); + if (map is null) return; - if (map is null || editor is null) { - return; - } - - if(UI::MenuItem("\\$cf9" + Icons::Flag + "\\$z Map Validator", "", menu_visibility)) { - menu_visibility = !menu_visibility; + if(UI::MenuItem("\\$cf9" + Icons::Flag + "\\$z Map Validator", "", G_MenuVisibility)) { + G_MenuVisibility = !G_MenuVisibility; } } + +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; +} \ No newline at end of file diff --git a/MapValidator/info.toml b/MapValidator/info.toml index 983c26c..feddaef 100644 --- a/MapValidator/info.toml +++ b/MapValidator/info.toml @@ -1,9 +1,8 @@ -[meta] -name = "Map Validator" -author = "Beu" -category = "Map Editor" - -siteid = 91 -version = "1.6" - -blocks = [ "Plugin_MapValidator" ] \ No newline at end of file +[meta] +name = "Map Validator" +author = "Beu" +category = "Map Editor" +siteid = 91 +version = "1.7" +blocks = [ "Plugin_MapValidator" ] +