delinting
This commit is contained in:
@@ -6,41 +6,56 @@ let savedOnRuntimeInitialized;
|
|||||||
|
|
||||||
// starts nethack
|
// starts nethack
|
||||||
function nethackStart(cb, inputModule = {}) {
|
function nethackStart(cb, inputModule = {}) {
|
||||||
if(typeof cb !== "string" && typeof cb !== "function") throw new TypeError("expected first argument to be 'Function' or 'String' representing global callback function name");
|
if (typeof cb !== "string" && typeof cb !== "function") {
|
||||||
if(typeof inputModule !== "object") throw new TypeError("expected second argument to be object");
|
throw new TypeError("expected first argument to be 'Function' or 'String' representing global callback function name");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof inputModule !== "object") {
|
||||||
|
throw new TypeError("expected second argument to be object");
|
||||||
|
}
|
||||||
|
|
||||||
let cbName;
|
let cbName;
|
||||||
if(typeof cb === "function") {
|
if (typeof cb === "function") {
|
||||||
cbName = cb.name;
|
cbName = cb.name;
|
||||||
if (cbName === "") cbName = "__anonymousNetHackCallback";
|
if (cbName === "") {
|
||||||
if (globalThis[cbName] === undefined) globalThis[cbName] = cb;
|
cbName = "__anonymousNetHackCallback";
|
||||||
else if (globalThis[cbName] !== cb) throw new Error (`'globalThis["${cbName}"]' is not the same as specified callback`);
|
}
|
||||||
|
|
||||||
|
if (globalThis[cbName] === undefined) {
|
||||||
|
globalThis[cbName] = cb;
|
||||||
|
} else if (globalThis[cbName] !== cb) {
|
||||||
|
throw new Error(`'globalThis["${cbName}"]' is not the same as specified callback`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* global globalThis */
|
/* global globalThis */
|
||||||
userCallback = globalThis[cbName];
|
userCallback = globalThis[cbName];
|
||||||
if(typeof userCallback !== "function") throw new TypeError(`expected 'globalThis["${cbName}"]' to be a function`);
|
if (typeof userCallback !== "function") {
|
||||||
|
throw new TypeError(`expected 'globalThis["${cbName}"]' to be a function`);
|
||||||
|
}
|
||||||
// if(userCallback.constructor.name !== "AsyncFunction") throw new TypeError(`expected 'globalThis["${cbName}"]' to be an async function`);
|
// if(userCallback.constructor.name !== "AsyncFunction") throw new TypeError(`expected 'globalThis["${cbName}"]' to be an async function`);
|
||||||
|
|
||||||
// Emscripten Module config
|
// Emscripten Module config
|
||||||
Module = inputModule;
|
Module = inputModule;
|
||||||
savedOnRuntimeInitialized = Module.onRuntimeInitialized;
|
savedOnRuntimeInitialized = Module.onRuntimeInitialized;
|
||||||
Module.onRuntimeInitialized = function (... args) {
|
Module.onRuntimeInitialized = function(... args) {
|
||||||
// after the WASM is loaded, add the shim graphics callback function
|
// after the WASM is loaded, add the shim graphics callback function
|
||||||
Module.ccall(
|
Module.ccall(
|
||||||
"shim_graphics_set_callback", // C function name
|
"shim_graphics_set_callback", // C function name
|
||||||
null, // return type
|
null, // return type
|
||||||
["string"], // arg types
|
["string"], // arg types
|
||||||
[cbName], // arg values
|
[cbName], // arg values
|
||||||
{async: true} // options
|
{async: true}, // options
|
||||||
);
|
);
|
||||||
|
|
||||||
// if the user had their own onRuntimeInitialized(), call it now
|
// if the user had their own onRuntimeInitialized(), call it now
|
||||||
if (savedOnRuntimeInitialized) savedOnRuntimeInitialized(... args);
|
if (savedOnRuntimeInitialized) {
|
||||||
|
savedOnRuntimeInitialized(... args);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// load and run the module
|
// load and run the module
|
||||||
var factory = require(path.join(__dirname, "../build/nethack.js"));
|
let factory = require(path.join(__dirname, "../build/nethack.js"));
|
||||||
factory(Module);
|
factory(Module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user