1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-10 08:44:47 +00:00
Funkin/source/ui/animDebugShit/DebugBoundingState.hx

531 lines
14 KiB
Haxe
Raw Normal View History

2021-06-04 16:53:53 +00:00
package ui.animDebugShit;
2021-04-08 00:19:49 +00:00
2021-05-27 23:15:03 +00:00
import flixel.FlxCamera;
2021-04-08 00:19:49 +00:00
import flixel.FlxSprite;
import flixel.FlxState;
2021-05-26 23:22:15 +00:00
import flixel.addons.display.FlxGridOverlay;
2021-06-04 06:01:34 +00:00
import flixel.addons.ui.FlxInputText;
import flixel.addons.ui.FlxUIDropDownMenu;
2021-05-26 23:22:15 +00:00
import flixel.graphics.frames.FlxAtlasFrames;
2021-06-05 04:46:03 +00:00
import flixel.graphics.frames.FlxFrame;
2021-05-27 23:15:03 +00:00
import flixel.group.FlxGroup;
2021-06-04 21:39:28 +00:00
import flixel.math.FlxPoint;
2021-06-24 07:15:14 +00:00
import flixel.system.FlxSound;
2021-05-27 23:15:03 +00:00
import flixel.text.FlxText;
import flixel.util.FlxColor;
import flixel.util.FlxSpriteUtil;
2021-06-24 07:15:14 +00:00
import flixel.util.FlxTimer;
2021-06-04 06:01:34 +00:00
import lime.utils.Assets as LimeAssets;
2021-04-08 00:19:49 +00:00
import openfl.Assets;
2021-06-04 07:06:15 +00:00
import openfl.events.Event;
import openfl.events.IOErrorEvent;
2021-06-04 20:45:08 +00:00
import openfl.geom.Rectangle;
2021-06-04 07:06:15 +00:00
import openfl.net.FileReference;
2021-06-24 07:15:14 +00:00
import openfl.net.URLLoader;
import openfl.net.URLRequest;
import openfl.utils.ByteArray;
2021-04-08 00:19:49 +00:00
2021-06-04 07:06:15 +00:00
using StringTools;
2021-05-27 23:15:03 +00:00
using flixel.util.FlxSpriteUtil;
2021-07-14 23:00:22 +00:00
#if web
import js.html.FileList;
#end
2021-06-24 07:15:14 +00:00
#if sys
import sys.io.File;
#end
2021-04-08 00:19:49 +00:00
class DebugBoundingState extends FlxState
{
2021-06-04 06:01:34 +00:00
/*
TODAY'S TO-DO
2021-06-05 04:24:55 +00:00
- Cleaner UI
2021-06-04 06:01:34 +00:00
*/
2021-05-27 23:15:03 +00:00
var bg:FlxSprite;
var fileInfo:FlxText;
var txtGrp:FlxGroup;
var hudCam:FlxCamera;
2021-06-04 06:01:34 +00:00
var charInput:FlxUIDropDownMenu;
2021-06-04 06:31:27 +00:00
var curView:ANIMDEBUGVIEW = SPRITESHEET;
var spriteSheetView:FlxGroup;
2021-06-04 16:53:53 +00:00
var offsetView:FlxGroup;
2021-06-04 06:31:27 +00:00
var animDropDownMenu:FlxUIDropDownMenu;
var dropDownSetup:Bool = false;
2021-06-04 20:45:08 +00:00
var onionSkinChar:FlxSprite;
2021-06-05 04:24:55 +00:00
var txtOffsetShit:FlxText;
2021-06-04 20:45:08 +00:00
2021-04-08 00:19:49 +00:00
override function create()
{
2021-06-04 06:01:34 +00:00
Paths.setCurrentLevel('week1');
2021-05-27 23:15:03 +00:00
hudCam = new FlxCamera();
hudCam.bgColor.alpha = 0;
FlxG.cameras.add(hudCam, false);
2021-08-02 17:54:19 +00:00
bg = FlxGridOverlay.create(10, 10);
// bg = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.GREEN);
2021-05-26 23:22:15 +00:00
bg.scrollFactor.set();
add(bg);
2021-06-04 06:31:27 +00:00
initSpritesheetView();
2021-06-04 16:53:53 +00:00
initOffsetView();
2021-06-04 06:31:27 +00:00
// charInput = new FlxInputText(300, 10, 150, "bf", 16);
// charInput.focusCam = hudCam;
// charInput.cameras = [hudCam];
// charInput.scrollFactor.set();
super.create();
}
2021-06-05 04:46:03 +00:00
var bf:FlxSprite;
var swagOutlines:FlxSprite;
2021-06-04 06:31:27 +00:00
function initSpritesheetView():Void
{
spriteSheetView = new FlxGroup();
add(spriteSheetView);
2021-05-26 23:22:15 +00:00
var tex = Paths.getSparrowAtlas('characters/temp');
// tex.frames[0].uv
2021-06-05 04:46:03 +00:00
bf = new FlxSprite();
2021-05-26 23:22:15 +00:00
bf.loadGraphic(tex.parent);
2021-06-04 06:31:27 +00:00
spriteSheetView.add(bf);
2021-04-08 00:19:49 +00:00
2021-06-05 04:46:03 +00:00
swagOutlines = new FlxSprite().makeGraphic(tex.parent.width, tex.parent.height, FlxColor.TRANSPARENT);
2021-05-27 23:15:03 +00:00
2021-06-05 04:46:03 +00:00
generateOutlines(tex.frames);
2021-05-27 23:15:03 +00:00
txtGrp = new FlxGroup();
txtGrp.cameras = [hudCam];
2021-06-04 06:31:27 +00:00
spriteSheetView.add(txtGrp);
2021-06-04 06:01:34 +00:00
2021-05-27 23:15:03 +00:00
addInfo('boyfriend.xml', "");
addInfo('Width', bf.width);
addInfo('Height', bf.height);
2021-06-05 04:46:03 +00:00
swagOutlines.antialiasing = true;
spriteSheetView.add(swagOutlines);
2021-05-27 23:15:03 +00:00
2021-04-08 00:19:49 +00:00
FlxG.stage.window.onDropFile.add(function(path:String)
{
2021-06-24 07:15:14 +00:00
// WACKY ASS TESTING SHIT FOR WEB FILE LOADING??
#if web
var swagList:FileList = cast path;
var objShit = js.html.URL.createObjectURL(swagList.item(0));
trace(objShit);
var funnysound = new FlxSound().loadStream('https://cdn.discordapp.com/attachments/767500676166451231/817821618251759666/Flutter.mp3', false,
false, null, function()
{
trace('LOADED SHIT??');
});
funnysound.volume = 1;
funnysound.play();
var urlShit = new URLLoader(new URLRequest(objShit));
new FlxTimer().start(3, function(tmr:FlxTimer)
{
// music lol!
if (urlShit.dataFormat == BINARY)
{
// var daSwagBytes:ByteArray = urlShit.data;
// FlxG.sound.playMusic();
// trace('is binary!!');
}
trace(urlShit.dataFormat);
});
// remove(bf);
// FlxG.bitmap.removeByKey(Paths.image('characters/temp'));
// Assets.cache.clear();
// bf.loadGraphic(objShit);
// add(bf);
// trace(swagList.item(0).name);
// var urlShit = js.html.URL.createObjectURL(path);
#end
#if sys
2021-04-08 00:19:49 +00:00
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-06-24 07:15:14 +00:00
#end
2021-04-08 00:19:49 +00:00
});
}
2021-05-26 23:22:15 +00:00
2021-06-05 04:46:03 +00:00
function generateOutlines(frameShit:Array<FlxFrame>):Void
{
2021-06-05 04:58:10 +00:00
// swagOutlines.width = frameShit[0].parent.width;
// swagOutlines.height = frameShit[0].parent.height;
2021-06-05 04:46:03 +00:00
swagOutlines.pixels.fillRect(new Rectangle(0, 0, swagOutlines.width, swagOutlines.height), 0x00000000);
for (i in frameShit)
{
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));
swagOutlines.drawRect(i.uv.x * i.parent.width, i.uv.y * i.parent.height, uvW, uvH, FlxColor.TRANSPARENT, lineStyle);
// swagGraphic.setPosition(, );
// trace(uvH);
}
}
2021-06-04 16:53:53 +00:00
function initOffsetView():Void
{
offsetView = new FlxGroup();
add(offsetView);
2021-06-04 20:45:08 +00:00
onionSkinChar = new FlxSprite().makeGraphic(FlxG.width * 2, FlxG.height * 2, FlxColor.TRANSPARENT);
2021-06-04 21:39:28 +00:00
onionSkinChar.visible = false;
2021-06-04 20:45:08 +00:00
offsetView.add(onionSkinChar);
2021-06-05 04:24:55 +00:00
txtOffsetShit = new FlxText(20, 20, 0, "", 20);
txtOffsetShit.setFormat(Paths.font("vcr.ttf"), 26, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
txtOffsetShit.cameras = [hudCam];
offsetView.add(txtOffsetShit);
2021-06-05 04:46:03 +00:00
animDropDownMenu = new FlxUIDropDownMenu(630, 20, FlxUIDropDownMenu.makeStrIdLabelArray(['weed'], true));
2021-06-04 16:53:53 +00:00
animDropDownMenu.cameras = [hudCam];
offsetView.add(animDropDownMenu);
var characters:Array<String> = CoolUtil.coolTextFile(Paths.txt('characterList'));
2021-06-05 04:58:10 +00:00
// charInput isnt only exclusive to offsetView shit now
2021-06-05 04:24:55 +00:00
charInput = new FlxUIDropDownMenu(500, 20, FlxUIDropDownMenu.makeStrIdLabelArray(characters, true), function(str:String)
2021-06-04 16:53:53 +00:00
{
loadAnimShit(characters[Std.parseInt(str)]);
// trace();
});
// charInput.
charInput.cameras = [hudCam];
2021-06-05 04:58:10 +00:00
add(charInput);
2021-06-04 16:53:53 +00:00
}
2021-06-04 21:39:28 +00:00
public var mouseOffset:FlxPoint = FlxPoint.get(0, 0);
public var oldPos:FlxPoint = FlxPoint.get(0, 0);
function mouseOffsetMovement()
{
if (swagChar != null)
{
if (FlxG.mouse.justPressed)
{
mouseOffset.set(FlxG.mouse.x - -swagChar.offset.x, FlxG.mouse.y - -swagChar.offset.y);
// oldPos.set(swagChar.offset.x, swagChar.offset.y);
// oldPos.set(FlxG.mouse.x, FlxG.mouse.y);
}
if (FlxG.mouse.pressed)
{
swagChar.offset.x = (FlxG.mouse.x - mouseOffset.x) * -1;
swagChar.offset.y = (FlxG.mouse.y - mouseOffset.y) * -1;
swagChar.animOffsets.set(animDropDownMenu.selectedLabel, [swagChar.offset.x, swagChar.offset.y]);
2021-06-05 04:24:55 +00:00
txtOffsetShit.text = 'Offset: ' + swagChar.offset;
2021-06-04 21:39:28 +00:00
}
}
}
2021-05-27 23:15:03 +00: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 06:01:34 +00: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 23:22:15 +00:00
override function update(elapsed:Float)
{
2021-06-04 06:31:27 +00:00
if (FlxG.keys.justPressed.ONE)
curView = SPRITESHEET;
if (FlxG.keys.justReleased.TWO)
2021-06-05 04:58:10 +00:00
{
2021-06-04 06:31:27 +00:00
curView = OFFSETSHIT;
2021-06-05 04:58:10 +00:00
if (swagChar != null)
{
FlxG.camera.focusOn(swagChar.getMidpoint());
FlxG.camera.zoom = 0.95;
}
}
2021-06-04 06:31:27 +00:00
switch (curView)
{
case SPRITESHEET:
spriteSheetView.visible = true;
2021-06-04 16:53:53 +00:00
offsetView.visible = false;
offsetView.active = false;
2021-06-04 06:31:27 +00:00
case OFFSETSHIT:
spriteSheetView.visible = false;
2021-06-04 16:53:53 +00:00
offsetView.visible = true;
offsetView.active = true;
2021-06-04 06:43:05 +00:00
offsetControls();
2021-06-04 21:39:28 +00:00
mouseOffsetMovement();
2021-06-04 06:31:27 +00:00
}
2021-06-04 20:45:08 +00:00
if (FlxG.keys.justPressed.H)
hudCam.visible = !hudCam.visible;
2021-06-04 06:01:34 +00:00
/* if (charInput.hasFocus && FlxG.keys.justPressed.ENTER)
{
loadAnimShit();
}*/
2021-05-26 23:22:15 +00:00
CoolUtil.mouseCamDrag();
2021-05-27 23:15:03 +00: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 23:22:15 +00:00
super.update(elapsed);
}
2021-06-04 06:01:34 +00:00
2021-06-04 06:43:05 +00:00
function offsetControls():Void
{
2021-06-04 20:45:08 +00:00
if (FlxG.keys.justPressed.RBRACKET || FlxG.keys.justPressed.E)
2021-06-04 06:43:05 +00:00
{
2021-06-04 16:53:53 +00:00
if (Std.parseInt(animDropDownMenu.selectedId) + 1 <= animDropDownMenu.length)
2021-06-04 06:43:05 +00:00
animDropDownMenu.selectedId = Std.string(Std.parseInt(animDropDownMenu.selectedId) + 1);
2021-06-04 16:53:53 +00:00
else
animDropDownMenu.selectedId = Std.string(0);
2021-06-04 06:43:05 +00:00
animDropDownMenu.callback(animDropDownMenu.selectedId);
}
2021-06-04 20:45:08 +00:00
if (FlxG.keys.justPressed.LBRACKET || FlxG.keys.justPressed.Q)
2021-06-04 06:43:05 +00:00
{
if (Std.parseInt(animDropDownMenu.selectedId) - 1 >= 0)
animDropDownMenu.selectedId = Std.string(Std.parseInt(animDropDownMenu.selectedId) - 1);
2021-06-04 16:53:53 +00:00
else
animDropDownMenu.selectedId = Std.string(animDropDownMenu.length - 1);
animDropDownMenu.callback(animDropDownMenu.selectedId);
}
2021-06-04 20:45:08 +00:00
// Keyboards controls for general WASD "movement"
// modifies the animDropDownMenu so that it's properly updated and shit
// and then it's just played and updated from the animDropDownMenu callback, which is set in the loadAnimShit() function probabbly
2021-06-04 16:53:53 +00:00
if (FlxG.keys.justPressed.W || FlxG.keys.justPressed.S || FlxG.keys.justPressed.D || FlxG.keys.justPressed.A)
{
var missShit:String = '';
if (FlxG.keys.pressed.SHIFT)
missShit = 'miss';
if (FlxG.keys.justPressed.W)
animDropDownMenu.selectedLabel = 'singUP' + missShit;
if (FlxG.keys.justPressed.S)
animDropDownMenu.selectedLabel = 'singDOWN' + missShit;
if (FlxG.keys.justPressed.A)
animDropDownMenu.selectedLabel = 'singLEFT' + missShit;
if (FlxG.keys.justPressed.D)
animDropDownMenu.selectedLabel = 'singRIGHT' + missShit;
2021-06-04 06:43:05 +00:00
animDropDownMenu.callback(animDropDownMenu.selectedId);
}
2021-06-04 06:57:43 +00:00
2021-06-04 20:45:08 +00:00
if (FlxG.keys.justPressed.F)
{
onionSkinChar.visible = !onionSkinChar.visible;
}
// Plays the idle animation
if (FlxG.keys.justPressed.SPACE)
{
animDropDownMenu.selectedLabel = 'idle';
animDropDownMenu.callback(animDropDownMenu.selectedId);
}
// Playback the animation
if (FlxG.keys.justPressed.ENTER)
animDropDownMenu.callback(animDropDownMenu.selectedId);
2021-06-04 06:57:43 +00:00
if (FlxG.keys.justPressed.RIGHT || FlxG.keys.justPressed.LEFT || FlxG.keys.justPressed.UP || FlxG.keys.justPressed.DOWN)
{
var animName = animDropDownMenu.selectedLabel;
var coolValues:Array<Dynamic> = swagChar.animOffsets.get(animName);
var multiplier:Float = 5;
if (FlxG.keys.pressed.CONTROL)
multiplier = 1;
if (FlxG.keys.pressed.SHIFT)
multiplier = 10;
if (FlxG.keys.justPressed.RIGHT)
coolValues[0] -= 1 * multiplier;
else if (FlxG.keys.justPressed.LEFT)
coolValues[0] += 1 * multiplier;
else if (FlxG.keys.justPressed.UP)
coolValues[1] += 1 * multiplier;
else if (FlxG.keys.justPressed.DOWN)
coolValues[1] -= 1 * multiplier;
swagChar.animOffsets.set(animDropDownMenu.selectedLabel, coolValues);
swagChar.playAnim(animName);
2021-06-05 04:24:55 +00:00
txtOffsetShit.text = 'Offset: ' + coolValues;
2021-06-04 06:57:43 +00:00
trace(animName);
}
2021-06-04 07:06:15 +00:00
if (FlxG.keys.justPressed.ESCAPE)
{
var outputString:String = "";
for (i in swagChar.animOffsets.keys())
{
outputString += i + " " + swagChar.animOffsets.get(i)[0] + " " + swagChar.animOffsets.get(i)[1] + "\n";
}
outputString.trim();
saveOffsets(outputString);
}
2021-06-04 06:43:05 +00:00
}
2021-06-04 06:01:34 +00:00
var swagChar:Character;
function loadAnimShit(char:String)
{
if (swagChar != null)
{
2021-06-05 04:46:03 +00:00
offsetView.remove(swagChar);
2021-06-04 06:01:34 +00:00
swagChar.destroy();
}
swagChar = new Character(100, 100, char);
swagChar.debugMode = true;
2021-06-05 04:46:03 +00:00
offsetView.add(swagChar);
generateOutlines(swagChar.frames.frames);
bf.pixels = swagChar.pixels;
2021-06-04 06:31:27 +00: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)
{
2021-06-04 20:45:08 +00:00
// clears the canvas
onionSkinChar.pixels.fillRect(new Rectangle(0, 0, FlxG.width * 2, FlxG.height * 2), 0x00000000);
onionSkinChar.stamp(swagChar, Std.int(swagChar.x - swagChar.offset.x), Std.int(swagChar.y - swagChar.offset.y));
onionSkinChar.alpha = 0.6;
2021-06-04 06:57:43 +00:00
2021-06-04 20:45:08 +00:00
var animName = animThing[Std.parseInt(str)];
swagChar.playAnim(animName, true); // trace();
2021-06-04 06:57:43 +00:00
trace(swagChar.animOffsets.get(animName));
2021-06-05 04:24:55 +00:00
txtOffsetShit.text = 'Offset: ' + swagChar.offset;
2021-06-04 06:31:27 +00:00
};
dropDownSetup = true;
2021-06-04 06:01:34 +00:00
}
2021-06-04 07:06:15 +00:00
var _file:FileReference;
private function saveOffsets(saveString:String)
{
if ((saveString != null) && (saveString.length > 0))
{
_file = new FileReference();
_file.addEventListener(Event.COMPLETE, onSaveComplete);
_file.addEventListener(Event.CANCEL, onSaveCancel);
_file.addEventListener(IOErrorEvent.IO_ERROR, onSaveError);
_file.save(saveString, swagChar.curCharacter + "Offsets.txt");
}
}
function onSaveComplete(_):Void
{
_file.removeEventListener(Event.COMPLETE, onSaveComplete);
_file.removeEventListener(Event.CANCEL, onSaveCancel);
_file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError);
_file = null;
FlxG.log.notice("Successfully saved LEVEL DATA.");
}
/**
* Called when the save file dialog is cancelled.
*/
function onSaveCancel(_):Void
{
_file.removeEventListener(Event.COMPLETE, onSaveComplete);
_file.removeEventListener(Event.CANCEL, onSaveCancel);
_file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError);
_file = null;
}
/**
* Called if there is an error while saving the gameplay recording.
*/
function onSaveError(_):Void
{
_file.removeEventListener(Event.COMPLETE, onSaveComplete);
_file.removeEventListener(Event.CANCEL, onSaveCancel);
_file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError);
_file = null;
FlxG.log.error("Problem saving Level data");
}
2021-04-08 00:19:49 +00:00
}
2021-06-04 06:31:27 +00:00
enum ANIMDEBUGVIEW
{
SPRITESHEET;
OFFSETSHIT;
}