(section = 'reading', force = false)
| 1144 | var currentlyRegistered = false; |
| 1145 | |
| 1146 | async function register(section = 'reading', force = false) |
| 1147 | { |
| 1148 | if(currentlyRegistered === reading && !force) |
| 1149 | return; |
| 1150 | |
| 1151 | await loadShoSho(); |
| 1152 | loadShoShoObject(); |
| 1153 | loadShortcuts(); |
| 1154 | |
| 1155 | shosho.reset(); |
| 1156 | shoshoMouse.reset(); |
| 1157 | mouseWheel.reset(); |
| 1158 | |
| 1159 | for(let shortcut in shortcuts[section].shortcuts) |
| 1160 | { |
| 1161 | let actionKey = shortcuts[section].shortcuts[shortcut]; |
| 1162 | let action = shortcuts[section].actions[actionKey]; |
| 1163 | |
| 1164 | const callback = function(event) { |
| 1165 | |
| 1166 | if(inputIsFocused() || (section === 'reading' && !reading.isLoaded())) |
| 1167 | return false; |
| 1168 | |
| 1169 | return action.function(event); |
| 1170 | |
| 1171 | } |
| 1172 | |
| 1173 | if(isMouseShortcut(shortcut)) |
| 1174 | shoshoMouse.register(shortcut, callback); |
| 1175 | else if(isMouseWheelShortcut(shortcut)) |
| 1176 | mouseWheel.register(shortcut, callback); |
| 1177 | else |
| 1178 | shosho.register(shortcut, callback); |
| 1179 | } |
| 1180 | |
| 1181 | shosho.start(); |
| 1182 | shoshoMouse.start(); |
| 1183 | mouseWheel.start(); |
| 1184 | |
| 1185 | // Gamepad |
| 1186 | gamepad.reset('shortcuts'); |
| 1187 | |
| 1188 | for(let button in shortcuts[section].gamepad) |
| 1189 | { |
| 1190 | let actionKey = shortcuts[section].gamepad[button]; |
| 1191 | let action = shortcuts[section].actions[actionKey]; |
| 1192 | |
| 1193 | gamepad.setButtonEvent('shortcuts', gamepad.buttonKey(button), action.function); |
| 1194 | } |
| 1195 | |
| 1196 | currentlyRegistered = section; |
| 1197 | } |
| 1198 | |
| 1199 | function unregister(force = false) |
| 1200 | { |
no test coverage detected