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

assets/min-runtime/godot-loader.js

View on GitHub
(function (global) {
    const root = global;
    const windowObject = root.window || root;
    const gameGlobal = root.GameGlobal || (root.GameGlobal = {});
    const wxApi = root.wx;

    class GodotLoader {
        constructor(onScreenCanvas, config) {
            this.onScreenCanvas = onScreenCanvas;
            this.offScreenCanvas = document.createElement("canvas");
            this.config = config;
            this.progress = 0;
            this.currentText = config.textConfig.firstStartText;
            this.backgroundImage = null;
            this.iconImage = null;
            this.dpr = this.getDevicePixelRatio();
            this.resizeHandler = this.resizeCanvases.bind(this);

            this.initWebGL();
            this.loadImages();
            this.resizeCanvases();
            windowObject.addEventListener("resize", this.resizeHandler);

            this.render();
            this.loadGameEngine();
        }

        getWindowInfo() {
            if (wxApi && typeof wxApi.getWindowInfo === "function") {
                return wxApi.getWindowInfo();
            }
            if (wxApi && typeof wxApi.getSystemInfoSync === "function") {
                return wxApi.getSystemInfoSync();
            }
            return null;
        }

        getDevicePixelRatio() {
            const info = this.getWindowInfo();
            const ratio = Math.max(
                1,
                Number(info && (info.pixelRatio || info.devicePixelRatio)) ||
                Number(gameGlobal.__godotMinigamePixelRatio) ||
                Number(windowObject.devicePixelRatio) ||
                1
            );

            gameGlobal.__godotMinigamePixelRatio = ratio;
            this.syncWindowDevicePixelRatio(ratio);
            return ratio;
        }

        syncWindowDevicePixelRatio(ratio) {
            try {
                const descriptor = Object.getOwnPropertyDescriptor(windowObject, "devicePixelRatio");
                if (!descriptor || descriptor.configurable) {
                    Object.defineProperty(windowObject, "devicePixelRatio", {
                        configurable: true,
                        get: () => gameGlobal.__godotMinigamePixelRatio || ratio,
                    });
                } else if (descriptor.writable || descriptor.set) {
                    windowObject.devicePixelRatio = ratio;
                }
            } catch (err) {
                try {
                    windowObject.devicePixelRatio = ratio;
                } catch (assignErr) {}
            }
        }

        getViewportSize() {
            const info = this.getWindowInfo();
            if (info && info.windowWidth && info.windowHeight) {
                return {
                    width: info.windowWidth,
                    height: info.windowHeight,
                };
            }
            return {
                width: windowObject.innerWidth,
                height: windowObject.innerHeight,
            };
        }

        initWebGL() {
            const attrs = {
                alpha: false,
                antialias: false,
                depth: true,
                enableExtensionsByDefault: 1,
                explicitSwapControl: 1,
                failIfMajorPerformanceCaveat: false,
                majorVersion: 2,
                minorVersion: 0,
                powerPreference: "default",
                premultipliedAlpha: true,
                preserveDrawingBuffer: true,
                proxyContextToMainThread: 0,
                renderViaOffscreenBackBuffer: true,
                stencil: false,
            };

            const useWXGLX =
                gameGlobal.__GODOT_DISABLE_WXGLX !== true &&
                !!wxApi &&
                !!wxApi.env &&
                !!wxApi.env.isSupportEmscriptenGLX;
            gameGlobal.__godotMinigameWXGLXEnabled = useWXGLX;
            const contextType = useWXGLX ? "wxwebgl2" : "webgl2";
            this.gl = this.onScreenCanvas.getContext(contextType, attrs);
            if (!this.gl) {
                console.error(`Unable to initialize ${contextType}.`);
                return;
            }

            const vertexShaderSource = `
                attribute vec2 a_position;
                attribute vec2 a_texCoord;
                varying vec2 v_texCoord;
                void main() {
                    gl_Position = vec4(a_position, 0.0, 1.0);
                    v_texCoord = vec2(a_texCoord.x, 1.0 - a_texCoord.y);
                }
            `;

            const fragmentShaderSource = `
                precision highp float;
                uniform sampler2D u_image;
                varying vec2 v_texCoord;
                void main() {
                    gl_FragColor = texture2D(u_image, v_texCoord);
                }
            `;

            const vertexShader = this.createShader(this.gl.VERTEX_SHADER, vertexShaderSource);
            const fragmentShader = this.createShader(this.gl.FRAGMENT_SHADER, fragmentShaderSource);
            this.program = this.createProgram(vertexShader, fragmentShader);
            this.positionLocation = this.gl.getAttribLocation(this.program, "a_position");
            this.texCoordLocation = this.gl.getAttribLocation(this.program, "a_texCoord");

            this.positionBuffer = this.gl.createBuffer();
            this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.positionBuffer);
            this.gl.bufferData(
                this.gl.ARRAY_BUFFER,
                new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
                this.gl.STATIC_DRAW
            );

            this.texCoordBuffer = this.gl.createBuffer();
            this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.texCoordBuffer);
            this.gl.bufferData(
                this.gl.ARRAY_BUFFER,
                new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]),
                this.gl.STATIC_DRAW
            );

            this.texture = this.gl.createTexture();
            this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
            this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
            this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
            this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
            this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
        }

        createShader(type, source) {
            const shader = this.gl.createShader(type);
            this.gl.shaderSource(shader, source);
            this.gl.compileShader(shader);
            if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) {
                console.error("Shader compile failed: " + this.gl.getShaderInfoLog(shader));
                this.gl.deleteShader(shader);
                return null;
            }
            return shader;
        }

        createProgram(vertexShader, fragmentShader) {
            const program = this.gl.createProgram();
            this.gl.attachShader(program, vertexShader);
            this.gl.attachShader(program, fragmentShader);
            this.gl.linkProgram(program);
            if (!this.gl.getProgramParameter(program, this.gl.LINK_STATUS)) {
                console.error("Program link failed: " + this.gl.getProgramInfoLog(program));
                return null;
            }
            return program;
        }

        imageSourceFallbacks(src) {
            if (!src || /^(https?:|data:|wxfile:|file:)/.test(src)) {
                return src ? [src] : [];
            }

            const relative = src.charAt(0) === "/" ? src.slice(1) : src;
            return [relative, "/" + relative].filter((item, index, list) => item && list.indexOf(item) === index);
        }

        loadImage(src, label, assign) {
            const sources = this.imageSourceFallbacks(src);
            if (!sources.length) {
                return;
            }

            const image = new Image();
            let index = 0;
            image.onload = () => {
                assign(image);
                this.render();
            };
            image.onerror = (event) => {
                if (index + 1 < sources.length) {
                    index += 1;
                    image.src = sources[index];
                    return;
                }
                console.warn("[godot-loader] image load failed", label, image.src, event && (event.errMsg || event.message || event));
            };
            image.src = sources[index];
        }

        loadImages() {
            const materialConfig = this.config.materialConfig || {};
            this.loadImage(materialConfig.backgroundImage, "background", (image) => {
                this.backgroundImage = image;
            });
            this.loadImage(materialConfig.iconImage, "icon", (image) => {
                this.iconImage = image;
            });
        }

        resizeCanvases() {
            const viewport = this.getViewportSize();
            const width = viewport.width;
            const height = viewport.height;

            this.dpr = this.getDevicePixelRatio();
            this.onScreenCanvas.width = width * this.dpr;
            this.onScreenCanvas.height = height * this.dpr;
            this.onScreenCanvas.style.width = width + "px";
            this.onScreenCanvas.style.height = height + "px";
            this.offScreenCanvas.width = width * this.dpr;
            this.offScreenCanvas.height = height * this.dpr;

            if (this.gl) {
                this.gl.viewport(0, 0, this.onScreenCanvas.width, this.onScreenCanvas.height);
            }

            this.render();
        }

        drawRoundedRect(ctx, x, y, width, height, radius) {
            if (width < 2 * radius) {
                radius = width / 2;
            }
            if (height < 2 * radius) {
                radius = height / 2;
            }
            ctx.beginPath();
            ctx.moveTo(x + radius, y);
            ctx.arcTo(x + width, y, x + width, y + height, radius);
            ctx.arcTo(x + width, y + height, x, y + height, radius);
            ctx.arcTo(x, y + height, x, y, radius);
            ctx.arcTo(x, y, x + width, y, radius);
            ctx.closePath();
            ctx.fill();
        }

        drawCoverImage(ctx, image, width, height) {
            if (!image.width || !image.height) {
                ctx.drawImage(image, 0, 0, width, height);
                return;
            }

            const scale = Math.max(width / image.width, height / image.height);
            const drawWidth = image.width * scale;
            const drawHeight = image.height * scale;
            ctx.drawImage(image, (width - drawWidth) / 2, (height - drawHeight) / 2, drawWidth, drawHeight);
        }

        render() {
            if (!this.gl) {
                return;
            }

            const ctx = this.offScreenCanvas.getContext("2d");
            const width = this.offScreenCanvas.width;
            const height = this.offScreenCanvas.height;

            ctx.clearRect(0, 0, width, height);
            ctx.imageSmoothingEnabled = true;
            ctx.imageSmoothingQuality = "high";

            if (this.backgroundImage) {
                this.drawCoverImage(ctx, this.backgroundImage, width, height);
            }

            const barConfig = this.config.barConfig.style;
            const iconConfig = this.config.iconConfig.style;
            const barX = (width - barConfig.width * this.dpr) / 2;
            const barY =
                height -
                iconConfig.bottom * this.dpr -
                iconConfig.height * this.dpr -
                30 * this.dpr -
                barConfig.height * this.dpr;

            ctx.fillStyle = barConfig.backgroundColor;
            this.drawRoundedRect(
                ctx,
                barX,
                barY,
                barConfig.width * this.dpr,
                barConfig.height * this.dpr,
                barConfig.borderRadius * this.dpr
            );

            if (this.progress > 0) {
                const progressWidth = Math.max(
                    0,
                    (barConfig.width * this.dpr - 2 * barConfig.padding * this.dpr) * this.progress
                );
                ctx.fillStyle = barConfig.foregroundColor;
                this.drawRoundedRect(
                    ctx,
                    barX + barConfig.padding * this.dpr,
                    barY + barConfig.padding * this.dpr,
                    progressWidth,
                    barConfig.height * this.dpr - 2 * barConfig.padding * this.dpr,
                    (barConfig.borderRadius - barConfig.padding) * this.dpr
                );
            }

            const textConfig = this.config.textConfig;
            ctx.font = textConfig.style.fontSize * this.dpr + "px Arial";
            ctx.fillStyle = textConfig.style.color;
            ctx.textAlign = "center";
            ctx.textBaseline = "middle";
            ctx.fillText(this.currentText, width / 2, barY + (barConfig.height * this.dpr) / 2);

            if (this.config.iconConfig.visible && this.iconImage) {
                const iconX = (width - iconConfig.width * this.dpr) / 2;
                const iconY = height - iconConfig.bottom * this.dpr - iconConfig.height * this.dpr;
                ctx.drawImage(this.iconImage, iconX, iconY, iconConfig.width * this.dpr, iconConfig.height * this.dpr);
            }

            this.renderToWebGL();
        }

        renderToWebGL() {
            if (!this.gl) {
                return;
            }

            this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
            this.gl.texImage2D(
                this.gl.TEXTURE_2D,
                0,
                this.gl.RGBA,
                this.gl.RGBA,
                this.gl.UNSIGNED_BYTE,
                this.offScreenCanvas
            );

            this.gl.useProgram(this.program);

            this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.positionBuffer);
            this.gl.enableVertexAttribArray(this.positionLocation);
            this.gl.vertexAttribPointer(this.positionLocation, 2, this.gl.FLOAT, false, 0, 0);

            this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.texCoordBuffer);
            this.gl.enableVertexAttribArray(this.texCoordLocation);
            this.gl.vertexAttribPointer(this.texCoordLocation, 2, this.gl.FLOAT, false, 0, 0);

            this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4);

            if (typeof this.gl.flush === "function") {
                this.gl.flush();
            }
            if (typeof this.gl.commit === "function") {
                this.gl.commit();
            }
        }

        normalizeProgress(progress) {
            const value = Number(progress) || 0;
            return Math.max(0, Math.min(1, value > 1 ? value / 100 : value));
        }

        updateProgress(progress, text) {
            const normalized = this.normalizeProgress(progress);
            this.progress = Math.max(this.progress || 0, normalized);
            if (text) {
                this.currentText = text;
            }
            this.render();

            if (typeof windowObject.requestAnimationFrame === "function") {
                windowObject.requestAnimationFrame(() => this.render());
            }
        }

        loadGameEngine() {
            if (!wxApi || typeof wxApi.loadSubpackage !== "function") {
                return;
            }

            const task = wxApi.loadSubpackage({
                name: "engine",
                success: () => {
                    this.progress = 1;
                    this.updateProgress(this.progress, this.config.textConfig.initText);
                },
            });

            if (task && typeof task.onProgressUpdate === "function") {
                task.onProgressUpdate(({ progress }) => {
                    this.updateProgress(progress, this.config.textConfig.downloadingText[0]);
                });
            }
        }

        cleanup() {
            windowObject.removeEventListener("resize", this.resizeHandler);

            if (!this.gl) {
                return;
            }

            this.gl.deleteProgram(this.program);
            this.gl.deleteBuffer(this.positionBuffer);
            this.gl.deleteBuffer(this.texCoordBuffer);
            this.gl.deleteTexture(this.texture);
            this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);
            this.gl.bindTexture(this.gl.TEXTURE_2D, null);
            this.gl.useProgram(null);
            this.gl.disable(this.gl.BLEND);
            this.gl.disable(this.gl.DEPTH_TEST);
            this.gl.disable(this.gl.CULL_FACE);
            this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
            this.gl.clearColor(0, 0, 0, 0);
            this.gl.clear(this.gl.COLOR_BUFFER_BIT);
        }
    }

    gameGlobal.GodotLoader = GodotLoader;
})(typeof globalThis !== "undefined" ? globalThis : this);
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