1
0
forked from sent/waves
waves/public/assets/g/turbowarp/main/js/addon-entry-editor-extra-keys.js
2025-04-09 17:11:14 -05:00

117 lines
4.2 KiB
JavaScript

(window["webpackJsonpGUI"] = window["webpackJsonpGUI"] || []).push([["addon-entry-editor-extra-keys"],{
/***/ "./src/addons/addons/editor-extra-keys/_runtime_entry.js":
/*!***************************************************************!*\
!*** ./src/addons/addons/editor-extra-keys/_runtime_entry.js ***!
\***************************************************************/
/*! exports provided: resources */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "resources", function() { return resources; });
/* harmony import */ var _userscript_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./userscript.js */ "./src/addons/addons/editor-extra-keys/userscript.js");
/* generated by pull.js */
const resources = {
"userscript.js": _userscript_js__WEBPACK_IMPORTED_MODULE_0__["default"]
};
/***/ }),
/***/ "./src/addons/addons/editor-extra-keys/userscript.js":
/*!***********************************************************!*\
!*** ./src/addons/addons/editor-extra-keys/userscript.js ***!
\***********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony default export */ __webpack_exports__["default"] = (async function ({
addon,
msg
}) {
const ScratchBlocks = await addon.tab.traps.getBlockly();
let defaultKeys = null;
function appendKeys(keys, enableShiftKeys) {
if (!defaultKeys) {
defaultKeys = [...keys];
}
if (!addon.self.disabled) {
keys.push(...[["-", "-"], [",", ","], [".", "."]]);
keys.splice(5, 0, [msg("enter-key"), "enter"]);
if (addon.settings.get("experimentalKeys")) {
keys.push(...[["`", "`"], ["=", "="], ["[", "["], ["]", "]"], ["\\", "\\"], [";", ";"], ["'", "'"], ["/", "/"]]);
}
if (enableShiftKeys && addon.settings.get("shiftKeys")) {
keys.push(...[["!", "!"], ["@", "@"], ["#", "#"], ["$", "$"], ["%", "%"], ["^", "^"], ["&", "&"], ["*", "*"], ["(", "("], [")", ")"], ["_", "_"], ["+", "+"], ["{", "{"], ["}", "}"], ["|", "|"], [":", ":"], ['"', '"'], ["?", "?"], ["<", "<"], [">", ">"], ["~", "~"]]);
}
if (addon.settings.get("twKeys")) {
keys.push(...[["backspace", "backspace"], ["delete", "delete"], ["shift", "shift"], ["caps lock", "caps lock"], ["scroll lock", "scroll lock"], ["control", "control"], ["escape", "escape"], ["insert", "insert"], ["home", "home"], ["end", "end"], ["page up", "page up"], ["page down", "page down"]]);
}
}
return keys;
}
for (const opcode of ["sensing_keyoptions", "event_whenkeypressed"]) {
const block = ScratchBlocks.Blocks[opcode];
const originalInit = block.init;
block.init = function (...args) {
const originalJsonInit = this.jsonInit;
this.jsonInit = function (obj) {
appendKeys(obj.args0[0].options, opcode === "event_whenkeypressed");
return originalJsonInit.call(this, obj);
};
return originalInit.call(this, ...args);
};
}
const updateExistingBlocks = () => {
const workspace = Blockly.getMainWorkspace();
const flyout = workspace && workspace.getFlyout();
if (workspace && flyout) {
const allBlocks = [...workspace.getAllBlocks(), ...flyout.getWorkspace().getAllBlocks()];
for (const block of allBlocks) {
if (block.type !== "event_whenkeypressed" && block.type !== "sensing_keyoptions") {
continue;
}
const input = block.inputList[0];
if (!input) {
continue;
}
const field = input.fieldRow.find(i => i && Array.isArray(i.menuGenerator_));
if (!field) {
continue;
}
field.menuGenerator_ = appendKeys(defaultKeys ? [...defaultKeys] : field.menuGenerator_, block.type === "event_whenkeypressed");
}
}
};
updateExistingBlocks();
addon.settings.addEventListener("change", updateExistingBlocks);
addon.self.addEventListener("disabled", updateExistingBlocks);
addon.self.addEventListener("reenabled", updateExistingBlocks);
});
/***/ })
}]);
//# sourceMappingURL=addon-entry-editor-extra-keys.js.map