From 64c9371a8b1da32fae6fb9a7c9b99b7ee8922c81 Mon Sep 17 00:00:00 2001 From: Frakist <90983918+Frakist@users.noreply.github.com> Date: Sat, 30 Sep 2023 14:32:17 +0300 Subject: [PATCH] event/script packing wip --- source/funkin/backend/assets/Paths.hx | 3 +++ source/funkin/backend/chart/EventsData.hx | 11 +++++++---- source/funkin/editors/charter/CharterEvent.hx | 9 +++++++-- source/funkin/game/PlayState.hx | 8 +++++++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/source/funkin/backend/assets/Paths.hx b/source/funkin/backend/assets/Paths.hx index 2d7c0c75..921d6584 100644 --- a/source/funkin/backend/assets/Paths.hx +++ b/source/funkin/backend/assets/Paths.hx @@ -48,6 +48,9 @@ class Paths inline static public function txt(key:String, ?library:String) return getPath('data/$key.txt', library); + inline static public function pack(key:String, ?library:String) + return getPath('data/$key.pack', library); + inline static public function ini(key:String, ?library:String) return getPath('data/$key.ini', library); diff --git a/source/funkin/backend/chart/EventsData.hx b/source/funkin/backend/chart/EventsData.hx index 0c8f0a97..254ce779 100644 --- a/source/funkin/backend/chart/EventsData.hx +++ b/source/funkin/backend/chart/EventsData.hx @@ -42,15 +42,18 @@ class EventsData { hscriptParser.allowJSON = hscriptParser.allowMetadata = false; for (file in Paths.getFolderContent('data/events/', true, BOTH)) { - if (Path.extension(file) != "json") continue; + if (Path.extension(file) != "json" && Path.extension(file) != "pack") continue; var eventName:String = Path.withoutExtension(Path.withoutDirectory(file)); + var fileTxt:String = Assets.getText(file); + if (fileTxt.trim() == "") continue; + if (Path.extension(file) == "pack") { + eventName = Path.withoutExtension(fileTxt.split("________PACKSEP________")[0]); + fileTxt = fileTxt.split("________PACKSEP________")[2]; + } eventsList.push(eventName); eventsParams.set(eventName, []); - var fileTxt:String = Assets.getText(file); - if (fileTxt.trim() == "") continue; - try { var data:Dynamic = Json.parse(fileTxt); if (data == null || data.params == null) continue; diff --git a/source/funkin/editors/charter/CharterEvent.hx b/source/funkin/editors/charter/CharterEvent.hx index 6de57ceb..1e6cab0c 100644 --- a/source/funkin/editors/charter/CharterEvent.hx +++ b/source/funkin/editors/charter/CharterEvent.hx @@ -45,10 +45,15 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable { } private static function generateDefaultIcon(name:String) { + var isBase64:Bool = false; var path:String = Paths.image('editors/charter/event-icons/$name'); - if (!Assets.exists(path)) path = Paths.image('editors/charter/event-icons/Unknown'); + if (!Assets.exists(path) && Assets.exists(Paths.pack('events/$name'))) { + path = Assets.getText(Paths.pack('events/$name')).split('________PACKSEP________')[3]; + isBase64 = true; + } + else if (!Assets.exists(path)) path = Paths.image('editors/charter/event-icons/Unknown'); - var spr = new FlxSprite().loadGraphic(path); + var spr = new FlxSprite().loadGraphic(isBase64 ? openfl.display.BitmapData.fromBase64(path.trim(), 'UTF8') : path); return spr; } diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index fbf8dba8..16d6abe6 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -576,7 +576,13 @@ class PlayState extends MusicBeatState for (file in Paths.getFolderContent('data/events/', true, fromMods ? MODS : BOTH)) { var fileName:String = Path.withoutExtension(Path.withoutDirectory(file)); - if (EventsData.eventsList.contains(fileName) && songEvents.contains(fileName)) addScript(file); + if (EventsData.eventsList.contains(fileName) && songEvents.contains(fileName)) { + if (Path.extension(file) == "pack"){ + var txtArray:Array = Assets.getText(Paths.pack('events/$fileName')).split("________PACKSEP________"); + scripts.add(Script.fromString(txtArray[1], Path.extension(txtArray[0]), Path.withoutExtension(txtArray[0]))); + } + else addScript(file); + } } } }