Add , and . hotkeys to chart editor.

This commit is contained in:
EliteMasterEric 2024-05-02 03:38:27 -04:00
parent 656e5e7cf1
commit b06a35ea2f
2 changed files with 49 additions and 0 deletions

View File

@ -290,6 +290,16 @@ class SongDataUtils
return data.indexOf(note.data) != -1;
});
}
/**
* Filter a list of events to only include events whose kind is one of the given values.
*/
public static function getEventsWithKind(events:Array<SongEventData>, kinds:Array<String>):Array<SongEventData>
{
return events.filter(function(event:SongEventData):Bool {
return kinds.indexOf(event.eventKind) != -1;
});
}
}
typedef SongClipboardItems =

View File

@ -5171,6 +5171,10 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
// Do nothing.
}
// Place events at playhead.
if (FlxG.keys.justPressed.COMMA) placeEventAtPlayhead(true);
if (FlxG.keys.justPressed.PERIOD) placeEventAtPlayhead(false);
updatePlayheadGhostHoldNotes();
}
@ -5207,6 +5211,41 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
}
}
function placeEventAtPlayhead(isOpponent:Bool):Void
{
// SHIFT + press or LEFT_SHOULDER + press to remove events instead of placing them.
var removeEventInstead:Bool = FlxG.keys.pressed.SHIFT || (FlxG.gamepads.firstActive?.pressed?.LEFT_SHOULDER ?? false);
var playheadPos:Float = scrollPositionInPixels + playheadPositionInPixels;
var playheadPosFractionalStep:Float = playheadPos / GRID_SIZE / noteSnapRatio;
var playheadPosStep:Int = Std.int(Math.floor(playheadPosFractionalStep));
var playheadPosSnappedMs:Float = playheadPosStep * Conductor.instance.stepLengthMs * noteSnapRatio;
// Look for events within 1 step of the playhead.
var eventsAtPos:Array<SongEventData> = SongDataUtils.getEventsInTimeRange(currentSongChartEventData, playheadPosSnappedMs,
playheadPosSnappedMs + Conductor.instance.stepLengthMs * noteSnapRatio);
eventsAtPos = SongDataUtils.getEventsWithKind(eventsAtPos, ['FocusCamera']);
if (eventsAtPos.length == 0 && !removeEventInstead)
{
trace('Placing event ${isOpponent}');
var newEventData:SongEventData = new SongEventData(playheadPosSnappedMs, 'FocusCamera',
{
char: isOpponent ? 1 : 0,
});
performCommand(new AddEventsCommand([newEventData], FlxG.keys.pressed.CONTROL));
}
else if (removeEventInstead)
{
trace('Removing existing event at position.');
performCommand(new RemoveEventsCommand(eventsAtPos));
}
else
{
trace('Already an event there.');
}
}
function updatePlayheadGhostHoldNotes():Void
{
// Ensure all the ghost hold notes exist.