Skip to content

Commit

Permalink
some features and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KoloInDaCrib committed Dec 12, 2024
1 parent 649d895 commit a9bd577
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 96 deletions.
8 changes: 6 additions & 2 deletions source/funkin/ui/debug/char/CharCreatorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ class CharCreatorState extends UIState
menubarItemExit.onClick = _ -> exitEditor();
menubarItemAbout.onClick = _ -> new CharCreatorAboutDialog().showDialog();

menubarSliderAnimSpeed.onChange = function(_) menubarLabelAnimSpeed.text = 'Animation Speed: ${menubarSliderAnimSpeed.pos}%';
menubarSliderAnimSpeed.onChange = function(_) {
FlxG.animationTimeScale = (menubarSliderAnimSpeed.pos / 100);
menubarLabelAnimSpeed.text = 'Animation Speed: ${menubarSliderAnimSpeed.pos}%';
}
}

function handleShortcuts():Void
Expand Down Expand Up @@ -146,14 +149,15 @@ class CharCreatorState extends UIState
menubarOptionCharSelect.disabled = menubarOptionFreeplay.disabled = menubarOptionResults.disabled = !params.generatePlayerData;

menubarOptionGameplay.selected = (params.generateCharacter);
menubarOptionCharSelect.selected = !menubarOptionGameplay.selected;
menubarOptionCharSelect.selected = !(params.generateCharacter);
menubarOptionFreeplay.selected = menubarOptionResults.selected = false;

switchToPage(params.generateCharacter ? Gameplay : CharacterSelect);
}

function exitEditor():Void
{
menubarSliderAnimSpeed.pos = 100;
Cursor.hide();
FlxG.switchState(() -> new DebugMenuSubState());
FunkinSound.playMusic('freakyMenu',
Expand Down
41 changes: 19 additions & 22 deletions source/funkin/ui/debug/char/animate/CharSelectAtlasSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ class CharSelectAtlasSprite extends FlxAnimate
initSymbols();
}

var symbolsInitialized:Bool = false;

public function initSymbols()
{
if (symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;

symbolsInitialized = true;
onAnimationComplete.add(cleanupAnimation);

// This defaults the sprite to play the first animation in the atlas,
Expand All @@ -104,7 +101,7 @@ class CharSelectAtlasSprite extends FlxAnimate
*/
public function listAnimations():Array<String>
{
if (!symbolsInitialized) return [];
if (this.frames == null || this.anim == null) return [];

var mainSymbol = this.anim.symbolDictionary[this.anim.stageInstance.symbol.name];
if (mainSymbol == null)
Expand All @@ -121,7 +118,7 @@ class CharSelectAtlasSprite extends FlxAnimate
*/
public function hasAnimation(id:String):Bool
{
if (!symbolsInitialized) return false;
if (this.frames == null || this.anim == null) return false;
return getLabelIndex(id) != -1 || anim.symbolDictionary.exists(id);
}

Expand All @@ -130,7 +127,7 @@ class CharSelectAtlasSprite extends FlxAnimate
*/
public function getCurrentAnimation():String
{
if (!symbolsInitialized) return "";
if (this.frames == null || this.anim == null) return "";
return this.currentAnimation;
}

Expand All @@ -155,7 +152,7 @@ class CharSelectAtlasSprite extends FlxAnimate
*/
public function playAnimation(id:String, restart:Bool = false, ignoreOther:Bool = false, loop:Bool = false, startFrame:Int = 0):Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;

// Skip if not allowed to play animations.
if ((!canPlayOtherAnims))
Expand Down Expand Up @@ -255,7 +252,7 @@ class CharSelectAtlasSprite extends FlxAnimate
*/
public function isAnimationFinished():Bool
{
if (!symbolsInitialized) return false;
if (this.frames == null || this.anim == null) return false;
return this.anim.finished;
}

Expand All @@ -265,7 +262,7 @@ class CharSelectAtlasSprite extends FlxAnimate
*/
public function isLoopComplete():Bool
{
if (!symbolsInitialized) return false;
if (this.frames == null || this.anim == null) return false;
if (this.anim == null) return false;
if (!this.anim.isPlaying) return false;

Expand All @@ -279,7 +276,7 @@ class CharSelectAtlasSprite extends FlxAnimate
*/
public function stopAnimation():Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;
if (this.currentAnimation == null) return;

this.anim.removeAllCallbacksFrom(getNextFrameLabel(this.currentAnimation));
Expand All @@ -289,20 +286,20 @@ class CharSelectAtlasSprite extends FlxAnimate

function addFrameCallback(label:String, callback:Void->Void):Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;
var frameLabel = this.anim.getFrameLabel(label);
frameLabel.add(callback);
}

function goToFrameLabel(label:String):Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;
this.anim.goToFrameLabel(label);
}

function getFrameLabelNames(?layer:haxe.extern.EitherType<Int, String> = null)
{
if (!symbolsInitialized) return [];
if (this.frames == null || this.anim == null) return [];
var labels = this.anim.getFrameLabels(layer);
var array = [];
for (label in labels)
Expand All @@ -315,25 +312,25 @@ class CharSelectAtlasSprite extends FlxAnimate

function getNextFrameLabel(label:String):String
{
if (!symbolsInitialized) return "";
if (this.frames == null || this.anim == null) return "";
return listAnimations()[(getLabelIndex(label) + 1) % listAnimations().length];
}

function getLabelIndex(label:String):Int
{
if (!symbolsInitialized) return -1;
if (this.frames == null || this.anim == null) return -1;
return listAnimations().indexOf(label);
}

function goToFrameIndex(index:Int):Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;
this.anim.curFrame = index;
}

public function cleanupAnimation(_:String):Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;

canPlayOtherAnims = true;
// this.currentAnimation = null;
Expand All @@ -342,7 +339,7 @@ class CharSelectAtlasSprite extends FlxAnimate

function _onAnimationFrame(frame:Int):Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;

if (currentAnimation != null)
{
Expand All @@ -368,7 +365,7 @@ class CharSelectAtlasSprite extends FlxAnimate

function _onAnimationComplete():Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;

if (currentAnimation != null)
{
Expand All @@ -384,7 +381,7 @@ class CharSelectAtlasSprite extends FlxAnimate

public function replaceFrameGraphic(index:Int, ?graphic:FlxGraphicAsset):Void
{
if (!symbolsInitialized) return;
if (this.frames == null || this.anim == null) return;

if (graphic == null || !Assets.exists(graphic))
{
Expand Down Expand Up @@ -424,7 +421,7 @@ class CharSelectAtlasSprite extends FlxAnimate

public function getPivotPosition():Null<FlxPoint>
{
if (!symbolsInitialized) return null;
if (this.frames == null || this.anim == null) return null;
return anim?.curInstance?.symbol?.transformationPoint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class CharMetadataDialog extends DefaultPageDialog
charIsPixel.selected = char.isPixel;
charHasDeathData.selected = (char.deathData != null);
charDeathBox.disabled = !charHasDeathData.selected;
charName.text = char.characterName;

charDeathCamOffsetX.pos = char.deathData?.cameraOffsets[0] ?? 0;
charDeathCamOffsetY.pos = char.deathData?.cameraOffsets[1] ?? 0;
charDeathCamZoom.pos = char.deathData?.cameraZoom ?? 1;
charDeathTransDelay.pos = char.deathData?.preTransitionDelay ?? 0;

// callbaccd
charName.onChange = function(_) char.characterName = charName.text;

charOffsetsX.onChange = charOffsetsY.onChange = function(_) {
char.globalOffsets = [charOffsetsX.pos, charOffsetsY.pos];
daPage.updateCharPerStageData(char.characterType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ class HealthIconDialog extends DefaultPageDialog
{
super(daPage);

if (char.healthIcon != null && char.healthIconFiles.length >= 1) // set the data considering we have all the stuff we need
if (char.healthIcon != null) // set the data considering we have all the stuff we need
{
healthIcon = new FlxSprite();
var bitmap = openfl.display.BitmapData.fromBytes(char.healthIconFiles[0].bytes);

if (char.healthIconFiles.length == 1) // legacy
if (!Assets.exists(Paths.image('icons/icon-${char.healthIcon.id}')))
{
var iconSize = HealthIcon.HEALTH_ICON_SIZE;
return;
}

var isRetro = !Assets.exists(Paths.file('images/icons/icon-${char.healthIcon.id}'));
healthIconLoadField.text = char.healthIcon.id;
if (isRetro)
{
var iconSize:Int = HealthIcon.HEALTH_ICON_SIZE;
@:privateAccess if (char.healthIcon.isPixel) iconSize = HealthIcon.PIXEL_ICON_SIZE;

healthIcon.loadGraphic(bitmap, true, iconSize, iconSize);
healthIcon.loadGraphic(Paths.image('icons/icon-${char.healthIcon.id}'), true, iconSize, iconSize);
healthIcon.animation.add("idle", [0], 0, false, false);
healthIcon.animation.add("losing", [1], 0, false, false);
if (healthIcon.animation.numFrames >= 3)
Expand All @@ -36,18 +42,14 @@ class HealthIconDialog extends DefaultPageDialog
}
else
{
healthIcon.frames = FlxAtlasFrames.fromSparrow(bitmap, char.healthIconFiles[1].bytes.toString());
if (healthIcon.frames.frames.length == 0) return;

healthIcon.frames = Paths.getSparrowAtlas('icons/icon-${char.healthIcon.id}');
healthIcon.animation.addByPrefix("idle", "idle", 24, true);
healthIcon.animation.addByPrefix("winning", "winning", 24, true);
healthIcon.animation.addByPrefix("losing", "losing", 24, true);
healthIcon.animation.addByPrefix("toWinning", "toWinning", 24, false);
healthIcon.animation.addByPrefix("toLosing", "toLosing", 24, false);
healthIcon.animation.addByPrefix("fromWinning", "fromWinning", 24, false);
healthIcon.animation.addByPrefix("fromLosing", "fromLosing", 24, false);

if (healthIcon.animation.getNameList().length == 0) return;
}

// some cosmetic stuff
Expand All @@ -71,12 +73,25 @@ class HealthIconDialog extends DefaultPageDialog
}

healthIconPreviewBtn.onClick = function(_) {
if (healthIconLoadField.text == null || !healthIconLoadField.text.endsWith(".png")) return;
if (CharCreatorUtil.gimmeTheBytes(healthIconLoadField.text) == null) return;
if (healthIconLoadField.text.length == 0)
{
return;
}

if (haxe.io.Path.isAbsolute(healthIconLoadField.text) && haxe.io.Path.extension(healthIconLoadField.text) != "png")
{
return;
}

var endPath = haxe.io.Path.isAbsolute(healthIconLoadField.text) ? healthIconLoadField.text : Paths.image("icons/icon-" + healthIconLoadField.text);
if (CharCreatorUtil.gimmeTheBytes(endPath) == null)
{
return;
}

// getting bitmap
var imgBytes = CharCreatorUtil.gimmeTheBytes(healthIconLoadField.text);
var xmlBytes = CharCreatorUtil.gimmeTheBytes(healthIconLoadField.text.replace(".png", ".xml"));
var imgBytes = CharCreatorUtil.gimmeTheBytes(endPath);
var xmlBytes = CharCreatorUtil.gimmeTheBytes(endPath.replace(".png", ".xml"));

var bitmap = openfl.display.BitmapData.fromBytes(imgBytes);
if (bitmap == null) return;
Expand Down Expand Up @@ -131,12 +146,12 @@ class HealthIconDialog extends DefaultPageDialog
healthIcon.animation.play("idle");

char.healthIconFiles = [
{name: healthIconLoadField.text, bytes: imgBytes}];
if (xmlBytes != null) char.healthIconFiles.push({name: healthIconLoadField.text.replace(".png", ".xml"), bytes: xmlBytes});
{name: endPath, bytes: imgBytes}];
if (xmlBytes != null) char.healthIconFiles.push({name: endPath.replace(".png", ".xml"), bytes: xmlBytes});
char.healthIcon =
{
scale: healthIconScale.pos,
id: char.characterId,
id: haxe.io.Path.isAbsolute(endPath) ? char.characterId : healthIconLoadField.text,
offsets: [healthIconOffsetX.pos, healthIconOffsetY.pos],
flipX: healthIconFlipX.selected,
isPixel: healthIconPixelated.selected
Expand Down
Loading

0 comments on commit a9bd577

Please sign in to comment.