Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bopper speed songevent #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import funkin.play.notes.SustainTrail;
import funkin.play.scoring.Scoring;
import funkin.play.song.Song;
import funkin.play.stage.Stage;
import funkin.play.stage.Bopper;
import funkin.save.Save;
import funkin.ui.debug.charting.ChartEditorState;
import funkin.ui.debug.stage.StageOffsetSubState;
Expand Down Expand Up @@ -1006,8 +1007,6 @@ class PlayState extends MusicBeatSubState
FlxG.watch.addQuick('health', health);
FlxG.watch.addQuick('cameraBopIntensity', cameraBopIntensity);

// TODO: Add a song event for Handle GF dance speed.

// Handle player death.
if (!isInCutscene && !disableKeys)
{
Expand Down
81 changes: 81 additions & 0 deletions source/funkin/play/event/BopperSpeedEvent.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package funkin.play.event;

// Data from the chart
import funkin.play.character.BaseCharacter;
import funkin.data.song.SongData;
import funkin.data.song.SongData.SongEventData;
// Data from the event schema
import funkin.play.event.SongEvent;
import funkin.data.event.SongEventSchema;
import funkin.data.event.SongEventSchema.SongEventFieldType;

import funkin.play.stage.Bopper;
import flixel.FlxSprite;
import flixel.util.FlxTimer;

class BopperSpeedEvent extends SongEvent
{
public function new()
{
super("BopperSpeed");
}

static final DEFAULT_DANCE_EVERY:Int = 1;

public override function handleEvent(data:SongEventData):Void
{
if (PlayState.instance == null || PlayState.instance.currentStage == null) return;

var bopperName:String = data.getString('bopper');

var speed:Int = data.getInt('danceEvery') ?? DEFAULT_DANCE_EVERY;

var bopperProp:FlxSprite = null;

switch(bopperName)
{
case 'boyfriend' | 'bf' | 'player':
bopperProp = PlayState.instance.currentStage.getBoyfriend();
case 'dad' | 'opponent':
bopperProp = PlayState.instance.currentStage.getDad();
case 'girlfriend' | 'gf':
bopperProp = PlayState.instance.currentStage.getGirlfriend();
default:
bopperProp = PlayState.instance.currentStage.getNamedProp(bopperName);
}

if(bopperProp != null) {
if ((Std.isOfType(bopperProp, Bopper)) || (Std.isOfType(bopperProp, BaseCharacter)))
{
var bopper = cast(bopperProp, Bopper);
trace('Setting $bopperName speed to $speed.');
bopper.danceEvery = speed;
}
}
}

public override function getTitle():String
{
return 'Set Bopper Speed';
}

public override function getEventSchema():SongEventSchema
{
return new SongEventSchema([
{
name: 'bopper',
title: 'Target (ID)',
type: SongEventFieldType.STRING,
defaultValue: 'girlfriend',
},
{
name: 'danceEvery',
title: 'Dance Every Value',
defaultValue: 1,
step: 1,
min: 1,
type: SongEventFieldType.INTEGER,
}
]);
}
}
52 changes: 20 additions & 32 deletions source/funkin/play/stage/Stage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import funkin.data.stage.StageData;
import funkin.data.stage.StageData.StageDataCharacter;
import funkin.data.stage.StageRegistry;
import funkin.play.stage.StageProp;
import funkin.play.character.CharacterData;
import funkin.play.character.CharacterData.CharacterDataParser;
import funkin.util.SortUtil;
import funkin.util.assets.FlxAnimationUtil;

Expand Down Expand Up @@ -105,39 +107,19 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
public function resetStage():Void
{
// Reset positions of characters.
if (getBoyfriend() != null)
{
getBoyfriend().resetCharacter(true);
// Reapply the camera offsets.
var stageCharData:StageDataCharacter = _data.characters.bf;
var finalScale:Float = getBoyfriend().getBaseScale() * stageCharData.scale;
getBoyfriend().setScale(finalScale);
getBoyfriend().cameraFocusPoint.x += stageCharData.cameraOffsets[0];
getBoyfriend().cameraFocusPoint.y += stageCharData.cameraOffsets[1];
}
else
{
trace('STAGE RESET: No boyfriend found.');
}
if (getGirlfriend() != null)
{
getGirlfriend().resetCharacter(true);
// Reapply the camera offsets.
var stageCharData:StageDataCharacter = _data.characters.gf;
var finalScale:Float = getGirlfriend().getBaseScale() * stageCharData.scale;
getGirlfriend().setScale(finalScale);
getGirlfriend().cameraFocusPoint.x += stageCharData.cameraOffsets[0];
getGirlfriend().cameraFocusPoint.y += stageCharData.cameraOffsets[1];
}
if (getDad() != null)
{
getDad().resetCharacter(true);
for (id => character in characters) {
var char = getCharacter(id);

char.resetCharacter(true);

// Reapply the camera offsets.
var stageCharData:StageDataCharacter = _data.characters.dad;
var finalScale:Float = getDad().getBaseScale() * stageCharData.scale;
getDad().setScale(finalScale);
getDad().cameraFocusPoint.x += stageCharData.cameraOffsets[0];
getDad().cameraFocusPoint.y += stageCharData.cameraOffsets[1];
var stageCharData:StageDataCharacter = Reflect.field(_data.characters, id);
var charData:CharacterData = CharacterDataParser.fetchCharacterData(character.characterId);
var finalScale:Float = char.getBaseScale() * stageCharData.scale;
char.setScale(finalScale);
char.cameraFocusPoint.x += stageCharData.cameraOffsets[0];
char.cameraFocusPoint.y += stageCharData.cameraOffsets[1];
char.danceEvery = charData.danceEvery;
}

// Reset positions of named props.
Expand All @@ -152,6 +134,12 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
prop.x = dataProp.position[0];
prop.y = dataProp.position[1];
prop.zIndex = dataProp.zIndex;
// Reset bop speed.
if (Std.isOfType(prop, Bopper))
{
var bopper = cast(prop, Bopper);
bopper.danceEvery = dataProp.danceEvery;
}
}
}

Expand Down
Loading