From 832edd27fc37f89e2385907ff50fa0fb60326ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:00:38 +0200 Subject: [PATCH] applying formats and parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also due to a merge conflict apparently the deathCounter++ was never merged from my original old pr😭 --- source/funkin/backend/FunkinText.hx | 4 ++-- .../funkin/backend/utils/TranslationsUtil.hx | 19 ++++++++++--------- source/funkin/game/PlayState.hx | 1 + source/funkin/menus/FreeplayState.hx | 8 ++++---- source/funkin/menus/PauseSubState.hx | 3 +-- source/funkin/menus/ui/Alphabet.hx | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/source/funkin/backend/FunkinText.hx b/source/funkin/backend/FunkinText.hx index 8517e929..6da272f9 100644 --- a/source/funkin/backend/FunkinText.hx +++ b/source/funkin/backend/FunkinText.hx @@ -4,8 +4,8 @@ import flixel.util.FlxColor; import flixel.text.FlxText; class FunkinText extends FlxText { - public function new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, Size:Int = 16, Border:Bool = true, ?TranslationID:String) { - super(X, Y, FieldWidth, TranslationsUtil.checkTransl(Text, TranslationID), Size); + public function new(X:Float = 0, Y:Float = 0, FieldWidth:Float = 0, ?Text:String, Size:Int = 16, Border:Bool = true, ?TranslationID:String, ?TranslParameters:Array) { + super(X, Y, FieldWidth, TranslationsUtil.getTransl(Text, TranslationID, TranslParameters), Size); setFormat(Paths.font("vcr.ttf"), Size, FlxColor.WHITE); if (Border) { borderStyle = OUTLINE; diff --git a/source/funkin/backend/utils/TranslationsUtil.hx b/source/funkin/backend/utils/TranslationsUtil.hx index 184d7248..d9305f24 100644 --- a/source/funkin/backend/utils/TranslationsUtil.hx +++ b/source/funkin/backend/utils/TranslationsUtil.hx @@ -17,7 +17,7 @@ class TranslationsUtil * * Using this class function it'll never be `null`. */ - public static var transMap(default, null):Map = []; + public static var transMap(default, null):Map = []; /** * The default language used inside of the source code. @@ -56,17 +56,18 @@ class TranslationsUtil transMap = loadLanguage(name == null ? curLanguage : name); /** - * This is for checking a translation, `defString` it's just the string that gets returned just in case it won't find the translation OR the current language selected is ``DEFAULT_LANGUAGE``. + * This is for checking and getting a translation, `defString` it's just the string that gets returned just in case it won't find the translation OR the current language selected is ``DEFAULT_LANGUAGE``. * * If `id` is `null` then it's gonna search using `defString`. */ - public static function checkTransl(defString:String, ?id:String):String + public static function getTransl(defString:String, ?id:String, ?parms:Array):String { + if(parms == null) parms = []; #if TRANSLATIONS_SUPPORT if(id == null) id = defString; - if(transMap.exists(id)) return transMap.get(id); + if(transMap.exists(id)) return transMap.get(id).format(parms); #end - return defString; + return new FormatInfo(defString).format(parms); } /** @@ -86,7 +87,7 @@ class TranslationsUtil /** * Returns a map of translations based on its XML. */ - public static function loadLanguage(name:String):Map + public static function loadLanguage(name:String):Map { #if TRANSLATIONS_SUPPORT var path:String = Paths.translationsMain(name); @@ -106,7 +107,7 @@ class TranslationsUtil return []; } - var leMap:Map = []; + var leMap:Map = []; for(node in xml.node.translations.elements) { switch(node.name) { case "trans": @@ -118,7 +119,7 @@ class TranslationsUtil FlxG.log.warn("A translation node requires a string attribute."); continue; } - leMap.set(node.att.id, node.att.string); + leMap.set(node.att.id, new FormatInfo(node.att.string)); } } return leMap; @@ -164,7 +165,7 @@ class FormatInfo { var str:String = ""; for(i=>s in strings) { str += s; - if(i < strings.length-1) + if(i < indexes.length) str += values[indexes[i]]; } diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index f585e89f..4af44e5d 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -1409,6 +1409,7 @@ class PlayState extends MusicBeatState FlxG.sound.music.stop(); for (strumLine in strumLines.members) strumLine.vocals.stop(); + deathCounter++; openSubState(new GameOverSubstate(event.x, event.y, event.deathCharID, event.isPlayer, event.gameOverSong, event.lossSFX, event.retrySFX)); scripts.event("onPostGameOver", event); diff --git a/source/funkin/menus/FreeplayState.hx b/source/funkin/menus/FreeplayState.hx index 8b740a31..a1a1114e 100644 --- a/source/funkin/menus/FreeplayState.hx +++ b/source/funkin/menus/FreeplayState.hx @@ -347,10 +347,10 @@ class FreeplayState extends MusicBeatState * Array containing all labels for Co-Op / Opponent modes. */ public var coopLabels:Array = [ - TranslationsUtil.checkTransl("[TAB] Solo"), - TranslationsUtil.checkTransl("[TAB] Opponent Mode"), - TranslationsUtil.checkTransl("[TAB] Co-Op Mode"), - TranslationsUtil.checkTransl("[TAB] Co-Op Mode (Switched)") + TranslationsUtil.getTransl("[TAB] Solo"), + TranslationsUtil.getTransl("[TAB] Opponent Mode"), + TranslationsUtil.getTransl("[TAB] Co-Op Mode"), + TranslationsUtil.getTransl("[TAB] Co-Op Mode (Switched)") ]; /** diff --git a/source/funkin/menus/PauseSubState.hx b/source/funkin/menus/PauseSubState.hx index 74b57a80..040149ac 100644 --- a/source/funkin/menus/PauseSubState.hx +++ b/source/funkin/menus/PauseSubState.hx @@ -72,8 +72,7 @@ class PauseSubState extends MusicBeatSubstate var levelInfo:FunkinText = new FunkinText(20, 15, 0, PlayState.SONG.meta.displayName, 32, false); var levelDifficulty:FunkinText = new FunkinText(20, 15, 0, PlayState.difficulty.toUpperCase(), 32, false); var multiplayerText:FunkinText = new FunkinText(20, 15, 0, PlayState.opponentMode ? 'OPPONENT MODE' : (PlayState.coopMode ? 'CO-OP MODE' : ''), 32, false); - var deathCounter:FunkinText = new FunkinText(20, 15, 0, "Blue balled", 32, false); - deathCounter.text += ": " + PlayState.deathCounter; // Adding it later for the translation - Nex + var deathCounter:FunkinText = new FunkinText(20, 15, 0, "Blue balled: {0}", 32, false, "blue_balled", [PlayState.deathCounter]); for(k=>label in [levelInfo, levelDifficulty, deathCounter, multiplayerText]) { label.scrollFactor.set(); diff --git a/source/funkin/menus/ui/Alphabet.hx b/source/funkin/menus/ui/Alphabet.hx index e8c01f09..b9e274ea 100644 --- a/source/funkin/menus/ui/Alphabet.hx +++ b/source/funkin/menus/ui/Alphabet.hx @@ -77,11 +77,11 @@ class Alphabet extends FlxSpriteGroup trace(e.details()); } } - public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false, ?transID:String) + public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false, ?transID:String, ?transParams:Array) { super(x, y); - _finalText = this.text = TranslationsUtil.checkTransl(text, transID); + _finalText = this.text = TranslationsUtil.getTransl(text, transID, transParams); isBold = bold; var alphabetPath = Paths.xml("alphabet");