From 0e3501b6adbe7ed81516cc8a698367d1428893e4 Mon Sep 17 00:00:00 2001 From: MaybeMaru <97055307+MaybeMaru@users.noreply.github.com> Date: Sun, 5 May 2024 23:30:34 +0200 Subject: [PATCH] move alphabet font data to json --- assets/preload/images/alphabet-font.json | 356 ++++++++++++++++++ .../flixel/graphics/tile/FlxGraphicsShader.hx | 11 +- .../funkin/objects/alphabet/AlphabetFont.hx | 101 +---- source/funkin/states/options/items/ModItem.hx | 5 + 4 files changed, 378 insertions(+), 95 deletions(-) create mode 100644 assets/preload/images/alphabet-font.json diff --git a/assets/preload/images/alphabet-font.json b/assets/preload/images/alphabet-font.json new file mode 100644 index 00000000..ac95e977 --- /dev/null +++ b/assets/preload/images/alphabet-font.json @@ -0,0 +1,356 @@ +{ + "letters": [ + { + "lowerOffset": 5, + "boldOffset": -24, + "upperOffset": -18, + "id": "ã" + }, + { + "id": "@" + }, + { + "lowerOffset": 26, + "boldOffset": 2, + "upperOffset": 2, + "id": "ç" + }, + { + "lowerOffset": -4, + "boldOffset": -31, + "upperOffset": -20, + "id": "é" + }, + { + "boldOffset": -30, + "upperOffset": -19, + "id": "ê" + }, + { + "lowerOffset": 5, + "boldOffset": -32, + "upperOffset": -19, + "id": "í" + }, + { + "lowerOffset": 17, + "boldOffset": -18, + "upperOffset": -10, + "id": "ï" + }, + { + "lowerOffset": 10, + "boldOffset": -22, + "upperOffset": -10, + "id": "ñ" + }, + { + "lowerOffset": 2, + "boldOffset": -33, + "upperOffset": -22, + "id": "ó" + }, + { + "lowerOffset": 5, + "boldOffset": -31, + "upperOffset": -18, + "id": "ô" + }, + { + "lowerOffset": 9, + "boldOffset": -25, + "upperOffset": -15, + "id": "õ" + }, + { + "lowerOffset": 1, + "boldOffset": -27, + "upperOffset": -15, + "id": "ú" + }, + { + "lowerOffset": 11, + "boldOffset": -13, + "upperOffset": -4, + "id": "ü" + }, + { + "id": "[" + }, + { + "id": "]" + }, + { + "id": "^" + }, + { + "id": "_" + }, + { + "lowerOffset": 22, + "id": "a" + }, + { + "boldOffset": -10, + "name": "exclamation", + "id": "!" + }, + { + "lowerOffset": 8, + "boldOffset": -3, + "id": "b" + }, + { + "lowerOffset": 25, + "boldOffset": 1, + "upperOffset": 1, + "id": "c" + }, + { + "id": "#" + }, + { + "lowerOffset": 5, + "upperOffset": 2, + "id": "d" + }, + { + "id": "$" + }, + { + "lowerOffset": 21, + "boldOffset": 1, + "upperOffset": 5, + "id": "e" + }, + { + "id": "%" + }, + { + "lowerOffset": 10, + "upperOffset": 6, + "id": "f" + }, + { + "lowerOffset": 32, + "boldOffset": -3, + "upperOffset": 2, + "id": "g" + }, + { + "name": "apostrophe", + "id": "'" + }, + { + "lowerOffset": 12, + "upperOffset": 5, + "id": "h" + }, + { + "id": "(" + }, + { + "lowerOffset": 15, + "boldOffset": 1, + "upperOffset": 6, + "id": "i" + }, + { + "id": ")" + }, + { + "lowerOffset": 15, + "boldOffset": -3, + "upperOffset": 4, + "id": "j" + }, + { + "id": "*" + }, + { + "lowerOffset": 10, + "boldOffset": -3, + "upperOffset": 6, + "id": "k" + }, + { + "id": "+" + }, + { + "lowerOffset": 10, + "upperOffset": 5, + "id": "l" + }, + { + "lowerOffset": 40, + "name": "comma", + "id": "," + }, + { + "lowerOffset": 31, + "boldOffset": 3, + "upperOffset": 8, + "id": "m" + }, + { + "boldOffset": 25, + "id": "-" + }, + { + "lowerOffset": 31, + "upperOffset": 8, + "id": "n" + }, + { + "lowerOffset": 40, + "boldOffset": 50, + "name": "period", + "id": "." + }, + { + "lowerOffset": 27, + "boldOffset": -3, + "upperOffset": 3, + "id": "o" + }, + { + "lowerOffset": 3, + "id": "0" + }, + { + "lowerOffset": 30, + "boldOffset": -3, + "upperOffset": 7, + "id": "p" + }, + { + "lowerOffset": 4, + "id": "1" + }, + { + "lowerOffset": 34, + "upperOffset": 6, + "id": "q" + }, + { + "lowerOffset": 5, + "boldOffset": 2, + "id": "2" + }, + { + "lowerOffset": 29, + "upperOffset": 3, + "id": "r" + }, + { + "lowerOffset": 2, + "boldOffset": 1, + "id": "3" + }, + { + "lowerOffset": 23, + "upperOffset": 3, + "id": "s" + }, + { + "lowerOffset": 3, + "boldOffset": 2, + "id": "4" + }, + { + "lowerOffset": 10, + "boldOffset": 1, + "upperOffset": 7, + "id": "t" + }, + { + "lowerOffset": 4, + "id": "5" + }, + { + "lowerOffset": 25, + "boldOffset": 7, + "upperOffset": 8, + "id": "u" + }, + { + "lowerOffset": 26, + "upperOffset": 9, + "id": "v" + }, + { + "lowerOffset": 4, + "id": "6" + }, + { + "lowerOffset": 27, + "boldOffset": 3, + "upperOffset": 7, + "id": "w" + }, + { + "lowerOffset": 8, + "boldOffset": 3, + "id": "7" + }, + { + "lowerOffset": 25, + "upperOffset": 5, + "id": "x" + }, + { + "lowerOffset": 1, + "id": "8" + }, + { + "lowerOffset": 25, + "boldOffset": -3, + "upperOffset": 5, + "id": "y" + }, + { + "lowerOffset": 1, + "id": "9" + }, + { + "lowerOffset": 27, + "upperOffset": 10, + "id": "z" + }, + { + "boldOffset": 10, + "id": ":" + }, + { + "id": ";" + }, + { + "id": "|" + }, + { + "id": "<" + }, + { + "id": "~" + }, + { + "id": ">" + }, + { + "lowerOffset": -5, + "boldOffset": -33, + "upperOffset": -24, + "id": "á" + }, + { + "boldOffset": -27, + "upperOffset": -20, + "id": "â" + }, + { + "boldOffset": -5, + "name": "question", + "id": "?" + } + ] +} \ No newline at end of file diff --git a/source/flixel/graphics/tile/FlxGraphicsShader.hx b/source/flixel/graphics/tile/FlxGraphicsShader.hx index 941ce322..e47b215e 100644 --- a/source/flixel/graphics/tile/FlxGraphicsShader.hx +++ b/source/flixel/graphics/tile/FlxGraphicsShader.hx @@ -20,7 +20,7 @@ class FlxGraphicsShader extends GraphicsShader if (hasColorTransform) { - openfl_ColorOffsetv = colorOffset / 255.0; + openfl_ColorOffsetv = colorOffset * 0.00392; openfl_ColorMultiplierv = colorMultiplier; } }") @@ -43,14 +43,7 @@ class FlxGraphicsShader extends GraphicsShader } color = vec4(color.rgb / color.a, color.a); - - mat4 colorMultiplier = mat4(0); - colorMultiplier[0][0] = openfl_ColorMultiplierv.x; - colorMultiplier[1][1] = openfl_ColorMultiplierv.y; - colorMultiplier[2][2] = openfl_ColorMultiplierv.z; - colorMultiplier[3][3] = openfl_ColorMultiplierv.w; - - color = clamp(openfl_ColorOffsetv + (color * colorMultiplier), 0.0, 1.0); + color = clamp(openfl_ColorOffsetv + (color * openfl_ColorMultiplierv), 0.0, 1.0); return vec4(color.rgb * color.a * openfl_Alphav, color.a * openfl_Alphav); } ") diff --git a/source/funkin/objects/alphabet/AlphabetFont.hx b/source/funkin/objects/alphabet/AlphabetFont.hx index 243f7e46..6707ba01 100644 --- a/source/funkin/objects/alphabet/AlphabetFont.hx +++ b/source/funkin/objects/alphabet/AlphabetFont.hx @@ -4,8 +4,13 @@ import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxBitmapFont; import flixel.graphics.frames.FlxFrame; +typedef AlphabetFontJson = { + letters:Array +} + typedef LetterData = { + id:String, // character id ?name:String, // prefix ?upperOffset:Float, // uppercase ?lowerOffset:Float, // lowercase @@ -14,88 +19,6 @@ typedef LetterData = class AlphabetFont extends FlxBitmapFont { - public static final characters:Map = [ - // Alphabet - "a" => {lowerOffset: 22}, - "b" => {boldOffset: -3, lowerOffset: 8}, - "c" => {boldOffset: 1, lowerOffset: 25, upperOffset: 1}, - "d" => {lowerOffset: 5, upperOffset: 2}, - "e" => {boldOffset: 1, lowerOffset: 21, upperOffset: 5}, - "f" => {lowerOffset: 10, upperOffset: 6}, - "g" => {boldOffset: -3, lowerOffset: 32, upperOffset: 2}, - "h" => {lowerOffset: 12, upperOffset: 5}, - "i" => {boldOffset: 1, lowerOffset: 15, upperOffset: 6}, - "j" => {boldOffset: -3, lowerOffset: 15, upperOffset: 4}, - "k" => {boldOffset: -3, lowerOffset: 10, upperOffset: 6}, - "l" => {lowerOffset: 10, upperOffset: 5}, - "m" => {boldOffset: 3, lowerOffset: 31, upperOffset: 8}, - "n" => {lowerOffset: 31, upperOffset: 8}, - "o" => {boldOffset: -3, lowerOffset: 27, upperOffset: 3}, - "p" => {boldOffset: -3, lowerOffset: 30, upperOffset: 7}, - "q" => {lowerOffset: 34, upperOffset: 6}, - "r" => {lowerOffset: 29, upperOffset: 3}, - "s" => {lowerOffset: 23, upperOffset: 3}, - "t" => {boldOffset: 1, lowerOffset: 10, upperOffset: 7}, - "u" => {boldOffset: 7, lowerOffset: 25, upperOffset: 8}, - "v" => {lowerOffset: 26, upperOffset: 9}, - "w" => {boldOffset: 3, lowerOffset: 27, upperOffset: 7}, - "x" => {lowerOffset: 25, upperOffset: 5}, - "y" => {boldOffset: -3, lowerOffset: 25, upperOffset: 5}, - "z" => {lowerOffset: 27, upperOffset: 10}, - // Numbers - "0" => {lowerOffset: 3}, - "1" => {lowerOffset: 4}, - "2" => {boldOffset: 2, lowerOffset: 5}, - "3" => {boldOffset: 1, lowerOffset: 2}, - "4" => {boldOffset: 2, lowerOffset: 3}, - "5" => {lowerOffset: 4}, - "6" => {lowerOffset: 4}, - "7" => {boldOffset: 3, lowerOffset: 8}, - "8" => {lowerOffset: 1}, - "9" => {lowerOffset: 1}, - // Symbols - "|" => null, - "~" => null, - "#" => null, - "$" => null, - "%" => null, - "(" => null, - ")" => null, - "*" => null, - "+" => null, - "-" => {boldOffset: 25}, - "_" => null, - ":" => {boldOffset: 10}, - ";" => null, - "<" => null, - ">" => null, - // "=" => null, - "@" => null, - "[" => null, - "]" => null, - "^" => null, - "." => {name: "period", boldOffset: 50, lowerOffset: 40}, - "," => {name: "comma", lowerOffset: 40}, - "'" => {name: "apostrophe"}, - "!" => {name: "exclamation", boldOffset: -10}, - "?" => {name: "question", boldOffset: -5}, - // Spanish and Portuguese Characters - "á" => {boldOffset: -33, lowerOffset: -5, upperOffset: -24}, - "é" => {boldOffset: -31, lowerOffset: -4, upperOffset: -20}, - "í" => {boldOffset: -32, lowerOffset: 5, upperOffset: -19}, - "ó" => {boldOffset: -33, lowerOffset: 2, upperOffset: -22}, - "ú" => {boldOffset: -27, lowerOffset: 1, upperOffset: -15}, - "â" => {boldOffset: -27, upperOffset: -20}, - "ê" => {boldOffset: -30, upperOffset: -19}, - "ô" => {boldOffset: -31, lowerOffset: 5, upperOffset: -18}, - "ã" => {boldOffset: -24, lowerOffset: 5, upperOffset: -18}, - "õ" => {boldOffset: -25, lowerOffset: 9, upperOffset: -15}, - "ï" => {boldOffset: -18, lowerOffset: 17, upperOffset: -10}, - "ü" => {boldOffset: -13, lowerOffset: 11, upperOffset: -4}, - "ñ" => {boldOffset: -22, lowerOffset: 10, upperOffset: -10}, - "ç" => {boldOffset: 2, lowerOffset: 26, upperOffset: 2} - ]; - public static var cachedAlphabets:Map> = []; public var animFrames:Array> = []; @@ -117,12 +40,17 @@ class AlphabetFont extends FlxBitmapFont public var lodScale:Float; + // TODO: make this not forced to be sparrow atlas + public function new(key:String, bold:Bool) { var graphic:LodGraphic = AssetManager.cacheGraphicPath(key); var xml = CoolUtil.getFileContent(key.replace(".png", ".xml")); var atlas = Paths.__checkLodFrames(Paths.getFrames(graphic, () -> return FlxAtlasFrames.fromSparrow(graphic, xml))); + var rawFont = CoolUtil.getFileContent(key.replace(".png", "-font.json")); + var font:AlphabetFontJson = Json.parse(rawFont); + AssetManager.getAsset(key).onDispose = () -> { cachedAlphabets.remove(key); } @@ -131,12 +59,13 @@ class AlphabetFont extends FlxBitmapFont super(graphic.imageFrame.frame); - for (key => data in characters) + for (data in font.letters) { - var upperCode = key.toUpperCase().charCodeAt(0); - var code = key.charCodeAt(0); + var id = data.id; + var upperCode = id.toUpperCase().charCodeAt(0); + var code = id.charCodeAt(0); - var name:String = key; + var name:String = id; var boldOffset:Float = 0; var lowerOffset:Float = 0; var upperOffset:Float = 0; diff --git a/source/funkin/states/options/items/ModItem.hx b/source/funkin/states/options/items/ModItem.hx index c57236bb..be2851f2 100644 --- a/source/funkin/states/options/items/ModItem.hx +++ b/source/funkin/states/options/items/ModItem.hx @@ -32,6 +32,11 @@ class ModItem extends FlxSpriteGroup { modTitle.scale.scale(0.666, 0.666); // Satan entered the chat add(modTitle); + @:privateAccess + modTitle.fieldWidth = Std.int((modBox.width * 1.2) / modTitle.alphabetFont.lodScale); + modTitle.autoSize = false; + modTitle.wrap = WORD(NEVER); + var modDesc:FlxFunkText = new FlxFunkText(modTitle.x, modTitle.y + modTitle.height + 5, mod.description, FlxPoint.weak(modBox.width*0.6, modBox.height), 20); modDesc.font = "phantommuff_"; modDesc.style = SHADOW(FlxPoint.weak(-2, -2), FlxColor.BLACK);