]> granicus.if.org Git - nethack/commitdiff
js test code
authorAdam Powers <apowers@ato.ms>
Sat, 12 Sep 2020 19:34:45 +0000 (12:34 -0700)
committerAdam Powers <apowers@ato.ms>
Sat, 12 Sep 2020 19:34:45 +0000 (12:34 -0700)
sys/lib/npm-package/test/test.js [new file with mode: 0644]

diff --git a/sys/lib/npm-package/test/test.js b/sys/lib/npm-package/test/test.js
new file mode 100644 (file)
index 0000000..3032399
--- /dev/null
@@ -0,0 +1,55 @@
+let nethackStart = require("../src/nethackShim.js");
+Error.stackTraceLimit = 20;
+
+// debugging to make sure the JavaScript event loop isn't blocked
+// const {performance} = require("perf_hooks");
+// let currentTime = 0;
+// let lastTime = 0;
+// setInterval(() => {
+//     lastTime = currentTime;
+//     currentTime = performance.now();
+//     console.log("Time since last JavaScript loop:", currentTime-lastTime);
+// }, 10);
+
+let Module = {};
+let winCount = 0;
+
+/* global globalThis */
+nethackStart(async function (name, ... args) {
+    switch(name) {
+    case "shim_init_nhwindows":
+        console.log("globalThis.nethackGlobal", globalThis.nethackGlobal);
+        break;
+    case "shim_create_nhwindow":
+        winCount++;
+        console.log("creating window", args, "returning", winCount);
+        return winCount;
+    case "shim_print_glyph":
+        var x = args[1];
+        var y = args[2];
+        var glyph = args[3];
+
+        var ret = globalThis.nethackGlobal.helpers.mapglyphHelper(glyph, x, y, 0);
+        console.log(`GLYPH (${x},${y}): ${String.fromCharCode(ret.ch)}`);
+        return;
+    // case "shim_update_inventory":
+    //     globalThis.nethackGlobal.helpers.displayInventory();
+    //     return;
+    case "shim_select_menu":
+        return await selectMenu(...args);
+    case "shim_yn_function":
+    case "shim_message_menu":
+        return 121; // 'y'
+    case "shim_nhgetch":
+    case "shim_nh_poskey":
+        return 0;
+    default:
+        console.log(`called doGraphics: ${name} [${args}]`);
+        return 0;
+    }
+}, Module);
+
+async function selectMenu(window, how, selected) {
+    Module.setValue(selected, 0, "*");
+    return -1;
+}
\ No newline at end of file