Skip to content

Commit

Permalink
oh look updated input system
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline committed Mar 30, 2024
1 parent 6952de5 commit 01d21e3
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 237 deletions.
1 change: 1 addition & 0 deletions source/objects/Note.hx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Note extends FlxSprite

public var strumTime:Float = 0;
public var noteData:Int = 0;
public var strumLine:Int = 0;

public var mustPress:Bool = false;
public var canBeHit:Bool = false;
Expand Down
240 changes: 119 additions & 121 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1398,10 +1398,10 @@ class PlayState extends MusicBeatState
notes = new FlxTypedGroup<Note>();
add(notes);

var noteData:Array<SwagSection>;
/*var noteData:Array<SwagSection>;
// NEW SHIT
noteData = songData.notes;
noteData = songData.notes;*/

var file:String = Paths.json(songName + '/events');
#if MODS_ALLOWED
Expand All @@ -1410,95 +1410,119 @@ class PlayState extends MusicBeatState
if(OpenFlAssets.exists(file)) {
#end
var eventsData:Array<Dynamic> = Song.loadFromJson('events', songName).events;
for (event in eventsData) //Event Notes
for (i in 0...event[1].length) makeEvent(event, i);
for (event in eventsData) for (i in 0...event[1].length) makeEvent(event, i); //Event Notes
}

for (section in noteData)
var ghostNotesCleared: Int = 0;
var noteDatas: Array<ChartNoteData> = [];

for (section in songData.notes)
{
for (songNotes in section.sectionNotes)
for (i in 0...section.sectionNotes.length)
{
var daStrumTime:Float = songNotes[0];
var daNoteData:Int = Std.int(songNotes[1] % 4);
var gottaHitNote:Bool = section.mustHitSection;

if(songNotes[1] > 3) gottaHitNote = !section.mustHitSection;

var oldNote:Note;
if(unspawnNotes.length > 0) oldNote = unspawnNotes[Std.int(unspawnNotes.length - 1)];
else oldNote = null;

var swagNote:Note = new Note(daStrumTime, daNoteData, oldNote);
swagNote.mustPress = gottaHitNote;
swagNote.sustainLength = songNotes[2];
swagNote.gfNote = (section.gfSection && (songNotes[1]<4));
swagNote.noteType = songNotes[3];
if(!Std.isOfType(songNotes[3], String)) swagNote.noteType = ChartingState.noteTypeList[songNotes[3]]; //Backward compatibility + compatibility with Week 7 charts

swagNote.scrollFactor.set();
final songNotes: Array<Dynamic> = section.sectionNotes[i];
if (songNotes[1] == -1)
continue;

unspawnNotes.push(swagNote);

final susLength:Float = swagNote.sustainLength / Conductor.stepCrochet;
final floorSus:Int = Math.floor(susLength);

if(floorSus > 0) {
for (susNote in 0...floorSus + 1)
var gottaHitNote:Bool = section.mustHitSection;
if (songNotes[1] > 3) gottaHitNote = !section.mustHitSection;

final leNoteData: ChartNoteData = {
time: songNotes[0],
id: Std.int(songNotes[1] % 4),
sLen: songNotes[2],
strumLine: gottaHitNote ? 1 : 0,
isGfNote: (section.gfSection && (songNotes[1]<4)),
type: songNotes[3]
};
if(!Std.isOfType(songNotes[3], String)) leNoteData.type = ChartingState.noteTypeList[songNotes[3]]; //Backwards compatibility + compatibility with Week 7/Funkin' Yarn charts and some other engines

if (i != 0) {
// CLEAR ANY POSSIBLE JACKS
for (evilNoteData in noteDatas) {
if (evilNoteData.id == leNoteData.id // does its direction match?
&& evilNoteData.strumLine == leNoteData.strumLine // does it strumline match?
&& Math.abs(evilNoteData.time - leNoteData.time) < 1.0) { // is it in the same step?
evilNoteData.dispose();
noteDatas.remove(evilNoteData);
ghostNotesCleared++;
//continue;
}
}
}
noteDatas.push(leNoteData);
}
}

for (i in 0...noteDatas.length) {
var oldNote:Note = null;
if (unspawnNotes.length > 0) oldNote = unspawnNotes[Std.int(unspawnNotes.length - 1)];

var swagNote:Note = new Note(noteDatas[i].time, noteDatas[i].id, oldNote);
swagNote.mustPress = noteDatas[i].strumLine == 1;
swagNote.sustainLength = noteDatas[i].sLen;
swagNote.strumLine = noteDatas[i].strumLine;
swagNote.gfNote = noteDatas[i].isGfNote;
swagNote.noteType = noteDatas[i].type;
swagNote.scrollFactor.set();
unspawnNotes.push(swagNote);

final susLength:Float = swagNote.sustainLength / Conductor.stepCrochet;
final floorSus:Int = Math.floor(susLength);

if(floorSus != 0) {
for (susNote in 0...floorSus + 1) {
oldNote = unspawnNotes[Std.int(unspawnNotes.length - 1)];

var sustainNote:Note = new Note(noteDatas[i].time + (Conductor.stepCrochet * susNote), noteDatas[i].id, oldNote, true);
sustainNote.mustPress = swagNote.mustPress;
sustainNote.gfNote = swagNote.gfNote;
sustainNote.strumLine = swagNote.strumLine;
sustainNote.noteType = swagNote.noteType;
sustainNote.scrollFactor.set();
sustainNote.parent = swagNote;
unspawnNotes.push(sustainNote);
swagNote.tail.push(sustainNote);

sustainNote.correctionOffset = swagNote.height / 2;
if(!PlayState.isPixelStage)
{
oldNote = unspawnNotes[Std.int(unspawnNotes.length - 1)];

var sustainNote:Note = new Note(daStrumTime + (Conductor.stepCrochet * susNote), daNoteData, oldNote, true);
sustainNote.mustPress = gottaHitNote;
sustainNote.gfNote = (section.gfSection && (songNotes[1]<4));
sustainNote.noteType = swagNote.noteType;
sustainNote.scrollFactor.set();
sustainNote.parent = swagNote;
unspawnNotes.push(sustainNote);
swagNote.tail.push(sustainNote);

sustainNote.correctionOffset = swagNote.height / 2;
if(!PlayState.isPixelStage)
if(oldNote.isSustainNote)
{
if(oldNote.isSustainNote)
{
oldNote.scale.y *= Note.SUSTAIN_SIZE / oldNote.frameHeight;
oldNote.scale.y /= playbackRate;
oldNote.updateHitbox();
}

if(ClientPrefs.data.downScroll) sustainNote.correctionOffset = 0;
}else if(oldNote.isSustainNote){
oldNote.scale.y *= Note.SUSTAIN_SIZE / oldNote.frameHeight;
oldNote.scale.y /= playbackRate;
oldNote.updateHitbox();
}

if (sustainNote.mustPress) sustainNote.x += FlxG.width / 2; // general offset
else if(ClientPrefs.data.middleScroll)
{
sustainNote.x += 310;
if(daNoteData > 1) //Up and Right
sustainNote.x += FlxG.width / 2 + 25;
}
if(ClientPrefs.data.downScroll) sustainNote.correctionOffset = 0;
}
else if(oldNote.isSustainNote) {
oldNote.scale.y /= playbackRate;
oldNote.updateHitbox();
}
}

if(swagNote.mustPress){
swagNote.x += FlxG.width / 2; // general offset
}else if(ClientPrefs.data.middleScroll){
swagNote.x += 310;
if(daNoteData > 1) //Up and Right
{
swagNote.x += FlxG.width / 2 + 25;
if (sustainNote.mustPress) sustainNote.x += FlxG.width / 2; // general offset
else if(ClientPrefs.data.middleScroll) {
sustainNote.x += 310;
if (noteDatas[i].id > 1) sustainNote.x += FlxG.width / 2 + 25; //Up and Right
}
}
}

if(!noteTypes.contains(swagNote.noteType)) noteTypes.push(swagNote.noteType);
if (swagNote.mustPress) swagNote.x += FlxG.width / 2; // general offset
else if(ClientPrefs.data.middleScroll)
{
swagNote.x += 310;
if (noteDatas[i].id > 1) swagNote.x += FlxG.width / 2 + 25; //Up and Right
}

if (!noteTypes.contains(swagNote.noteType)) noteTypes.push(swagNote.noteType);
}
for (event in songData.events) //Event Notes
for (i in 0...event[1].length) makeEvent(event, i);

trace('["${SONG.song.toUpperCase()}" CHART INFO]: Ghost Notes Cleared: $ghostNotesCleared');
unspawnNotes.sort(sortByTime);

generatedMusic = true;
}

Expand Down Expand Up @@ -2763,51 +2787,38 @@ class PlayState extends MusicBeatState

private function keyPressed(key:Int)
{
if(cpuControlled || paused || inCutscene || key < 0 || key >= playerStrums.length || !generatedMusic || endingSong || boyfriend.stunned) return;
if(cpuControlled || paused || inCutscene || key < 0 || key > playerStrums.length || !generatedMusic || endingSong || boyfriend.stunned) return;

var ret:Dynamic = callOnScripts('onKeyPressPre', [key]);
if(ret == FunkinLua.Function_Stop) return;

if(ret == LuaUtils.Function_Stop) return;
// more accurate hit time for the ratings?
var lastTime:Float = Conductor.songPosition;
if(Conductor.songPosition >= 0) Conductor.songPosition = FlxG.sound.music.time;

// obtain notes that the player can hit
var plrInputNotes:Array<Note> = notes.members.filter(function(n:Note):Bool {
var canHit:Bool = !strumsBlocked[n.noteData] && n.canBeHit && n.mustPress && !n.tooLate && !n.wasGoodHit && !n.blockHit;
return n != null && canHit && !n.isSustainNote && n.noteData == key;
final plrInputNotes:Array<Note> = notes.members.filter(function(n:Note):Bool {
final noteIsHittable:Bool = strumsBlocked[n.noteData] == false && n.canBeHit && n.mustPress && !n.tooLate && !n.wasGoodHit && !n.blockHit;
return n != null && noteIsHittable && !n.isSustainNote && n.noteData == key;
});
plrInputNotes.sort(sortHitNotes);
shouldMiss = !ClientPrefs.data.ghostTapping;
if (plrInputNotes.length != 0) { // slightly faster than doing `> 0` lol
var funnyNote:Note = plrInputNotes[0]; // front note
// trace('✡⚐🕆☼ 💣⚐💣');
if (plrInputNotes.length > 1) {
var doubleNote:Note = plrInputNotes[1];
if (doubleNote.noteData == funnyNote.noteData) {
// if the note has a 0ms distance (is on top of the current note), kill it
if (Math.abs(doubleNote.strumTime - funnyNote.strumTime) < 1.0)
invalidateNote(doubleNote);
else if (doubleNote.strumTime < funnyNote.strumTime)
{
// replace the note if its ahead of time (or at least ensure "doubleNote" is ahead)
funnyNote = doubleNote;
}
}
}

final shouldMiss:Bool = !ClientPrefs.data.ghostTapping;
if (plrInputNotes.length != 0) { // nicer on the GPU usage than doing `> 0` lol
final funnyNote:Note = plrInputNotes[0]; // front note
goodNoteHit(funnyNote);
}
else if(shouldMiss)
{
callOnScripts('onGhostTap', [key]);
noteMissPress(key);
}

// Needed for the "Just the Two of Us" achievement.
// - Shadow Mario
if(!keysPressed.contains(key)) keysPressed.push(key);
//more accurate hit time for the ratings? part 2 (Now that the calculations are done, go back to the time it was before for not causing a note stutter)
Conductor.songPosition = lastTime;
var spr:StrumNote = playerStrums.members[key];

final spr:StrumNote = playerStrums.members[key];
if(strumsBlocked[key] != true && spr != null && spr.animation.curAnim.name != 'confirm')
{
spr.playAnim('pressed');
Expand Down Expand Up @@ -2935,15 +2946,13 @@ class PlayState extends MusicBeatState

function noteMissCommon(direction:Int, note:Note = null)
{
if(shakeOnMiss) FlxG.camera.shake(0.0075, 0.1, null, true, X);

// score and data
var subtract:Float = 0.05;
if(note != null) subtract = note.missHealth;
if (note != null) subtract = note.missHealth;

// GUITAR HERO SUSTAIN CHECK LOL!!!!
if (note != null && guitarHeroSustains && note.parent == null) {
if(note.tail.length > 0) {
if(note.tail.length != 0) {
note.alpha = 0.35;
for(childNote in note.tail) {
childNote.alpha = note.alpha;
Expand All @@ -2954,22 +2963,18 @@ class PlayState extends MusicBeatState
}
note.missed = true;
note.canBeHit = false;

//subtract += 0.385; // you take more damage if playing with this gameplay changer enabled.
// i mean its fair :p -Crow
// i mean its fair :P -Crow
subtract *= note.tail.length + 1;
// i think it would be fair if damage multiplied based on how long the sustain is -Tahir
}

if (note.missed)
return;
if (note.missed) return;
}
if (note != null && guitarHeroSustains && note.parent != null && note.isSustainNote) {
if (note.missed)
return;
if (note.missed) return;

var parentNote:Note = note.parent;
if (parentNote.wasGoodHit && parentNote.tail.length > 0) {
if (parentNote.wasGoodHit && parentNote.tail.length != 0) {
for (child in parentNote.tail) if (child != note) {
child.missed = true;
child.canBeHit = false;
Expand All @@ -2978,35 +2983,28 @@ class PlayState extends MusicBeatState
}
}
}

if(instakillOnMiss)
{
vocals.volume = 0;
opponentVocals.volume = 0;
doDeathCheck(true);
}

var lastCombo:Int = combo;
combo = 0;

health -= subtract * healthLoss;
if(!practiceMode) songScore -= 10;
if(!endingSong) songMisses++;
totalPlayed++;
RecalculateRating(true);

// play character anims
var char:Character = boyfriend;
if((note != null && note.gfNote) || (SONG.notes[curSection] != null && SONG.notes[curSection].gfSection)) char = gf;

if(char != null && (note == null || !note.noMissAnimation) && char.hasMissAnimations)
{
var suffix:String = '';
if(note != null) suffix = note.animSuffix;

var animToPlay:String = singAnimations[Std.int(Math.abs(Math.min(singAnimations.length-1, direction)))] + 'miss' + suffix;
var postfix:String = '';
if(note != null) postfix = note.animSuffix;
var animToPlay:String = singAnimations[Std.int(Math.abs(Math.min(singAnimations.length-1, direction)))] + 'miss' + postfix;
char.playAnim(animToPlay, true);

if(char != gf && lastCombo > 5 && gf != null && gf.animOffsets.exists('sad'))
{
gf.playAnim('sad');
Expand Down Expand Up @@ -3564,10 +3562,10 @@ class PlayState extends MusicBeatState

function fullComboUpdate()
{
var sicks:Int = ratingsData[0].hits;
var goods:Int = ratingsData[1].hits;
var bads:Int = ratingsData[2].hits;
var shits:Int = ratingsData[3].hits;
final sicks:Int = ratingsData[0].hits;
final goods:Int = ratingsData[1].hits;
final bads:Int = ratingsData[2].hits;
final shits:Int = ratingsData[3].hits;

ratingFC = 'Clear';
if(songMisses < 1){
Expand Down
Loading

0 comments on commit 01d21e3

Please sign in to comment.