-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathview_widget_tools.js
70 lines (65 loc) · 2.6 KB
/
view_widget_tools.js
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
/// <reference path="../utilities/rollback_state.js" />
/**
* Singleton with function that help
* in maintain view elements.
*/
const ViewWidgetTools = (function() {
/**
* Increment a range input element's state.
*
* @param {RollbackStateType} state // state bound to range control
* @param {string} parameter // name of state parameter
* @param {string} parameterLive // name of live update state parameter
* @param {number} increment // range's increment value
* @param {number} maxRange // range's maximum allowed value
* @param {number} decimals // number of decimals to show in value
*/
function onRangeIncrement(state, parameter, parameterLive, increment, maxRange, decimals) {
// update state to cause a redraw on game loop
let value = state.getValue(parameter);
if((typeof value == "number") && (value <= (maxRange - increment)))
{
value = constrain(parseFloat((value + increment).toFixed(decimals)), 0, 1);
state.setValue(parameter, value);
state.setValue(parameterLive, value);
}
}
/**
* Decrement a range input element's state.
*
* @param {RollbackStateType} state // state bound to range control
* @param {string} parameter // name of state parameter
* @param {string} parameterLive // name of live update state parameter
* @param {number} increment // range's increment value
* @param {number} minRange // range's minimum allowed value
* @param {number} decimals // number of decimals to show in value
*/
function onRangeDecrement(state, parameter, parameterLive, increment, minRange, decimals) {
// update state to cause a redraw on game loop
let value = state.getValue(parameter);
if((typeof value == "number") && (value >= (minRange + increment)))
{
value = constrain(parseFloat((value - increment).toFixed(decimals)), 0, 1);
state.setValue(parameter, value);
state.setValue(parameterLive, value);
}
}
/**
* Clear all the select menu options.
*
* @param {HTMLSelectElement} select
*/
function clearSelectOptions(select) {
if (select) {
while (select.options.length > 0) {
select.remove(0);
}
}
}
const exports = Object.freeze({
"onRangeIncrement": onRangeIncrement,
"onRangeDecrement": onRangeDecrement,
"clearSelectOptions": clearSelectOptions,
});
return exports;
}());