Merge remote-tracking branch 'upstream/master' into patch-3

This commit is contained in:
Lucky56
2021-06-26 12:45:39 +02:00
33 changed files with 1167 additions and 437 deletions

View File

@ -1,12 +1,15 @@
package;
import openfl.ui.KeyLocation;
import openfl.events.Event;
import haxe.EnumTools;
import openfl.ui.Keyboard;
import openfl.events.KeyboardEvent;
import Replay.Ana;
import Replay.Analysis;
#if cpp
import webm.WebmPlayer;
#end
import flixel.input.keyboard.FlxKey;
import haxe.Exception;
import openfl.geom.Matrix;
@ -250,6 +253,8 @@ class PlayState extends MusicBeatState
}
misses = 0;
highestCombo = 0;
repPresses = 0;
repReleases = 0;
@ -996,7 +1001,7 @@ class PlayState extends MusicBeatState
add(healthBar);
// Add Kade Engine watermark
kadeEngineWatermark = new FlxText(4,healthBarBG.y + 50,0,SONG.song + " " + CoolUtil.difficultyFromInt(storyDifficulty) + (Main.watermarks ? " - KE " + MainMenuState.kadeEngineVer : ""), 16);
kadeEngineWatermark = new FlxText(4,healthBarBG.y + 50,0,SONG.song + " - " + CoolUtil.difficultyFromInt(storyDifficulty) + (Main.watermarks ? " | KE " + MainMenuState.kadeEngineVer : ""), 16);
kadeEngineWatermark.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, RIGHT, FlxTextBorderStyle.OUTLINE,FlxColor.BLACK);
kadeEngineWatermark.scrollFactor.set();
add(kadeEngineWatermark);
@ -1124,6 +1129,7 @@ class PlayState extends MusicBeatState
rep = new Replay("na");
FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN,handleInput);
FlxG.stage.addEventListener(KeyboardEvent.KEY_UP,releaseInput);
super.create();
}
@ -1353,24 +1359,94 @@ class PlayState extends MusicBeatState
var songTime:Float = 0;
private function getKey(charCode:Int):String
{
for (key => value in FlxKey.fromStringMap)
{
if (charCode == value)
return key;
}
return null;
}
var keys = [false,false,false,false];
private function releaseInput(evt:KeyboardEvent):Void // handles releases
{
@:privateAccess
var key = FlxKey.toStringMap.get(Keyboard.__convertKeyCode(evt.keyCode));
var binds:Array<String> = [FlxG.save.data.leftBind,FlxG.save.data.downBind, FlxG.save.data.upBind, FlxG.save.data.rightBind];
var data = -1;
switch(evt.keyCode) // arrow keys
{
case 37:
data = 0;
case 40:
data = 1;
case 38:
data = 2;
case 39:
data = 3;
}
for (i in 0...binds.length) // binds
{
if (binds[i].toLowerCase() == key.toLowerCase())
data = i;
}
if (data == -1)
return;
keys[data] = false;
}
private function handleInput(evt:KeyboardEvent):Void { // this actually handles press inputs
if (PlayStateChangeables.botPlay || loadRep || paused)
return;
var key = String.fromCharCode(evt.charCode);
// first convert it from openfl to a flixel key code
// then use FlxKey to get the key's name based off of the FlxKey dictionary
// this makes it work for special characters
@:privateAccess
var key = FlxKey.toStringMap.get(Keyboard.__convertKeyCode(evt.keyCode));
var binds:Array<String> = [FlxG.save.data.leftBind,FlxG.save.data.downBind, FlxG.save.data.upBind, FlxG.save.data.rightBind];
var data = -1;
switch(evt.keyCode) // arrow keys
{
case 37:
data = 0;
case 40:
data = 1;
case 38:
data = 2;
case 39:
data = 3;
}
for (i in 0...binds.length)
if (binds[i].toLowerCase() == key)
for (i in 0...binds.length) // binds
{
if (binds[i].toLowerCase() == key.toLowerCase())
data = i;
}
if (data == -1)
return;
if (keys[data])
{
return;
}
keys[data] = true;
var ana = new Ana(Conductor.songPosition, null, false, "miss", data);
var dataNotes = [];
@ -1382,7 +1458,7 @@ class PlayState extends MusicBeatState
dataNotes.sort((a, b) -> Std.int(a.strumTime - b.strumTime)); // sort by the earliest note
if (dataNotes.length != 0)
{
var coolNote = dataNotes[0];
@ -1555,6 +1631,18 @@ class PlayState extends MusicBeatState
swagNote.sustainLength = songNotes[2];
swagNote.scrollFactor.set(0, 0);
var addNote = false;
for (i in unspawnNotes)
if (i.strumTime == daStrumTime && i.noteData == daNoteData)
addNote = true;
if (addNote)
{
trace('stacked note, thats cringe');
continue;
}
var susLength:Float = swagNote.sustainLength;
susLength = susLength / Conductor.stepCrochet;
@ -1656,73 +1744,73 @@ class PlayState extends MusicBeatState
babyArrow.animation.add('confirm', [12, 16], 24, false);
}
case 'normal':
babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets');
babyArrow.animation.addByPrefix('green', 'arrowUP');
babyArrow.animation.addByPrefix('blue', 'arrowDOWN');
babyArrow.animation.addByPrefix('purple', 'arrowLEFT');
babyArrow.animation.addByPrefix('red', 'arrowRIGHT');
babyArrow.antialiasing = true;
babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7));
switch (Math.abs(i))
{
case 0:
babyArrow.x += Note.swagWidth * 0;
babyArrow.animation.addByPrefix('static', 'arrowLEFT');
babyArrow.animation.addByPrefix('pressed', 'left press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'left confirm', 24, false);
case 1:
babyArrow.x += Note.swagWidth * 1;
babyArrow.animation.addByPrefix('static', 'arrowDOWN');
babyArrow.animation.addByPrefix('pressed', 'down press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'down confirm', 24, false);
case 2:
babyArrow.x += Note.swagWidth * 2;
babyArrow.animation.addByPrefix('static', 'arrowUP');
babyArrow.animation.addByPrefix('pressed', 'up press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'up confirm', 24, false);
case 3:
babyArrow.x += Note.swagWidth * 3;
babyArrow.animation.addByPrefix('static', 'arrowRIGHT');
babyArrow.animation.addByPrefix('pressed', 'right press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'right confirm', 24, false);
}
case 'normal':
babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets');
babyArrow.animation.addByPrefix('green', 'arrow static instance 1');
babyArrow.animation.addByPrefix('blue', 'arrow static instance 2');
babyArrow.animation.addByPrefix('purple', 'arrow static instance 3');
babyArrow.animation.addByPrefix('red', 'arrow static instance 4');
default:
babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets');
babyArrow.animation.addByPrefix('green', 'arrowUP');
babyArrow.animation.addByPrefix('blue', 'arrowDOWN');
babyArrow.animation.addByPrefix('purple', 'arrowLEFT');
babyArrow.animation.addByPrefix('red', 'arrowRIGHT');
babyArrow.antialiasing = true;
babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7));
babyArrow.antialiasing = true;
babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7));
switch (Math.abs(i))
{
case 0:
babyArrow.x += Note.swagWidth * 0;
babyArrow.animation.addByPrefix('static', 'arrowLEFT');
babyArrow.animation.addByPrefix('pressed', 'left press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'left confirm', 24, false);
case 1:
babyArrow.x += Note.swagWidth * 1;
babyArrow.animation.addByPrefix('static', 'arrowDOWN');
babyArrow.animation.addByPrefix('pressed', 'down press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'down confirm', 24, false);
case 2:
babyArrow.x += Note.swagWidth * 2;
babyArrow.animation.addByPrefix('static', 'arrowUP');
babyArrow.animation.addByPrefix('pressed', 'up press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'up confirm', 24, false);
case 3:
babyArrow.x += Note.swagWidth * 3;
babyArrow.animation.addByPrefix('static', 'arrowRIGHT');
babyArrow.animation.addByPrefix('pressed', 'right press', 24, false);
babyArrow.animation.addByPrefix('confirm', 'right confirm', 24, false);
switch (Math.abs(i))
{
case 0:
babyArrow.x += Note.swagWidth * 0;
babyArrow.animation.addByPrefix('static', 'arrow static instance 1');
babyArrow.animation.addByPrefix('pressed', 'left press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'left confirm instance 1', 24, false);
case 1:
babyArrow.x += Note.swagWidth * 1;
babyArrow.animation.addByPrefix('static', 'arrow static instance 2');
babyArrow.animation.addByPrefix('pressed', 'down press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'down confirm instance 1', 24, false);
case 2:
babyArrow.x += Note.swagWidth * 2;
babyArrow.animation.addByPrefix('static', 'arrow static instance 4');
babyArrow.animation.addByPrefix('pressed', 'up press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'up confirm instance 1', 24, false);
case 3:
babyArrow.x += Note.swagWidth * 3;
babyArrow.animation.addByPrefix('static', 'arrow static instance 3');
babyArrow.animation.addByPrefix('pressed', 'right press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'right confirm instance 1', 24, false);
}
default:
babyArrow.frames = Paths.getSparrowAtlas('NOTE_assets');
babyArrow.animation.addByPrefix('green', 'arrow static instance 1');
babyArrow.animation.addByPrefix('blue', 'arrow static instance 2');
babyArrow.animation.addByPrefix('purple', 'arrow static instance 3');
babyArrow.animation.addByPrefix('red', 'arrow static instance 4');
babyArrow.antialiasing = true;
babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7));
switch (Math.abs(i))
{
case 0:
babyArrow.x += Note.swagWidth * 0;
babyArrow.animation.addByPrefix('static', 'arrow static instance 1');
babyArrow.animation.addByPrefix('pressed', 'left press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'left confirm instance 1', 24, false);
case 1:
babyArrow.x += Note.swagWidth * 1;
babyArrow.animation.addByPrefix('static', 'arrow static instance 2');
babyArrow.animation.addByPrefix('pressed', 'down press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'down confirm instance 1', 24, false);
case 2:
babyArrow.x += Note.swagWidth * 2;
babyArrow.animation.addByPrefix('static', 'arrow static instance 4');
babyArrow.animation.addByPrefix('pressed', 'up press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'up confirm instance 1', 24, false);
case 3:
babyArrow.x += Note.swagWidth * 3;
babyArrow.animation.addByPrefix('static', 'arrow static instance 3');
babyArrow.animation.addByPrefix('pressed', 'right press instance 1', 24, false);
babyArrow.animation.addByPrefix('confirm', 'right confirm instance 1', 24, false);
}
}
babyArrow.updateHitbox();
@ -1970,7 +2058,7 @@ class PlayState extends MusicBeatState
scoreTxt.x = (originalX - (lengthInPx / 2)) + 335;
if (FlxG.keys.justPressed.ENTER && startedCountdown && canPause)
if (controls.PAUSE && startedCountdown && canPause)
{
persistentUpdate = false;
persistentDraw = true;
@ -1986,6 +2074,7 @@ class PlayState extends MusicBeatState
openSubState(new PauseSubState(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y));
}
if (FlxG.keys.justPressed.SEVEN)
{
if (useVideo)
@ -2001,6 +2090,7 @@ class PlayState extends MusicBeatState
#end
FlxG.switchState(new ChartingState());
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN,handleInput);
FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP,releaseInput);
#if windows
if (luaModchart != null)
{
@ -2053,6 +2143,7 @@ class PlayState extends MusicBeatState
FlxG.switchState(new AnimationDebug(SONG.player2));
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN,handleInput);
FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP,releaseInput);
#if windows
if (luaModchart != null)
{
@ -2066,6 +2157,7 @@ class PlayState extends MusicBeatState
{
FlxG.switchState(new AnimationDebug(SONG.player1));
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN,handleInput);
FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP,releaseInput);
#if windows
if (luaModchart != null)
{
@ -2620,6 +2712,7 @@ class PlayState extends MusicBeatState
function endSong():Void
{
FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN,handleInput);
FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP,releaseInput);
if (useVideo)
{
GlobalVideo.get().stop();
@ -2817,7 +2910,7 @@ class PlayState extends MusicBeatState
ss = false;
shits++;
if (FlxG.save.data.accuracyMod == 0)
totalNotesHit += 0.25;
totalNotesHit -= 1;
case 'bad':
daRating = 'bad';
score = 0;
@ -3078,7 +3171,7 @@ class PlayState extends MusicBeatState
var rightHold:Bool = false;
var leftHold:Bool = false;
// THIS FUNCTION JUST FUCKS WIT HELD NOTES AND BOTPLAY/REPLAY
// THIS FUNCTION JUST FUCKS WIT HELD NOTES AND BOTPLAY/REPLAY (also gamepad shit)
private function keyShit():Void // I've invested in emma stocks
{
@ -3104,6 +3197,9 @@ class PlayState extends MusicBeatState
if (controls.RIGHT_P){luaModchart.executeState('keyPressed',["right"]);};
};
#end
var nonCpp = false;
// Prevent player input if botplay is on
if(PlayStateChangeables.botPlay)
@ -3113,11 +3209,15 @@ class PlayState extends MusicBeatState
releaseArray = [false, false, false, false];
}
#if !cpp
nonCpp = true;
#end
var anas:Array<Ana> = [null,null,null,null];
/*for (i in 0...pressArray.length)
for (i in 0...pressArray.length)
if (pressArray[i])
anas[i] = new Ana(Conductor.songPosition, null, false, "miss", i);*/
anas[i] = new Ana(Conductor.songPosition, null, false, "miss", i);
// HOLDS, check for sustain notes
if (holdArray.contains(true) && /*!boyfriend.stunned && */ generatedMusic)
@ -3129,103 +3229,98 @@ class PlayState extends MusicBeatState
});
}
// PRESSES, check for note hits
/*if (pressArray.contains(true) && generatedMusic)
if ((KeyBinds.gamepad && !FlxG.keys.justPressed.ANY) || nonCpp)
{
boyfriend.holdTimer = 0;
var possibleNotes:Array<Note> = []; // notes that can be hit
var directionList:Array<Int> = []; // directions that can be hit
var dumbNotes:Array<Note> = []; // notes to kill later
var directionsAccounted:Array<Bool> = [false,false,false,false]; // we don't want to do judgments for more than one presses
notes.forEachAlive(function(daNote:Note)
// PRESSES, check for note hits
if (pressArray.contains(true) && generatedMusic)
{
if (daNote.canBeHit && daNote.mustPress && !daNote.tooLate && !daNote.wasGoodHit)
{
if (!directionsAccounted[daNote.noteData])
boyfriend.holdTimer = 0;
var possibleNotes:Array<Note> = []; // notes that can be hit
var directionList:Array<Int> = []; // directions that can be hit
var dumbNotes:Array<Note> = []; // notes to kill later
var directionsAccounted:Array<Bool> = [false,false,false,false]; // we don't want to do judgments for more than one presses
notes.forEachAlive(function(daNote:Note)
{
if (directionList.contains(daNote.noteData))
{
directionsAccounted[daNote.noteData] = true;
for (coolNote in possibleNotes)
if (daNote.canBeHit && daNote.mustPress && !daNote.tooLate && !daNote.wasGoodHit && !directionsAccounted[daNote.noteData])
{
if (directionList.contains(daNote.noteData))
{
if (coolNote.noteData == daNote.noteData && Math.abs(daNote.strumTime - coolNote.strumTime) < 10)
{ // if it's the same note twice at < 10ms distance, just delete it
// EXCEPT u cant delete it in this loop cuz it fucks with the collection lol
dumbNotes.push(daNote);
break;
}
else if (coolNote.noteData == daNote.noteData && daNote.strumTime < coolNote.strumTime)
{ // if daNote is earlier than existing note (coolNote), replace
possibleNotes.remove(coolNote);
possibleNotes.push(daNote);
break;
directionsAccounted[daNote.noteData] = true;
for (coolNote in possibleNotes)
{
if (coolNote.noteData == daNote.noteData && Math.abs(daNote.strumTime - coolNote.strumTime) < 10)
{ // if it's the same note twice at < 10ms distance, just delete it
// EXCEPT u cant delete it in this loop cuz it fucks with the collection lol
dumbNotes.push(daNote);
break;
}
else if (coolNote.noteData == daNote.noteData && daNote.strumTime < coolNote.strumTime)
{ // if daNote is earlier than existing note (coolNote), replace
possibleNotes.remove(coolNote);
possibleNotes.push(daNote);
break;
}
}
}
}
else
{
possibleNotes.push(daNote);
directionList.push(daNote.noteData);
}
}
}
});
trace('notes that can be hit: ' + possibleNotes.length);
for (note in dumbNotes)
{
FlxG.log.add("killing dumb ass note at " + note.strumTime);
note.kill();
notes.remove(note, true);
note.destroy();
}
possibleNotes.sort((a, b) -> Std.int(a.strumTime - b.strumTime));
if (perfectMode)
goodNoteHit(possibleNotes[0]);
else if (possibleNotes.length > 0)
{
if (!FlxG.save.data.ghost)
{
for (shit in 0...pressArray.length)
{ // if a direction is hit that shouldn't be
if (pressArray[shit] && !directionList.contains(shit))
noteMiss(shit, null);
else
{
possibleNotes.push(daNote);
directionList.push(daNote.noteData);
}
}
}
for (coolNote in possibleNotes)
});
for (note in dumbNotes)
{
if (pressArray[coolNote.noteData])
FlxG.log.add("killing dumb ass note at " + note.strumTime);
note.kill();
notes.remove(note, true);
note.destroy();
}
possibleNotes.sort((a, b) -> Std.int(a.strumTime - b.strumTime));
if (perfectMode)
goodNoteHit(possibleNotes[0]);
else if (possibleNotes.length > 0)
{
if (!FlxG.save.data.ghost)
{
if (mashViolations != 0)
mashViolations--;
scoreTxt.color = FlxColor.WHITE;
var noteDiff:Float = -(coolNote.strumTime - Conductor.songPosition);
anas[coolNote.noteData].hit = true;
anas[coolNote.noteData].hitJudge = Ratings.CalculateRating(noteDiff, Math.floor((PlayStateChangeables.safeFrames / 60) * 1000));
anas[coolNote.noteData].nearestNote = [coolNote.strumTime,coolNote.noteData,coolNote.sustainLength];
goodNoteHit(coolNote);
for (shit in 0...pressArray.length)
{ // if a direction is hit that shouldn't be
if (pressArray[shit] && !directionList.contains(shit))
noteMiss(shit, null);
}
}
for (coolNote in possibleNotes)
{
if (pressArray[coolNote.noteData])
{
if (mashViolations != 0)
mashViolations--;
scoreTxt.color = FlxColor.WHITE;
var noteDiff:Float = -(coolNote.strumTime - Conductor.songPosition);
anas[coolNote.noteData].hit = true;
anas[coolNote.noteData].hitJudge = Ratings.CalculateRating(noteDiff, Math.floor((PlayStateChangeables.safeFrames / 60) * 1000));
anas[coolNote.noteData].nearestNote = [coolNote.strumTime,coolNote.noteData,coolNote.sustainLength];
goodNoteHit(coolNote);
}
}
}
else if (!FlxG.save.data.ghost)
{
for (shit in 0...pressArray.length)
if (pressArray[shit])
noteMiss(shit, null);
}
}
else if (!FlxG.save.data.ghost)
{
for (shit in 0...pressArray.length)
if (pressArray[shit])
noteMiss(shit, null);
}
}*/
/*if (!loadRep)
for (i in anas)
if (i != null)
replayAna.anaArray.push(i); // put em all there*/
if (!loadRep)
for (i in anas)
if (i != null)
replayAna.anaArray.push(i); // put em all there
}
notes.forEachAlive(function(daNote:Note)
{
if(PlayStateChangeables.useDownscroll && daNote.y > strumLine.y ||
@ -3331,6 +3426,7 @@ class PlayState extends MusicBeatState
public function backgroundVideo(source:String) // for background videos
{
#if cpp
useVideo = true;
FlxG.stage.window.onFocusOut.add(focusOut);
@ -3381,6 +3477,7 @@ class PlayState extends MusicBeatState
webmHandler.pause();
else
webmHandler.resume();
#end
}
function noteMiss(direction:Int = 1, daNote:Note):Void