hexicon 0.3.0

Hexicon, for writing interactive fiction: builds a game, plays it in a terminal, tests it, documents it, and serves editors
# Hexicon

Hexicon is a system for writing interactive fiction, focusing on two kinds that authors tend to write.

- **parser games**, played by typing commands such as `open the box` or `go north`
- **choice games**, played by choosing from a list, by a click or a number (think Twine and ChoiceScript)

You can create games that mix the two together: moments of choosing inside a parser game, or a game played by choosing with a whole world model under it, where a choice to take the lamp is a real TAKE, which the world can refuse.

Hexicon is made up of three parts:

- **the language** a game is written in (`.hxn` files)
- **Hexad**, the library every game is built on: rooms, things, doors, characters, the parser and the choices, and the messages a game prints
- **the `hexicon` program**, which builds a game into a single `.hxg` file and plays it in a terminal
- **the player**, which plays the compiled game in a window, with its pictures, sounds, and styled text, just as a web browser displays it

Hexicon owes much of its design to TADS 3 and the libraries written for it: the shape of its language, its model of a game's world, and the way that world answers what a player does. That being said, Hexicon _is_ its own system, not a version of TADS. It is not bound to be compatible with TADS 3: its games, files, and libraries are Hexicon's own, and it changes as and when I come up with more and (hopefully!) interesting ideas.

<table>
  <tr>
    <td width="50%" valign="top"><img src="docs/images/player-lighthouse.png" alt="The player, playing The Lighthouse: commands typed at a prompt, the score going up as a door is unlocked, and a status line with the room and its exits"></td>
    <td width="50%" valign="top"><img src="docs/images/web-locked-house.png" alt="A browser, playing The Locked House by choosing alone: the hall, its choices dimmed once one is made, and the keeper's conversation as new choices"></td>
  </tr>
  <tr>
    <td>A parser game, <em>The Lighthouse</em>, in the player</td>
    <td>A game told in choices, <em>The Locked House</em>, in a browser</td>
  </tr>
  <tr>
    <td colspan="2" align="center"><img src="docs/images/web-gallery.png" width="60%" alt="A browser, playing The Gallery: a painting of a harbor at sunset shown in the text, a brass plaque drawn as a styled box, a bell pictured beside the text, and the game's own colors and headings"></td>
  </tr>
  <tr>
    <td colspan="2" align="center">A game with its own pictures and look, <em>The Gallery</em>, in a browser</td>
  </tr>
</table>

## Getting started

The easiest way to get Hexicon is an installer from [the releases](https://github.com/jeffnyman/hexicon/releases/latest). There are installers for Windows, macOS, and Linux, and each one gives you both the player and the `hexicon` program. The Windows and Linux ones put `hexicon` on your PATH. On macOS, the disk image has the app, `Hexicon.app`, with `hexicon` inside it, in `Hexicon.app/Contents/MacOS/hexicon`. The VS Code extension finds it there. To use it in a terminal, link it onto your PATH once, after dragging the app to Applications:

```
sudo mkdir -p /usr/local/bin
sudo ln -sf /Applications/Hexicon.app/Contents/MacOS/hexicon /usr/local/bin/hexicon
```

If you have Rust installed ([rustup.rs](https://rustup.rs)), you can instead install the `hexicon` program from [crates.io](https://crates.io/crates/hexicon). This gives you the program only, not the player:

```
cargo install hexicon
```

You can also build Hexicon yourself. It is written in Rust and needs Rust 1.98 or later (rustup keeps Rust up to date). From this folder:

```
cargo build --release
```

That builds the `hexicon` program into `target/release`. Hexad, and everything else a game needs, is built into the program. The commands below run it as `hexicon`, so first add `target/release` to your `PATH`, or copy the program to a folder that is on it; otherwise, run it by its full path. Then, to jump start creating a game:

```
hexicon new my-game
cd my-game
hexicon build
hexicon run my-game.hxg
```

## Writing in VS Code

The VS Code extension, **Hexicon** (`jeffnyman.hexicon`), is for writing games in VS Code. It is published in the Marketplace: search for Hexicon in VS Code's Extensions view, or run:

```
code --install-extension jeffnyman.hexicon
```

It colors the language, both in Hexicon sources (`.hxn`, `.hxh`) and in English ones (`.hxe`). Through a language server, which is the `hexicon` program itself (`hexicon lsp`), it also gives you:

- each game's problems as you type, marked where they are on the line
- the outline
- Go to Definition, including into Hexad's own files
- Find All References, and Rename
- hover and completion

It also:

- builds a game, and plays it in a tab, which is Hexicon's player
- runs a game's scenarios in the Testing view
- shows a game's reference, and Hexad's
- draws a game's map

The extension does not include the `hexicon` program. It finds the one you installed or built, and if there is none, it tells you where to get it. [The extension's README](editors/vscode/README.md) describes everything it does, and how to work on it.

## Playing in a window, or in a browser

The player, `hexicon-player`, shows a game using the system's web view (WebView2 on Windows, WebKit on macOS and Linux). The page in `web/` is the same player, for a web browser.

If you used an installer from [the releases](https://github.com/jeffnyman/hexicon/releases/latest), you already have the player. It is in your system's menus, and it opens a `.hxg` file when you open one from Explorer, the Finder, or a file manager. (`cargo install hexicon` installs only the `hexicon` program, not the player.)

The programs are not signed yet, so the first time you use them:

- **Windows** may warn you before the installer runs, and an antivirus program may hold the player the first time it starts, while it checks it.
- **macOS** will not open the app at first, saying that Apple could not check it. To open it anyway, try opening it once, then go to System Settings > Privacy & Security, where Hexicon is listed with **Open Anyway**. Choose that and confirm. After that, it opens like any other app. (On macOS 14 and earlier, Control-click the app and choose Open instead.) The `hexicon` program inside the app may be refused the same way the first time it runs, from a terminal or from VS Code: allow it with **Open Anyway** too, or take the downloaded mark off the whole app with `xattr -dr com.apple.quarantine /Applications/Hexicon.app`.

To build the player yourself, run this from this folder. It first builds the web page and its WebAssembly build, which needs the tools listed at the top of `tools/build-web.sh`:

```
tools/build-app.sh
target/release/hexicon-player my-game.hxg
```

You can also open a game from the player's window, or drop it onto the window.

The player keeps each game's saved games as files, in a `Hexicon` folder in your documents, with a folder for each game. Its "Saved games" button opens that folder. Saving and restoring use the system's own file dialog, starting in that folder.

| System | Saved games |
|---|---|
| Windows | `Documents\Hexicon`, in your user folder (`C:\Users\<you>\Documents\Hexicon`), or wherever Windows keeps your Documents, such as OneDrive |
| macOS | `~/Documents/Hexicon` |
| Linux | `Hexicon` in your desktop's documents folder, usually `~/Documents/Hexicon` |

If you have no documents folder, the player uses a `Hexicon` folder in your home folder instead. To keep saved games somewhere else, such as beside the player on a USB stick, set `HEXICON_GAMES_FOLDER` to that folder before starting the player.

In a browser, saved games are not files. The page keeps them in the browser's own storage for that site, so clearing the site's data deletes them.

To build just the browser's page, into `web/`, run `tools/build-web.sh`. Then `node tools/web-serve.js` serves it at `http://127.0.0.1:8765/web/index.html`.

## Building the installers, and releases

**Windows:** `tools/build-installer.sh` builds an installer, `build/installer/hexicon-<version>-setup.exe`, using [Inno Setup 6](https://jrsoftware.org/isinfo.php). The installer installs for the current user only, and needs no administrator rights. It installs the player, which then opens `.hxg` files from Explorer, and the `hexicon` program, which it adds to your PATH unless you untick that option. To uninstall, use Settings > Apps.

**macOS:** `tools/build-mac-app.sh` builds the player as an app, `build/mac/Hexicon.app`, which opens `.hxg` files from the Finder, and puts the `hexicon` program in it, in `Contents/MacOS`. It also builds a disk image to give to others, `build/mac/Hexicon-<version>.dmg`. Set `UNIVERSAL=1` to build for both Apple silicon and Intel Macs. The app is signed only for the Mac that built it (an "ad hoc" signature). It is not signed with a Developer ID or notarized by Apple, so on any other Mac it has to be opened as described above.

**Linux:** `tools/build-linux-package.sh` builds the player and the `hexicon` program as packages, in `build/linux`:

- a `.deb`, for Debian, Ubuntu, and distributions based on them. `sudo apt install ./hexicon_<version>_<arch>.deb` installs it, along with what the player needs (WebKitGTK, and GStreamer's plugins for the games' sounds).
- a `.tar.gz` of the same files, for any other distribution, with a README listing what to install.

Either one puts the player in the desktop's menus, opening `.hxg` files from a file manager, and puts the `hexicon` program on your PATH. Building them needs `dpkg-dev`, as well as everything `tools/build-app.sh` needs.

**On GitHub,** every push to `main` and every pull request is checked (`.github/workflows/checks.yml`). The checks build and test Hexicon with the newest Rust, and build it with the oldest Rust it supports (1.98).

Pushing a tag that starts with `v`, such as `v0.1.0`, makes a release (`.github/workflows/release.yml`). It builds the Windows installer, the Mac app, the Linux packages, and the VS Code extension, and attaches them all to the release. The `.deb` takes its maintainer's name and email from the repository's Actions variables `DEBFULLNAME` and `DEBEMAIL`.

The crates are published to crates.io by hand, at the release's version, with `tools/publish-crates.sh` (see the top of the script for how).

## Documentation

[The Hexicon Guide](docs/guide/README.md) takes you from nothing to a small finished game, and covers Hexad and the language. [The tutorial](docs/tutorial/README.md) writes one longer game, *Calder Ridge*, a chapter at a time, from an empty folder to a finished game.

Two of the guide's pages cover the other ways of writing:

- [Choices](docs/guide/choices.md) is about choice games, from a single moment of choosing in a parser game to a game played only by choosing. `hexicon new --choices` starts a new choice game.
- [Writing in English](docs/guide/english.md) is about writing a game in sentences ("The Rocky Shore is a room."), in `.hxe` sources, with blocks of the language for everything else.

To read the guide and the tutorial as a website, build them as HTML pages, with Node 22 or later: run `npm ci` and then `npm run build` in `tools/docs-site`. The pages are written to `build/site`; open `build/site/index.html`, or put the folder on any web server.

## Testing

```
cargo test
python tools/program-check.py
python tools/doc-check.py
```

`cargo test` leaves out the player, because the player needs the web page built first. Once the page is built, `cargo test --workspace` includes it.

[tests/README.md](tests/README.md) explains what each of these checks.

## License

Hexicon is free software: you can redistribute it and modify it under the terms of the GNU General Public License, version 3 or (at your option) any later version. See [LICENSE](LICENSE).

The libraries in `lib` (the system library and Hexad) carry an additional permission, [LIBRARY-EXCEPTION](LIBRARY-EXCEPTION): a game built on them may be distributed under terms of its author's choice.