Skip to content

Commit

Permalink
might do note coloring stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Joalor64GH authored Oct 19, 2024
1 parent a896eb8 commit 67f82d4
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 53 deletions.
1 change: 1 addition & 0 deletions source/backend/SaveData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<Int>> = [[221, 0, 255], [0, 128, 255], [0, 215, 54], [255, 0, 106]];
public var keyboardBinds:Array<FlxKey> = [LEFT, DOWN, UP, RIGHT, ENTER, ESCAPE, SPACE];
public var gamepadBinds:Array<FlxGamepadInputID> = [DPAD_LEFT, DPAD_DOWN, DPAD_UP, DPAD_RIGHT, A, B];
}
Expand Down
20 changes: 20 additions & 0 deletions source/backend/Utilities.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
57 changes: 57 additions & 0 deletions source/objects/ColorSwap.hx
Original file line number Diff line number Diff line change
@@ -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();
}
}
13 changes: 13 additions & 0 deletions source/objects/Note.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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() {
Expand Down
22 changes: 22 additions & 0 deletions source/objects/NoteColors.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package objects;

class NoteColors {
public static var noteColors:Array<Array<Int>> = SaveData.settings.notesRGB;

public static final defaultColors:Array<Array<Int>> = [
[221, 0, 255],
[0, 128, 255],
[0, 215, 54],
[255, 0, 106]
];

public static function setNoteColor(note:Int, color:Array<Int>):Void {
noteColors[note] = color;;
SaveData.settings.notesRGB[note] = color;
SaveData.saveSettings();
}

public static function getNoteColor(note:Int):Array<Int> {
return noteColors[note];
}
}
12 changes: 1 addition & 11 deletions source/objects/NoteSplash.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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";
}
}
}
30 changes: 5 additions & 25 deletions source/states/ChartingState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
24 changes: 7 additions & 17 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -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":
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 67f82d4

Please sign in to comment.