1 Star 0 Fork 5

flanpan/RMMZ脚本框架中文注释

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.js 5.10 KB
一键复制 编辑 原始数据 按行查看 历史
9梦菌 提交于 2020-09-30 00:43 . MZ框架脚本更新至1.0.2
//=============================================================================
// main.js v1.0.2
//=============================================================================
// 脚本地址
const scriptUrls = [
"js/libs/pixi.js",
"js/libs/pako.min.js",
"js/libs/localforage.min.js",
"js/libs/effekseer.min.js",
"js/libs/vorbisdecoder.js",
"js/rmmz_core.js",
"js/rmmz_managers.js",
"js/rmmz_objects.js",
"js/rmmz_scenes.js",
"js/rmmz_sprites.js",
"js/rmmz_windows.js",
"js/plugins.js"
];
// Effekseer的 wasm 文件地址
const effekseerWasmUrl = "js/libs/effekseer.wasm";
class Main {
// 构造函数
constructor() {
this.xhrSucceeded = false;
this.loadCount = 0;
this.error = null;
}
// 运行
run() {
this.showLoadingSpinner();
this.testXhr();
this.loadMainScripts();
}
// 显示加载的旋转框
showLoadingSpinner() {
const loadingSpinner = document.createElement("div");
const loadingSpinnerImage = document.createElement("div");
loadingSpinner.id = "loadingSpinner";
loadingSpinnerImage.id = "loadingSpinnerImage";
loadingSpinner.appendChild(loadingSpinnerImage);
document.body.appendChild(loadingSpinner);
}
// 消除加载的旋转框
eraseLoadingSpinner() {
const loadingSpinner = document.getElementById("loadingSpinner");
if (loadingSpinner) {
document.body.removeChild(loadingSpinner);
}
}
// 测试 XMLHttpRequest
testXhr() {
const xhr = new XMLHttpRequest();
xhr.open("GET", document.currentScript.src);
xhr.onload = () => (this.xhrSucceeded = true);
xhr.send();
}
// 加载主脚本
loadMainScripts() {
for (const url of scriptUrls) {
const script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
script.async = false;
script.defer = true;
script.onload = this.onScriptLoad.bind(this);
script.onerror = this.onScriptError.bind(this);
script._url = url;
document.body.appendChild(script);
}
this.numScripts = scriptUrls.length;
window.addEventListener("load", this.onWindowLoad.bind(this));
window.addEventListener("error", this.onWindowError.bind(this));
}
// 当脚本加载
onScriptLoad() {
if (++this.loadCount === this.numScripts) {
PluginManager.setup($plugins);
}
}
// 当脚本错误
onScriptError(e) {
this.printError("Failed to load", e.target._url);
}
// 打印错误
printError(name, message) {
this.eraseLoadingSpinner();
if (!document.getElementById("errorPrinter")) {
const errorPrinter = document.createElement("div");
errorPrinter.id = "errorPrinter";
errorPrinter.innerHTML = this.makeErrorHtml(name, message);
document.body.appendChild(errorPrinter);
}
}
// 制作错误页面
makeErrorHtml(name, message) {
const nameDiv = document.createElement("div");
const messageDiv = document.createElement("div");
nameDiv.id = "errorName";
messageDiv.id = "errorMessage";
nameDiv.innerHTML = name;
messageDiv.innerHTML = message;
return nameDiv.outerHTML + messageDiv.outerHTML;
}
//当窗口加载
onWindowLoad() {
if (!this.xhrSucceeded) {
const message = "Your browser does not allow to read local files.";
this.printError("Error", message);
} else if (this.isPathRandomized()) {
const message = "Please move the Game.app to a different folder.";
this.printError("Error", message);
} else if (this.error) {
this.printError(this.error.name, this.error.message);
} else {
this.initEffekseerRuntime();
}
}
//当窗口错误
onWindowError(event) {
if (!this.error) {
this.error = event.error;
}
}
// 是否路径随机化
isPathRandomized() {
// [备注] 当网守路径随机化生效时,我们无法正确保存游戏。
// [Note] We cannot save the game properly when Gatekeeper Path
// Randomization is in effect.
return (
Utils.isNwjs() &&
process.mainModule.filename.startsWith("/private/var")
);
}
// 初始化 Effeckseer 运行时库
initEffekseerRuntime() {
const onLoad = this.onEffekseerLoad.bind(this);
const onError = this.onEffekseerError.bind(this);
effekseer.initRuntime(effekseerWasmUrl, onLoad, onError);
}
// 当 Effectseer 加载
onEffekseerLoad() {
this.eraseLoadingSpinner();
SceneManager.run(Scene_Boot);
}
// 当 Effectseer 错误
onEffekseerError() {
this.printError("Failed to load", effekseerWasmUrl);
}
}
const main = new Main();
main.run();
//-----------------------------------------------------------------------------
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/flanpan/rmmz.git
git@gitee.com:flanpan/rmmz.git
flanpan
rmmz
RMMZ脚本框架中文注释
master

搜索帮助