diff --git a/source/backend/SaveData.hx b/source/backend/SaveData.hx index 2de2a77..18c3cd4 100644 --- a/source/backend/SaveData.hx +++ b/source/backend/SaveData.hx @@ -22,6 +22,7 @@ package backend; public var antiMash:Bool = false; public var displayMS:Bool = false; public var smoothScore:Bool = false; + public var notesRGB:Array> = [[221, 0, 255], [0, 128, 255], [0, 215, 54], [255, 0, 106]]; public var keyboardBinds:Array = [LEFT, DOWN, UP, RIGHT, ENTER, ESCAPE, SPACE]; public var gamepadBinds:Array = [DPAD_LEFT, DPAD_DOWN, DPAD_UP, DPAD_RIGHT, A, B]; } diff --git a/source/backend/Utilities.hx b/source/backend/Utilities.hx index a0fb76a..f15f6ff 100644 --- a/source/backend/Utilities.hx +++ b/source/backend/Utilities.hx @@ -31,4 +31,24 @@ class Utilities { num = Math.round(num) / Math.pow(10, precision); return num; } + + public static function getDirection(index:Int):String { + return switch (index) { + case 0: "left"; + case 1: "down"; + case 2: "up"; + case 3: "right"; + default: "unknown"; + } + } + + public static function getNoteIndex(direction:String):Int { + return switch (direction) { + case "left": 0; + case "down": 1; + case "up": 2; + case "right": 3; + default: -1; + } + } } \ No newline at end of file diff --git a/source/objects/ColorSwap.hx b/source/objects/ColorSwap.hx new file mode 100644 index 0000000..0e9aac3 --- /dev/null +++ b/source/objects/ColorSwap.hx @@ -0,0 +1,57 @@ +package objects; + +import flixel.system.FlxAssets.FlxShader; + +class ColorSwap { + public var shader(default, null):ColorSwapShader = new ColorSwapShader(); + public var r(default, set):Float = 255; + public var g(default, set):Float = 0; + public var b(default, set):Float = 0; + + private function set_r(value:Float) { + r = value; + shader.red.value = [r/255]; + return r; + } + + private function set_g(value:Float) { + g = value; + shader.green.value = [g/255]; + return g; + } + + private function set_b(value:Float) { + b = value; + shader.blue.value = [b/255]; + return b; + } + + public function new() { + r = 255/255; + g = 0/255; + b = 0/255; + } +} + +class ColorSwapShader extends FlxShader { + @:glFragmentSource(' + #pragma header + + uniform float red; + uniform float green; + uniform float blue; + + void main() { + + vec4 col = flixel_texture2D(bitmap, openfl_TextureCoordv); + + // Get difference to use for falloff if required + float diff = col.r - ((col.g + col.b) / 2.0); + + gl_FragColor = vec4(((col.g + col.b) / 2.0) + (red * diff), col.g + (green * diff), col.b + (blue * diff), col.a); + } + ') + public function new() { + super(); + } +} \ No newline at end of file diff --git a/source/objects/Note.hx b/source/objects/Note.hx index 5bec20f..0e3cedf 100644 --- a/source/objects/Note.hx +++ b/source/objects/Note.hx @@ -15,6 +15,8 @@ class Note extends GameSprite { public var strum:Float = 0.0; + public var colorSwap:ColorSwap; + public function new(x:Float, y:Float, dir:String, type:String) { super(x, y); @@ -29,6 +31,17 @@ class Note extends GameSprite { animation.add("receptor", [2], 1); animation.play((type == 'receptor') ? "receptor" : "note"); + + colorSwap = new ColorSwap(); + shader = colorSwap.shader; + + var noteColor = NoteColors.getNoteColor(Utilities.getNoteIndex(dir)); + + if (colorSwap != null && noteColor != null) { + colorSwap.r = noteColor[0]; + colorSwap.g = noteColor[1]; + colorSwap.b = noteColor[2]; + } } public function press() { diff --git a/source/objects/NoteColors.hx b/source/objects/NoteColors.hx new file mode 100644 index 0000000..fd8b35b --- /dev/null +++ b/source/objects/NoteColors.hx @@ -0,0 +1,22 @@ +package objects; + +class NoteColors { + public static var noteColors:Array> = SaveData.settings.notesRGB; + + public static final defaultColors:Array> = [ + [221, 0, 255], + [0, 128, 255], + [0, 215, 54], + [255, 0, 106] + ]; + + public static function setNoteColor(note:Int, color:Array):Void { + noteColors[note] = color;; + SaveData.settings.notesRGB[note] = color; + SaveData.saveSettings(); + } + + public static function getNoteColor(note:Int):Array { + return noteColors[note]; + } +} \ No newline at end of file diff --git a/source/objects/NoteSplash.hx b/source/objects/NoteSplash.hx index bc9a96d..e9d46a1 100644 --- a/source/objects/NoteSplash.hx +++ b/source/objects/NoteSplash.hx @@ -4,7 +4,7 @@ class NoteSplash extends GameSprite { public function setupSplash(x:Float = 0, y:Float = 0, noteData:Int = 0) { setPosition(x, y); - loadGraphic(Paths.image('gameplay/splash_${getDirection(noteData)}'), true, 200, 200); + loadGraphic(Paths.image('gameplay/splash_${Utilities.getDirection(noteData)}'), true, 200, 200); scale.set(0.6, 0.6); alpha = 0.6; @@ -24,14 +24,4 @@ class NoteSplash extends GameSprite { super.update(elapsed); } - - function getDirection(index:Int):String { - return switch (index) { - case 0: "left"; - case 1: "down"; - case 2: "up"; - case 3: "right"; - default: "unknown"; - } - } } \ No newline at end of file diff --git a/source/states/ChartingState.hx b/source/states/ChartingState.hx index 13f0b45..debd612 100644 --- a/source/states/ChartingState.hx +++ b/source/states/ChartingState.hx @@ -243,7 +243,7 @@ class ChartingState extends UIState { && (Math.floor((gridBG.x + FlxG.mouse.x / gridSize) - 2)) == note.rawNoteData && coolNess) { coolNess = false; - if (FlxG.keys.pressed.CONTROL) + if (Input.pressed('control')) selectNote(note); else { trace("trying to delete note"); @@ -315,7 +315,7 @@ class ChartingState extends UIState { function deleteNote(note:Note):Void { for (sectionNote in song.notes[curSection].sectionNotes) - if (sectionNote.noteStrum == note.strum && sectionNote.noteData % 4 == getNoteIndex(note.dir)) + if (sectionNote.noteStrum == note.strum && sectionNote.noteData % 4 == Utilities.getNoteIndex(note.dir)) song.notes[curSection].sectionNotes.remove(sectionNote); updateGrid(); @@ -325,7 +325,7 @@ class ChartingState extends UIState { var swagNum:Int = 0; for (sectionNote in song.notes[curSection].sectionNotes) { - if (sectionNote.noteStrum == note.strum && sectionNote.noteData % 4 == getNoteIndex(note.dir)) { + if (sectionNote.noteStrum == note.strum && sectionNote.noteData % 4 == Utilities.getNoteIndex(note.dir)) { curSelectedNote = sectionNote; } @@ -344,7 +344,7 @@ class ChartingState extends UIState { renderedNotes.clear(); for (sectionNote in song.notes[curSection].sectionNotes) { - var direction:String = getDirection(sectionNote.noteData % 4); + var direction:String = Utilities.getDirection(sectionNote.noteData % 4); var note:Note = new Note(0, 0, direction, "note"); note.setGraphicSize(gridSize, gridSize); @@ -459,31 +459,11 @@ class ChartingState extends UIState { return daPos; } - function loadJson(song:String):Void { // will be used in later update + function loadJson(song:String):Void { PlayState.song = Song.loadSongfromJson(Paths.formatToSongPath(song)); ExtendableState.resetState(); } - function getDirection(index:Int):String { - return switch (index) { - case 0: "left"; - case 1: "down"; - case 2: "up"; - case 3: "right"; - default: "unknown"; - } - } - - function getNoteIndex(direction:String):Int { - return switch (direction) { - case "left": 0; - case "down": 1; - case "up": 2; - case "right": 3; - default: -1; - } - } - function undo() { undos.pop(); } diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index acfc7e8..93a3b21 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -310,7 +310,7 @@ class PlayState extends ExtendableState { } for (note in notes) { - var strum = strumline.members[getNoteIndex(note.dir)]; + var strum = strumline.members[Utilities.getNoteIndex(note.dir)]; if (SaveData.settings.downScroll) note.y = strum.y + (0.45 * (Conductor.songPosition - note.strum) * FlxMath.roundDecimal(speed, 2)); @@ -456,7 +456,7 @@ class PlayState extends ExtendableState { for (i in 0...possibleNotes.length) { var note = possibleNotes[i]; - if ((justPressed[getNoteIndex(note.dir)] && !doNotHit[getNoteIndex(note.dir)] && !SaveData.settings.botPlay) + if ((justPressed[Utilities.getNoteIndex(note.dir)] && !doNotHit[Utilities.getNoteIndex(note.dir)] && !SaveData.settings.botPlay) || SaveData.settings.botPlay) { if (SaveData.settings.hitSoundVolume > 0) FlxG.sound.play(Paths.sound('hitsound'), SaveData.settings.hitSoundVolume / 100); @@ -480,10 +480,10 @@ class PlayState extends ExtendableState { if (Math.abs(noteMs) > 135) curRating = 'no'; - noteDataTimes[getNoteIndex(note.dir)] = note.strum; - doNotHit[getNoteIndex(note.dir)] = true; + noteDataTimes[Utilities.getNoteIndex(note.dir)] = note.strum; + doNotHit[Utilities.getNoteIndex(note.dir)] = true; - strumline.members[getNoteIndex(note.dir)].press(); + strumline.members[Utilities.getNoteIndex(note.dir)].press(); switch (curRating) { case "perfect" | "perfect-golden": @@ -505,7 +505,7 @@ class PlayState extends ExtendableState { if (curRating == 'perfect' || curRating == 'perfect-golden') { var splash:NoteSplash = noteSplashes.recycle(NoteSplash); - splash.setupSplash(note.x, note.y, getNoteIndex(note.dir)); + splash.setupSplash(note.x, note.y, Utilities.getNoteIndex(note.dir)); noteSplashes.add(splash); } @@ -568,7 +568,7 @@ class PlayState extends ExtendableState { for (i in 0...possibleNotes.length) { var note = possibleNotes[i]; - if (note.strum == noteDataTimes[getNoteIndex(note.dir)] && doNotHit[getNoteIndex(note.dir)]) { + if (note.strum == noteDataTimes[Utilities.getNoteIndex(note.dir)] && doNotHit[Utilities.getNoteIndex(note.dir)]) { note.active = false; notes.remove(note); note.kill(); @@ -663,16 +663,6 @@ class PlayState extends ExtendableState { function sortStuff(Obj1:Note, Obj2:Note):Int return FlxSort.byValues(FlxSort.ASCENDING, Obj1.strum, Obj2.strum); - function getNoteIndex(direction:String):Int { - return switch (direction) { - case "left": 0; - case "down": 1; - case "up": 2; - case "right": 3; - default: -1; - } - } - function msToTimestamp(ms:Float) { var seconds = Math.round(ms) / 1000; var minutesLeft = Std.string(seconds / 60).split(".")[0];