Skip to content

Commit

Permalink
STATIC CHARTER SHIT :DDD
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarcleint committed Feb 5, 2024
1 parent e9e7daa commit f72a768
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 37 deletions.
2 changes: 1 addition & 1 deletion source/funkin/editors/SaveWarning.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SaveWarning {
}
},
{
label: closingWindow ? "Save & Exit Game" : "Save&Exit To Menu",
label: closingWindow ? "Save & Exit Game" : "Save & Exit To Menu",
color: 0x969533,
onClick: function(_) {
if (saveFunc != null) saveFunc();
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/editors/charter/ChartDataScreen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ class ChartDataScreen extends UISubstateWindow {
PlayState.SONG.stage = stageTextBox.label.text;
PlayState.SONG.scrollSpeed = scrollSpeedStepper.value;

Charter.instance.undos.addToUndo(CEditChartData(oldData, {stage: stageTextBox.label.text, speed: scrollSpeedStepper.value}));
Charter.undos.addToUndo(CEditChartData(oldData, {stage: stageTextBox.label.text, speed: scrollSpeedStepper.value}));
}
}
155 changes: 140 additions & 15 deletions source/funkin/editors/charter/Charter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import openfl.net.FileReference;

class Charter extends UIState {
public static var __song:String;
public static var __lastPos:Float;
static var __diff:String;
static var __reload:Bool;

Expand Down Expand Up @@ -82,10 +81,12 @@ class Charter extends UIState {
public var uiCamera:FlxCamera;
public var selectionBox:UISliceSprite;

public var selection:Selection = new Selection();
public var undos:UndoList<CharterChange> = new UndoList<CharterChange>();
public static var selection:Selection;

public var clipboard:Array<CharterCopyboardObject> = [];
public static var playtestInfo:PlaytestInfo;
public static var undos:UndoList<CharterChange>;

public static var clipboard:Array<CharterCopyboardObject> = [];

public function new(song:String, diff:String, reload:Bool = true) {
super();
Expand Down Expand Up @@ -454,6 +455,8 @@ class Charter extends UIState {
}

override function destroy() {
__updatePlaytestInfo();

if(Framerate.isLoaded) {
Framerate.fpsCounter.alpha = 1;
Framerate.memoryCounter.alpha = 1;
Expand All @@ -464,13 +467,12 @@ class Charter extends UIState {

public function loadSong() {
if (__reload) {
EventsData.reloadEvents(); __lastPos = 0;
EventsData.reloadEvents();
PlayState.loadSong(__song, __diff, false, false);
__resetStatics();
}
Conductor.setupSong(PlayState.SONG);
Conductor.songPosition = __lastPos;
noteTypes = PlayState.SONG.noteTypes;
// noteTypes = ["Hurt Note", "Bullet Note", "Penis Note", "Boobs Note"];

FlxG.sound.setMusic(FlxG.sound.load(Paths.inst(__song, __diff)));
vocals = FlxG.sound.load(Paths.voices(__song, __diff));
Expand Down Expand Up @@ -500,6 +502,7 @@ class Charter extends UIState {
notesGroup.autoSort = true;

// create events
eventsGroup.autoSort = false;
var __last:CharterEvent = null;
var __lastTime:Float = Math.NaN;
for(e in PlayState.SONG.events) {
Expand All @@ -513,11 +516,20 @@ class Charter extends UIState {
}
}

eventsGroup.sortEvents();
eventsGroup.autoSort = true;

for(e in eventsGroup.members)
e.refreshEventIcons();


buildNoteTypesUI();
refreshBPMSensitive();

// Cool shit :DD
__relinkSelection();
__relinkUndos();
__applyPlaytestInfo();
}

public var __endStep:Float = 0;
Expand Down Expand Up @@ -667,7 +679,10 @@ class Charter extends UIState {
if (s is CharterNote) cast(s, CharterNote).snappedToStrumline = true;
if (s is UISprite) cast(s, UISprite).cursor = BUTTON;
}
if (!(verticalChange == 0 && horizontalChange == 0)) undos.addToUndo(CSelectionDrag(undoDrags));
if (!(verticalChange == 0 && horizontalChange == 0)) {
notesGroup.sortNotes(); eventsGroup.sortEvents();
undos.addToUndo(CSelectionDrag(undoDrags));
}

hoverOffset.put();
gridActionType = NONE;
Expand Down Expand Up @@ -779,11 +794,13 @@ class Charter extends UIState {

if (selected is CharterNote) {
var note:CharterNote = cast selected;
notesGroup.remove(note, true);
note.strumLineID = strumLines.members.indexOf(note.strumLine);
note.strumLine = null; // For static undos :D
notesGroup.remove(note);
note.kill();
} else if (selected is CharterEvent) {
var event:CharterEvent = cast selected;
eventsGroup.remove(event, true);
eventsGroup.remove(event);
event.kill();
}

Expand All @@ -798,11 +815,12 @@ class Charter extends UIState {

notesGroup.autoSort = false;
selection.loop(function (n:CharterNote) {
notesGroup.add(n);
n.strumLine = strumLines.members[n.strumLineID];
n.revive();
notesGroup.add(n);
}, function (e:CharterEvent) {
eventsGroup.add(e);
e.revive();
eventsGroup.add(e);
e.refreshEventIcons();
}, false);
notesGroup.sortNotes();
Expand Down Expand Up @@ -1023,7 +1041,6 @@ class Charter extends UIState {
vocals.pause();
for (strumLine in strumLines.members) strumLine.vocals.pause();
}
__lastPos = Conductor.songPosition;

songPosInfo.text = '${CoolUtil.timeToStr(Conductor.songPosition)} / ${CoolUtil.timeToStr(songLength)}'
+ '\nStep: ${curStep}'
Expand Down Expand Up @@ -1077,7 +1094,7 @@ class Charter extends UIState {
#if REGION
function _file_exit(_) {
if (undos.unsaved) SaveWarning.triggerWarning();
else FlxG.switchState(new CharterSelection());
else {undos = null; FlxG.switchState(new CharterSelection());}
}

function _file_save(_) {
Expand Down Expand Up @@ -1180,6 +1197,7 @@ class Charter extends UIState {

selection = [];
var undo = undos.undo();
trace(undo);
switch(undo) {
case null: // do nothing
case CDeleteStrumLine(strumLineID, strumLine):
Expand All @@ -1201,7 +1219,7 @@ class Charter extends UIState {
for (s in selectionDrags)
if (s.selectable.draggable) s.selectable.handleDrag(s.change * -1);

this.selection = [for (s in selectionDrags) s.selectable];
selection = [for (s in selectionDrags) s.selectable];
case CEditSustains(changes):
for(n in changes)
n.note.updatePos(n.note.step, n.note.id, n.before, n.note.type);
Expand Down Expand Up @@ -1527,6 +1545,7 @@ class Charter extends UIState {
s.strumLine.notes = [];
PlayState.SONG.strumLines.push(s.strumLine);
}
notesGroup.sortNotes();
for(n in notesGroup.members) {
if (PlayState.SONG.strumLines[n.strumLineID] != null)
PlayState.SONG.strumLines[n.strumLineID].notes.push(buildNote(n));
Expand Down Expand Up @@ -1556,6 +1575,101 @@ class Charter extends UIState {

public inline function hitsoundsEnabled(id:Int)
return strumLines.members[id] != null && strumLines.members[id].hitsounds;

// UH OH!!! DANGER ZONE APPOARCHING !!!! LUNARS SHITTY CODE !!!! -lunar

@:noCompletion public function __fixSingleSelection(selectable:ICharterSelectable):ICharterSelectable {
if (selectable is CharterNote)
return selectable.ID == -1 ? cast(selectable, CharterNote) : notesGroup.members[selectable.ID];
else if (selectable is CharterEvent)
return selectable.ID == -1 ? cast(selectable, CharterEvent) : eventsGroup.members[selectable.ID];
return null;
}

@:noCompletion public function __fixSelection(selection:Selection) @:privateAccess {
var newSelection:Selection = new Selection();
for (i => selectable in selection)
newSelection[i] = __fixSingleSelection(selectable);
return newSelection;
}

@:noCompletion public inline function __relinkSelection()
selection = __fixSelection(selection);

@:noCompletion public inline function __relinkUndos() {
for (list => changeList in [undos.undoList, undos.redoList]) {
var newChanges:Array<CharterChange> = [];
for (i => change in changeList) {
switch (change) {
case CCreateSelection(selection):
newChanges[i] = CCreateSelection(__fixSelection(selection));
case CDeleteSelection(selection):
newChanges[i] = CDeleteSelection(__fixSelection(selection));
case CSelectionDrag(selectionDrags):
newChanges[i] = CSelectionDrag([
for (selectionDrag in selectionDrags)
{
selectable: __fixSingleSelection(selectionDrag.selectable),
change: selectionDrag.change
}
]);
case CEditSustains(noteChanges):
newChanges[i] = CEditSustains([
for (noteChange in noteChanges)
{
note: cast(__fixSingleSelection(noteChange.note), CharterNote),
before: noteChange.before,
after: noteChange.after
}
]);
case CEditEvent(event, oldEvents, newEvents):
newChanges[i] = CEditEvent(cast(__fixSingleSelection(event), CharterEvent), oldEvents, newEvents);
case CEditSpecNotesType(notesChanged, oldNoteTypes, newNoteTypes):
newChanges[i] = CEditSpecNotesType([
for (noteChanged in notesChanged)
cast(__fixSingleSelection(noteChanged), CharterNote)
], oldNoteTypes, newNoteTypes);
default: newChanges[i] = change;
}
}

if (list == 0) undos.undoList = newChanges;
else undos.redoList = newChanges;
}
}

@:noCompletion public function __resetStatics() {
selection = new Selection();
undos = new UndoList<CharterChange>();
clipboard = []; playtestInfo = null;
}

@:noCompletion public function __updatePlaytestInfo() {
playtestInfo = {
songPosition: Conductor.songPosition,
playbackSpeed: playBackSlider.value,
quantSelected: quant,
noteTypeSelected: noteType,
strumlinesDraggable: strumLines.draggable,
hitSounds: [for (strumLine in strumLines.members) strumLine.hitsounds],
mutedVocals: [for (strumLine in strumLines.members) !(strumLine.vocals.volume > 0)],
}
}

@:noCompletion public function __applyPlaytestInfo() {
if (playtestInfo == null) return;

Conductor.songPosition = playtestInfo.songPosition;
playBackSlider.value = playtestInfo.playbackSpeed;
quant = playtestInfo.quantSelected;
noteType = playtestInfo.noteTypeSelected;
strumLines.draggable = playtestInfo.strumlinesDraggable;

for (i => strumLine in strumLines.members)
strumLine.hitsounds = playtestInfo.hitSounds[i];
for (i => strumLine in strumLines.members)
strumLine.vocals.volume = playtestInfo.mutedVocals[i] ? 0 : 1;
}
}

enum CharterChange {
Expand Down Expand Up @@ -1607,6 +1721,7 @@ typedef SelectionDragChange = {
interface ICharterSelectable {
public var x(default, set):Float;
public var y(default, set):Float;
public var ID:Int;
public var step:Float;

public var selected:Bool;
Expand All @@ -1623,3 +1738,13 @@ enum abstract CharterGridActionType(Int) {
var DRAG = 2;
var INVALID_DRAG = 3;
}

typedef PlaytestInfo = {
var songPosition:Float;
var playbackSpeed:Float;
var quantSelected:Int;
var noteTypeSelected:Int;
var strumlinesDraggable:Bool;
var hitSounds:Array<Bool>;
var mutedVocals:Array<Bool>;
}
15 changes: 13 additions & 2 deletions source/funkin/editors/charter/CharterEventGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import flixel.util.FlxSort;

class CharterEventGroup extends FlxTypedGroup<CharterEvent> {
public var eventsBackdrop:EventBackdrop;

public var autoSort:Bool = true;
var __lastSort:Int = 0;

public override function update(elapsed:Float) {
filterEvents();
if (length != __lastSort)
if (autoSort && members.length != __lastSort)
sortEvents();

super.update(elapsed);
}

public override function remove(v:CharterEvent, force:Bool = true):CharterEvent {
v.ID = -1;
return super.remove(v, force);
}

public override function draw() {
for (event in members) {
event.eventsBackdrop = eventsBackdrop;
Expand All @@ -24,12 +31,16 @@ class CharterEventGroup extends FlxTypedGroup<CharterEvent> {
}

public inline function sortEvents() {
__lastSort = length;
__lastSort = members.length;
this.sort(function(i, e1, e2) {
return FlxSort.byValues(FlxSort.ASCENDING, e1.step, e2.step);
});
updateEventsIDs();
}

public inline function updateEventsIDs()
for (i => n in members) n.ID = i;

public inline function filterEvents() {
for (event in members)
if (event.events.length == 0) {
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/editors/charter/CharterEventScreen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CharterEventScreen extends UISubstateWindow {
chartEvent.events = [for (i in eventsList.buttons.members) i.event];
chartEvent.refreshEventIcons();

Charter.instance.undos.addToUndo(CEditEvent(chartEvent, oldEvents, [for (event in events) Reflect.copy(event)]));
Charter.undos.addToUndo(CEditEvent(chartEvent, oldEvents, [for (event in events) Reflect.copy(event)]));
}
}

Expand Down
7 changes: 4 additions & 3 deletions source/funkin/editors/charter/CharterNote.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class CharterNote extends UISprite implements ICharterSelectable {

public function new() {
super();
antialiasing = true;

antialiasing = true; ID = -1;
loadGraphic(Paths.image('editors/charter/note'), true, 157, 154);
animation.add("note", [for(i in 0...frames.frames.length) i], 0, true);
animation.play("note");
Expand Down Expand Up @@ -58,9 +59,9 @@ class CharterNote extends UISprite implements ICharterSelectable {
public var type:Int;

public var strumLine:CharterStrumline;
public var strumLineID(get, never):Int;
public var strumLineID(get, default):Int = -1;
public function get_strumLineID():Int
return strumLine == null ? -1 : Charter.instance.strumLines.members.indexOf(strumLine);
return strumLineID = (strumLine == null ? strumLineID : Charter.instance.strumLines.members.indexOf(strumLine));

public var snappedToStrumline:Bool = true;

Expand Down
Loading

0 comments on commit f72a768

Please sign in to comment.