From 1a5b68acd84699da1952c70cd66210796de711bb Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 5 Apr 2023 00:56:02 -0400 Subject: [PATCH] substate loading type beat --- source/funkin/play/PlayState.hx | 2 +- source/funkin/ui/StickerSubState.hx | 69 +++++++++++++++++++-- source/funkin/ui/debug/DebugMenuSubState.hx | 7 +++ 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 8e51db8a0..1f62b71ed 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1512,7 +1512,7 @@ class PlayState extends MusicBeatState else { var boyfriendPos = currentStage.getBoyfriend().getScreenPosition(); - var pauseSubState = new PauseSubState(boyfriendPos.x, boyfriendPos.y); + var pauseSubState = new PauseSubState(); openSubState(pauseSubState); pauseSubState.camera = camHUD; boyfriendPos.put(); diff --git a/source/funkin/ui/StickerSubState.hx b/source/funkin/ui/StickerSubState.hx index 3411f2c57..6df671f95 100644 --- a/source/funkin/ui/StickerSubState.hx +++ b/source/funkin/ui/StickerSubState.hx @@ -2,6 +2,7 @@ package funkin.ui; import flixel.FlxSprite; import haxe.Json; +import lime.utils.Assets; class StickerSubState extends MusicBeatSubstate { @@ -9,10 +10,14 @@ class StickerSubState extends MusicBeatSubstate { super(); - var stickerInfo:StickerInfo = new StickerInfo('sticker-set-1'); + var stickerInfo:StickerInfo = new StickerInfo('stickers-set-1'); for (stickerSets in stickerInfo.getPack("all")) { - trace(stickerSets); + for (stickerShit in stickerInfo.getStickers(stickerSets)) + { + var sticky:StickerSprite = new StickerSprite(FlxG.random.int(0, FlxG.width), FlxG.random.int(0, FlxG.height), stickerInfo.name, stickerShit); + add(sticky); + } } } } @@ -21,7 +26,7 @@ class StickerSprite extends FlxSprite { public function new(x:Float, y:Float, stickerSet:String, stickerName:String):Void { - super(x, y, Paths.file('assets/images/transitionSwag/' + stickerSet + '/' + stickerName + '.png')); + super(x, y, Paths.image('transitionSwag/' + stickerSet + '/' + stickerName)); } } @@ -34,12 +39,64 @@ class StickerInfo public function new(stickerSet:String):Void { - var jsonInfo:StickerShit = cast Json.parse(Paths.file('assets/images/transitionSwag/' + stickerSet + '/stickers.json')); + var path = Paths.file('images/transitionSwag/' + stickerSet + '/stickers.json'); + var json = Json.parse(Assets.getText(path)); + trace(json); + + // doin this dipshit nonsense cuz i dunno how to deal with casting a json object with + // a dash in its name (sticker-packs) + var jsonInfo:StickerShit = cast json; this.name = jsonInfo.name; this.artist = jsonInfo.artist; - this.stickers = jsonInfo.stickers; - this.stickerPacks = jsonInfo.stickerPacks; + + stickerPacks = new Map>(); + + for (field in Reflect.fields(json.stickerPacks)) + { + var stickerFunny = json.stickerPacks; + var stickerStuff = Reflect.field(stickerFunny, field); + + stickerPacks.set(field, cast stickerStuff); + + trace(field); + trace(Reflect.field(stickerFunny, field)); + } + + trace(stickerPacks); + + // creates a similar for loop as before but for the stickers + stickers = new Map>(); + + for (field in Reflect.fields(json.stickers)) + { + var stickerFunny = json.stickers; + var stickerStuff = Reflect.field(stickerFunny, field); + + stickers.set(field, cast stickerStuff); + + trace(field); + trace(Reflect.field(stickerFunny, field)); + } + + trace(stickers); + + // this.stickerPacks = cast jsonInfo.stickerPacks; + // this.stickers = cast jsonInfo.stickers; + + // trace(stickerPacks); + // trace(stickers); + + // for (packs in stickers) + // { + // // this.stickers.set(packs, Reflect.field(json, "sticker-packs")); + // trace(packs); + // } + } + + public function getStickers(stickerName:String):Array + { + return this.stickers[stickerName]; } public function getPack(packName:String):Array diff --git a/source/funkin/ui/debug/DebugMenuSubState.hx b/source/funkin/ui/debug/DebugMenuSubState.hx index 476f0ae9d..7a12eb7fb 100644 --- a/source/funkin/ui/debug/DebugMenuSubState.hx +++ b/source/funkin/ui/debug/DebugMenuSubState.hx @@ -46,6 +46,7 @@ class DebugMenuSubState extends MusicBeatSubstate onMenuChange(createItem("CHART EDITOR", openChartEditor)); createItem("ANIMATION EDITOR", openAnimationEditor); createItem("STAGE EDITOR", openStageEditor); + createItem("TEST STICKERS", testStickers); } function onMenuChange(selected:TextMenuItem) @@ -83,6 +84,12 @@ class DebugMenuSubState extends MusicBeatSubstate trace('Animation Editor'); } + function testStickers() + { + openSubState(new funkin.ui.StickerSubState()); + trace('opened stickers'); + } + function openStageEditor() { trace('Stage Editor');