Skip to content

godothub/godot-minigame / skills

godot-wechat-minigame-adapter

Unverified

Apply the bundled self-contained Godot WeChat Mini Game adapter kit to an official Godot checkout. Use when the user wants to port official Godot to WeChat Mini Game, refresh a nearby 4.6-based port, or inspect the shipped patch/source bundle for WXMEMFS, `wx.request`, audio cleanup, display/input, WXGLX dual-path rendering, `.wasm.br`, and `wx.exitMiniProgram`. This skill is version-locked to the bundled upstream base and must not be described as a generic “Godot 4.x” patch dump.

FileKindSize
SKILL.mdskill md6.0 KB
agents/openai.yamlconfig269 B
assets/min-runtime/godot-loader.jsscript16.6 KB
assets/min-runtime/godot-sdk.jsscript7.8 KB
patches/fixes/4.7-webgl-context/001-context-swap-control.patchother4.2 KB
patches/fixes/4.7-webgl-context/README.mdmarkdown1.5 KB
patches/godot-4.6.2-rc-a16e481cf4/core/001-build-and-runtime-glue.patchother12.4 KB
patches/godot-4.6.2-rc-a16e481cf4/core/002-native-audio-routing.patchother6.3 KB
patches/godot-4.6.2-rc-a16e481cf4/core/003-wxglx-nine-patch-expansion.patchother5.7 KB
patches/godot-4.6.2-rc-a16e481cf4/core/004-wxglx-nine-patch-runtime-scope.patchother7.2 KB
patches/godot-4.6.2-rc-a16e481cf4/core/series.txtmarkdown142 B
patches/godot-4.6.2-rc-a16e481cf4/manifest.jsonconfig993 B
patches/godot-4.6.2-rc-a16e481cf4/optional/001-audio-worker.patchother820 B
patches/godot-4.6.2-rc-a16e481cf4/optional/series.txtmarkdown23 B
references/compatibility-matrix.mdmarkdown1.2 KB
references/migration-modules.mdmarkdown5.8 KB
references/recent-commit-deltas.mdmarkdown2.2 KB
references/runtime-shell.mdmarkdown3.8 KB
references/validation-checklist.mdmarkdown3.4 KB
references/wxglx-adaptation.mdmarkdown8.8 KB
scripts/apply_godot_patchset.pyscript5.6 KB
scripts/compress_wasm.batscript100 B
scripts/compress_wasm.shscript91 B
scripts/godot_process.jsscript5.3 KB
scripts/install_min_runtime.pyscript1.1 KB
scripts/validate_template_runtime.jsscript2.8 KB
sources/godot-4.6.2-rc-a16e481cf4/compress_wasm.batscript237 B
sources/godot-4.6.2-rc-a16e481cf4/compress_wasm.shscript215 B
sources/godot-4.6.2-rc-a16e481cf4/godot_process.jsscript5.3 KB
sources/godot-4.6.2-rc-a16e481cf4/optional/platform/web/js/libs/audio.worker.jsscript6.6 KB
sources/godot-4.6.2-rc-a16e481cf4/optional/platform/web/js/libs/lib.wx.api.d.tsscript516.7 KB
sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_blob.jsscript27.1 KB
sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_godot_audio.jsscript88.8 KB
sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_godot_crypto.jsscript116 B
sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_godot_display.jsscript26.4 KB
sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_godot_fetch.jsscript8.9 KB
sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_godot_fs.jsscript29.4 KB
sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_godot_input.jsscript23.2 KB
tests/test_godot_process_commit_frame.jsscript2.6 KB
tests/test_min_runtime_loader.jsscript3.8 KB
tests/test_template_glx_config.jsscript1.3 KB
tests/test_wechat_audio_context_source_reuse.jsscript3.9 KB
tests/test_wxglx_nine_patch_patch.jsscript2.2 KB

sources/godot-4.6.2-rc-a16e481cf4/platform/web/js/libs/library_godot_input.js

View on GitHub
/**************************************************************************/
/*  library_godot_input.js                                                */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

/*
 * IME API helper.
 */

const GodotIME = {
	$GodotIME__deps: ['$GodotRuntime', '$GodotEventListeners'],
	$GodotIME__postset: 'GodotOS.atexit(function(resolve, reject) { GodotIME.clear(); resolve(); });',
	$GodotIME: {
		ime: null,
		active: false,

		getModifiers: function (evt) {
			return (evt.shiftKey + 0) + ((evt.altKey + 0) << 1) + ((evt.ctrlKey + 0) << 2) + ((evt.metaKey + 0) << 3);
		},

		ime_active: function (active) {
			if (GodotIME.ime) {
				if (active) {
					GodotIME.ime.show()
				} else {
					GodotIME.ime.hide()
				}
			}
		},

		ime_position: function (x, y) {
		},

		init: function (ime_cb, key_cb, code, key) {
			function ime_event_cb(type, event) {
				if (GodotIME.ime) {
					const ptr = GodotRuntime.allocString(event.value);
					ime_cb(type, ptr);
					GodotRuntime.free(ptr)
				}
			}
			let lastValue = ""
			let lastValueLength = 0
			let sessionInitialValue = ""
			let sessionInitialLength = 0
			let currentLength = 0
			let imeEnded = false
			let sendKey = (codeStr, keyStr, modifiers = 0) => {
				GodotRuntime.stringToHeap(codeStr, code, 32)
				GodotRuntime.stringToHeap(keyStr, key, 32)
				key_cb(1, 0, modifiers)
				key_cb(0, 0, modifiers)
			}
			let clearExistingText = (length) => {
				if (length <= 0) {
					return
				}
				// Try select-all then backspace to replace, and also fallback to backspace N times.
				sendKey("KeyA", "a", 4)
				sendKey("Backspace", "Backspace", 0)
				for (let i = 0; i < length; i++) {
					sendKey("Backspace", "Backspace", 0)
				}
			}
			let insertText = (text) => {
				for (const ch of text) {
					sendKey("Unidentified", ch, 0)
				}
			}
			let inputCb = evt => {
				if (!evt || typeof evt.value !== "string") {
					return
				}
				const value = evt.value
				if (value === lastValue) {
					return
				}
				if (!imeEnded) {
					// End IME so key events are not ignored.
					ime_event_cb(2, { value: "" })
					imeEnded = true
				}
				clearExistingText(currentLength)
				insertText(value)
				lastValue = value
				lastValueLength = value.length
				currentLength = lastValueLength
				GodotIME.initialText = lastValue
			}
			let inputConfirm = evt => {
				const value = (evt && typeof evt.value === "string") ? evt.value : lastValue
				ime_event_cb(2, { value: "" })
				clearExistingText(currentLength)
				insertText(value)
				GodotIME.initialText = value
				lastValue = value
				lastValueLength = value.length
				currentLength = lastValueLength
				ime.hide();
			}
			let inputComplete = evt => {
				if (!GodotIME.active) {
					ime.hide();
					return
				}
				const value = (evt && typeof evt.value === "string") ? evt.value : lastValue
				ime_event_cb(2, { value: "" })
				clearExistingText(currentLength)
				insertText(value)
				GodotIME.initialText = value
				lastValue = value
				lastValueLength = value.length
				currentLength = lastValueLength
				ime.hide();
			}
			let ime = {
				activeTime: 0,
				show() {
					let delta = Date.now() - ime.activeTime
					if (delta < 100) {
						return
					}
					if (GodotIME.active) return;
					GodotIME.active = true;
					if (typeof GodotIME.initialText === "string") {
						lastValue = GodotIME.initialText
					}
					lastValueLength = lastValue.length
					sessionInitialValue = lastValue
					sessionInitialLength = lastValueLength
					currentLength = sessionInitialLength
					imeEnded = false
					wx.showKeyboard({
						defaultValue: lastValue,
						maxLength: 99,
						multiple: false,
						confirmHold: true,
						confirmType: "done"
					});
					ime_event_cb(0, { value: "" });
					wx.onKeyboardInput(inputCb);
					wx.onKeyboardConfirm(inputConfirm);
					__globalAdapter.onKeyboardComplete(inputComplete);
				},
				hide() {
					if (!GodotIME.active)
						return;
					__globalAdapter.hideKeyboard();
					ime.activeTime = Date.now()
					GodotIME.active = false;
					__globalAdapter.offKeyboardInput(inputCb);
					__globalAdapter.offKeyboardConfirm(inputConfirm);
					__globalAdapter.offKeyboardComplete(inputComplete)
				}
			};
			GodotIME.ime = ime
		},

		clear: function () {
			if (GodotIME.ime) {
				GodotIME.ime.remove();
				GodotIME.ime = null;
			}
		},
	},
};
mergeInto(LibraryManager.library, GodotIME);

/*
 * Gamepad API helper.
 */
const GodotInputGamepads = {
	$GodotInputGamepads__deps: ['$GodotRuntime', '$GodotEventListeners'],
	$GodotInputGamepads: {
		samples: [],

		get_pads: function () {
			try {
				return [];
			} catch (e) {
				return [];
			}
		},

		get_samples: function () {
			return GodotInputGamepads.samples;
		},

		get_sample: function (index) {
			const samples = GodotInputGamepads.samples;
			return index < samples.length ? samples[index] : null;
		},

		sample: function () {
			const pads = GodotInputGamepads.get_pads();
			const samples = [];
			for (let i = 0; i < pads.length; i++) {
				const pad = pads[i];
				if (!pad) {
					samples.push(null);
					continue;
				}
				const s = {
					standard: pad.mapping === 'standard',
					buttons: [],
					axes: [],
					connected: pad.connected,
				};
				for (let b = 0; b < pad.buttons.length; b++) {
					s.buttons.push(pad.buttons[b].value);
				}
				for (let a = 0; a < pad.axes.length; a++) {
					s.axes.push(pad.axes[a]);
				}
				samples.push(s);
			}
			GodotInputGamepads.samples = samples;
		},

		init: function (onchange) {
			GodotInputGamepads.samples = [];
			function add(pad) {
				const guid = GodotInputGamepads.get_guid(pad);
				const c_id = GodotRuntime.allocString(pad.id);
				const c_guid = GodotRuntime.allocString(guid);
				onchange(pad.index, 1, c_id, c_guid);
				GodotRuntime.free(c_id);
				GodotRuntime.free(c_guid);
			}
			const pads = GodotInputGamepads.get_pads();
			for (let i = 0; i < pads.length; i++) {
				// Might be reserved space.
				if (pads[i]) {
					add(pads[i]);
				}
			}
			GodotEventListeners.add(window, 'gamepadconnected', function (evt) {
				if (evt.gamepad) {
					add(evt.gamepad);
				}
			}, false);
			GodotEventListeners.add(window, 'gamepaddisconnected', function (evt) {
				if (evt.gamepad) {
					onchange(evt.gamepad.index, 0);
				}
			}, false);
		},

		get_guid: function (pad) {
			if (pad.mapping) {
				return pad.mapping;
			}
			const ua = navigator.userAgent;
			let os = 'Unknown';
			if (ua.indexOf('Android') >= 0) {
				os = 'Android';
			} else if (ua.indexOf('Linux') >= 0) {
				os = 'Linux';
			} else if (ua.indexOf('iPhone') >= 0) {
				os = 'iOS';
			} else if (ua.indexOf('Macintosh') >= 0) {
				// Updated iPads will fall into this category.
				os = 'MacOSX';
			} else if (ua.indexOf('Windows') >= 0) {
				os = 'Windows';
			}

			const id = pad.id;
			// Chrom* style: NAME (Vendor: xxxx Product: xxxx).
			const exp1 = /vendor: ([0-9a-f]{4}) product: ([0-9a-f]{4})/i;
			// Firefox/Safari style (Safari may remove leading zeroes).
			const exp2 = /^([0-9a-f]+)-([0-9a-f]+)-/i;
			let vendor = '';
			let product = '';
			if (exp1.test(id)) {
				const match = exp1.exec(id);
				vendor = match[1].padStart(4, '0');
				product = match[2].padStart(4, '0');
			} else if (exp2.test(id)) {
				const match = exp2.exec(id);
				vendor = match[1].padStart(4, '0');
				product = match[2].padStart(4, '0');
			}
			if (!vendor || !product) {
				return `${os}Unknown`;
			}
			return os + vendor + product;
		},
	},
};
mergeInto(LibraryManager.library, GodotInputGamepads);

/*
 * Drag and drop helper.
 * This is pretty big, but basically detect dropped files on GodotConfig.canvas,
 * process them one by one (recursively for directories), and copies them to
 * the temporary FS path '/tmp/drop-[random]/' so it can be emitted as a godot
 * event (that requires a string array of paths).
 *
 * NOTE: The temporary files are removed after the callback. This means that
 * deferred callbacks won't be able to access the files.
 */
const GodotInputDragDrop = {
	$GodotInputDragDrop__deps: ['$FS', '$GodotFS'],
	$GodotInputDragDrop: {
		promises: [],
		pending_files: [],

		add_entry: function (entry) {
			if (entry.isDirectory) {
				GodotInputDragDrop.add_dir(entry);
			} else if (entry.isFile) {
				GodotInputDragDrop.add_file(entry);
			} else {
				GodotRuntime.error('Unrecognized entry...', entry);
			}
		},

		add_dir: function (entry) {
			GodotInputDragDrop.promises.push(new Promise(function (resolve, reject) {
				const reader = entry.createReader();
				reader.readEntries(function (entries) {
					for (let i = 0; i < entries.length; i++) {
						GodotInputDragDrop.add_entry(entries[i]);
					}
					resolve();
				});
			}));
		},

		add_file: function (entry) {
			GodotInputDragDrop.promises.push(new Promise(function (resolve, reject) {
				entry.file(function (file) {
					const reader = new FileReader();
					reader.onload = function () {
						const f = {
							'path': file.relativePath || file.webkitRelativePath,
							'name': file.name,
							'type': file.type,
							'size': file.size,
							'data': reader.result,
						};
						if (!f['path']) {
							f['path'] = f['name'];
						}
						GodotInputDragDrop.pending_files.push(f);
						resolve();
					};
					reader.onerror = function () {
						GodotRuntime.print('Error reading file');
						reject();
					};
					reader.readAsArrayBuffer(file);
				}, function (err) {
					GodotRuntime.print('Error!');
					reject();
				});
			}));
		},

		process: function (resolve, reject) {
			if (GodotInputDragDrop.promises.length === 0) {
				resolve();
				return;
			}
			GodotInputDragDrop.promises.pop().then(function () {
				setTimeout(function () {
					GodotInputDragDrop.process(resolve, reject);
				}, 0);
			});
		},

		_process_event: function (ev, callback) {
			ev.preventDefault();
			if (ev.dataTransfer.items) {
				// Use DataTransferItemList interface to access the file(s)
				for (let i = 0; i < ev.dataTransfer.items.length; i++) {
					const item = ev.dataTransfer.items[i];
					let entry = null;
					if ('getAsEntry' in item) {
						entry = item.getAsEntry();
					} else if ('webkitGetAsEntry' in item) {
						entry = item.webkitGetAsEntry();
					}
					if (entry) {
						GodotInputDragDrop.add_entry(entry);
					}
				}
			} else {
				GodotRuntime.error('File upload not supported');
			}
			new Promise(GodotInputDragDrop.process).then(function () {
				const DROP = `/tmp/drop-${parseInt(Math.random() * (1 << 30), 10)}/`;
				const drops = [];
				const files = [];
				FS.mkdir(DROP.slice(0, -1)); // Without trailing slash
				GodotInputDragDrop.pending_files.forEach((elem) => {
					const path = elem['path'];
					GodotFS.copy_to_fs(DROP + path, elem['data']);
					let idx = path.indexOf('/');
					if (idx === -1) {
						// Root file
						drops.push(DROP + path);
					} else {
						// Subdir
						const sub = path.substr(0, idx);
						idx = sub.indexOf('/');
						if (idx < 0 && drops.indexOf(DROP + sub) === -1) {
							drops.push(DROP + sub);
						}
					}
					files.push(DROP + path);
				});
				GodotInputDragDrop.promises = [];
				GodotInputDragDrop.pending_files = [];
				callback(drops);
				if (GodotConfig.persistent_drops) {
					// Delay removal at exit.
					GodotOS.atexit(function (resolve, reject) {
						GodotInputDragDrop.remove_drop(files, DROP);
						resolve();
					});
				} else {
					GodotInputDragDrop.remove_drop(files, DROP);
				}
			});
		},

		remove_drop: function (files, drop_path) {
			const dirs = [drop_path.substr(0, drop_path.length - 1)];
			// Remove temporary files
			files.forEach(function (file) {
				FS.unlink(file);
				let dir = file.replace(drop_path, '');
				let idx = dir.lastIndexOf('/');
				while (idx > 0) {
					dir = dir.substr(0, idx);
					if (dirs.indexOf(drop_path + dir) === -1) {
						dirs.push(drop_path + dir);
					}
					idx = dir.lastIndexOf('/');
				}
			});
			// Remove dirs.
			dirs.sort(function (a, b) {
				const al = (a.match(/\//g) || []).length;
				const bl = (b.match(/\//g) || []).length;
				if (al > bl) {
					return -1;
				} else if (al < bl) {
					return 1;
				}
				return 0;
			}).forEach(function (dir) {
				FS.rmdir(dir);
			});
		},

		handler: function (callback) {
			return function (ev) {
				GodotInputDragDrop._process_event(ev, callback);
			};
		},
	},
};
mergeInto(LibraryManager.library, GodotInputDragDrop);

/*
 * Godot exposed input functions.
 */
const GodotInput = {
	$GodotInput__deps: ['$GodotRuntime', '$GodotConfig', '$GodotEventListeners', '$GodotInputGamepads', '$GodotInputDragDrop', '$GodotIME'],
	$GodotInput: {
		inputKeyCallback: null,
		setInputKeyData: null,

		getModifiers: function (evt) {
			return (evt.shiftKey + 0) + ((evt.altKey + 0) << 1) + ((evt.ctrlKey + 0) << 2) + ((evt.metaKey + 0) << 3);
		},

		computePosition: function (evt, rect) {
			const canvas = GodotConfig.canvas;
			const rw = canvas.width / rect.width;
			const rh = canvas.height / rect.height;
			const x = (evt.clientX - rect.x) * rw;
			const y = (evt.clientY - rect.y) * rh;
			return [x, y];
		},

		onKeyEvent: function (pIsPressed, pEvent) {
			if (GodotInput.inputKeyCallback == null) {
				throw new TypeError('GodotInput.onKeyEvent(): GodotInput.inputKeyCallback is null, cannot process key event.');
			}
			if (GodotInput.setInputKeyData == null) {
				throw new TypeError('GodotInput.onKeyEvent(): GodotInput.setInputKeyData is null, cannot process key event.');
			}

			const modifiers = GodotInput.getModifiers(pEvent);
			GodotInput.setInputKeyData(pEvent.code, pEvent.key);
			GodotInput.inputKeyCallback(pIsPressed ? 1 : 0, pEvent.repeat, modifiers);
			pEvent.preventDefault();
		},
	},

	/*
	 * Mouse API
	 */
	godot_js_input_mouse_move_cb__proxy: 'sync',
	godot_js_input_mouse_move_cb__sig: 'vi',
	godot_js_input_mouse_move_cb: function (callback) {
		const func = GodotRuntime.get_func(callback);
		const canvas = GodotConfig.canvas;
		function move_cb(evt) {
			const rect = canvas.getBoundingClientRect();
			const pos = GodotInput.computePosition(evt, rect);
			// Scale movement
			const rw = canvas.width / rect.width;
			const rh = canvas.height / rect.height;
			const rel_pos_x = evt.movementX * rw;
			const rel_pos_y = evt.movementY * rh;
			const modifiers = GodotInput.getModifiers(evt);
			func(pos[0], pos[1], rel_pos_x, rel_pos_y, modifiers);
		}
		GodotEventListeners.add(window, 'mousemove', move_cb, false);
	},

	godot_js_input_mouse_wheel_cb__proxy: 'sync',
	godot_js_input_mouse_wheel_cb__sig: 'vi',
	godot_js_input_mouse_wheel_cb: function (callback) {
		const func = GodotRuntime.get_func(callback);
		function wheel_cb(evt) {
			if (func(evt['deltaX'] || 0, evt['deltaY'] || 0)) {
				evt.preventDefault();
			}
		}
		GodotEventListeners.add(GodotConfig.canvas, 'wheel', wheel_cb, false);
	},

	godot_js_input_mouse_button_cb__proxy: 'sync',
	godot_js_input_mouse_button_cb__sig: 'vi',
	godot_js_input_mouse_button_cb: function (callback) {
		const func = GodotRuntime.get_func(callback);
		const canvas = GodotConfig.canvas;
		function button_cb(p_pressed, evt) {
			const rect = canvas.getBoundingClientRect();
			const pos = GodotInput.computePosition(evt, rect);
			const modifiers = GodotInput.getModifiers(evt);
			// Since the event is consumed, focus manually.
			// NOTE: The iframe container may not have focus yet, so focus even when already active.
			if (p_pressed) {
				GodotConfig.canvas.focus();
			}
			if (func(p_pressed, evt.button, pos[0], pos[1], modifiers)) {
				evt.preventDefault();
			}
		}
		GodotEventListeners.add(canvas, 'mousedown', button_cb.bind(null, 1), false);
		GodotEventListeners.add(window, 'mouseup', button_cb.bind(null, 0), false);
	},

	/*
	 * Touch API
	 */
	godot_js_input_touch_cb__proxy: 'sync',
	godot_js_input_touch_cb__sig: 'viii',
	godot_js_input_touch_cb: function (callback, ids, coords) {
		const func = GodotRuntime.get_func(callback);
		const canvas = GodotConfig.canvas;
		function touch_cb(type, evt) {
			// Since the event is consumed, focus manually.
			// NOTE: The iframe container may not have focus yet, so focus even when already active.
			if (type === 0) {
				GodotConfig.canvas.focus();
			}
			const rect = canvas.getBoundingClientRect();
			rect.x = 0;
			rect.y = 0;
			const touches = evt.changedTouches;
			for (let i = 0; i < touches.length; i++) {
				const touch = touches[i];
				const pos = GodotInput.computePosition(touch, rect);
				GodotRuntime.setHeapValue(coords + (i * 2) * 8, pos[0], 'double');
				GodotRuntime.setHeapValue(coords + (i * 2 + 1) * 8, pos[1], 'double');
				GodotRuntime.setHeapValue(ids + i * 4, touch.identifier, 'i32');
			}
			func(type, touches.length);
			if (evt.cancelable) {
				evt.preventDefault();
			}
		}
		GodotEventListeners.add(canvas, 'touchstart', touch_cb.bind(null, 0), false);
		GodotEventListeners.add(canvas, 'touchend', touch_cb.bind(null, 1), false);
		GodotEventListeners.add(canvas, 'touchcancel', touch_cb.bind(null, 1), false);
		GodotEventListeners.add(canvas, 'touchmove', touch_cb.bind(null, 2), false);
	},

	/*
	 * Key API
	 */
	godot_js_input_key_cb__proxy: 'sync',
	godot_js_input_key_cb__sig: 'viii',
	godot_js_input_key_cb: function (pCallback, pCodePtr, pKeyPtr) {
		GodotInput.inputKeyCallback = GodotRuntime.get_func(pCallback);
		GodotInput.setInputKeyData = (pCode, pKey) => {
			GodotRuntime.stringToHeap(pCode, pCodePtr, 32);
			GodotRuntime.stringToHeap(pKey, pKeyPtr, 32);
		};
		GodotEventListeners.add(GodotConfig.canvas, 'keydown', GodotInput.onKeyEvent.bind(null, true), false);
		GodotEventListeners.add(GodotConfig.canvas, 'keyup', GodotInput.onKeyEvent.bind(null, false), false);
	},

	/*
	 * IME API
	 */
	godot_js_set_ime_active__proxy: 'sync',
	godot_js_set_ime_active__sig: 'vi',
	godot_js_set_ime_active: function (p_active) {
		GodotIME.ime_active(p_active);
	},

	godot_js_set_ime_position__proxy: 'sync',
	godot_js_set_ime_position__sig: 'vii',
	godot_js_set_ime_position: function (p_x, p_y) {
		GodotIME.ime_position(p_x, p_y);
	},

	godot_js_set_ime_cb__proxy: 'sync',
	godot_js_set_ime_cb__sig: 'viiii',
	godot_js_set_ime_cb: function (p_ime_cb, p_key_cb, code, key) {
		const ime_cb = GodotRuntime.get_func(p_ime_cb);
		const key_cb = GodotRuntime.get_func(p_key_cb);
		GodotIME.init(ime_cb, key_cb, code, key);
	},

	godot_js_is_ime_focused__proxy: 'sync',
	godot_js_is_ime_focused__sig: 'i',
	godot_js_is_ime_focused: function () {
		return GodotIME.active;
	},

	/*
	 * Gamepad API
	 */
	godot_js_input_gamepad_cb__proxy: 'sync',
	godot_js_input_gamepad_cb__sig: 'vi',
	godot_js_input_gamepad_cb: function (change_cb) {
		const onchange = GodotRuntime.get_func(change_cb);
		GodotInputGamepads.init(onchange);
	},

	godot_js_input_gamepad_sample_count__proxy: 'sync',
	godot_js_input_gamepad_sample_count__sig: 'i',
	godot_js_input_gamepad_sample_count: function () {
		return GodotInputGamepads.get_samples().length;
	},

	godot_js_input_gamepad_sample__proxy: 'sync',
	godot_js_input_gamepad_sample__sig: 'i',
	godot_js_input_gamepad_sample: function () {
		GodotInputGamepads.sample();
		return 0;
	},

	godot_js_input_gamepad_sample_get__proxy: 'sync',
	godot_js_input_gamepad_sample_get__sig: 'iiiiiii',
	godot_js_input_gamepad_sample_get: function (p_index, r_btns, r_btns_num, r_axes, r_axes_num, r_standard) {
		const sample = GodotInputGamepads.get_sample(p_index);
		if (!sample || !sample.connected) {
			return 1;
		}
		const btns = sample.buttons;
		const btns_len = btns.length < 16 ? btns.length : 16;
		for (let i = 0; i < btns_len; i++) {
			GodotRuntime.setHeapValue(r_btns + (i << 2), btns[i], 'float');
		}
		GodotRuntime.setHeapValue(r_btns_num, btns_len, 'i32');
		const axes = sample.axes;
		const axes_len = axes.length < 10 ? axes.length : 10;
		for (let i = 0; i < axes_len; i++) {
			GodotRuntime.setHeapValue(r_axes + (i << 2), axes[i], 'float');
		}
		GodotRuntime.setHeapValue(r_axes_num, axes_len, 'i32');
		const is_standard = sample.standard ? 1 : 0;
		GodotRuntime.setHeapValue(r_standard, is_standard, 'i32');
		return 0;
	},

	/*
	 * Drag/Drop API
	 */
	godot_js_input_drop_files_cb__proxy: 'sync',
	godot_js_input_drop_files_cb__sig: 'vi',
	godot_js_input_drop_files_cb: function (callback) {
		const func = GodotRuntime.get_func(callback);
		const dropFiles = function (files) {
			const args = files || [];
			if (!args.length) {
				return;
			}
			const argc = args.length;
			const argv = GodotRuntime.allocStringArray(args);
			func(argv, argc);
			GodotRuntime.freeStringArray(argv, argc);
		};
		const canvas = GodotConfig.canvas;
		GodotEventListeners.add(canvas, 'dragover', function (ev) {
			// Prevent default behavior (which would try to open the file(s))
			ev.preventDefault();
		}, false);
		GodotEventListeners.add(canvas, 'drop', GodotInputDragDrop.handler(dropFiles));
	},

	/* Paste API */
	godot_js_input_paste_cb__proxy: 'sync',
	godot_js_input_paste_cb__sig: 'vi',
	godot_js_input_paste_cb: function (callback) {
		const func = GodotRuntime.get_func(callback);
		GodotEventListeners.add(window, 'paste', function (evt) {
			const text = evt.clipboardData.getData('text');
			const ptr = GodotRuntime.allocString(text);
			func(ptr);
			GodotRuntime.free(ptr);
		}, false);
	},

	godot_js_input_vibrate_handheld__proxy: 'sync',
	godot_js_input_vibrate_handheld__sig: 'vi',
	godot_js_input_vibrate_handheld: function (p_duration_ms) {
		if (typeof navigator.vibrate !== 'function') {
			GodotRuntime.print('This browser does not support vibration.');
		} else {
			navigator.vibrate(p_duration_ms);
		}
	},
};

autoAddDeps(GodotInput, '$GodotInput');
mergeInto(LibraryManager.library, GodotInput);
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 323kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 323kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 323kUpdated Claude CodeCodexVerifiedInstall