From 8f4f4f8476bae7aff4549186652d6d3cb08c786a Mon Sep 17 00:00:00 2001 From: Bulby Date: Tue, 16 Feb 2021 15:28:42 -0500 Subject: [PATCH] AHHHHHHHHHHHHHHHHHHHH --- assets/data/freeplaySongJson.jsonc | 41 ++++ assets/data/freeplaySongJson.yaml | 38 ---- .../{custom_chars.yaml => custom_chars.jsonc} | 1 - source/CategoryState.hx | 10 +- source/Character.hx | 10 +- source/GameOverSubstate.hx | 4 +- source/HealthIcon.hx | 6 +- source/NewCharacterState.hx | 188 ++++++++++++++++++ source/SaveDataState.hx | 28 ++- source/VictoryLoopState.hx | 4 +- 10 files changed, 271 insertions(+), 59 deletions(-) create mode 100644 assets/data/freeplaySongJson.jsonc delete mode 100644 assets/data/freeplaySongJson.yaml rename assets/images/custom_chars/{custom_chars.yaml => custom_chars.jsonc} (95%) create mode 100644 source/NewCharacterState.hx diff --git a/assets/data/freeplaySongJson.jsonc b/assets/data/freeplaySongJson.jsonc new file mode 100644 index 000000000..52da22182 --- /dev/null +++ b/assets/data/freeplaySongJson.jsonc @@ -0,0 +1,41 @@ +[ + { + "name": "Base Game", + "songs": [ + // we use tjson so we can do comments and do some incorrect things + // the reason we use tjson is because json is hard + // The category screen won't show up unless there are more than 1 categories + "Tutorial", + "Bopeebo", + "Fresh", + "Dadbattle", + "Spookeez", + "South", + "Monster", + "Pico", + "Philly", + "Blammed", + "Satin-Panties", + "High", + "Milf", + "Cocoa", + "Eggnog", + "Winter-Horrorland", + "Senpai", + "Roses", + "Thorns" + ] + }, + // trailing commas don't matter with tjson + // visual studio code is just pissy + /* + uncomment this for an example + { + "name": "Custom 1", + "songs": [ + "Bopeebo", + "Fresh", + ] + }, + */ +] diff --git a/assets/data/freeplaySongJson.yaml b/assets/data/freeplaySongJson.yaml deleted file mode 100644 index 3bc2ac788..000000000 --- a/assets/data/freeplaySongJson.yaml +++ /dev/null @@ -1,38 +0,0 @@ -[ - !!map { - name: "Base Game", - songs: !!seq [ - # we use yaml so we can do comments and do some incorrect things - #the reason we use yaml is because json is hard - # The category screen won't show up unless there are more than 1 categories - Tutorial, - Bopeebo, - Fresh, - Dadbattle, - Spookeez, - South, - Monster, - Pico, - Philly, - Blammed, - Satin-Panties, - High, - Milf, - Cocoa, - Eggnog, - Winter-Horrorland, - Senpai, - Roses, - Thorns - ] - }, - # - # uncomment this for an example - # { - # "name": "Custom 1", - # "songs": [ - # "Bopeebo", - # "Fresh", - # ] - # }, -] diff --git a/assets/images/custom_chars/custom_chars.yaml b/assets/images/custom_chars/custom_chars.jsonc similarity index 95% rename from assets/images/custom_chars/custom_chars.yaml rename to assets/images/custom_chars/custom_chars.jsonc index a68730298..eecf242fa 100644 --- a/assets/images/custom_chars/custom_chars.yaml +++ b/assets/images/custom_chars/custom_chars.jsonc @@ -1,5 +1,4 @@ { - # valid json is valid yaml so you can just rename your file "template": { "like": "bf", "icons": [0,1] diff --git a/source/CategoryState.hx b/source/CategoryState.hx index 8f00856c8..621fc2321 100644 --- a/source/CategoryState.hx +++ b/source/CategoryState.hx @@ -37,16 +37,16 @@ class CategoryState extends MusicBeatState override function create() { // it's a js file to make syntax highlighting acceptable - var epicCategoryJs:Array = Yaml.parse(Assets.getText('assets/data/freeplaySongJson.yaml')); + var epicCategoryJs:Array = CoolUtil.parseJson(Assets.getText('assets/data/freeplaySongJson.jsonc')); if (epicCategoryJs.length > 1) { for (category in epicCategoryJs) { - categories.push(category.get("name")); - categorySongs.push(category.get("songs")); + categories.push(category.name); + categorySongs.push(category.songs); } } else { // just set freeplay states songs to the only category - trace(epicCategoryJs[0].get("songs")); - FreeplayState.currentSongList = epicCategoryJs[0].get("songs"); + trace(epicCategoryJs[0].songs); + FreeplayState.currentSongList = epicCategoryJs[0].songs; FlxG.switchState(new FreeplayState()); } diff --git a/source/Character.hx b/source/Character.hx index 653062fb3..44a66f999 100644 --- a/source/Character.hx +++ b/source/Character.hx @@ -546,15 +546,15 @@ class Character extends FlxSprite var charJson:Dynamic = null; var isError:Bool = false; try { - charJson = Yaml.parse(Assets.getText('assets/images/custom_chars/custom_chars.yaml')); + charJson = CoolUtil.parseJson(Assets.getText('assets/images/custom_chars/custom_chars.jsonc')); } catch (exception) { // uh oh someone messed up their json - Application.current.window.alert("Hey! You messed up your custom_chars.yaml. Your game won't crash but it will load bf. "+exception, "Alert"); + Application.current.window.alert("Hey! You messed up your custom_chars.jsonc. Your game won't crash but it will load bf. "+exception, "Alert"); isError = true; } if (!isError) { // use assets, as it is less laggy - var animJson = File.getContent("assets/images/custom_chars/"+charJson.get(curCharacter).get("like")+".json"); + var animJson = File.getContent("assets/images/custom_chars/"+Reflect.field(charJson,curCharacter).like+".json"); var parsedAnimJson:Dynamic = CoolUtil.parseJson(animJson); @@ -918,8 +918,8 @@ class Character extends FlxSprite animOffsets[name] = [x, y]; } public static function getAnimJson(char:String) { - var charJson = Yaml.parse(Assets.getText('assets/images/custom_chars/custom_chars.yaml')); - var animJson = CoolUtil.parseJson(File.getContent('assets/images/custom_chars/'+charJson.get(char).get("like") + '.json')); + var charJson = CoolUtil.parseJson(Assets.getText('assets/images/custom_chars/custom_chars.jsonc')); + var animJson = CoolUtil.parseJson(File.getContent('assets/images/custom_chars/'+Reflect.field(charJson,char).like + '.json')); return animJson; } } diff --git a/source/GameOverSubstate.hx b/source/GameOverSubstate.hx index 27bf2b44e..ae45006d5 100644 --- a/source/GameOverSubstate.hx +++ b/source/GameOverSubstate.hx @@ -38,9 +38,9 @@ class GameOverSubstate extends MusicBeatSubstate } var characterList = Assets.getText('assets/data/characterList.txt'); if (!StringTools.contains(characterList, p1)) { - var parsedCharJson:Dynamic = Yaml.parse(Assets.getText('assets/images/custom_chars/custom_chars.yaml')); + var parsedCharJson:Dynamic = CoolUtil.parseJson(Assets.getText('assets/images/custom_chars/custom_chars.jsonc')); //another CTRL+C CTRL+V ritual - var unparsedAnimJson = File.getContent("assets/images/custom_chars/"+parsedCharJson.get(p1).get("like")+".json"); //it might keep throwing an error if i dont do this + var unparsedAnimJson = File.getContent("assets/images/custom_chars/"+Reflect.field(parsedCharJson,p1).like+".json"); //it might keep throwing an error if i dont do this var parsedAnimJson = CoolUtil.parseJson(unparsedAnimJson); switch (parsedAnimJson.like) { case "bf": diff --git a/source/HealthIcon.hx b/source/HealthIcon.hx index 0ec8f44b2..e7b2c72b0 100644 --- a/source/HealthIcon.hx +++ b/source/HealthIcon.hx @@ -21,7 +21,7 @@ class HealthIcon extends FlxSprite { super(); #if sys - var charJson:Dynamic = Yaml.parse(File.getContent("assets/images/custom_chars/custom_chars.yaml")); + var charJson:Dynamic = CoolUtil.parseJson(File.getContent("assets/images/custom_chars/custom_chars.jsonc")); #end antialiasing = true; switch (char) { @@ -87,10 +87,10 @@ class HealthIcon extends FlxSprite if (FileSystem.exists('assets/images/custom_chars/'+char+"/icons.png")) { var rawPic:BitmapData = BitmapData.fromFile('assets/images/custom_chars/'+char+"/icons.png"); loadGraphic(rawPic, true, 150, 150); - animation.add('icon', charJson.get(char).get("icons"), false, isPlayer); + animation.add('icon', Reflect.field(charJson,char).icons, false, isPlayer); } else { loadGraphic('assets/images/iconGrid.png', true, 150, 150); - animation.add('icon', charJson.get(char).get("icons"), false, isPlayer); + animation.add('icon', Reflect.field(charJson,char).icons, false, isPlayer); } } animation.play('icon'); diff --git a/source/NewCharacterState.hx b/source/NewCharacterState.hx new file mode 100644 index 000000000..c820c489e --- /dev/null +++ b/source/NewCharacterState.hx @@ -0,0 +1,188 @@ +package; + +import flash.text.TextField; +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.addons.display.FlxGridOverlay; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.math.FlxMath; +import flixel.text.FlxText; +import flixel.util.FlxColor; +import lime.utils.Assets; +import DifficultyIcons; +import flixel.addons.ui.FlxInputText; +import flixel.addons.ui.FlxUI9SliceSprite; +import flixel.addons.ui.FlxUI; +import flixel.addons.ui.FlxUICheckBox; +import flixel.addons.ui.FlxUIDropDownMenu; +import flixel.addons.ui.FlxUIInputText; +import flixel.addons.ui.FlxUINumericStepper; +import flixel.ui.FlxButton; +import flixel.ui.FlxSpriteButton; +import flixel.addons.ui.FlxUITabMenu; +import lime.system.System; +#if sys +import sys.io.File; +import haxe.io.Path; +import openfl.utils.ByteArray; +import lime.media.AudioBuffer; +import sys.FileSystem; +import flash.media.Sound; + +#end +import lime.ui.FileDialog; +import lime.app.Event; +import haxe.Json; +import tjson.TJSON; +import yaml.Yaml; +import yaml.util.ObjectMap; +import openfl.net.FileReference; +import openfl.utils.ByteArray; +using StringTools; + +class NewCharacterState extends MusicBeatState +{ + var addCharUi:FlxUI; + var nameText:FlxUIInputText; + var mainPngButton:FlxButton; + var mainXmlButton:FlxButton; + var deadPngButton:FlxButton; + var deadXmlButton:FlxButton; + var crazyPngButton:FlxButton; + var crazyXmlButton:FlxButton; + var likeText:FlxUIInputText; + var iconAlive:FlxUINumericStepper; + var iconDead:FlxUINumericStepper; + var iconPoison:FlxUINumericStepper; + var finishButton:FlxButton; + var coolFile:FileReference; + var coolData:ByteArray; + var epicFiles:Dynamic; + private var grpSongs:FlxTypedGroup; + private var curPlaying:Bool = false; + + override function create() + { + addCharUi = new FlxUI(); + FlxG.mouse.visible = true; + epicFiles = { + "charpng": null, + "charxml":null, + "deadpng":null, + "deadxml":null, + "crazyxml":null, + "crazypng":null + }; + var bg:FlxSprite = new FlxSprite().loadGraphic('assets/images/menuBGBlue.png'); + add(bg); + mainPngButton = new FlxButton(10,10,"char.png",function ():Void { + var coolDialog = new FileDialog(); + coolDialog.browse(); + coolDialog.onSelect.add(function (path:String):Void { + epicFiles.charpng = path; + }); + }); + likeText = new FlxUIInputText(100, 10, 70,"bf"); + nameText = new FlxUIInputText(100,50,70,"template"); + var aliveText = new FlxText(100,70,"Alive Icon"); + iconAlive = new FlxUINumericStepper(100, 90,1,0,0,49); + var deadText = new FlxText(100,120,"Dead Icon"); + iconDead = new FlxUINumericStepper(100, 140,1,1,0,49); + var poisonText = new FlxText(100,170,"Poison Icon"); + iconPoison = new FlxUINumericStepper(100, 190,1,24,0,49); + add(nameText); + add(likeText); + add(iconAlive); + add(iconDead); + add(iconPoison); + add(poisonText); + add(deadText); + add(aliveText); + add(mainPngButton); + mainXmlButton = new FlxButton(10,60,"char.xml/txt",function ():Void { + var coolDialog = new FileDialog(); + coolDialog.browse(); + coolDialog.onSelect.add(function (path:String):Void { + epicFiles.charxml = path; + }); + }); + add(mainXmlButton); + deadPngButton = new FlxButton(10,110,"dead.png",function ():Void { + var coolDialog = new FileDialog(); + coolDialog.browse(); + coolDialog.onSelect.add(function (path:String):Void { + epicFiles.deadpng = path; + }); + }); + crazyPngButton = new FlxButton(10,170,"crazy.png",function ():Void { + var coolDialog = new FileDialog(); + coolDialog.browse(); + coolDialog.onSelect.add(function (path:String):Void { + epicFiles.crazypng = path; + }); + }); + deadXmlButton = new FlxButton(10,220,"dead.xml",function ():Void { + var coolDialog = new FileDialog(); + coolDialog.browse(); + coolDialog.onSelect.add(function (path:String):Void { + epicFiles.deadxml = path; + }); + }); + crazyXmlButton = new FlxButton(10,260,"crazy.xml",function ():Void { + var coolDialog = new FileDialog(); + coolDialog.browse(); + coolDialog.onSelect.add(function (path:String):Void { + epicFiles.crazyxml = path; + }); + }); + finishButton = new FlxButton(FlxG.width - 170, FlxG.height - 50, "Finish", function():Void { + writeCharacters(); + FlxG.switchState(new SaveDataState()); + }); + add(crazyXmlButton); + add(deadXmlButton); + add(deadPngButton); + add(finishButton); + add(crazyPngButton); + super.create(); + } + + override function update(elapsed:Float) + { + super.update(elapsed); + + } + function writeCharacters() { + // check to see if directory exists + #if sys + if (!FileSystem.exists('assets/images/custom_chars/'+nameText.text)) { + FileSystem.createDirectory('assets/images/custom_chars/'+nameText.text); + } + trace(epicFiles.charpng); + trace("hello"); + File.copy(epicFiles.charpng,'assets/images/custom_chars/'+nameText.text+'/char.png'); + // if it was an xml file save it as one + // otherwise save it as txt + if (StringTools.endsWith(epicFiles.charxml,"xml")) + File.copy(epicFiles.charxml,'assets/images/custom_chars/'+nameText.text+'/char.xml'); + else + File.copy(epicFiles.charxml,'assets/images/custom_chars/'+nameText.text+'/char.txt'); + if (epicFiles.deadpng != null) { + File.copy(epicFiles.deadpng,'assets/images/custom_chars/'+nameText.text+'/dead.png'); + File.copy(epicFiles.deadxml,'assets/images/custom_chars/'+nameText.text+'/dead.xml'); + } + if (epicFiles.crazypng != null) { + File.copy(epicFiles.crazypng,'assets/images/custom_chars/'+nameText.text+'/crazy.png'); + File.copy(epicFiles.crazyxml,'assets/images/custom_chars/'+nameText.text+'/crazy.xml'); + } + trace("hello"); + var epicCharFile:Dynamic =CoolUtil.parseJson(Assets.getText('assets/images/custom_chars/custom_chars.jsonc')); + trace("parsed"); + var coolReplacementMap:ObjectMap = new ObjectMap(); + Reflect.setField(epicCharFile,nameText.text,{like:likeText.text,icons: [Std.int(iconAlive.value),Std.int(iconDead.value),Std.int(iconPoison.value)]}); + + File.saveContent('assets/images/custom_chars/custom_chars.jsonc', CoolUtil.stringifyJson(epicCharFile)); + trace("cool stuff"); + #end + } +} diff --git a/source/SaveDataState.hx b/source/SaveDataState.hx index 92ea7207e..47665e61a 100644 --- a/source/SaveDataState.hx +++ b/source/SaveDataState.hx @@ -12,7 +12,10 @@ import flixel.tweens.FlxTween; import flixel.tweens.FlxEase; import flixel.util.FlxColor; import lime.utils.Assets; +// visual studio code gets pissy when you don't use conditionals +#if sys import sys.io.File; +#end import haxe.Json; import tjson.TJSON; @@ -35,7 +38,7 @@ class SaveDataState extends MusicBeatState override function create() { var menuBG:FlxSprite = new FlxSprite().loadGraphic('assets/images/menuDesat.png'); - optionList = [{name: "Always Show Cutscenes", value: false}, {name: "Skip Modifier Menu", value: false}, {name: "Skip Victory Screen", value: false}]; + optionList = [{name: "Always Show Cutscenes", value: false}, {name: "Skip Modifier Menu", value: false}, {name: "Skip Victory Screen", value: false},{name:"New Character...", value: false}]; optionList[0].value = FlxG.save.data.options.alwaysDoCutscenes; optionList[1].value = FlxG.save.data.options.skipModifierMenu; optionList[2].value = FlxG.save.data.options.skipVictoryScreen; @@ -153,8 +156,27 @@ class SaveDataState extends MusicBeatState FlxG.sound.play('assets/sounds/scrollMenu.ogg'); saves.members[curSelected].beSelected(true); } else { - checkmarks.members[optionsSelected].visible = !checkmarks.members[optionsSelected].visible; - optionList[optionsSelected].value = checkmarks.members[optionsSelected].visible; + if (optionList[optionsSelected].name != "New Character...") { + checkmarks.members[optionsSelected].visible = !checkmarks.members[optionsSelected].visible; + optionList[optionsSelected].value = checkmarks.members[optionsSelected].visible; + } else { + // doing this to make later stuff earlier + switch (optionList[optionsSelected].name) { + case "New Character...": + // our current save saves this + // we are gonna have to do some shenanagins to save our preffered save + + FlxG.save.data.options = { + "skipVictoryScreen": optionList[2].value, + "skipModifierMenu": optionList[1].value, + "alwaysDoCutscenes": optionList[0].value + }; + trace(FlxG.save.data.options); + FlxG.switchState(new NewCharacterState()); + } + + } + FlxG.sound.play('assets/sounds/scrollMenu.ogg'); } } diff --git a/source/VictoryLoopState.hx b/source/VictoryLoopState.hx index ee21179c6..4936c4f6b 100644 --- a/source/VictoryLoopState.hx +++ b/source/VictoryLoopState.hx @@ -102,8 +102,8 @@ class VictoryLoopState extends MusicBeatSubstate accuracyTxt.setFormat("assets/fonts/vcr.ttf", 26, FlxColor.WHITE, RIGHT); var characterList = Assets.getText('assets/data/characterList.txt'); if (!StringTools.contains(characterList, p1)) { - var parsedCharJson:Dynamic = CoolUtil.parseJson(Assets.getText('assets/images/custom_chars/custom_chars.yaml')); - var parsedAnimJson = CoolUtil.parseJson(File.getContent("assets/images/custom_chars/"+parsedCharJson.get(p1).get("like")+".json")); + var parsedCharJson:Dynamic = CoolUtil.parseJson(Assets.getText('assets/images/custom_chars/custom_chars.jsonc')); + var parsedAnimJson = CoolUtil.parseJson(File.getContent("assets/images/custom_chars/"+Reflect.field(parsedCharJson,p1).like+".json")); switch (parsedAnimJson.like) { case "bf-pixel": // gotta deal with this dude