From 883ab879318e52e903c323c080a59483e945c393 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 13 Jul 2023 20:25:01 -0400 Subject: [PATCH] Moved AnimationData into the data package --- .../{play => data/animation}/AnimationData.hx | 48 ++++++++++++++++++- source/funkin/data/level/LevelData.hx | 2 +- source/funkin/play/character/CharacterData.hx | 1 + .../play/cutscene/dialogue/DialogueBoxData.hx | 1 + .../play/cutscene/dialogue/SpeakerData.hx | 2 + source/funkin/play/stage/StageData.hx | 1 + source/funkin/util/assets/FlxAnimationUtil.hx | 6 +-- 7 files changed, 56 insertions(+), 5 deletions(-) rename source/funkin/{play => data/animation}/AnimationData.hx (60%) diff --git a/source/funkin/play/AnimationData.hx b/source/funkin/data/animation/AnimationData.hx similarity index 60% rename from source/funkin/play/AnimationData.hx rename to source/funkin/data/animation/AnimationData.hx index e512bb757..2116109db 100644 --- a/source/funkin/play/AnimationData.hx +++ b/source/funkin/data/animation/AnimationData.hx @@ -1,14 +1,60 @@ -package funkin.play; +package funkin.data.animation; +class AnimationDataUtil +{ + public static function toNamed(data:UnnamedAnimationData, ?name:String = ""):AnimationData + { + return { + name: name, + prefix: data.prefix, + assetPath: data.assetPath, + offsets: data.offsets, + looped: data.looped, + flipX: data.flipX, + flipY: data.flipY, + frameRate: data.frameRate, + frameIndices: data.frameIndices + }; + } + + public static function toUnnamed(data:AnimationData):UnnamedAnimationData + { + return { + prefix: data.prefix, + assetPath: data.assetPath, + offsets: data.offsets, + looped: data.looped, + flipX: data.flipX, + flipY: data.flipY, + frameRate: data.frameRate, + frameIndices: data.frameIndices + }; + } +} + +/** + * A data structure representing an animation in a spritesheet. + * This is a generic data structure used by characters, stage props, and more! + * BE CAREFUL when changing it. + */ typedef AnimationData = { + > UnnamedAnimationData, + /** * The name for the animation. * This should match the animation name queried by the game; * for example, characters need animations with names `idle`, `singDOWN`, `singUPmiss`, etc. */ var name:String; +} +/** + * A data structure representing an animation in a spritesheet. + * This animation doesn't specify a name, that's presumably specified by the parent data structure. + */ +typedef UnnamedAnimationData = +{ /** * The prefix for the frames of the animation as defined by the XML file. * This will may or may not differ from the `name` of the animation, diff --git a/source/funkin/data/level/LevelData.hx b/source/funkin/data/level/LevelData.hx index 0342c3d39..0ba26354a 100644 --- a/source/funkin/data/level/LevelData.hx +++ b/source/funkin/data/level/LevelData.hx @@ -1,6 +1,6 @@ package funkin.data.level; -import funkin.play.AnimationData; +import funkin.data.animation.AnimationData; /** * A type definition for the data in a story mode level JSON file. diff --git a/source/funkin/play/character/CharacterData.hx b/source/funkin/play/character/CharacterData.hx index 16bf3a8a6..18a537a40 100644 --- a/source/funkin/play/character/CharacterData.hx +++ b/source/funkin/play/character/CharacterData.hx @@ -1,5 +1,6 @@ package funkin.play.character; +import funkin.data.animation.AnimationData; import funkin.modding.events.ScriptEvent; import funkin.modding.events.ScriptEventDispatcher; import funkin.play.character.ScriptedCharacter.ScriptedAnimateAtlasCharacter; diff --git a/source/funkin/play/cutscene/dialogue/DialogueBoxData.hx b/source/funkin/play/cutscene/dialogue/DialogueBoxData.hx index 2ae79f8d8..537a27129 100644 --- a/source/funkin/play/cutscene/dialogue/DialogueBoxData.hx +++ b/source/funkin/play/cutscene/dialogue/DialogueBoxData.hx @@ -1,5 +1,6 @@ package funkin.play.cutscene.dialogue; +import funkin.data.animation.AnimationData; import funkin.util.SerializerUtil; /** diff --git a/source/funkin/play/cutscene/dialogue/SpeakerData.hx b/source/funkin/play/cutscene/dialogue/SpeakerData.hx index 44e13b025..a0f9a3300 100644 --- a/source/funkin/play/cutscene/dialogue/SpeakerData.hx +++ b/source/funkin/play/cutscene/dialogue/SpeakerData.hx @@ -1,5 +1,7 @@ package funkin.play.cutscene.dialogue; +import funkin.data.animation.AnimationData; + /** * Data about a conversation. * Includes what speakers are in the conversation, and what phrases they say. diff --git a/source/funkin/play/stage/StageData.hx b/source/funkin/play/stage/StageData.hx index 6164c3cde..de8804cfb 100644 --- a/source/funkin/play/stage/StageData.hx +++ b/source/funkin/play/stage/StageData.hx @@ -1,5 +1,6 @@ package funkin.play.stage; +import funkin.data.animation.AnimationData; import flixel.util.typeLimit.OneOfTwo; import funkin.play.stage.ScriptedStage; import funkin.play.stage.Stage; diff --git a/source/funkin/util/assets/FlxAnimationUtil.hx b/source/funkin/util/assets/FlxAnimationUtil.hx index bab1e090b..0e32a1918 100644 --- a/source/funkin/util/assets/FlxAnimationUtil.hx +++ b/source/funkin/util/assets/FlxAnimationUtil.hx @@ -2,12 +2,12 @@ package funkin.util.assets; import flixel.FlxSprite; import flixel.graphics.frames.FlxFramesCollection; -import funkin.play.AnimationData; +import funkin.data.animation.AnimationData; class FlxAnimationUtil { /** - * Properly adds an animation to a sprite based on JSON data. + * Properly adds an animation to a sprite based on the provided animation data. */ public static function addAtlasAnimation(target:FlxSprite, anim:AnimationData) { @@ -31,7 +31,7 @@ class FlxAnimationUtil } /** - * Properly adds multiple animations to a sprite based on JSON data. + * Properly adds multiple animations to a sprite based on the provided animation data. */ public static function addAtlasAnimations(target:FlxSprite, animations:Array) {