From 0a9ef58129fbb3eba0128caaa00a52945b9ff445 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Sat, 17 Dec 2022 23:47:20 +0100 Subject: [PATCH] some more markdown stuff --- Project.xml | 2 +- buildnumber.txt | 2 +- source/funkin/system/MarkdownUtil.hx | 70 +++++++++++++++++++ .../funkin/updating/UpdateAvailableScreen.hx | 15 ++-- source/funkin/updating/UpdateUtil.hx | 23 ------ 5 files changed, 76 insertions(+), 36 deletions(-) create mode 100644 source/funkin/system/MarkdownUtil.hx diff --git a/Project.xml b/Project.xml index beefe066..2e250dce 100644 --- a/Project.xml +++ b/Project.xml @@ -134,7 +134,7 @@ - + diff --git a/buildnumber.txt b/buildnumber.txt index 9221efbe..93682b45 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1523 \ No newline at end of file +1538 \ No newline at end of file diff --git a/source/funkin/system/MarkdownUtil.hx b/source/funkin/system/MarkdownUtil.hx new file mode 100644 index 00000000..a28b2f49 --- /dev/null +++ b/source/funkin/system/MarkdownUtil.hx @@ -0,0 +1,70 @@ +package funkin.system; + +import flixel.util.FlxColor; +import flixel.text.FlxText; + +class MarkdownUtil { + public static function applyMarkdownText(text:FlxText, str:String) { + text.textField.htmlText = Markdown.markdownToHtml(prepareMarkdown(str)); + var changes:Array = [ + createSizedMarkerPair("{title}", 0xFFFFFFFF, text.size * 2, false, true, true), + createSizedMarkerPair("{subtitle}", 0xFFFFFFFF, text.size * 1.5, false, true, true), + createSizedMarkerPair("{subsubtitle}", 0xFFFFFFFF, text.size * 1.25, false, true, true), + new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFFFF00, false, true), "{o}"), + new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFF0000, false, true), "{r}"), + new FlxTextFormatMarkerPair(new FlxTextFormat(0xFF00FF08, false, true), "{g}"), + new FlxTextFormatMarkerPair(new FlxTextFormat(0xFF7D7D7D, false, true), "{gray}"), + new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFFFFFF, false, true, 0xFF222222), "{italic}"), + new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFFFFFF, false, true, 0xFF666666), "{bold}"), + new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFFFFFF, false, true, 0xFF888888), "{bold-italic}"), + ]; + + // BIG TEXT + text.applyMarkup( + parseWarnings(text.textField.text), + changes + ); + } + + public static function createSizedMarkerPair(marker:String, color:FlxColor, size:Float, bold:Bool = false, italic:Bool = false, ?underline:Bool = false) { + @:privateAccess { + var format = new FlxTextFormat(color, bold, italic); + format.format.size = Std.int(size); + format.format.underline = underline; + return new FlxTextFormatMarkerPair(format, marker); + } + } + + public static function parseWarnings(text:String) { + text = parseEmote(text, "⚠", "{o}(!)", "{o}"); + text = parseEmote(text, "❌", "{r}(X)", "{r}"); + text = parseEmote(text, "✔", "{g}(+)", "{g}"); + return text; + } + + public static function prepareMarkdown(text:String) { + text = "\n" + text; + text = parseEmote(text, "\n> ", "\n{gray}", "{gray}"); + text = parseEmote(text, "\n### ", "\n{subsubtitle}", "{subsubtitle}"); + text = parseEmote(text, "\n## ", "\n{subtitle}", "{subtitle}"); + text = parseEmote(text, "\n# ", "\n{title}", "{title}"); + text = parseEmote(text, "***", "{bold-italic}", "{bold-italic}", "***"); + text = parseEmote(text, "**", "{bold}", "{bold}", "**"); + text = parseEmote(text, "*", "{italic}", "{italic}", "*"); + text = parseEmote(text, "_", "{italic}", "{italic}", "*"); + text = parseEmote(text, "__", "{bold}", "{bold}", "*"); + text.substr("\n".length); + return text; + } + + public static function parseEmote(text:String, emote:String, beginning:String, end:String, emoteEnd:String = "\n") { + var index:Int; + while((index = text.indexOf(emote)) >= 0) { + var nextIndex = text.indexOf(emoteEnd, index + emote.length); + if (nextIndex < 0) + nextIndex = text.length; + text = text.substr(0, index) + beginning + text.substring(index + emote.length, nextIndex) + end + (emote == emoteEnd ? "" : emoteEnd) + text.substring(nextIndex + emoteEnd.length); + } + return text; + } +} \ No newline at end of file diff --git a/source/funkin/updating/UpdateAvailableScreen.hx b/source/funkin/updating/UpdateAvailableScreen.hx index 17819d35..f5f017d9 100644 --- a/source/funkin/updating/UpdateAvailableScreen.hx +++ b/source/funkin/updating/UpdateAvailableScreen.hx @@ -1,5 +1,6 @@ package funkin.updating; +import funkin.system.MarkdownUtil; import funkin.menus.MainMenuState; import flixel.math.FlxPoint; import flixel.math.FlxMath; @@ -63,17 +64,9 @@ class UpdateAvailableScreen extends MusicBeatState { versionCheckBG.updateHitbox(); versionCheckBG.scrollFactor.set(); - changeLogText = new FunkinText(0, versionCheckBG.y + versionCheckBG.height + 10, FlxG.width, "", 20, false); - changeLogText.textField.htmlText = Markdown.markdownToHtml(check.updates.last().body.replace("\t", " ")); - changeLogText.applyMarkup( - UpdateUtil.parseWarnings(changeLogText.textField.text), - [ - new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFFFF00, false, true), ""), - new FlxTextFormatMarkerPair(new FlxTextFormat(0xFFFF0000, false, true), ""), - new FlxTextFormatMarkerPair(new FlxTextFormat(0xFF00FF08, false, true), ""), - new FlxTextFormatMarkerPair(new FlxTextFormat(0xFF7D7D7D, false, true), ""), - ] - ); + changeLogText = new FunkinText(0, versionCheckBG.y + versionCheckBG.height + 10, FlxG.width, "", 20, true); + changeLogText.borderColor = 0xFF000000; + MarkdownUtil.applyMarkdownText(changeLogText, check.updates.last().body); installButton = new FunkinText(0, FlxG.height - 25, Std.int(FlxG.width / 2), "> INSTALL <", 32); skipButton = new FunkinText(Std.int(FlxG.width / 2), FlxG.height - 25, Std.int(FlxG.width / 2), "SKIP", 32); diff --git a/source/funkin/updating/UpdateUtil.hx b/source/funkin/updating/UpdateUtil.hx index 67745101..9e052c82 100644 --- a/source/funkin/updating/UpdateUtil.hx +++ b/source/funkin/updating/UpdateUtil.hx @@ -60,29 +60,6 @@ class UpdateUtil { return newArray.length <= 0 ? newArray : newArray.splice(__curVersionPos+1, newArray.length-(__curVersionPos+1)); } - - /** - * Replaces all `⚠ TEXT` into `/!\ TEXT` - * @param text - */ - public static function parseWarnings(text:String) { - text = parseEmote(text, "⚠", "(!)", ""); - text = parseEmote(text, "❌", "(X)", ""); - text = parseEmote(text, "✔", "(+)", ""); - text = parseEmote(text, "\n> ", "\n| ", ""); - return text; - } - - public static function parseEmote(text:String, emote:String, beginning:String, end:String) { - var index:Int; - while((index = text.indexOf(emote)) >= 0) { - var nextIndex = text.indexOf("\n", index + emote.length); - if (nextIndex < 0) - nextIndex = text.length; - text = text.substr(0, index) + beginning + text.substring(index + emote.length, nextIndex) + end + text.substring(nextIndex); - } - return text; - } } typedef UpdateCheckCallback = {