2023-06-02 18:35:28 +00:00
|
|
|
package funkin.play.event;
|
|
|
|
|
|
|
|
import flixel.tweens.FlxTween;
|
|
|
|
import flixel.FlxCamera;
|
|
|
|
import flixel.tweens.FlxEase;
|
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-06-02 18:35:28 +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-06-02 18:35:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents a handler for camera zoom events.
|
2023-06-15 04:15:57 +00:00
|
|
|
*
|
2023-06-02 18:35:28 +00:00
|
|
|
* Example: Zoom to 1.3x:
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* 'e': 'ZoomCamera',
|
|
|
|
* 'v': 1.3
|
|
|
|
* }
|
|
|
|
* ```
|
2023-06-15 04:15:57 +00:00
|
|
|
*
|
|
|
|
* Example: Zoom to 1.3x
|
2023-06-02 18:35:28 +00:00
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* 'e': 'FocusCamera',
|
|
|
|
* 'v': {
|
|
|
|
* 'char': 2,
|
|
|
|
* 'y': -10,
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2023-06-15 04:15:57 +00:00
|
|
|
*
|
2023-06-02 18:35:28 +00:00
|
|
|
* Example: Focus on (100, 100):
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* 'e': 'FocusCamera',
|
|
|
|
* 'v': {
|
|
|
|
* 'char': -1,
|
|
|
|
* 'x': 100,
|
|
|
|
* 'y': 100,
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
class ZoomCameraSongEvent extends SongEvent
|
|
|
|
{
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super('ZoomCamera');
|
|
|
|
}
|
|
|
|
|
2024-03-23 00:29:35 +00:00
|
|
|
static final DEFAULT_ZOOM:Float = 1.0;
|
|
|
|
static final DEFAULT_DURATION:Float = 4.0;
|
|
|
|
static final DEFAULT_MODE:String = 'direct';
|
|
|
|
static final DEFAULT_EASE:String = 'linear';
|
|
|
|
|
2023-06-02 18:35:28 +00:00
|
|
|
public override function handleEvent(data:SongEventData):Void
|
|
|
|
{
|
|
|
|
// Does nothing if there is no PlayState camera or stage.
|
2024-03-13 01:35:55 +00:00
|
|
|
if (PlayState.instance == null || PlayState.instance.currentStage == null) return;
|
|
|
|
|
|
|
|
// Does nothing if we are minimal mode.
|
2024-03-14 04:27:09 +00:00
|
|
|
if (PlayState.instance.isMinimalMode) return;
|
2023-06-02 18:35:28 +00:00
|
|
|
|
2024-03-23 00:29:35 +00:00
|
|
|
var zoom:Float = data.getFloat('zoom') ?? DEFAULT_ZOOM;
|
2023-06-02 18:35:28 +00:00
|
|
|
|
2024-03-23 00:29:35 +00:00
|
|
|
var duration:Float = data.getFloat('duration') ?? DEFAULT_DURATION;
|
2024-03-16 15:38:10 +00:00
|
|
|
|
2024-03-23 00:29:35 +00:00
|
|
|
var mode:String = data.getString('mode') ?? DEFAULT_MODE;
|
|
|
|
var isDirectMode:Bool = mode == 'direct';
|
2023-06-02 18:35:28 +00:00
|
|
|
|
2024-03-23 00:29:35 +00:00
|
|
|
var ease:String = data.getString('ease') ?? DEFAULT_EASE;
|
2024-03-16 15:38:10 +00:00
|
|
|
|
2023-06-02 18:35:28 +00:00
|
|
|
// If it's a string, check the value.
|
|
|
|
switch (ease)
|
|
|
|
{
|
|
|
|
case 'INSTANT':
|
2024-03-23 00:29:35 +00:00
|
|
|
PlayState.instance.tweenCameraZoom(zoom, 0, isDirectMode);
|
2023-06-02 18:35:28 +00:00
|
|
|
default:
|
2024-03-10 23:35:41 +00:00
|
|
|
var durSeconds = Conductor.instance.stepLengthMs * duration / 1000;
|
2023-06-02 18:35:28 +00:00
|
|
|
var easeFunction:Null<Float->Float> = Reflect.field(FlxEase, ease);
|
|
|
|
if (easeFunction == null)
|
|
|
|
{
|
|
|
|
trace('Invalid ease function: $ease');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-23 00:29:35 +00:00
|
|
|
PlayState.instance.tweenCameraZoom(zoom, durSeconds, isDirectMode, easeFunction);
|
2023-06-02 18:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function getTitle():String
|
|
|
|
{
|
|
|
|
return 'Zoom Camera';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* 'zoom': FLOAT, // Target zoom level.
|
2024-03-29 00:47:38 +00:00
|
|
|
* 'duration': FLOAT, // Duration in steps.
|
|
|
|
* 'mode': ENUM, // Whether zoom is relative to the stage or absolute zoom.
|
|
|
|
* 'ease': ENUM, // Easing function.
|
2023-06-02 18:35:28 +00:00
|
|
|
* }
|
|
|
|
* @return SongEventSchema
|
|
|
|
*/
|
|
|
|
public override function getEventSchema():SongEventSchema
|
|
|
|
{
|
2024-01-04 02:10:14 +00:00
|
|
|
return new SongEventSchema([
|
2023-06-02 18:35:28 +00:00
|
|
|
{
|
|
|
|
name: 'zoom',
|
|
|
|
title: 'Zoom Level',
|
|
|
|
defaultValue: 1.0,
|
|
|
|
step: 0.1,
|
2024-01-27 01:51:36 +00:00
|
|
|
type: SongEventFieldType.FLOAT,
|
|
|
|
units: 'x'
|
2023-06-02 18:35:28 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'duration',
|
2024-01-27 01:51:36 +00:00
|
|
|
title: 'Duration',
|
2023-06-02 18:35:28 +00:00
|
|
|
defaultValue: 4.0,
|
|
|
|
step: 0.5,
|
|
|
|
type: SongEventFieldType.FLOAT,
|
2024-01-27 01:51:36 +00:00
|
|
|
units: 'steps'
|
2023-06-02 18:35:28 +00:00
|
|
|
},
|
2024-03-16 15:38:10 +00:00
|
|
|
{
|
|
|
|
name: 'mode',
|
|
|
|
title: 'Mode',
|
2024-03-29 00:47:38 +00:00
|
|
|
defaultValue: 'stage',
|
2024-03-16 15:38:10 +00:00
|
|
|
type: SongEventFieldType.ENUM,
|
2024-03-29 00:47:38 +00:00
|
|
|
keys: ['Stage zoom' => 'stage', 'Absolute zoom' => 'direct']
|
2024-03-16 15:38:10 +00:00
|
|
|
},
|
2023-06-02 18:35:28 +00:00
|
|
|
{
|
|
|
|
name: 'ease',
|
|
|
|
title: 'Easing Type',
|
|
|
|
defaultValue: 'linear',
|
|
|
|
type: SongEventFieldType.ENUM,
|
|
|
|
keys: [
|
|
|
|
'Linear' => 'linear',
|
|
|
|
'Instant' => 'INSTANT',
|
2024-03-28 19:34:13 +00:00
|
|
|
'Sine In' => 'sineIn',
|
|
|
|
'Sine Out' => 'sineOut',
|
|
|
|
'Sine In/Out' => 'sineInOut',
|
2023-06-02 18:35:28 +00:00
|
|
|
'Quad In' => 'quadIn',
|
|
|
|
'Quad Out' => 'quadOut',
|
|
|
|
'Quad In/Out' => 'quadInOut',
|
|
|
|
'Cube In' => 'cubeIn',
|
|
|
|
'Cube Out' => 'cubeOut',
|
|
|
|
'Cube In/Out' => 'cubeInOut',
|
|
|
|
'Quart In' => 'quartIn',
|
|
|
|
'Quart Out' => 'quartOut',
|
|
|
|
'Quart In/Out' => 'quartInOut',
|
|
|
|
'Quint In' => 'quintIn',
|
|
|
|
'Quint Out' => 'quintOut',
|
|
|
|
'Quint In/Out' => 'quintInOut',
|
2024-03-28 19:34:13 +00:00
|
|
|
'Expo In' => 'expoIn',
|
|
|
|
'Expo Out' => 'expoOut',
|
|
|
|
'Expo In/Out' => 'expoInOut',
|
2023-06-02 18:35:28 +00:00
|
|
|
'Smooth Step In' => 'smoothStepIn',
|
|
|
|
'Smooth Step Out' => 'smoothStepOut',
|
|
|
|
'Smooth Step In/Out' => 'smoothStepInOut',
|
|
|
|
'Elastic In' => 'elasticIn',
|
|
|
|
'Elastic Out' => 'elasticOut',
|
2024-03-28 19:34:13 +00:00
|
|
|
'Elastic In/Out' => 'elasticInOut'
|
2023-06-02 18:35:28 +00:00
|
|
|
]
|
|
|
|
}
|
2024-01-04 02:10:14 +00:00
|
|
|
]);
|
2023-06-02 18:35:28 +00:00
|
|
|
}
|
|
|
|
}
|