2023-01-23 00:55:30 +00:00
|
|
|
package funkin.play.event;
|
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import funkin.play.character.BaseCharacter;
|
2023-09-08 21:46:44 +00:00
|
|
|
// Data from the chart
|
|
|
|
import funkin.data.song.SongData;
|
|
|
|
import funkin.data.song.SongData.SongEventData;
|
|
|
|
// Data from the event schema
|
2023-01-23 00:55:30 +00:00
|
|
|
import funkin.play.event.SongEvent;
|
2024-01-04 02:10:14 +00:00
|
|
|
import funkin.data.event.SongEventSchema;
|
|
|
|
import funkin.data.event.SongEventSchema.SongEventFieldType;
|
2023-01-23 00:55:30 +00:00
|
|
|
|
|
|
|
class PlayAnimationSongEvent extends SongEvent
|
|
|
|
{
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super('PlayAnimation');
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function handleEvent(data:SongEventData)
|
|
|
|
{
|
|
|
|
// Does nothing if there is no PlayState camera or stage.
|
2023-01-23 03:25:45 +00:00
|
|
|
if (PlayState.instance == null || PlayState.instance.currentStage == null) return;
|
2023-01-23 00:55:30 +00:00
|
|
|
|
|
|
|
var targetName = data.getString('target');
|
|
|
|
var anim = data.getString('anim');
|
|
|
|
var force = data.getBool('force');
|
2023-01-23 03:25:45 +00:00
|
|
|
if (force == null) force = false;
|
2023-01-23 00:55:30 +00:00
|
|
|
|
|
|
|
var target:FlxSprite = null;
|
|
|
|
|
|
|
|
switch (targetName)
|
|
|
|
{
|
2024-05-08 07:23:00 +00:00
|
|
|
case 'boyfriend' | 'bf' | 'player':
|
2023-01-23 00:55:30 +00:00
|
|
|
trace('Playing animation $anim on boyfriend.');
|
|
|
|
target = PlayState.instance.currentStage.getBoyfriend();
|
2024-05-08 07:23:00 +00:00
|
|
|
case 'dad' | 'opponent':
|
2023-01-23 00:55:30 +00:00
|
|
|
trace('Playing animation $anim on dad.');
|
|
|
|
target = PlayState.instance.currentStage.getDad();
|
2024-05-08 07:23:00 +00:00
|
|
|
case 'girlfriend' | 'gf':
|
2023-01-23 00:55:30 +00:00
|
|
|
trace('Playing animation $anim on girlfriend.');
|
|
|
|
target = PlayState.instance.currentStage.getGirlfriend();
|
|
|
|
default:
|
|
|
|
target = PlayState.instance.currentStage.getNamedProp(targetName);
|
2023-01-23 03:25:45 +00:00
|
|
|
if (target == null) trace('Unknown animation target: $targetName');
|
2023-01-23 00:55:30 +00:00
|
|
|
else
|
|
|
|
trace('Fetched animation target $targetName from stage.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target != null)
|
|
|
|
{
|
|
|
|
if (Std.isOfType(target, BaseCharacter))
|
|
|
|
{
|
|
|
|
var targetChar:BaseCharacter = cast target;
|
|
|
|
targetChar.playAnimation(anim, force, force);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target.animation.play(anim, force);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function getTitle():String
|
|
|
|
{
|
|
|
|
return "Play Animation";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* "target": STRING, // Name of character or prop to point to.
|
|
|
|
* "anim": STRING, // Name of animation to play.
|
|
|
|
* "force": BOOL, // Whether to force the animation to play.
|
|
|
|
* }
|
|
|
|
* @return SongEventSchema
|
|
|
|
*/
|
|
|
|
public override function getEventSchema():SongEventSchema
|
|
|
|
{
|
2024-01-04 02:10:14 +00:00
|
|
|
return new SongEventSchema([
|
2023-01-23 00:55:30 +00:00
|
|
|
{
|
|
|
|
name: 'target',
|
|
|
|
title: 'Target',
|
|
|
|
type: SongEventFieldType.STRING,
|
|
|
|
defaultValue: 'boyfriend',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'anim',
|
|
|
|
title: 'Animation',
|
|
|
|
type: SongEventFieldType.STRING,
|
|
|
|
defaultValue: 'idle',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'force',
|
|
|
|
title: 'Force',
|
|
|
|
type: SongEventFieldType.BOOL,
|
|
|
|
defaultValue: false
|
|
|
|
}
|
2024-01-04 02:10:14 +00:00
|
|
|
]);
|
2023-01-23 00:55:30 +00:00
|
|
|
}
|
|
|
|
}
|