@@ -3,6 +3,8 @@ import AbstractSubModule from "../AbstractSubModule";
3
3
import Ambilight from "../ambilight" ;
4
4
import ControllerManager from "../ControllerManager" ;
5
5
import Keypad from "../ControllerManager/Keypad" ;
6
+ import Timer from "../timer" ;
7
+ import TimerRunner from "../timer/TimerRunner" ;
6
8
7
9
const COMBAT_DURATION_TACTICAL_DISCUSSION = 60000 ; //ms
8
10
const COMBAT_DURATION_FORCED_DODGE = 7000 ; //ms
@@ -28,11 +30,7 @@ export default class CombatIndicator extends AbstractSubModule {
28
30
}
29
31
30
32
static get moduleDependencies ( ) {
31
- return [
32
- ...super . moduleDependencies ,
33
- ControllerManager . name ,
34
- AmbientLight . name ,
35
- ] ;
33
+ return [ ...super . moduleDependencies , ControllerManager . name , Timer . name ] ;
36
34
}
37
35
38
36
/**
@@ -43,10 +41,10 @@ export default class CombatIndicator extends AbstractSubModule {
43
41
}
44
42
45
43
/**
46
- * @returns {Ambilight }
44
+ * @returns {Timer }
47
45
*/
48
- get ambilight ( ) {
49
- return this . instance . modules [ Ambilight . name ] ;
46
+ get timer ( ) {
47
+ return this . instance . modules [ Timer . name ] ;
50
48
}
51
49
52
50
/**
@@ -119,61 +117,15 @@ export default class CombatIndicator extends AbstractSubModule {
119
117
}
120
118
}
121
119
}
122
- async #startTacticalTimer( updateCombatCallback , timeInMS ) {
123
- const totalLEDs = this . instance . settings . ambilight . led . count ;
124
- if ( this . #updateLEDsTimer !== null ) {
125
- window . clearInterval ( this . #updateLEDsTimer) ;
126
- }
127
- if ( totalLEDs <= 0 ) {
128
- window . setTimeout ( updateCombatCallback , timeInMS ) ;
129
- } else {
130
- this . ambilight . enabled = false ;
131
- this . #updateLEDsTimer = window . setInterval (
132
- this . #updateLEDs. bind ( this , updateCombatCallback ) ,
133
- Math . floor ( timeInMS / totalLEDs )
134
- ) ;
135
- this . #currentLED = 0 ;
136
- this . #updateLEDs( updateCombatCallback ) ;
137
- }
138
- }
139
120
140
- async #finishTacticalTimer( callback ) {
141
- this . ambilight . enabled = true ;
142
- window . clearInterval ( this . #updateLEDsTimer) ;
143
- this . #updateLEDsTimer = null ;
144
- callback ( ) ;
145
- }
146
-
147
- #updateLEDs( callback ) {
148
- const total = this . instance . settings . ambilight . led . count ;
149
- const totalValues = total * 3 ;
150
- const offset = this . instance . settings . ambilight . led . offset ;
151
- const minBright = this . instance . settings . ambilight . brightness . min ;
152
- const remaining = total - this . #currentLED;
153
- const completion = remaining / total ;
154
- const leds = [ ] ;
155
- let color ;
156
- this . #currentLED++ ;
157
- if ( completion > 2 / 3 ) {
158
- color = hexToRgb ( "#00FF00" ) ;
159
- } else if ( completion > 1 / 3 ) {
160
- color = hexToRgb ( "#FFFF00" ) ;
161
- } else if ( remaining <= 0 ) {
162
- return this . #finishTacticalTimer( callback ) ;
163
- } else {
164
- color = hexToRgb ( "#FF0000" ) ;
165
- }
166
- for ( let i = 0 ; i < total ; i ++ ) {
167
- if ( i < remaining ) {
168
- leds [ ( offset + i * 3 + 0 ) % totalValues ] = color . r ;
169
- leds [ ( offset + i * 3 + 1 ) % totalValues ] = color . g ;
170
- leds [ ( offset + i * 3 + 2 ) % totalValues ] = color . b ;
171
- } else {
172
- leds [ ( offset + i * 3 + 0 ) % totalValues ] = minBright ;
173
- leds [ ( offset + i * 3 + 1 ) % totalValues ] = minBright ;
174
- leds [ ( offset + i * 3 + 2 ) % totalValues ] = minBright ;
175
- }
176
- }
177
- this . ambilight . sendAmbilightData ( leds ) ;
121
+ async #startTacticalTimer( updateCombatCallback , timeInMS ) {
122
+ const start = new Date ( ) . valueOf ( ) ;
123
+ this . timer . addTimer ( {
124
+ start : start ,
125
+ end : start + timeInMS ,
126
+ options : {
127
+ onDone : updateCombatCallback ,
128
+ } ,
129
+ } ) ;
178
130
}
179
131
}
0 commit comments