Cleanup + Focus Camera: Use Tween toggle converted to "Classic" ease type.

This commit is contained in:
Jenny Crowe 2024-03-28 12:34:13 -07:00
parent c658862f48
commit 76885c421d
3 changed files with 64 additions and 67 deletions

View file

@ -3104,6 +3104,15 @@ class PlayState extends MusicBeatSubState
FlxG.camera.focusOn(cameraFollowPoint.getPosition()); FlxG.camera.focusOn(cameraFollowPoint.getPosition());
} }
/**
* Sets the camera follow point's position and tweens the camera there.
*/
public function tweenCameraToPosition(?x:Float, ?y:Float, ?duration:Float, ?ease:Null<Float->Float>):Void
{
cameraFollowPoint.setPosition(x, y);
tweenCameraToFollowPoint(duration, ease);
}
/** /**
* Disables camera following and tweens the camera to the follow point manually. * Disables camera following and tweens the camera to the follow point manually.
*/ */

View file

@ -70,83 +70,76 @@ class FocusCameraSongEvent extends SongEvent
if (char == null) char = cast data.value; if (char == null) char = cast data.value;
var useTween:Null<Bool> = data.getBool('useTween');
if (useTween == null) useTween = false;
var duration:Null<Float> = data.getFloat('duration'); var duration:Null<Float> = data.getFloat('duration');
if (duration == null) duration = 4.0; if (duration == null) duration = 4.0;
var ease:Null<String> = data.getString('ease'); var ease:Null<String> = data.getString('ease');
if (ease == null) ease = 'linear'; if (ease == null) ease = 'CLASSIC';
var currentStage = PlayState.instance.currentStage;
// Get target position based on char.
var targetX:Float = posX;
var targetY:Float = posY;
switch (char) switch (char)
{ {
case -1: // Position case -1: // Position ("focus" on origin)
trace('Focusing camera on static position.'); trace('Focusing camera on static position.');
var xTarget:Float = posX;
var yTarget:Float = posY;
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget); case 0: // Boyfriend (focus on player)
case 0: // Boyfriend if (currentStage.getBoyfriend() == null)
// Focus the camera on the player.
if (PlayState.instance.currentStage.getBoyfriend() == null)
{ {
trace('No BF to focus on.'); trace('No BF to focus on.');
return; return;
} }
trace('Focusing camera on player.'); trace('Focusing camera on player.');
var xTarget:Float = PlayState.instance.currentStage.getBoyfriend().cameraFocusPoint.x + posX; var bfPoint = currentStage.getBoyfriend().cameraFocusPoint;
var yTarget:Float = PlayState.instance.currentStage.getBoyfriend().cameraFocusPoint.y + posY; targetX += bfPoint.x;
targetY += bfPoint.y;
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget); case 1: // Dad (focus on opponent)
case 1: // Dad if (currentStage.getDad() == null)
// Focus the camera on the dad.
if (PlayState.instance.currentStage.getDad() == null)
{ {
trace('No dad to focus on.'); trace('No dad to focus on.');
return; return;
} }
trace('Focusing camera on dad.'); trace('Focusing camera on opponent.');
trace(PlayState.instance.currentStage.getDad()); var dadPoint = currentStage.getDad().cameraFocusPoint;
var xTarget:Float = PlayState.instance.currentStage.getDad().cameraFocusPoint.x + posX; targetX += dadPoint.x;
var yTarget:Float = PlayState.instance.currentStage.getDad().cameraFocusPoint.y + posY; targetY += dadPoint.y;
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget); case 2: // Girlfriend (focus on girlfriend)
case 2: // Girlfriend if (currentStage.getGirlfriend() == null)
// Focus the camera on the girlfriend.
if (PlayState.instance.currentStage.getGirlfriend() == null)
{ {
trace('No GF to focus on.'); trace('No GF to focus on.');
return; return;
} }
trace('Focusing camera on girlfriend.'); trace('Focusing camera on girlfriend.');
var xTarget:Float = PlayState.instance.currentStage.getGirlfriend().cameraFocusPoint.x + posX; var gfPoint = currentStage.getGirlfriend().cameraFocusPoint;
var yTarget:Float = PlayState.instance.currentStage.getGirlfriend().cameraFocusPoint.y + posY; targetX += gfPoint.x;
targetY += gfPoint.y;
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget);
default: default:
trace('Unknown camera focus: ' + data); trace('Unknown camera focus: ' + data);
} }
if (useTween) // Apply tween based on ease.
switch (ease)
{ {
switch (ease) case 'CLASSIC': // Old-school. No ease. Just set follow point.
{ PlayState.instance.cancelCameraFollowTween();
case 'INSTANT': PlayState.instance.cameraFollowPoint.setPosition(targetX, targetY);
PlayState.instance.tweenCameraToFollowPoint(0); case 'INSTANT': // Instant ease. Duration is automatically 0.
case 'classic': PlayState.instance.tweenCameraToPosition(targetX, targetY, 0);
var classicDur = 1.0; // This is probably a fixed duration given how old zoom works. Need to sus it out. default:
PlayState.instance.tweenCameratoFollowPoint(classicDur); // Need to create an ease function to recreate classic follow-style movement. var durSeconds = Conductor.instance.stepLengthMs * duration / 1000;
default: var easeFunction:Null<Float->Float> = Reflect.field(FlxEase, ease);
var durSeconds = Conductor.instance.stepLengthMs * duration / 1000; if (easeFunction == null)
{
var easeFunction:Null<Float->Float> = Reflect.field(FlxEase, ease); trace('Invalid ease function: $ease');
if (easeFunction == null) return;
{ }
trace('Invalid ease function: $ease'); PlayState.instance.tweenCameraToPosition(targetX, targetY, durSeconds, easeFunction);
return;
}
PlayState.instance.tweenCameraToFollowPoint(durSeconds, easeFunction);
}
} }
} }
@ -190,12 +183,6 @@ class FocusCameraSongEvent extends SongEvent
type: SongEventFieldType.FLOAT, type: SongEventFieldType.FLOAT,
units: "px" units: "px"
}, },
{
name: 'useTween',
title: 'Use Tween',
type: SongEventFieldType.BOOL,
defaultValue: false
},
{ {
name: 'duration', name: 'duration',
title: 'Duration', title: 'Duration',
@ -211,7 +198,9 @@ class FocusCameraSongEvent extends SongEvent
type: SongEventFieldType.ENUM, type: SongEventFieldType.ENUM,
keys: [ keys: [
'Linear' => 'linear', 'Linear' => 'linear',
'Instant' => 'INSTANT', 'Sine In' => 'sineIn',
'Sine Out' => 'sineOut',
'Sine In/Out' => 'sineInOut',
'Quad In' => 'quadIn', 'Quad In' => 'quadIn',
'Quad Out' => 'quadOut', 'Quad Out' => 'quadOut',
'Quad In/Out' => 'quadInOut', 'Quad In/Out' => 'quadInOut',
@ -224,16 +213,17 @@ class FocusCameraSongEvent extends SongEvent
'Quint In' => 'quintIn', 'Quint In' => 'quintIn',
'Quint Out' => 'quintOut', 'Quint Out' => 'quintOut',
'Quint In/Out' => 'quintInOut', 'Quint In/Out' => 'quintInOut',
'Expo In' => 'expoIn',
'Expo Out' => 'expoOut',
'Expo In/Out' => 'expoInOut',
'Smooth Step In' => 'smoothStepIn', 'Smooth Step In' => 'smoothStepIn',
'Smooth Step Out' => 'smoothStepOut', 'Smooth Step Out' => 'smoothStepOut',
'Smooth Step In/Out' => 'smoothStepInOut', 'Smooth Step In/Out' => 'smoothStepInOut',
'Sine In' => 'sineIn',
'Sine Out' => 'sineOut',
'Sine In/Out' => 'sineInOut',
'Elastic In' => 'elasticIn', 'Elastic In' => 'elasticIn',
'Elastic Out' => 'elasticOut', 'Elastic Out' => 'elasticOut',
'Elastic In/Out' => 'elasticInOut', 'Elastic In/Out' => 'elasticInOut',
'Classic' => 'classic' 'Instant (Ignores duration)' => 'INSTANT',
'Classic (Ignores duration)' => 'CLASSIC'
] ]
} }
]); ]);

View file

@ -79,12 +79,8 @@ class ZoomCameraSongEvent extends SongEvent
{ {
case 'INSTANT': case 'INSTANT':
PlayState.instance.tweenCameraZoom(zoom, 0, isDirectMode); PlayState.instance.tweenCameraZoom(zoom, 0, isDirectMode);
case 'classic':
var classicDur = 1.0; // This is probably a fixed duration given how old zoom works. Need to sus it out.
PlayState.instance.tweenCameraZoom(zoom, 1.0; true); // Need to create an ease function to recreate classic lerp-style zooming.
default: default:
var durSeconds = Conductor.instance.stepLengthMs * duration / 1000; var durSeconds = Conductor.instance.stepLengthMs * duration / 1000;
var easeFunction:Null<Float->Float> = Reflect.field(FlxEase, ease); var easeFunction:Null<Float->Float> = Reflect.field(FlxEase, ease);
if (easeFunction == null) if (easeFunction == null)
{ {
@ -145,6 +141,9 @@ class ZoomCameraSongEvent extends SongEvent
keys: [ keys: [
'Linear' => 'linear', 'Linear' => 'linear',
'Instant' => 'INSTANT', 'Instant' => 'INSTANT',
'Sine In' => 'sineIn',
'Sine Out' => 'sineOut',
'Sine In/Out' => 'sineInOut',
'Quad In' => 'quadIn', 'Quad In' => 'quadIn',
'Quad Out' => 'quadOut', 'Quad Out' => 'quadOut',
'Quad In/Out' => 'quadInOut', 'Quad In/Out' => 'quadInOut',
@ -157,16 +156,15 @@ class ZoomCameraSongEvent extends SongEvent
'Quint In' => 'quintIn', 'Quint In' => 'quintIn',
'Quint Out' => 'quintOut', 'Quint Out' => 'quintOut',
'Quint In/Out' => 'quintInOut', 'Quint In/Out' => 'quintInOut',
'Expo In' => 'expoIn',
'Expo Out' => 'expoOut',
'Expo In/Out' => 'expoInOut',
'Smooth Step In' => 'smoothStepIn', 'Smooth Step In' => 'smoothStepIn',
'Smooth Step Out' => 'smoothStepOut', 'Smooth Step Out' => 'smoothStepOut',
'Smooth Step In/Out' => 'smoothStepInOut', 'Smooth Step In/Out' => 'smoothStepInOut',
'Sine In' => 'sineIn',
'Sine Out' => 'sineOut',
'Sine In/Out' => 'sineInOut',
'Elastic In' => 'elasticIn', 'Elastic In' => 'elasticIn',
'Elastic Out' => 'elasticOut', 'Elastic Out' => 'elasticOut',
'Elastic In/Out' => 'elasticInOut', 'Elastic In/Out' => 'elasticInOut'
'Classic' => 'classic'
] ]
} }
]); ]);