From ae37e98cdfb750ea36a34de3d5f2d16daa20a375 Mon Sep 17 00:00:00 2001
From: Cameron Taylor <cameron.taylor.ninja@gmail.com>
Date: Fri, 4 Jun 2021 02:01:34 -0400
Subject: [PATCH] anim debug bullshit

---
 source/Character.hx                           |   2 +-
 source/DebugBoundingState.hx                  |  74 ++++++++
 source/TitleState.hx                          |   1 +
 source/ui/stageBuildShit/SprStage.hx          |   2 +
 source/ui/stageBuildShit/StageBuilderState.hx | 175 +++++++++++++-----
 5 files changed, 209 insertions(+), 45 deletions(-)

diff --git a/source/Character.hx b/source/Character.hx
index 356eb1639..6b1d69727 100644
--- a/source/Character.hx
+++ b/source/Character.hx
@@ -547,7 +547,7 @@ class Character extends FlxSprite
 
 	private function loadOffsetFile(offsetCharacter:String)
 	{
-		var daFile:Array<String> = CoolUtil.coolTextFile(Paths.file("images/characters/" + offsetCharacter + "Offsets.txt"));
+		var daFile:Array<String> = CoolUtil.coolTextFile(Paths.file("images/characters/" + offsetCharacter + "Offsets.txt", TEXT, 'shared'));
 
 		for (i in daFile)
 		{
diff --git a/source/DebugBoundingState.hx b/source/DebugBoundingState.hx
index 7a8a1bef7..19ca44828 100644
--- a/source/DebugBoundingState.hx
+++ b/source/DebugBoundingState.hx
@@ -5,11 +5,14 @@ import flixel.FlxG;
 import flixel.FlxSprite;
 import flixel.FlxState;
 import flixel.addons.display.FlxGridOverlay;
+import flixel.addons.ui.FlxInputText;
+import flixel.addons.ui.FlxUIDropDownMenu;
 import flixel.graphics.frames.FlxAtlasFrames;
 import flixel.group.FlxGroup;
 import flixel.text.FlxText;
 import flixel.util.FlxColor;
 import flixel.util.FlxSpriteUtil;
+import lime.utils.Assets as LimeAssets;
 import openfl.Assets;
 import sys.io.File;
 
@@ -17,6 +20,17 @@ using flixel.util.FlxSpriteUtil;
 
 class DebugBoundingState extends FlxState
 {
+	/* 
+		TODAY'S TO-DO
+		- Refactor the animation offset menu to be in this one instead
+			- Cleaner UI
+			- Easier to access, test, and export data from.
+			- Easier movement
+			- Onion skinning
+			- Mouse controls??
+			- Load different characters on the fly
+
+	 */
 	var bg:FlxSprite;
 	var fileInfo:FlxText;
 
@@ -24,8 +38,12 @@ class DebugBoundingState extends FlxState
 
 	var hudCam:FlxCamera;
 
+	var charInput:FlxUIDropDownMenu;
+
 	override function create()
 	{
+		Paths.setCurrentLevel('week1');
+
 		hudCam = new FlxCamera();
 		hudCam.bgColor.alpha = 0;
 
@@ -62,6 +80,22 @@ class DebugBoundingState extends FlxState
 		txtGrp.cameras = [hudCam];
 		add(txtGrp);
 
+		// charInput = new FlxInputText(300, 10, 150, "bf", 16);
+		// charInput.focusCam = hudCam;
+		// charInput.cameras = [hudCam];
+		// charInput.scrollFactor.set();
+
+		var characters:Array<String> = CoolUtil.coolTextFile(Paths.txt('characterList'));
+
+		charInput = new FlxUIDropDownMenu(200, 20, FlxUIDropDownMenu.makeStrIdLabelArray(characters, true), function(str:String)
+		{
+			loadAnimShit(characters[Std.parseInt(str)]);
+			// trace();
+		});
+		// charInput.
+		charInput.cameras = [hudCam];
+		txtGrp.add(charInput);
+
 		addInfo('boyfriend.xml', "");
 		addInfo('Width', bf.width);
 		addInfo('Height', bf.height);
@@ -99,8 +133,31 @@ class DebugBoundingState extends FlxState
 		swagText.text = str + ": " + Std.string(value);
 	}
 
+	function checkLibrary(library:String)
+	{
+		trace(Assets.hasLibrary(library));
+		if (Assets.getLibrary(library) == null)
+		{
+			@:privateAccess
+			if (!LimeAssets.libraryPaths.exists(library))
+				throw "Missing library: " + library;
+
+			// var callback = callbacks.add("library:" + library);
+			Assets.loadLibrary(library).onComplete(function(_)
+			{
+				trace('LOADED... awesomeness...');
+				// callback();
+			});
+		}
+	}
+
 	override function update(elapsed:Float)
 	{
+		/* if (charInput.hasFocus && FlxG.keys.justPressed.ENTER)
+			{
+				loadAnimShit();
+		}*/
+
 		CoolUtil.mouseCamDrag();
 		CoolUtil.mouseWheelZoom();
 
@@ -111,4 +168,21 @@ class DebugBoundingState extends FlxState
 
 		super.update(elapsed);
 	}
+
+	var swagChar:Character;
+
+	function loadAnimShit(char:String)
+	{
+		// trace('TRYING TO LOAD - ' + charInput.text);
+
+		if (swagChar != null)
+		{
+			remove(swagChar);
+			swagChar.destroy();
+		}
+
+		swagChar = new Character(100, 100, char);
+		swagChar.debugMode = true;
+		add(swagChar);
+	}
 }
diff --git a/source/TitleState.hx b/source/TitleState.hx
index 392dd86f1..4e4760c15 100644
--- a/source/TitleState.hx
+++ b/source/TitleState.hx
@@ -15,6 +15,7 @@ import flixel.math.FlxPoint;
 import flixel.math.FlxRect;
 import flixel.system.FlxAssets.FlxGraphicAsset;
 import flixel.system.FlxAssets;
+import flixel.text.FlxText;
 import flixel.tweens.FlxEase;
 import flixel.tweens.FlxTween;
 import flixel.util.FlxColor;
diff --git a/source/ui/stageBuildShit/SprStage.hx b/source/ui/stageBuildShit/SprStage.hx
index eae402cb7..8ec150629 100644
--- a/source/ui/stageBuildShit/SprStage.hx
+++ b/source/ui/stageBuildShit/SprStage.hx
@@ -7,6 +7,8 @@ import flixel.math.FlxPoint;
 
 class SprStage extends FlxSprite
 {
+	public var imgName:String = '';
+
 	public var layer:Int = 0;
 	public var mousePressing:Bool = false;
 
diff --git a/source/ui/stageBuildShit/StageBuilderState.hx b/source/ui/stageBuildShit/StageBuilderState.hx
index 8eaa411c8..67150469d 100644
--- a/source/ui/stageBuildShit/StageBuilderState.hx
+++ b/source/ui/stageBuildShit/StageBuilderState.hx
@@ -1,5 +1,6 @@
 package ui.stageBuildShit;
 
+import flixel.FlxCamera;
 import flixel.FlxG;
 import flixel.FlxSprite;
 import flixel.addons.display.FlxGridOverlay;
@@ -7,21 +8,30 @@ import flixel.group.FlxGroup;
 import flixel.input.mouse.FlxMouseButton.FlxMouseButtonID;
 import flixel.input.mouse.FlxMouseEventManager;
 import flixel.math.FlxPoint;
+import flixel.text.FlxText;
 import flixel.ui.FlxButton;
+import flixel.util.FlxColor;
 import flixel.util.FlxSort;
 import flixel.util.FlxTimer;
 
 class StageBuilderState extends MusicBeatState
 {
 	private var hudGrp:FlxGroup;
+	var textInfo:FlxText;
 
 	private var sprGrp:FlxTypedGroup<SprStage>;
 
 	// var snd:Sound;
 	// var sndChannel:SoundChannel;
+	var hudCam:FlxCamera;
 
 	override function create()
 	{
+		hudCam = new FlxCamera();
+		hudCam.bgColor.alpha = 0;
+
+		FlxG.cameras.add(hudCam, false);
+
 		super.create();
 
 		FlxG.mouse.visible = true;
@@ -70,8 +80,14 @@ class StageBuilderState extends MusicBeatState
 		add(sprGrp);
 
 		hudGrp = new FlxGroup();
+		hudGrp.cameras = [hudCam];
 		add(hudGrp);
 
+		textInfo = new FlxText(10, 80, 0, "", 24);
+		textInfo.setFormat(Paths.font("vcr.ttf"), 20, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
+		textInfo.scrollFactor.set();
+		hudGrp.add(textInfo);
+
 		var imgBtn:FlxButton = new FlxButton(20, 20, "Load Image", loadImage);
 		hudGrp.add(imgBtn);
 
@@ -106,8 +122,11 @@ class StageBuilderState extends MusicBeatState
 				awesomeImg.loadGraphic(Paths.image('stageBuild/stageTempImg'), false, 0, 0, true);
 
 				awesomeImg.layer = sprGrp.members.length;
+				awesomeImg.imgName = fileName;
 
 				sprGrp.add(awesomeImg);
+
+				curFocus = MOVEMENTS;
 			});
 
 			// Load the image shit by
@@ -148,6 +167,101 @@ class StageBuilderState extends MusicBeatState
 
 	override function update(elapsed:Float)
 	{
+		if (FlxG.keys.justPressed.H)
+			hudGrp.visible = !hudGrp.visible;
+
+		if (FlxG.keys.justPressed.ESCAPE)
+		{
+			if (curFocus == ATTRIBUTES)
+				curFocus = MOVEMENTS;
+			else
+				curFocus = ATTRIBUTES;
+		}
+
+		switch (curFocus)
+		{
+			case MOVEMENTS:
+				movementControls();
+			case ATTRIBUTES:
+				attributeControls();
+			default:
+		}
+
+		if (FlxG.keys.justPressed.DELETE)
+		{
+			if (curSelectedSpr != null)
+				sprGrp.remove(curSelectedSpr, true);
+		}
+
+		CoolUtil.mouseCamDrag();
+
+		if (FlxG.keys.pressed.CONTROL)
+			CoolUtil.mouseWheelZoom();
+
+		if (isShaking)
+		{
+			FlxG.stage.window.x = Std.int(shakePos.x + (FlxG.random.float(-1, 1) * shakeIntensity));
+			FlxG.stage.window.y = Std.int(shakePos.y + (FlxG.random.float(-1, 1) * shakeIntensity));
+
+			shakeIntensity -= 30 * elapsed;
+
+			if (shakeIntensity <= 0)
+			{
+				isShaking = false;
+				shakeIntensity = 60;
+				FlxG.stage.window.x = Std.int(shakePos.x);
+				FlxG.stage.window.y = Std.int(shakePos.y);
+			}
+		}
+
+		if (curTool == GRABBING && FlxG.mouse.justReleased)
+		{
+			moveSprPos([
+				curSelectedSpr.x - curSelectedSpr.oldPos.x,
+				curSelectedSpr.y - curSelectedSpr.oldPos.y
+			]);
+		}
+
+		if (FlxG.keys.justPressed.Z && actionQueue.length > 0)
+		{
+			// trace('UNDO - QUEUE LENGTH: ' + actionQueue.length);
+			isUndoRedo = true;
+
+			var daFunc = actionQueue.pop();
+			var daValue = posQueue.pop();
+
+			daFunc(daValue);
+		}
+
+		super.update(elapsed);
+	}
+
+	function attributeControls():Void
+	{
+		textInfo.alpha = 1;
+
+		if (FlxG.keys.justPressed.LEFT || FlxG.keys.justPressed.RIGHT)
+		{
+			if (FlxG.keys.justPressed.LEFT)
+			{
+				curSelectedSpr.scrollFactor.x -= 0.1;
+				curSelectedSpr.scrollFactor.y -= 0.1;
+			}
+
+			if (FlxG.keys.justPressed.RIGHT)
+			{
+				curSelectedSpr.scrollFactor.x += 0.1;
+				curSelectedSpr.scrollFactor.y += 0.1;
+			}
+
+			updateTextInfo();
+		}
+	}
+
+	function movementControls():Void
+	{
+		textInfo.alpha = 0.5;
+
 		if (FlxG.keys.justPressed.CONTROL)
 		{
 			tempTool = curTool;
@@ -196,52 +310,10 @@ class StageBuilderState extends MusicBeatState
 			if (curSelectedSpr != null)
 				moveLayer(-1);
 		}
-
-		if (FlxG.keys.justPressed.DELETE)
-		{
-			if (curSelectedSpr != null)
-				sprGrp.remove(curSelectedSpr, true);
-		}
-
-		CoolUtil.mouseCamDrag();
-
-		if (FlxG.keys.pressed.CONTROL)
-			CoolUtil.mouseWheelZoom();
-
-		if (isShaking)
-		{
-			FlxG.stage.window.x = Std.int(shakePos.x + (FlxG.random.float(-1, 1) * shakeIntensity));
-			FlxG.stage.window.y = Std.int(shakePos.y + (FlxG.random.float(-1, 1) * shakeIntensity));
-
-			shakeIntensity -= 30 * elapsed;
-
-			if (shakeIntensity <= 0)
-			{
-				isShaking = false;
-				shakeIntensity = 60;
-				FlxG.stage.window.x = Std.int(shakePos.x);
-				FlxG.stage.window.y = Std.int(shakePos.y);
-			}
-		}
-
-		if (curTool == GRABBING && FlxG.mouse.justReleased)
-		{
-			moveSprPos([
-				curSelectedSpr.x - curSelectedSpr.oldPos.x,
-				curSelectedSpr.y - curSelectedSpr.oldPos.y
-			]);
-		}
-
-		if (FlxG.keys.justPressed.Z && actionQueue.length > 0)
-		{
-			// trace('UNDO - QUEUE LENGTH: ' + actionQueue.length);
-			isUndoRedo = true;
-			actionQueue.pop()(posQueue.pop());
-		}
-
-		super.update(elapsed);
 	}
 
+	var curFocus:FOCUS = MOVEMENTS;
+
 	static public function changeTool(newTool:TOOLS)
 	{
 		curTool = newTool;
@@ -264,6 +336,14 @@ class StageBuilderState extends MusicBeatState
 	{
 		undoRedoCheck(changeCurSelected, curSelectedSpr);
 		curSelectedSpr = spr;
+
+		updateTextInfo();
+	}
+
+	function updateTextInfo()
+	{
+		textInfo.text = curSelectedSpr.imgName;
+		textInfo.text += ' - parallax: ' + curSelectedSpr.scrollFactor;
 	}
 
 	// base check to see if its in a state of undo or redo
@@ -301,6 +381,7 @@ class StageBuilderState extends MusicBeatState
 		// trace(xDiff);
 		// trace(yDiff);
 
+		// usually set to false for the MOUSE DRAG, merely to track movements from the mouse
 		if (forceMove)
 		{
 			curSelectedSpr.x += xDiff;
@@ -353,6 +434,12 @@ class StageBuilderState extends MusicBeatState
 	}
 }
 
+enum FOCUS
+{
+	ATTRIBUTES;
+	MOVEMENTS;
+}
+
 enum TOOLS
 {
 	SELECT;