File size: 6,122 Bytes
1e40c2a |
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 |
var controlsLoaded = false;
var curControl = null;
function onControlsLoad() {
jaws.start(InputMonitor);
// check for an existing controls cookie
var customControls = readCookie('customControls');
// these actions will trigger the controls configurations
if (customControls === 'TRUE') {
// if there is a cookie, set up the controls for it
document.getElementById('customRadio').checked = true;
configureCustomControls();
} else {
// if no cookie, assign defaults, create the cookie
document.getElementById('defaultRadio').checked = true;
setDefaultControls();
}
configureAutoRepeat();
controlsLoaded = true;
}
function setDefaultControls() {
stopPollingInput();
document.getElementById('instructionsDefault').setAttribute('class', 'withDisplay');
document.getElementById('instructionsCustom').setAttribute('class', 'noDisplay');
document.getElementById('instructionsPending').setAttribute('class', 'noDisplay');
// set the cookies
createCookie('customControls', 'FALSE', 1000);
// configure the gui to the default text
document.getElementById('rotateLeftValue')
.innerHTML = 'Z';
document.getElementById('rotateRightValue')
.innerHTML = 'X, UP';
document.getElementById('shiftLeftValue')
.innerHTML = 'LEFT';
document.getElementById('shiftRightValue')
.innerHTML = 'RIGHT';
document.getElementById('softDropValue')
.innerHTML = 'DOWN';
document.getElementById('hardDropValue')
.innerHTML = 'SPACE';
document.getElementById('swapValue')
.innerHTML = 'SHIFT, C';
}
function configureCustomControls(fromCookie, fromThreshold) {
stopPollingInput();
document.getElementById('instructionsDefault').setAttribute('class', 'noDisplay');
document.getElementById('instructionsCustom').setAttribute('class', 'withDisplay');
document.getElementById('instructionsPending').setAttribute('class', 'noDisplay');
if (controlsLoaded && !fromCookie) {
// the cookies need to be created & initialized
createCookie('rotateLeft', 'Z', 1000);
createCookie('rotateRight', 'X', 1000);
createCookie('shiftLeft', 'LEFT', 1000);
createCookie('shiftRight', 'RIGHT', 1000);
createCookie('softDrop', 'DOWN', 1000);
createCookie('hardDrop', 'SPACE', 1000);
createCookie('swap', 'C', 1000);
createCookie('customControls', 'TRUE', 1000);
}
// assign all of the GUI elements based on the cookie
document.getElementById('rotateLeftValue')
.innerHTML = readCookie('rotateLeft');
document.getElementById('rotateRightValue')
.innerHTML = readCookie('rotateRight');
document.getElementById('shiftLeftValue')
.innerHTML = readCookie('shiftLeft');
document.getElementById('shiftRightValue')
.innerHTML = readCookie('shiftRight');
document.getElementById('softDropValue')
.innerHTML = readCookie('softDrop');
document.getElementById('hardDropValue')
.innerHTML = readCookie('hardDrop');
document.getElementById('swapValue')
.innerHTML = readCookie('swap');
}
function controlsUnitClicked(controlName) {
// if default controls, switch to custom
if (readCookie('customControls') !== 'TRUE') {
// if no cookie, assign defaults, create the cookie
document.getElementById('customRadio').checked = true;
configureCustomControls();
}
document.getElementById('instructionsDefault').setAttribute('class', 'noDisplay');
document.getElementById('instructionsCustom').setAttribute('class', 'noDisplay');
document.getElementById('instructionsPending').setAttribute('class', 'withDisplay');
if (curControl !== null) {
stopPollingInput();
}
curControl = {
name: controlName,
containerId: controlName + 'Div'
};
startPollingInput();
}
function startPollingInput() {
document.getElementById(curControl.containerId).setAttribute('class', 'controlsUnit controlsUnitPending');
inputPolling = true;
}
function stopPollingInput() {
if (curControl !== null) {
inputPolling = false;
document.getElementById(curControl.containerId).setAttribute('class', 'controlsUnit');
curControl = null;
}
}
function findWhereKeyUsed(key) {
var cookies = ['rotateLeft',
'rotateRight',
'shiftLeft',
'shiftRight',
'softDrop',
'hardDrop',
'swap'],
i;
for (i = 0; i < cookies.length; i += 1) {
if (readCookie(cookies[i]) === key) {
return cookies[i];
}
}
return null;
}
function reportKeyPressed(keyLower) {
// should never fail this case...
if (curControl !== null) {
var key = keyLower.toUpperCase();
// if this key is used anywhere else
var controlUsed = findWhereKeyUsed(key);
if (controlUsed !== null) {
// swap the two controls
createCookie(controlUsed, readCookie(curControl.name), 1000);
createCookie(curControl.name, key, 1000);
} else {
// set this key to the new value
createCookie(curControl.name, key, 1000);
}
configureCustomControls(true);
stopPollingInput();
}
}
function configureAutoRepeat() {
var autoRepeat = readCookie('autoRepeat');
if (autoRepeat === null) {
autoRepeat = "50";
createCookie('autoRepeat', autoRepeat, 1000);
}
var threshold = readCookie('threshold');
if (threshold === null) {
threshold = "200";
createCookie("threshold", threshold, 1000);
}
document.getElementById('autoRepeatRange').value = autoRepeat;
document.getElementById('autoRepeatValue').innerHTML = autoRepeat;
document.getElementById('thresholdRange').value = threshold;
document.getElementById('thresholdValue').innerHTML = threshold;
}
function updateAutoRepeat() {
var newVal = document.getElementById('autoRepeatRange').value;
document.getElementById('autoRepeatValue').innerHTML = newVal;
createCookie('autoRepeat', newVal, 1000);
}
function updateThreshold() {
var newVal = document.getElementById('thresholdRange').value;
document.getElementById('thresholdValue').innerHTML = newVal;
createCookie('threshold', newVal, 1000);
}
function resetAutoRepeat() {
eraseCookie('autoRepeat');
eraseCookie('threshold');
configureAutoRepeat();
} |