Merge branch 'libnethack' of https://github.com/apowers313/NetHack into libnethack2
This commit is contained in:
1127
sys/lib/libnethackmain.c
Normal file
1127
sys/lib/libnethackmain.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,11 @@ The main module returns a setup function: `startNethack(uiCallback, moduleOption
|
||||
* `moduleOptions` - An optional [emscripten Module object](https://emscripten.org/docs/api_reference/module.html) for configuring the WASM that will be run.
|
||||
* `Module.arguments` - Of note is the [arguments property](https://emscripten.org/docs/api_reference/module.html#Module.arguments) which gets passed to NetHack as its [command line parameters](https://nethackwiki.com/wiki/Options).
|
||||
|
||||
There are a number of auxilary functions and variables that may help with building your applications. All of these are under `globalThis.nethackOptions`. Use `console.log(globalThis.nethackOptions)` for a full list of options. Some worth mentioning are:
|
||||
* `globalThis.nethackOptions.helpers` - Helper functions that are useful for NetHack windowing ports
|
||||
* `globalThis.nethackOptions.mapglyphHelper` - Converts an integer glyph into a character to be displayed. Useful if you are using ASCII characters for representing NetHack (as opposed to tiles). Interface is `mapglyphHelper(glyph, x, y, mgflags)` and will typically be called as part of the `shim_print_glyph` function.
|
||||
* `globalThis.nethackOptions.constants` - A Object full of constants that are `#define`'d in NetHack's C code. Useful for translating to / from numbers in the APIs and return values.
|
||||
|
||||
## Example
|
||||
``` js
|
||||
let nethackStart = require("nethack");
|
||||
|
||||
5
sys/lib/npm-package/package-lock.json
generated
Normal file
5
sys/lib/npm-package/package-lock.json
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@neth4ck/neth4ck",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@neth4ck/neth4ck",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "The original NetHack rogue-like game built as a WebAssembly module",
|
||||
"main": "src/nethackShim.js",
|
||||
"scripts": {
|
||||
@@ -13,7 +13,12 @@
|
||||
"nethack",
|
||||
"rogue",
|
||||
"rogue-like",
|
||||
"game"
|
||||
"roguelike",
|
||||
"dungeon",
|
||||
"dungeons",
|
||||
"game",
|
||||
"rpg",
|
||||
"dnd"
|
||||
],
|
||||
"author": "Adam Powers <apowers@ato.ms>",
|
||||
"license": "SEE LICENSE IN LICENSE.md"
|
||||
|
||||
55
sys/lib/npm-package/test/test.js
Normal file
55
sys/lib/npm-package/test/test.js
Normal file
@@ -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;
|
||||
}
|
||||
@@ -146,5 +146,6 @@ PANICTRACE_LIBC=0
|
||||
# option settings via NETHACKOPTIONS in their environment or via
|
||||
# ~/.nethackrc run-time configuration file.
|
||||
#OPTIONS=!autopickup,fruit:tomato,symset:DECgraphics
|
||||
OPTIONS=perm_invent
|
||||
|
||||
#eof
|
||||
|
||||
Reference in New Issue
Block a user