2023-11-07 09:04:22 +00:00
|
|
|
package funkin.ui.debug.anim;
|
2021-04-08 00:19:49 +00:00
|
|
|
|
2022-09-08 08:03:50 +00:00
|
|
|
import flixel.addons.display.FlxGridOverlay;
|
|
|
|
import flixel.addons.ui.FlxInputText;
|
|
|
|
import flixel.addons.ui.FlxUIDropDownMenu;
|
2024-03-26 01:09:02 +00:00
|
|
|
import flixel.FlxCamera;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.FlxState;
|
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-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;
|
2024-03-26 01:09:02 +00:00
|
|
|
import funkin.audio.FunkinSound;
|
|
|
|
import funkin.input.Cursor;
|
2022-03-23 05:18:23 +00:00
|
|
|
import funkin.play.character.BaseCharacter;
|
2024-03-26 01:09:02 +00:00
|
|
|
import funkin.play.character.CharacterData;
|
2022-09-08 08:03:50 +00:00
|
|
|
import funkin.play.character.CharacterData.CharacterDataParser;
|
|
|
|
import funkin.play.character.SparrowCharacter;
|
2024-03-26 01:09:02 +00:00
|
|
|
import funkin.ui.mainmenu.MainMenuState;
|
|
|
|
import funkin.util.MouseUtil;
|
|
|
|
import funkin.util.SerializerUtil;
|
|
|
|
import funkin.util.SortUtil;
|
2022-09-08 08:03:50 +00:00
|
|
|
import haxe.ui.components.DropDown;
|
|
|
|
import haxe.ui.core.Component;
|
2024-03-26 01:09:02 +00:00
|
|
|
import haxe.ui.core.Screen;
|
2022-09-08 08:03:50 +00:00
|
|
|
import haxe.ui.events.ItemEvent;
|
|
|
|
import haxe.ui.events.UIEvent;
|
2024-03-26 01:09:02 +00:00
|
|
|
import haxe.ui.RuntimeComponentBuilder;
|
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-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
|
|
|
|
{
|
2023-06-08 20:30:45 +00:00
|
|
|
/*
|
2023-01-23 03:25:45 +00:00
|
|
|
TODAY'S TO-DO
|
|
|
|
- Cleaner UI
|
|
|
|
*/
|
|
|
|
var bg:FlxSprite;
|
|
|
|
var fileInfo:FlxText;
|
2021-05-27 23:15:03 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var txtGrp:FlxGroup;
|
2021-05-27 23:15:03 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var hudCam:FlxCamera;
|
2021-05-27 23:15:03 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var curView:ANIMDEBUGVIEW = SPRITESHEET;
|
2021-06-04 06:31:27 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var spriteSheetView:FlxGroup;
|
|
|
|
var offsetView:FlxGroup;
|
|
|
|
var animDropDownMenu:FlxUIDropDownMenu;
|
|
|
|
var dropDownSetup:Bool = false;
|
2021-06-04 06:31:27 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var onionSkinChar:FlxSprite;
|
|
|
|
var txtOffsetShit:FlxText;
|
2021-06-04 20:45:08 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var uiStuff:Component;
|
2022-09-08 08:03:50 +00:00
|
|
|
|
2024-02-20 05:29:11 +00:00
|
|
|
var haxeUIFocused(get, default):Bool = false;
|
|
|
|
|
|
|
|
function get_haxeUIFocused():Bool
|
|
|
|
{
|
|
|
|
// get the screen position, according to the HUD camera, temp default to FlxG.camera juuust in case?
|
|
|
|
var hudMousePos:FlxPoint = FlxG.mouse.getScreenPosition(hudCam ?? FlxG.camera);
|
|
|
|
return Screen.instance.hasSolidComponentUnderPoint(hudMousePos.x, hudMousePos.y);
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
override function create()
|
|
|
|
{
|
|
|
|
Paths.setCurrentLevel('week1');
|
2021-06-04 06:01:34 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
// lv.
|
|
|
|
// lv.onChange = function(e:UIEvent)
|
|
|
|
// {
|
|
|
|
// trace(e.type);
|
|
|
|
// // trace(e.data.curView);
|
|
|
|
// // var item:haxe.ui.core.ItemRenderer = cast e.target;
|
|
|
|
// trace(e.target);
|
|
|
|
// // if (e.type == "change")
|
|
|
|
// // {
|
|
|
|
// // curView = cast e.data;
|
|
|
|
// // }
|
|
|
|
// };
|
2022-09-08 08:03:50 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
hudCam = new FlxCamera();
|
|
|
|
hudCam.bgColor.alpha = 0;
|
2021-05-27 23:15:03 +00:00
|
|
|
|
2023-01-23 03:25:45 +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
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
bg.scrollFactor.set();
|
|
|
|
add(bg);
|
2021-05-26 23:22:15 +00:00
|
|
|
|
2024-02-20 05:29:11 +00:00
|
|
|
// we are setting this as the default draw camera only temporarily, to trick haxeui
|
|
|
|
FlxG.cameras.add(hudCam);
|
2021-06-04 06:31:27 +00:00
|
|
|
|
2024-02-20 05:29:11 +00:00
|
|
|
var str = Paths.xml('ui/animation-editor/offset-editor-view');
|
|
|
|
uiStuff = RuntimeComponentBuilder.fromAsset(str);
|
|
|
|
|
|
|
|
// uiStuff.findComponent("btnViewSpriteSheet").onClick = _ -> curView = SPRITESHEET;
|
|
|
|
var dropdown:DropDown = cast uiStuff.findComponent("swapper");
|
|
|
|
dropdown.onChange = function(e:UIEvent) {
|
|
|
|
trace(e.type);
|
|
|
|
curView = cast e.data.curView;
|
|
|
|
trace(e.data);
|
|
|
|
// trace(e.data);
|
|
|
|
};
|
2023-06-13 21:13:14 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
uiStuff.cameras = [hudCam];
|
2022-09-08 08:03:50 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
add(uiStuff);
|
2022-09-08 08:03:50 +00:00
|
|
|
|
2024-02-20 05:29:11 +00:00
|
|
|
// sets the default camera back to FlxG.camera, since we set it to hudCamera for haxeui stuf
|
|
|
|
FlxG.cameras.setDefaultDrawTarget(FlxG.camera, true);
|
|
|
|
FlxG.cameras.setDefaultDrawTarget(hudCam, false);
|
|
|
|
|
|
|
|
initSpritesheetView();
|
|
|
|
initOffsetView();
|
|
|
|
|
|
|
|
Cursor.show();
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
super.create();
|
|
|
|
}
|
2021-06-04 06:31:27 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var bf:FlxSprite;
|
|
|
|
var swagOutlines:FlxSprite;
|
2021-06-05 04:46:03 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
function initSpritesheetView():Void
|
|
|
|
{
|
|
|
|
spriteSheetView = new FlxGroup();
|
|
|
|
add(spriteSheetView);
|
2021-06-04 06:31:27 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
var tex = Paths.getSparrowAtlas('characters/BOYFRIEND');
|
2023-01-23 03:25:45 +00:00
|
|
|
// tex.frames[0].uv
|
|
|
|
|
|
|
|
bf = new FlxSprite();
|
|
|
|
bf.loadGraphic(tex.parent);
|
|
|
|
spriteSheetView.add(bf);
|
|
|
|
|
|
|
|
swagOutlines = new FlxSprite().makeGraphic(tex.parent.width, tex.parent.height, FlxColor.TRANSPARENT);
|
2021-06-24 07:15:14 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
generateOutlines(tex.frames);
|
|
|
|
|
|
|
|
txtGrp = new FlxGroup();
|
|
|
|
txtGrp.cameras = [hudCam];
|
|
|
|
spriteSheetView.add(txtGrp);
|
|
|
|
|
|
|
|
addInfo('boyfriend.xml', "");
|
|
|
|
addInfo('Width', bf.width);
|
|
|
|
addInfo('Height', bf.height);
|
|
|
|
|
|
|
|
spriteSheetView.add(swagOutlines);
|
2021-04-08 00:19:49 +00:00
|
|
|
|
2023-05-25 22:33:39 +00:00
|
|
|
FlxG.stage.window.onDropFile.add(function(path:String) {
|
2023-01-23 03:25:45 +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);
|
|
|
|
|
2024-03-23 21:50:48 +00:00
|
|
|
var funnysound = new FunkinSound().loadStream('https://cdn.discordapp.com/attachments/767500676166451231/817821618251759666/Flutter.mp3', false, false,
|
2023-05-25 22:33:39 +00:00
|
|
|
null, function() {
|
|
|
|
trace('LOADED SHIT??');
|
2023-01-23 03:25:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
funnysound.volume = 1;
|
|
|
|
funnysound.play();
|
|
|
|
|
|
|
|
var urlShit = new URLLoader(new URLRequest(objShit));
|
|
|
|
|
2023-05-25 22:33:39 +00:00
|
|
|
new FlxTimer().start(3, function(tmr:FlxTimer) {
|
2023-01-23 03:25:45 +00:00
|
|
|
// 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
|
|
|
|
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);
|
|
|
|
#end
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateOutlines(frameShit:Array<FlxFrame>):Void
|
|
|
|
{
|
|
|
|
// swagOutlines.width = frameShit[0].parent.width;
|
|
|
|
// swagOutlines.height = frameShit[0].parent.height;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initOffsetView():Void
|
|
|
|
{
|
|
|
|
offsetView = new FlxGroup();
|
|
|
|
add(offsetView);
|
|
|
|
|
|
|
|
onionSkinChar = new FlxSprite().makeGraphic(FlxG.width * 2, FlxG.height * 2, FlxColor.TRANSPARENT);
|
|
|
|
onionSkinChar.visible = false;
|
|
|
|
offsetView.add(onionSkinChar);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
animDropDownMenu = new FlxUIDropDownMenu(0, 0, FlxUIDropDownMenu.makeStrIdLabelArray(['weed'], true));
|
2023-01-23 03:25:45 +00:00
|
|
|
animDropDownMenu.cameras = [hudCam];
|
2023-06-13 21:13:14 +00:00
|
|
|
// Move to bottom right corner
|
|
|
|
animDropDownMenu.x = FlxG.width - animDropDownMenu.width - 20;
|
|
|
|
animDropDownMenu.y = FlxG.height - animDropDownMenu.height - 20;
|
2023-01-23 03:25:45 +00:00
|
|
|
offsetView.add(animDropDownMenu);
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
var characters:Array<String> = CharacterDataParser.listCharacterIds();
|
2023-10-11 23:16:04 +00:00
|
|
|
characters = characters.filter(function(charId:String) {
|
|
|
|
var char = CharacterDataParser.fetchCharacterData(charId);
|
|
|
|
return char.renderType != AnimateAtlas;
|
|
|
|
});
|
2023-06-13 21:13:14 +00:00
|
|
|
characters.sort(SortUtil.alphabetically);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
var charDropdown:DropDown = cast uiStuff.findComponent('characterDropdown');
|
|
|
|
for (char in characters)
|
|
|
|
{
|
|
|
|
charDropdown.dataSource.add({text: char});
|
|
|
|
}
|
|
|
|
|
2023-05-25 22:33:39 +00:00
|
|
|
charDropdown.onChange = function(e:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
loadAnimShit(e.data.text);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2023-06-13 21:13:14 +00:00
|
|
|
mouseOffset.set(FlxG.mouse.x - -swagChar.animOffsets[0], FlxG.mouse.y - -swagChar.animOffsets[1]);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.mouse.pressed)
|
|
|
|
{
|
2023-06-13 21:13:14 +00:00
|
|
|
swagChar.animOffsets = [(FlxG.mouse.x - mouseOffset.x) * -1, (FlxG.mouse.y - mouseOffset.y) * -1];
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
swagChar.animationOffsets.set(animDropDownMenu.selectedLabel, swagChar.animOffsets);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
txtOffsetShit.text = 'Offset: ' + swagChar.animOffsets;
|
2023-01-23 03:25:45 +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);
|
|
|
|
}
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
function clearInfo()
|
|
|
|
{
|
|
|
|
txtGrp.clear();
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +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);
|
2023-05-25 22:33:39 +00:00
|
|
|
Assets.loadLibrary(library).onComplete(function(_) {
|
2023-01-23 03:25:45 +00:00
|
|
|
trace('LOADED... awesomeness...');
|
|
|
|
// callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
if (FlxG.keys.justPressed.ONE)
|
|
|
|
{
|
|
|
|
var lv:DropDown = cast uiStuff.findComponent("swapper");
|
|
|
|
lv.selectedIndex = 0;
|
|
|
|
curView = SPRITESHEET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justReleased.TWO)
|
|
|
|
{
|
|
|
|
var lv:DropDown = cast uiStuff.findComponent("swapper");
|
|
|
|
lv.selectedIndex = 1;
|
2023-06-13 21:13:14 +00:00
|
|
|
curView = ANIMATIONS;
|
2023-01-23 03:25:45 +00:00
|
|
|
if (swagChar != null)
|
|
|
|
{
|
|
|
|
FlxG.camera.focusOn(swagChar.getMidpoint());
|
|
|
|
FlxG.camera.zoom = 0.95;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (curView)
|
|
|
|
{
|
|
|
|
case SPRITESHEET:
|
|
|
|
spriteSheetView.visible = true;
|
|
|
|
offsetView.visible = false;
|
|
|
|
offsetView.active = false;
|
2023-06-13 21:13:14 +00:00
|
|
|
case ANIMATIONS:
|
2023-01-23 03:25:45 +00:00
|
|
|
spriteSheetView.visible = false;
|
|
|
|
offsetView.visible = true;
|
|
|
|
offsetView.active = true;
|
|
|
|
offsetControls();
|
2024-02-20 05:29:11 +00:00
|
|
|
if (!haxeUIFocused) mouseOffsetMovement();
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.H) hudCam.visible = !hudCam.visible;
|
|
|
|
|
2024-02-06 00:46:11 +00:00
|
|
|
if (FlxG.keys.justPressed.F4) FlxG.switchState(() -> new MainMenuState());
|
2023-07-03 16:51:27 +00:00
|
|
|
|
2023-11-07 09:04:22 +00:00
|
|
|
MouseUtil.mouseCamDrag();
|
2024-02-20 05:29:11 +00:00
|
|
|
if (!haxeUIFocused) MouseUtil.mouseWheelZoom();
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
// bg.scale.x = FlxG.camera.zoom;
|
|
|
|
// bg.scale.y = FlxG.camera.zoom;
|
|
|
|
|
|
|
|
bg.setGraphicSize(Std.int(bg.width / FlxG.camera.zoom));
|
|
|
|
|
|
|
|
super.update(elapsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function offsetControls():Void
|
|
|
|
{
|
|
|
|
if (FlxG.keys.justPressed.RBRACKET || FlxG.keys.justPressed.E)
|
|
|
|
{
|
|
|
|
if (Std.parseInt(animDropDownMenu.selectedId) + 1 <= animDropDownMenu.length)
|
|
|
|
animDropDownMenu.selectedId = Std.string(Std.parseInt(animDropDownMenu.selectedId)
|
|
|
|
+ 1);
|
|
|
|
else
|
|
|
|
animDropDownMenu.selectedId = Std.string(0);
|
2023-06-13 21:13:14 +00:00
|
|
|
playCharacterAnimation(animDropDownMenu.selectedId, true);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
if (FlxG.keys.justPressed.LBRACKET || FlxG.keys.justPressed.Q)
|
|
|
|
{
|
|
|
|
if (Std.parseInt(animDropDownMenu.selectedId) - 1 >= 0) animDropDownMenu.selectedId = Std.string(Std.parseInt(animDropDownMenu.selectedId) - 1);
|
|
|
|
else
|
|
|
|
animDropDownMenu.selectedId = Std.string(animDropDownMenu.length - 1);
|
2023-06-13 21:13:14 +00:00
|
|
|
playCharacterAnimation(animDropDownMenu.selectedId, true);
|
2023-01-23 03:25:45 +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
|
|
|
|
if (FlxG.keys.justPressed.W || FlxG.keys.justPressed.S || FlxG.keys.justPressed.D || FlxG.keys.justPressed.A)
|
|
|
|
{
|
2023-06-13 21:13:14 +00:00
|
|
|
var suffix:String = '';
|
|
|
|
var targetLabel:String = '';
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
if (FlxG.keys.pressed.SHIFT) suffix = 'miss';
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
if (FlxG.keys.justPressed.W) targetLabel = 'singUP$suffix';
|
|
|
|
if (FlxG.keys.justPressed.S) targetLabel = 'singDOWN$suffix';
|
|
|
|
if (FlxG.keys.justPressed.A) targetLabel = 'singLEFT$suffix';
|
|
|
|
if (FlxG.keys.justPressed.D) targetLabel = 'singRIGHT$suffix';
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
if (targetLabel != animDropDownMenu.selectedLabel)
|
|
|
|
{
|
|
|
|
// Play the new animation if the IDs are the different.
|
|
|
|
// Override the onion skin.
|
|
|
|
animDropDownMenu.selectedLabel = targetLabel;
|
|
|
|
playCharacterAnimation(animDropDownMenu.selectedId, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Replay the current animation if the IDs are the same.
|
|
|
|
// Don't override the onion skin.
|
|
|
|
playCharacterAnimation(animDropDownMenu.selectedId, false);
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.F)
|
|
|
|
{
|
|
|
|
onionSkinChar.visible = !onionSkinChar.visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plays the idle animation
|
|
|
|
if (FlxG.keys.justPressed.SPACE)
|
|
|
|
{
|
|
|
|
animDropDownMenu.selectedLabel = 'idle';
|
2023-06-13 21:13:14 +00:00
|
|
|
playCharacterAnimation(animDropDownMenu.selectedId, true);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Playback the animation
|
2023-06-13 21:13:14 +00:00
|
|
|
if (FlxG.keys.justPressed.ENTER) playCharacterAnimation(animDropDownMenu.selectedId, false);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.RIGHT || FlxG.keys.justPressed.LEFT || FlxG.keys.justPressed.UP || FlxG.keys.justPressed.DOWN)
|
|
|
|
{
|
|
|
|
var animName = animDropDownMenu.selectedLabel;
|
2023-06-13 21:13:14 +00:00
|
|
|
var coolValues:Array<Float> = swagChar.animationOffsets.get(animName).copy();
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
var multiplier:Int = 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.animationOffsets.set(animDropDownMenu.selectedLabel, coolValues);
|
|
|
|
swagChar.playAnimation(animName);
|
|
|
|
|
|
|
|
txtOffsetShit.text = 'Offset: ' + coolValues;
|
|
|
|
|
|
|
|
trace(animName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.ESCAPE)
|
|
|
|
{
|
2023-07-03 16:51:27 +00:00
|
|
|
var outputString = FlxG.keys.pressed.CONTROL ? buildOutputStringOld() : buildOutputStringNew();
|
|
|
|
saveOffsets(outputString, FlxG.keys.pressed.CONTROL ? swagChar.characterId + "Offsets.txt" : swagChar.characterId + ".json");
|
2023-06-13 21:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
function buildOutputStringOld():String
|
|
|
|
{
|
|
|
|
var outputString:String = "";
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
for (i in swagChar.animationOffsets.keys())
|
|
|
|
{
|
|
|
|
outputString += i + " " + swagChar.animationOffsets.get(i)[0] + " " + swagChar.animationOffsets.get(i)[1] + "\n";
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
outputString.trim();
|
|
|
|
|
|
|
|
return outputString;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildOutputStringNew():String
|
|
|
|
{
|
2023-07-03 16:51:27 +00:00
|
|
|
var charData:CharacterData = Reflect.copy(swagChar._data);
|
2023-06-13 21:13:14 +00:00
|
|
|
|
2023-07-03 16:51:27 +00:00
|
|
|
for (charDataAnim in charData.animations)
|
2023-06-13 21:13:14 +00:00
|
|
|
{
|
|
|
|
var animName:String = charDataAnim.name;
|
|
|
|
charDataAnim.offsets = swagChar.animationOffsets.get(animName);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2023-06-13 21:13:14 +00:00
|
|
|
|
2023-07-03 16:51:27 +00:00
|
|
|
return SerializerUtil.toJSON(charData, true);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var swagChar:BaseCharacter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Called when animation dropdown is changed!
|
|
|
|
*/
|
|
|
|
function loadAnimShit(char:String)
|
|
|
|
{
|
|
|
|
if (swagChar != null)
|
|
|
|
{
|
|
|
|
offsetView.remove(swagChar);
|
|
|
|
swagChar.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
swagChar = CharacterDataParser.fetchCharacter(char);
|
|
|
|
swagChar.x = 100;
|
|
|
|
swagChar.y = 100;
|
|
|
|
// swagChar.debugMode = true;
|
|
|
|
offsetView.add(swagChar);
|
|
|
|
|
2024-05-02 04:32:40 +00:00
|
|
|
if (swagChar == null || swagChar.frames == null)
|
|
|
|
{
|
|
|
|
trace('ERROR: Failed to load character ${char}!');
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
generateOutlines(swagChar.frames.frames);
|
|
|
|
bf.pixels = swagChar.pixels;
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
clearInfo();
|
|
|
|
addInfo(swagChar._data.assetPath, "");
|
|
|
|
addInfo('Width', bf.width);
|
|
|
|
addInfo('Height', bf.height);
|
|
|
|
|
|
|
|
characterAnimNames = [];
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
for (i in swagChar.animationOffsets.keys())
|
|
|
|
{
|
2023-06-13 21:13:14 +00:00
|
|
|
characterAnimNames.push(i);
|
2023-01-23 03:25:45 +00:00
|
|
|
trace(i);
|
|
|
|
trace(swagChar.animationOffsets[i]);
|
|
|
|
}
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
animDropDownMenu.setData(FlxUIDropDownMenu.makeStrIdLabelArray(characterAnimNames, true));
|
2023-05-25 22:33:39 +00:00
|
|
|
animDropDownMenu.callback = function(str:String) {
|
2023-06-13 21:13:14 +00:00
|
|
|
playCharacterAnimation(str, true);
|
|
|
|
};
|
|
|
|
txtOffsetShit.text = 'Offset: ' + swagChar.animOffsets;
|
|
|
|
dropDownSetup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private var characterAnimNames:Array<String>;
|
|
|
|
|
|
|
|
function playCharacterAnimation(str:String, setOnionSkin:Bool = true)
|
|
|
|
{
|
|
|
|
if (setOnionSkin)
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
// clears the canvas
|
|
|
|
onionSkinChar.pixels.fillRect(new Rectangle(0, 0, FlxG.width * 2, FlxG.height * 2), 0x00000000);
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
onionSkinChar.stamp(swagChar, Std.int(swagChar.x), Std.int(swagChar.y));
|
2023-01-23 03:25:45 +00:00
|
|
|
onionSkinChar.alpha = 0.6;
|
2023-06-13 21:13:14 +00:00
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
var animName = characterAnimNames[Std.parseInt(str)];
|
|
|
|
swagChar.playAnimation(animName, true); // trace();
|
|
|
|
trace(swagChar.animationOffsets.get(animName));
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
txtOffsetShit.text = 'Offset: ' + swagChar.animOffsets;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _file:FileReference;
|
|
|
|
|
2023-06-13 21:13:14 +00:00
|
|
|
function saveOffsets(saveString:String, fileName:String)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
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);
|
2023-06-13 21:13:14 +00:00
|
|
|
_file.save(saveString,);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-09-08 08:03:50 +00:00
|
|
|
enum abstract ANIMDEBUGVIEW(String)
|
2021-06-04 06:31:27 +00:00
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
var SPRITESHEET;
|
2023-06-13 21:13:14 +00:00
|
|
|
var ANIMATIONS;
|
2021-06-04 06:31:27 +00:00
|
|
|
}
|