11// CODE WAS COMMENTED WITH BLACKBOX.AI (as i saw it commented everything right, but i'm not sure)
22
33import WebSocketManager from "./socket.js" ;
4+ import { generateColor , getRandomInt } from "./stackoverflow.js" ;
45
56let websocketUrl = "127.0.0.1:24050" ;
67const socket = new WebSocketManager ( websocketUrl ) ;
@@ -44,7 +45,7 @@ socket.commands((data) => {
4445 document . body . style . setProperty ( "--gradientColor2" , message . gradientColor2 ) ;
4546 document . body . style . setProperty ( "--dashedOutlineColor" , message . dashedOutlineColor ) ;
4647 document . body . style . setProperty ( "--activeKeyColor" , message . activeKeyColor ) ;
47- document . body . style . setProperty ( "--noteColor" , message . noteColor ) ;
48+ document . body . style . setProperty ( "--noteColor" , message . noteColor1 ) ;
4849 document . body . style . setProperty ( "--transitionDuration" , message . transitionDuration ) ;
4950 document . body . style . setProperty ( "--transitionTimingFunction" , message . transitionTimingFunction , ) ;
5051 document . body . style . setProperty ( "--trackWidth" , message . trackWidth ) ;
@@ -84,6 +85,19 @@ socket.commands((data) => {
8485 document . getElementById ( "trackK2" ) . parentElement . dataset . mode = message . visibilityK2 ;
8586 document . getElementById ( "trackM1" ) . parentElement . dataset . mode = message . visibilityM1 ;
8687 document . getElementById ( "trackM2" ) . parentElement . dataset . mode = message . visibilityM2 ;
88+
89+ window . startBpm = message . noteColoringRange . slice ( 0 , message . noteColoringRange . indexOf ( '-' ) )
90+ window . endBpm = message . noteColoringRange . slice ( message . noteColoringRange . indexOf ( '-' ) + 1 )
91+ window . steps = endBpm - startBpm
92+
93+ window . colors = [ message . noteColor1 ]
94+ colors = colors . concat ( generateColor ( message . noteColor2 , message . noteColor1 , steps ) )
95+
96+ window . shakePoint = message . noteShakingPoint
97+ window . shakeAmplitude = message . noteShakeAmplitude / 10000
98+
99+ window . noteShaking = message . noteShaking
100+ window . noteColoring = message . noteColoring
87101 }
88102 } catch ( error ) {
89103 console . log ( error ) ;
@@ -125,12 +139,11 @@ socket.api_v2_precise((data) => {
125139 note . style . width = "0px" ;
126140 note . style . marginRight = "0px" ;
127141
128- // Add the note to the track
129- document . getElementById ( `track${ _key } ` ) . prepend ( note ) ;
130-
131142 // Update the BPM display
143+ const bpm = Math . round ( ( 60 / ( Date . now ( ) - bpmCache [ _key ] . date ) ) * 500 )
144+
132145 document . getElementById ( `bpm${ _key } ` ) . innerHTML =
133- `${ Math . round ( ( 60 / ( Date . now ( ) - bpmCache [ _key ] . date ) ) * 500 ) } <span class="fs-small">bpm</span>` ;
146+ `${ bpm } <span class="fs-small">bpm</span>` ;
134147 bpmCache [ _key ] . date = Date . now ( ) ;
135148
136149 // Clear the BPM timeout and set a new one
@@ -139,6 +152,48 @@ socket.api_v2_precise((data) => {
139152 document . getElementById ( `bpm${ _key } ` ) . innerHTML =
140153 `0<span class="fs-small fw-regular">bpm</span>` ;
141154 } , 1000 ) ;
155+
156+ // Set bpm color if enabled
157+ if ( noteColoring ) {
158+ if ( bpm >= startBpm && bpm <= endBpm ) {
159+ note . style . backgroundColor = '#' + colors [ bpm - startBpm ]
160+ } else if ( bpm > endBpm ) {
161+ note . style . backgroundColor = '#' + colors [ steps ]
162+ }
163+ }
164+
165+ // Set shake if enabled
166+ if ( bpm >= shakePoint && noteShaking ) {
167+ let shakeCoords = [
168+ [ '2' , '1' , '0' ] ,
169+ [ '-1' , '-2' , '-1' ] ,
170+ [ '-3' , '0' , '1' ] ,
171+ [ '0' , '2' , '0' ] ,
172+ [ '1' , '-1' , '1' ] ,
173+ [ '-1' , '2' , '-1' ] ,
174+ [ '-3' , '1' , '0' ] ,
175+ [ '2' , '1' , '-1' ] ,
176+ [ '-1' , '-1' , '1' ] ,
177+ [ '0' , '0' , '0' ]
178+ ]
179+
180+ for ( let i = 0 ; i < 10 ; i ++ ) {
181+ setTimeout ( ( ) => {
182+ const firstCoord = shakeCoords [ getRandomInt ( 10 ) ] [ 0 ] * ( bpm - startBpm ) * shakeAmplitude
183+ const secondCoord = shakeCoords [ getRandomInt ( 10 ) ] [ 0 ] * ( bpm - startBpm ) * shakeAmplitude
184+ const thirdCoord = shakeCoords [ getRandomInt ( 10 ) ] [ 0 ] * ( bpm - startBpm ) * shakeAmplitude
185+
186+ document . getElementById ( `track${ _key } ` ) . style . transform =
187+ `translate(${ firstCoord } px, ${ secondCoord } px) rotate(${ thirdCoord } deg)`
188+ } , 50 * i ) ;
189+ setTimeout ( ( ) => {
190+ document . getElementById ( `track${ _key } ` ) . style . transform = null
191+ } , 500 )
192+ }
193+ }
194+
195+ // Add the note to the track
196+ document . getElementById ( `track${ _key } ` ) . prepend ( note ) ;
142197 } else {
143198 // Update the existing note element
144199 const notes = document
0 commit comments