2021-04-07 20:19:49 -04:00
|
|
|
package;
|
|
|
|
|
2021-05-27 19:15:03 -04:00
|
|
|
import flixel.FlxCamera;
|
2021-04-07 20:19:49 -04:00
|
|
|
import flixel.FlxG;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.FlxState;
|
2021-05-26 19:22:15 -04:00
|
|
|
import flixel.addons.display.FlxGridOverlay;
|
2021-06-04 02:01:34 -04:00
|
|
|
import flixel.addons.ui.FlxInputText;
|
|
|
|
import flixel.addons.ui.FlxUIDropDownMenu;
|
2021-05-26 19:22:15 -04:00
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
2021-05-27 19:15:03 -04:00
|
|
|
import flixel.group.FlxGroup;
|
|
|
|
import flixel.text.FlxText;
|
|
|
|
import flixel.util.FlxColor;
|
|
|
|
import flixel.util.FlxSpriteUtil;
|
2021-06-04 02:01:34 -04:00
|
|
|
import lime.utils.Assets as LimeAssets;
|
2021-04-07 20:19:49 -04:00
|
|
|
import openfl.Assets;
|
|
|
|
import sys.io.File;
|
|
|
|
|
2021-05-27 19:15:03 -04:00
|
|
|
using flixel.util.FlxSpriteUtil;
|
|
|
|
|
2021-04-07 20:19:49 -04:00
|
|
|
class DebugBoundingState extends FlxState
|
|
|
|
{
|
2021-06-04 02:01:34 -04:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
2021-05-27 19:15:03 -04:00
|
|
|
var bg:FlxSprite;
|
|
|
|
var fileInfo:FlxText;
|
|
|
|
|
|
|
|
var txtGrp:FlxGroup;
|
|
|
|
|
|
|
|
var hudCam:FlxCamera;
|
|
|
|
|
2021-06-04 02:01:34 -04:00
|
|
|
var charInput:FlxUIDropDownMenu;
|
|
|
|
|
2021-06-04 02:31:27 -04:00
|
|
|
var curView:ANIMDEBUGVIEW = SPRITESHEET;
|
|
|
|
|
|
|
|
var spriteSheetView:FlxGroup;
|
|
|
|
var animDropDownMenu:FlxUIDropDownMenu;
|
|
|
|
var dropDownSetup:Bool = false;
|
|
|
|
|
2021-04-07 20:19:49 -04:00
|
|
|
override function create()
|
|
|
|
{
|
2021-06-04 02:01:34 -04:00
|
|
|
Paths.setCurrentLevel('week1');
|
|
|
|
|
2021-05-27 19:15:03 -04:00
|
|
|
hudCam = new FlxCamera();
|
|
|
|
hudCam.bgColor.alpha = 0;
|
|
|
|
|
|
|
|
FlxG.cameras.add(hudCam, false);
|
|
|
|
|
|
|
|
bg = FlxGridOverlay.create(10, 10);
|
2021-05-26 19:22:15 -04:00
|
|
|
|
|
|
|
bg.scrollFactor.set();
|
|
|
|
add(bg);
|
|
|
|
|
2021-06-04 02:31:27 -04:00
|
|
|
initSpritesheetView();
|
|
|
|
|
|
|
|
// charInput = new FlxInputText(300, 10, 150, "bf", 16);
|
|
|
|
// charInput.focusCam = hudCam;
|
|
|
|
// charInput.cameras = [hudCam];
|
|
|
|
// charInput.scrollFactor.set();
|
|
|
|
|
|
|
|
animDropDownMenu = new FlxUIDropDownMenu(370, 20, FlxUIDropDownMenu.makeStrIdLabelArray(['weed'], true));
|
|
|
|
animDropDownMenu.cameras = [hudCam];
|
|
|
|
add(animDropDownMenu);
|
|
|
|
|
|
|
|
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];
|
|
|
|
add(charInput);
|
|
|
|
|
|
|
|
super.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
function initSpritesheetView():Void
|
|
|
|
{
|
|
|
|
spriteSheetView = new FlxGroup();
|
|
|
|
add(spriteSheetView);
|
|
|
|
|
2021-05-26 19:22:15 -04:00
|
|
|
var tex = Paths.getSparrowAtlas('characters/temp');
|
|
|
|
// tex.frames[0].uv
|
|
|
|
|
|
|
|
var bf:FlxSprite = new FlxSprite();
|
|
|
|
bf.loadGraphic(tex.parent);
|
2021-06-04 02:31:27 -04:00
|
|
|
spriteSheetView.add(bf);
|
2021-04-07 20:19:49 -04:00
|
|
|
|
2021-05-27 19:15:03 -04:00
|
|
|
var swagGraphic:FlxSprite = new FlxSprite().makeGraphic(tex.parent.width, tex.parent.height, FlxColor.TRANSPARENT);
|
|
|
|
|
|
|
|
for (i in tex.frames)
|
|
|
|
{
|
|
|
|
var lineStyle:LineStyle = {color: FlxColor.RED, thickness: 2};
|
|
|
|
|
|
|
|
var uvW:Float = (i.uv.width * i.parent.width) - (i.uv.x * i.parent.width);
|
|
|
|
var uvH:Float = (i.uv.height * i.parent.height) - (i.uv.y * i.parent.height);
|
|
|
|
|
|
|
|
// trace(Std.int(i.uv.width * i.parent.width));
|
|
|
|
swagGraphic.drawRect(i.uv.x * i.parent.width, i.uv.y * i.parent.height, uvW, uvH, FlxColor.TRANSPARENT, lineStyle);
|
|
|
|
// swagGraphic.setPosition(, );
|
|
|
|
// trace(uvH);
|
|
|
|
}
|
|
|
|
|
|
|
|
txtGrp = new FlxGroup();
|
|
|
|
txtGrp.cameras = [hudCam];
|
2021-06-04 02:31:27 -04:00
|
|
|
spriteSheetView.add(txtGrp);
|
2021-06-04 02:01:34 -04:00
|
|
|
|
2021-05-27 19:15:03 -04:00
|
|
|
addInfo('boyfriend.xml', "");
|
|
|
|
addInfo('Width', bf.width);
|
|
|
|
addInfo('Height', bf.height);
|
|
|
|
|
|
|
|
swagGraphic.antialiasing = true;
|
2021-06-04 02:31:27 -04:00
|
|
|
spriteSheetView.add(swagGraphic);
|
2021-05-27 19:15:03 -04:00
|
|
|
|
2021-04-07 20:19:49 -04:00
|
|
|
FlxG.stage.window.onDropFile.add(function(path:String)
|
|
|
|
{
|
|
|
|
trace("DROPPED FILE FROM: " + Std.string(path));
|
|
|
|
var newPath = "./" + Paths.image('characters/temp');
|
|
|
|
File.copy(path, newPath);
|
|
|
|
|
|
|
|
var swag = Paths.image('characters/temp');
|
|
|
|
|
|
|
|
if (bf != null)
|
|
|
|
remove(bf);
|
|
|
|
FlxG.bitmap.removeByKey(Paths.image('characters/temp'));
|
|
|
|
Assets.cache.clear();
|
|
|
|
|
|
|
|
bf.loadGraphic(Paths.image('characters/temp'));
|
|
|
|
add(bf);
|
|
|
|
});
|
|
|
|
}
|
2021-05-26 19:22:15 -04:00
|
|
|
|
2021-05-27 19:15:03 -04:00
|
|
|
function addInfo(str:String, value:Dynamic)
|
|
|
|
{
|
|
|
|
var swagText:FlxText = new FlxText(10, 10 + (28 * txtGrp.length));
|
|
|
|
swagText.setFormat(Paths.font("vcr.ttf"), 26, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
|
|
|
|
swagText.scrollFactor.set();
|
|
|
|
txtGrp.add(swagText);
|
|
|
|
|
|
|
|
swagText.text = str + ": " + Std.string(value);
|
|
|
|
}
|
|
|
|
|
2021-06-04 02:01:34 -04:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 19:22:15 -04:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
2021-06-04 02:31:27 -04:00
|
|
|
if (FlxG.keys.justPressed.ONE)
|
|
|
|
curView = SPRITESHEET;
|
|
|
|
if (FlxG.keys.justReleased.TWO)
|
|
|
|
curView = OFFSETSHIT;
|
|
|
|
|
|
|
|
switch (curView)
|
|
|
|
{
|
|
|
|
case SPRITESHEET:
|
|
|
|
spriteSheetView.visible = true;
|
|
|
|
case OFFSETSHIT:
|
|
|
|
spriteSheetView.visible = false;
|
2021-06-04 02:43:05 -04:00
|
|
|
offsetControls();
|
2021-06-04 02:31:27 -04:00
|
|
|
}
|
|
|
|
|
2021-06-04 02:01:34 -04:00
|
|
|
/* if (charInput.hasFocus && FlxG.keys.justPressed.ENTER)
|
|
|
|
{
|
|
|
|
loadAnimShit();
|
|
|
|
}*/
|
|
|
|
|
2021-05-26 19:22:15 -04:00
|
|
|
CoolUtil.mouseCamDrag();
|
2021-05-27 19:15:03 -04:00
|
|
|
CoolUtil.mouseWheelZoom();
|
|
|
|
|
|
|
|
// bg.scale.x = FlxG.camera.zoom;
|
|
|
|
// bg.scale.y = FlxG.camera.zoom;
|
|
|
|
|
|
|
|
bg.setGraphicSize(Std.int(bg.width / FlxG.camera.zoom));
|
|
|
|
|
2021-05-26 19:22:15 -04:00
|
|
|
super.update(elapsed);
|
|
|
|
}
|
2021-06-04 02:01:34 -04:00
|
|
|
|
2021-06-04 02:43:05 -04:00
|
|
|
function offsetControls():Void
|
|
|
|
{
|
|
|
|
if (FlxG.keys.justPressed.RBRACKET)
|
|
|
|
{
|
|
|
|
if (Std.parseInt(animDropDownMenu.selectedId) + 1 < animDropDownMenu.length)
|
|
|
|
animDropDownMenu.selectedId = Std.string(Std.parseInt(animDropDownMenu.selectedId) + 1);
|
|
|
|
animDropDownMenu.callback(animDropDownMenu.selectedId);
|
|
|
|
}
|
|
|
|
if (FlxG.keys.justPressed.LBRACKET)
|
|
|
|
{
|
|
|
|
if (Std.parseInt(animDropDownMenu.selectedId) - 1 >= 0)
|
|
|
|
animDropDownMenu.selectedId = Std.string(Std.parseInt(animDropDownMenu.selectedId) - 1);
|
|
|
|
animDropDownMenu.callback(animDropDownMenu.selectedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 02:01:34 -04:00
|
|
|
var swagChar:Character;
|
|
|
|
|
|
|
|
function loadAnimShit(char:String)
|
|
|
|
{
|
|
|
|
if (swagChar != null)
|
|
|
|
{
|
|
|
|
remove(swagChar);
|
|
|
|
swagChar.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
swagChar = new Character(100, 100, char);
|
|
|
|
swagChar.debugMode = true;
|
|
|
|
add(swagChar);
|
2021-06-04 02:31:27 -04:00
|
|
|
|
|
|
|
var animThing:Array<String> = [];
|
|
|
|
|
|
|
|
for (i in swagChar.animOffsets.keys())
|
|
|
|
{
|
|
|
|
animThing.push(i);
|
|
|
|
trace(i);
|
|
|
|
trace(swagChar.animOffsets[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
animDropDownMenu.setData(FlxUIDropDownMenu.makeStrIdLabelArray(animThing, true));
|
|
|
|
animDropDownMenu.callback = function(str:String)
|
|
|
|
{
|
|
|
|
swagChar.playAnim(animThing[Std.parseInt(str)]); // trace();
|
|
|
|
};
|
|
|
|
dropDownSetup = true;
|
2021-06-04 02:01:34 -04:00
|
|
|
}
|
2021-04-07 20:19:49 -04:00
|
|
|
}
|
2021-06-04 02:31:27 -04:00
|
|
|
|
|
|
|
enum ANIMDEBUGVIEW
|
|
|
|
{
|
|
|
|
SPRITESHEET;
|
|
|
|
OFFSETSHIT;
|
|
|
|
}
|