-
Notifications
You must be signed in to change notification settings - Fork 8
/
LayerSample.html
350 lines (296 loc) · 10.5 KB
/
LayerSample.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<html>
<head>
<style>
.divBox {
display: inline-table;
border:1px solid #000;
margin: 0.25em;
padding: 0.75em;
vertical-align: top;
}
.divColor {
display: inline-table;
border:1px solid #000;
background-color: #DDD;
margin: 0.1em;
padding: 0.25em;
vertical-align: center;
}
.divText {
display: inline-table;
padding-top: 0.5em;
vertical-align: top;
}
</style>
<script src="ChromaSDKImpl.js"></script>
<script>
var chromaSDK = undefined;
var initialized = false;
var buttonHeal = undefined;
var buttonDamage = undefined;
var buttonItemPickup = undefined;
var baseIntensity = undefined;
var effectIntensity = undefined;
var hotkeyIntensity = undefined;
var selectedAnimation = 0;
function chromaSetStaticColor(color) {
if (!initialized) {
console.log('chromaSetStaticColor', 'not initialized!');
return;
}
ChromaAnimation.staticColor(EChromaSDKDeviceEnum.DE_ChromaLink, color);
ChromaAnimation.staticColor(EChromaSDKDeviceEnum.DE_Headset, color);
ChromaAnimation.staticColor(EChromaSDKDeviceEnum.DE_Keyboard, color);
ChromaAnimation.staticColor(EChromaSDKDeviceEnum.DE_Keypad, color);
ChromaAnimation.staticColor(EChromaSDKDeviceEnum.DE_Mouse, color);
ChromaAnimation.staticColor(EChromaSDKDeviceEnum.DE_Mousepad, color);
}
function onPageLoad() {
chromaSDK = new ChromaSDK();
chromaSDK.init();
setTimeout(function() {
initialized = true;
var white = 0xFFFFFF;
chromaSetStaticColor(white);
}, 150);
}
function validateControls() {
buttonHeal = document.getElementById('buttonHeal');
if (buttonHeal == undefined) {
return false;
}
buttonDamage = document.getElementById('buttonDamage');
if (buttonDamage == undefined) {
return false;
}
buttonItemPickup = document.getElementById('buttonItemPickup');
if (buttonItemPickup == undefined) {
return false;
}
baseIntensity = document.getElementById('baseIntensity');
if (baseIntensity == undefined) {
return false;
}
effectIntensity = document.getElementById('effectIntensity');
if (effectIntensity == undefined) {
return false;
}
hotkeyIntensity = document.getElementById('hotkeyIntensity');
if (hotkeyIntensity == undefined) {
return false;
}
return true;
}
function addControlEvents() {
if (validateControls() == false) {
return;
}
buttonHeal.onclick = function() {
selectedAnimation = 0;
heal();
}
buttonDamage.onclick = function() {
selectedAnimation = 1;
damage();
}
buttonItemPickup.onclick = function() {
selectedAnimation = 2;
itemPickup();
}
baseIntensity.onchange = function() {
divBaseIntensity.innerText = baseIntensity.value + "%";
playSelectedAnimation();
}
effectIntensity.onchange = function() {
divEffectIntensity.innerText = effectIntensity.value + "%";
playSelectedAnimation();
}
hotkeyIntensity.onchange = function() {
divHotkeyIntensity.innerText = hotkeyIntensity.value + "%";
playSelectedAnimation();
}
}
function getHex(num) {
var result = num.toString(16);
if (result.length == 0) {
return "00";
} else if (result.length == 1) {
return "0" + result;
} else {
return result;
}
}
function heal() {
if (validateControls() == false) {
return;
}
var baseLayer = "EnvironmentSnow_Keyboard.chroma";
ChromaAnimation.closeAnimation(baseLayer);
var layer2 = "RingGray_Keyboard.chroma";
ChromaAnimation.closeAnimation(layer2);
var layer3 = "FadeInOutGray_Keyboard.chroma";
ChromaAnimation.closeAnimation(layer3);
var keys = [];
keys.push(RZLED.RZLED_LOGO);
keys.push(RZKEY.RZKEY_ESC);
keys.push(RZKEY.RZKEY_Q);
keys.push(RZKEY.RZKEY_E);
ChromaAnimation.openAnimation(baseLayer, function(baseAnimation) {
ChromaAnimation.openAnimation(layer2, function(layer2Animation) {
ChromaAnimation.openAnimation(layer3, function(layer3Animation) {
// now that all 3 animations have reloaded
// set base intensity
ChromaAnimation.multiplyIntensityAllFrames(baseLayer, 1.0 + 64.0 * (baseIntensity.value / 100.0));
// turn animation green
ChromaAnimation.offsetNonZeroColorsAllFrames(layer2, -127, 127, -127); //animation starts with 127,127,127 so adding -127,127,-127 results in 0,255,0 or green
// set intensity
ChromaAnimation.multiplyIntensityAllFrames(layer2, (effectIntensity.value / 100.0));
ChromaAnimation.copyNonZeroAllKeysAllFrames(layer2, baseLayer);
// change color
ChromaAnimation.offsetNonZeroColorsAllFrames(layer3, 173 - 127, 255 - 127, 47 - 127);
// set intensity
ChromaAnimation.multiplyIntensityAllFrames(layer3, (hotkeyIntensity.value / 100.0));
ChromaAnimation.copyKeysColorAllFrames(layer3, baseLayer, keys);
// set wasd keys
keys = [];
keys.push(RZKEY.RZKEY_W);
keys.push(RZKEY.RZKEY_A);
keys.push(RZKEY.RZKEY_S);
keys.push(RZKEY.RZKEY_D);
var red = Math.floor(255 * (hotkeyIntensity.value / 100.0));
var green = Math.floor(127 * (hotkeyIntensity.value / 100.0));
var blue = Math.floor(0 * (hotkeyIntensity.value / 100.0));
var color = red | (green << 8) | (blue << 16);
ChromaAnimation.setKeysColorAllFrames(baseLayer, keys, color);
ChromaAnimation.playAnimation(baseLayer, true);
});
});
});
}
function damage() {
if (validateControls() == false) {
return;
}
var baseLayer = "EnvironmentSnow_Keyboard.chroma";
ChromaAnimation.closeAnimation(baseLayer);
var layer2 = "RingGray_Keyboard.chroma";
ChromaAnimation.closeAnimation(layer2);
var layer3 = "FadeInOutGray_Keyboard.chroma";
ChromaAnimation.closeAnimation(layer3);
var keys = [];
keys.push(RZLED.RZLED_LOGO);
keys.push(RZKEY.RZKEY_ESC);
keys.push(RZKEY.RZKEY_Q);
keys.push(RZKEY.RZKEY_E);
ChromaAnimation.openAnimation(baseLayer, function(baseAnimation) {
ChromaAnimation.openAnimation(layer2, function(layer2Animation) {
ChromaAnimation.openAnimation(layer3, function(layer3Animation) {
// now that all 3 animations have reloaded
// set base intensity
ChromaAnimation.multiplyIntensityAllFrames(baseLayer, 1.0 + 64.0 * (baseIntensity.value / 100.0));
// turn animation red
ChromaAnimation.offsetNonZeroColorsAllFrames(layer2, 127, -127, -127); //animation starts with 127,127,127 so adding 127,-127,-127 results in 255,0,0 or red
// set intensity
ChromaAnimation.multiplyIntensityAllFrames(layer2, (effectIntensity.value / 100.0));
ChromaAnimation.copyNonZeroAllKeysAllFrames(layer2, baseLayer);
// change color
ChromaAnimation.offsetNonZeroColorsAllFrames(layer3, 220 - 127, 20 - 127, 60 - 127);
// set intensity
ChromaAnimation.multiplyIntensityAllFrames(layer3, (hotkeyIntensity.value / 100.0));
ChromaAnimation.copyKeysColorAllFrames(layer3, baseLayer, keys);
// set wasd keys
keys = [];
keys.push(RZKEY.RZKEY_W);
keys.push(RZKEY.RZKEY_A);
keys.push(RZKEY.RZKEY_S);
keys.push(RZKEY.RZKEY_D);
var red = Math.floor(255 * (hotkeyIntensity.value / 100.0));
var green = Math.floor(127 * (hotkeyIntensity.value / 100.0));
var blue = Math.floor(0 * (hotkeyIntensity.value / 100.0));
var color = red | (green << 8) | (blue << 16);
ChromaAnimation.setKeysColorAllFrames(baseLayer, keys, color);
ChromaAnimation.playAnimation(baseLayer, true);
});
});
});
}
function itemPickup() {
if (validateControls() == false) {
return;
}
var baseLayer = "EnvironmentSnow_Keyboard.chroma";
ChromaAnimation.closeAnimation(baseLayer);
var layer2 = "RingGray_Keyboard.chroma";
ChromaAnimation.closeAnimation(layer2);
var layer3 = "FadeInOutGray_Keyboard.chroma";
ChromaAnimation.closeAnimation(layer3);
var keys = [];
keys.push(RZLED.RZLED_LOGO);
keys.push(RZKEY.RZKEY_ESC);
keys.push(RZKEY.RZKEY_Q);
keys.push(RZKEY.RZKEY_E);
ChromaAnimation.openAnimation(baseLayer, function(baseAnimation) {
ChromaAnimation.openAnimation(layer2, function(layer2Animation) {
ChromaAnimation.openAnimation(layer3, function(layer3Animation) {
// now that all 3 animations have reloaded
// set base intensity
ChromaAnimation.multiplyIntensityAllFrames(baseLayer, 1.0 + 64.0 * (baseIntensity.value / 100.0));
// turn animation blue
ChromaAnimation.offsetNonZeroColorsAllFrames(layer2, -127, -127, 127); //animation starts with 127,127,127 so adding -127,-127,127 results in 0,0,255 or blue
// set intensity
ChromaAnimation.multiplyIntensityAllFrames(layer2, (effectIntensity.value / 100.0));
ChromaAnimation.copyNonZeroAllKeysAllFrames(layer2, baseLayer);
// change color
ChromaAnimation.offsetNonZeroColorsAllFrames(layer3, 64 - 127, 224 - 127, 208 - 127);
// set intensity
ChromaAnimation.multiplyIntensityAllFrames(layer3, (hotkeyIntensity.value / 100.0));
ChromaAnimation.copyKeysColorAllFrames(layer3, baseLayer, keys);
// set wasd keys
keys = [];
keys.push(RZKEY.RZKEY_W);
keys.push(RZKEY.RZKEY_A);
keys.push(RZKEY.RZKEY_S);
keys.push(RZKEY.RZKEY_D);
var red = Math.floor(255 * (hotkeyIntensity.value / 100.0));
var green = Math.floor(127 * (hotkeyIntensity.value / 100.0));
var blue = Math.floor(0 * (hotkeyIntensity.value / 100.0));
var color = red | (green << 8) | (blue << 16);
ChromaAnimation.setKeysColorAllFrames(baseLayer, keys, color);
ChromaAnimation.playAnimation(baseLayer, true);
});
});
});
}
function playSelectedAnimation() {
if (selectedAnimation == 0) {
heal();
} else if (selectedAnimation == 1) {
damage();
} else if (selectedAnimation == 2) {
itemPickup();
}
}
</script>
</head>
<body onload="onPageLoad()">
<button id="buttonHeal">Heal</button>
<button id="buttonDamage">Damage</button>
<button id="buttonItemPickup">Item Pickup</button><br/>
</br>
Base Intensity:
<input type="range" min="0" max="100" value="100" class="slider" id="baseIntensity"></input>
<div id="divBaseIntensity" style="display: inline-table;">100%</div>
<br/>
Effect Intensity:
<input type="range" min="0" max="100" value="100" class="slider" id="effectIntensity"></input>
<div id="divEffectIntensity" style="display: inline-table;">100%</div>
<br/>
Hotkey Intensity:
<input type="range" min="0" max="100" value="100" class="slider" id="hotkeyIntensity"></input>
<div id="divHotkeyIntensity" style="display: inline-table;">100%</div>
<br/>
<script>
addControlEvents();
</script>
</body>
</html>