2023-01-22 19:55:30 -05:00
|
|
|
package funkin.play.event;
|
|
|
|
|
2023-09-08 17:46:44 -04:00
|
|
|
// Data from the chart
|
|
|
|
import funkin.data.song.SongData;
|
|
|
|
import funkin.data.song.SongData.SongEventData;
|
|
|
|
// Data from the event schema
|
2023-06-02 14:35:28 -04:00
|
|
|
import funkin.play.event.SongEvent;
|
2023-09-08 17:46:44 -04:00
|
|
|
import funkin.data.event.SongEventData.SongEventSchema;
|
|
|
|
import funkin.data.event.SongEventData.SongEventFieldType;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents a handler for a type of song event.
|
|
|
|
* It is used by the ScriptedSongEvent class to handle user-defined events.
|
2023-06-08 16:30:45 -04:00
|
|
|
*
|
2023-01-22 19:55:30 -05:00
|
|
|
* Example: Focus on Boyfriend:
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* "e": "FocusCamera",
|
|
|
|
* "v": {
|
|
|
|
* "char": 0,
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2023-06-08 16:30:45 -04:00
|
|
|
*
|
2023-01-22 19:55:30 -05:00
|
|
|
* Example: Focus on 10px above Girlfriend:
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* "e": "FocusCamera",
|
|
|
|
* "v": {
|
|
|
|
* "char": 2,
|
|
|
|
* "y": -10,
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
2023-06-08 16:30:45 -04:00
|
|
|
*
|
2023-01-22 19:55:30 -05:00
|
|
|
* Example: Focus on (100, 100):
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* "e": "FocusCamera",
|
|
|
|
* "v": {
|
|
|
|
* "char": -1,
|
|
|
|
* "x": 100,
|
|
|
|
* "y": 100,
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
class FocusCameraSongEvent extends SongEvent
|
|
|
|
{
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super('FocusCamera');
|
|
|
|
}
|
|
|
|
|
2023-02-21 20:58:15 -05:00
|
|
|
public override function handleEvent(data:SongEventData):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
|
|
|
// Does nothing if there is no PlayState camera or stage.
|
2023-01-22 22:25:45 -05:00
|
|
|
if (PlayState.instance == null || PlayState.instance.currentStage == null) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-02-21 20:58:15 -05:00
|
|
|
var posX:Null<Float> = data.getFloat('x');
|
2023-01-22 22:25:45 -05:00
|
|
|
if (posX == null) posX = 0.0;
|
2023-02-21 20:58:15 -05:00
|
|
|
var posY:Null<Float> = data.getFloat('y');
|
2023-01-22 22:25:45 -05:00
|
|
|
if (posY == null) posY = 0.0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-02-21 20:58:15 -05:00
|
|
|
var char:Null<Int> = data.getInt('char');
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
if (char == null) char = cast data.value;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
switch (char)
|
|
|
|
{
|
|
|
|
case -1: // Position
|
|
|
|
trace('Focusing camera on static position.');
|
2023-02-21 20:58:15 -05:00
|
|
|
var xTarget:Float = posX;
|
|
|
|
var yTarget:Float = posY;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget);
|
|
|
|
case 0: // Boyfriend
|
|
|
|
// Focus the camera on the player.
|
2023-02-21 20:58:15 -05:00
|
|
|
if (PlayState.instance.currentStage.getBoyfriend() == null)
|
|
|
|
{
|
|
|
|
trace('No BF to focus on.');
|
|
|
|
return;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
trace('Focusing camera on player.');
|
2023-02-21 20:58:15 -05:00
|
|
|
var xTarget:Float = PlayState.instance.currentStage.getBoyfriend().cameraFocusPoint.x + posX;
|
|
|
|
var yTarget:Float = PlayState.instance.currentStage.getBoyfriend().cameraFocusPoint.y + posY;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget);
|
|
|
|
case 1: // Dad
|
|
|
|
// Focus the camera on the dad.
|
2023-02-21 20:58:15 -05:00
|
|
|
if (PlayState.instance.currentStage.getDad() == null)
|
|
|
|
{
|
|
|
|
trace('No dad to focus on.');
|
|
|
|
return;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
trace('Focusing camera on dad.');
|
2023-02-21 20:58:15 -05:00
|
|
|
trace(PlayState.instance.currentStage.getDad());
|
|
|
|
var xTarget:Float = PlayState.instance.currentStage.getDad().cameraFocusPoint.x + posX;
|
|
|
|
var yTarget:Float = PlayState.instance.currentStage.getDad().cameraFocusPoint.y + posY;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget);
|
|
|
|
case 2: // Girlfriend
|
|
|
|
// Focus the camera on the girlfriend.
|
2023-02-21 20:58:15 -05:00
|
|
|
if (PlayState.instance.currentStage.getGirlfriend() == null)
|
|
|
|
{
|
|
|
|
trace('No GF to focus on.');
|
|
|
|
return;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
trace('Focusing camera on girlfriend.');
|
2023-02-21 20:58:15 -05:00
|
|
|
var xTarget:Float = PlayState.instance.currentStage.getGirlfriend().cameraFocusPoint.x + posX;
|
|
|
|
var yTarget:Float = PlayState.instance.currentStage.getGirlfriend().cameraFocusPoint.y + posY;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
PlayState.instance.cameraFollowPoint.setPosition(xTarget, yTarget);
|
|
|
|
default:
|
|
|
|
trace('Unknown camera focus: ' + data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override function getTitle():String
|
|
|
|
{
|
2023-02-21 20:58:15 -05:00
|
|
|
return 'Focus Camera';
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ```
|
|
|
|
* {
|
|
|
|
* "char": ENUM, // Which character to point to
|
|
|
|
* "x": FLOAT, // Optional x offset
|
|
|
|
* "y": FLOAT, // Optional y offset
|
|
|
|
* }
|
|
|
|
* @return SongEventSchema
|
|
|
|
*/
|
|
|
|
public override function getEventSchema():SongEventSchema
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
name: "char",
|
|
|
|
title: "Character",
|
|
|
|
defaultValue: 0,
|
|
|
|
type: SongEventFieldType.ENUM,
|
|
|
|
keys: ["Position" => -1, "Boyfriend" => 0, "Dad" => 1, "Girlfriend" => 2]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "x",
|
|
|
|
title: "X Position",
|
|
|
|
defaultValue: 0,
|
|
|
|
step: 10.0,
|
|
|
|
type: SongEventFieldType.FLOAT,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "y",
|
|
|
|
title: "Y Position",
|
|
|
|
defaultValue: 0,
|
|
|
|
step: 10.0,
|
|
|
|
type: SongEventFieldType.FLOAT,
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|