|
1 | 1 | package funkin.editors.charter; |
2 | 2 |
|
| 3 | +import flixel.system.FlxAssets.FlxGraphicAsset; |
3 | 4 | import funkin.editors.charter.Charter.ICharterSelectable; |
4 | 5 | import flixel.math.FlxPoint; |
5 | 6 | import funkin.game.Character; |
@@ -47,14 +48,34 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable { |
47 | 48 | private static function generateDefaultIcon(name:String) { |
48 | 49 | var isBase64:Bool = false; |
49 | 50 | var path:String = Paths.image('editors/charter/event-icons/$name'); |
50 | | - if (!Assets.exists(path)) path = Paths.image('editors/charter/event-icons/Unknown'); |
51 | | - if (Assets.exists(Paths.pack('events/$name'))) { |
52 | | - var packimg = Assets.getText(Paths.pack('events/$name')).split('________PACKSEP________')[3]; |
53 | | - if (isBase64 = (packimg != null)) |
54 | | - path = Assets.getText(Paths.pack('events/$name')).split('________PACKSEP________')[3]; |
| 51 | + var defaultPath = Paths.image('editors/charter/event-icons/Unknown'); |
| 52 | + if (!Assets.exists(path)) path = defaultPath; |
| 53 | + |
| 54 | + var packPath = Paths.pack('events/$name'); |
| 55 | + if (Assets.exists(packPath)) { |
| 56 | + var packText = Assets.getText(packPath).split('________PACKSEP________'); |
| 57 | + var packImg = packText[3]; |
| 58 | + if(packImg != null && packImg.length > 0) { |
| 59 | + isBase64 = !packImg.startsWith("assets/"); |
| 60 | + path = packImg; |
| 61 | + } |
| 62 | + } |
| 63 | + path = path.trim(); |
| 64 | + |
| 65 | + var graphic:FlxGraphicAsset = try { |
| 66 | + isBase64 ? openfl.display.BitmapData.fromBase64(path, 'UTF8') : path; |
| 67 | + } catch(e:Dynamic) { |
| 68 | + Logs.trace('Failed to load event icon: ${e.toString()}', ERROR); |
| 69 | + isBase64 = false; |
| 70 | + defaultPath; |
55 | 71 | } |
56 | | - var spr = new FlxSprite().loadGraphic(isBase64 ? openfl.display.BitmapData.fromBase64(path.trim(), 'UTF8') : path); |
57 | | - return spr; |
| 72 | + |
| 73 | + if(!isBase64) { |
| 74 | + if (!Assets.exists(graphic)) |
| 75 | + graphic = defaultPath; |
| 76 | + } |
| 77 | + |
| 78 | + return new FlxSprite().loadGraphic(graphic); |
58 | 79 | } |
59 | 80 |
|
60 | 81 | public static function generateEventIcon(event:ChartEvent) { |
|
0 commit comments