Skip to content

Commit

Permalink
lil char select substate cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 27, 2024
1 parent d18a1d2 commit cfce0c3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 41 deletions.
15 changes: 6 additions & 9 deletions source/funkin/objects/NotesGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ class NotesGroup extends Group
unspawnNotes.sort((a:BasicNote, b:BasicNote) -> return FlxSort.byValues(FlxSort.ASCENDING, a.strumTime, b.strumTime));
events.sort((a:Event, b:Event) -> return FlxSort.byValues(FlxSort.ASCENDING, a.strumTime, b.strumTime));

curSpawnNote = unspawnNotes[0];
curCheckEvent = events[0];
curSpawnNote = unspawnNotes.shift();
curCheckEvent = events.shift();

if (isPlayState)
{
Expand Down Expand Up @@ -383,7 +383,7 @@ class NotesGroup extends Group
}
}

public var curSpawnNote(default, null):BasicNote = null;
public var curSpawnNote(default, null):BasicNote;

inline function spawnNotes():Void { // Generate notes
if (curSpawnNote != null) {
Expand All @@ -397,21 +397,18 @@ class NotesGroup extends Group

// Skip sorting
curSpawnNote.isSustainNote ? notes.insertBelow(curSpawnNote) : notes.insertTop(curSpawnNote);

unspawnNotes.splice(0, 1);
curSpawnNote = unspawnNotes[0];
curSpawnNote = unspawnNotes.shift();
}
}
}

public var curCheckEvent(default, null):Event = null;
public var curCheckEvent(default, null):Event;

inline function checkEvents():Void {
if (curCheckEvent != null) {
while (events.length > 0 && curCheckEvent.strumTime <= Conductor.songPosition) {
ModdingUtil.addCall('eventHit', [curCheckEvent]);
events.splice(0, 1);
curCheckEvent = events[0];
curCheckEvent = events.shift();
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions source/funkin/states/OutdatedState.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package funkin.states;
class OutdatedState extends MusicBeatState {

class OutdatedState extends MusicBeatState
{
public static var leftState:Bool = false;
public static var newVer:EngineVersion = null;
public static var newVer:EngineVersion;

override function create():Void {
super.create();

if (newVer == null) {
leftState = true;
SplashState.startGame();
return;
}

CoolUtil.playMusic('breakfast', 0.6);
var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK);
add(bg);
Expand Down
67 changes: 40 additions & 27 deletions source/funkin/substates/CharSelectSubstate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class CharSelectSubstate extends MusicBeatSubstate
var selectFunction:Void->Void = null;

var curFolder:Int = 0;
var curSelected:Array<Int> = [0,0];
var iconArray:Array<Array<HealthIcon>> = [[],[]];
var charArray:Array<Array<MenuAlphabet>> = [[],[]];
var curSelected:Array<Int> = [];
var iconArray:Array<Array<HealthIcon>> = [];
var charArray:Array<Array<MenuAlphabet>> = [];
var folderTxt:Alphabet;

var textGroup:TypedGroup<MenuAlphabet>;

public function new(?selectFunction:Void->Void):Void {
super();
this.selectFunction = selectFunction;
Expand All @@ -32,25 +34,33 @@ class CharSelectSubstate extends MusicBeatSubstate

var listsToAdd:Array<Array<String>> = [vanillaChars, modChars];

for (f in 0...listsToAdd.length) {
for (i in 0...listsToAdd[f].length) {
var list = listsToAdd[f];
var charText:MenuAlphabet = new MenuAlphabet(5, (70 * i) + 30, list[i], true, i);
textGroup = new TypedGroup<MenuAlphabet>();
add(textGroup);

listsToAdd.fastForEach((folder, f) ->
{
iconArray.push([]);
charArray.push([]);
curSelected.push(0);

folder.fastForEach((item, i) -> {
var charText:MenuAlphabet = new MenuAlphabet(5, (70 * i) + 30, item, true, i);
charText.scrollFactor.set();
charText.forceX = false;
charText.snapPosition();
add(charText);
textGroup.add(charText);

var iconName:String = Character.getCharData(list[i]).icon;
var iconName:String = Character.getCharData(item).icon;
var charIcon:HealthIcon = new HealthIcon(iconName);
charIcon.scrollFactor.set();
charIcon.sprTracker = charText;
add(charIcon);

iconArray[f].push(charIcon);
charArray[f].push(charText);
}
}
iconArray.unsafeGet(f).push(charIcon);
charArray.unsafeGet(f).push(charText);
});
});

changeFolder();
add(folderTxt);
cameras = [CoolUtil.getTopCam()];
Expand Down Expand Up @@ -84,27 +94,30 @@ class CharSelectSubstate extends MusicBeatSubstate
}

folderTxt.x = FlxG.width - folderTxt.width - 10;
for (f in 0...charArray.length) {
var showBool:Bool = (f == curFolder);
for (i in 0...charArray[f].length) {
charArray[f][i].visible = showBool;
iconArray[f][i].visible = showBool;

charArray.fastForEach((folder, f) -> {
var show = (f == curFolder);
for (i in 0...folder.length) {
folder[i].visible = show;
iconArray[f][i].visible = show;
}
}
});

changeSelection();
}

function changeSelection(change:Int = 0):Void {
if (charArray[curFolder].length <= 0) return;
function changeSelection(change:Int = 0):Void
{
if (charArray[curFolder].length <= 0)
return;

curSelected[curFolder] = FlxMath.wrap(curSelected[curFolder] + change, 0, charArray[curFolder].length - 1);
if (change != 0) CoolUtil.playSound('scrollMenu', 0.4);

for (i in 0...charArray[curFolder].length) {
charArray[curFolder][i].targetY = i - curSelected[curFolder];
charArray[curFolder][i].alpha = (charArray[curFolder][i].targetY == 0) ? 1 : 0.6;
iconArray[curFolder][i].alpha = charArray[curFolder][i].alpha;
}
charArray[curFolder].fastForEach((item, i) -> {
item.targetY = i - curSelected[curFolder];
item.alpha = (item.targetY == 0) ? 1 : 0.6;
iconArray[curFolder][i].alpha = item.alpha;
});
}
}
4 changes: 2 additions & 2 deletions source/funkin/util/song/WeekSetup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class WeekSetup
weeks = weeks.concat(modWeeks.map(week -> Paths.getFileMod(week)[1]));
weeks = CoolUtil.removeDuplicates(weeks);

weekList.splice(0, weekList.length);
vanillaWeekList.splice(0, vanillaWeekList.length);
weekList.clear();
vanillaWeekList.clear();
weekMap.clear();

final modMap:Map<String, String> = [];
Expand Down
11 changes: 10 additions & 1 deletion source/macros/FastArray.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ macro function fastForEach(iterableExpr: Expr, callbackExpr: Expr) {
@:unreflective
class FastArray<T>
{
// Keeping this if i find a better method later down the line
inline public static function unsafeGet<T>(array:Array<T>, index:Int):T {
#if cpp
return cpp.NativeArray.unsafeGet(array, index);
return untyped array.__unsafe_get(index);
#else
return array[index];
#end
Expand All @@ -64,4 +65,12 @@ class FastArray<T>
array.splice(0, array.length); // Splice is faster on html5 for whatever reason
#end
}

inline public static function removeAt<T>(array:Array<T>, index:Int) {
#if cpp
cpp.NativeArray.removeAt(array, index);
#else
array.splice(index, 1);
#end
}
}

0 comments on commit cfce0c3

Please sign in to comment.