From 486043a3905c748a17c45a0902e2e03c48d81d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=86=20stargen=20=E2=98=86?= Date: Fri, 6 Dec 2024 14:59:31 -0600 Subject: [PATCH] Create ruffle.js --- flashgames/ruffle.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 flashgames/ruffle.js diff --git a/flashgames/ruffle.js b/flashgames/ruffle.js new file mode 100644 index 0000000..b426b18 --- /dev/null +++ b/flashgames/ruffle.js @@ -0,0 +1,53 @@ +// eslint-disable-next-line no-unused-vars +/* global __webpack_public_path__:writable */ + +import { Setup } from "ruffle-core"; + +let currentScriptURL = null; + +try { + if ( + document.currentScript !== undefined && + document.currentScript !== null && + "src" in document.currentScript && + document.currentScript.src !== "" + ) { + let src = document.currentScript.src; + + // CDNs allow omitting the filename. If it's omitted, append a slash to + // prevent the last component from being dropped. + if (!src.endsWith(".js") && !src.endsWith("/")) { + src += "/"; + } + + currentScriptURL = new URL(".", src); + } + // eslint-disable-next-line no-unused-vars +} catch (_e) { + console.warn("Unable to get currentScript URL"); +} + +function publicPath(config) { + // Default to the directory where this script resides. + let path = currentScriptURL?.href ?? ""; + if ( + "publicPath" in config && + config.publicPath !== null && + config.publicPath !== undefined + ) { + path = config.publicPath; + } + + // Webpack expects the paths to end with a slash. + if (path !== "" && !path.endsWith("/")) { + path += "/"; + } + + return path; +} + +Setup.installRuffle("local", { + onFirstLoad: () => { + __webpack_public_path__ = publicPath(window.RufflePlayer?.config); + }, +});