npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@neth4ck/neth4ck

v1.0.4

Published

The original NetHack rogue-like game built as a WebAssembly module

Downloads

20

Readme

NetHack

This is the ACTUAL NetHack game, originally written in 1982 and one of the longest-standing open source collaborations. This isn't a wrapper around the binary NetHack, but the game itself compiled into WebAssembly (WASM) using emscripten. This module should run anywhere WebAssembly is supported including node.js and modern browsers.

Since NetHack typically uses the TTY to show depictions of the game and that won't work for WebAssembly, you are required to implement the graphics portion of NetHack to make this work. This allows a wide variety of UIs to be created, both text and graphics based as well as using keyboard and mouse to control the game. The API for implementing graphics is described below.

Install

npm install nethack

API

The main module returns a setup function: startNethack(uiCallback, moduleOptions).

  • uiCallback(name, ... args) - Your callback function that will handle rendering NetHack on the screen of your choice. The name argument is one of the UI functions of the NetHack Window Interface and the args are corresponding to the window interface function that is being called. You are required to return the correct type of data for the function that is implemented. The uiCallback may be an async function.
  • moduleOptions - An optional emscripten Module object for configuring the WASM that will be run.

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

let nethackStart = require("nethack");

nethackStart(doGraphics);

let winCount = 0;
async function doGraphics(name, ... args) {
    console.log(`shim graphics: ${name} [${args}]`);

    switch(name) {
    case "shim_create_nhwindow":
        winCount++;
        console.log("creating window", args, "returning", winCount);
        return winCount;
    case "shim_yn_function":
    case "shim_message_menu":
        return 121; // return 'y' to all questions
    case "shim_nhgetch":
    case "shim_nh_poskey":
        return 0; // simulates a mouse click on "exit up the stairs"
    default:
        return 0;
    }
}

Other Notes

  • This module isn't small -- the WASM code is about 10MB. It may be slow to load over non-broadband connections. There are some emscripten build optimizations that may help with browser builds (such as dynamic loading), but those aren't currently part of this package. Pull requests are always welcome. :)
  • This hasn't been tested on browsers. If you get this to work on a browser, please let me know and I will add notes. Or if anyone wants to help setup automated browser testing, that would be supremely appreciated.