Tweego Compiler
repository·master·Indexed 41 days ago
https://github.com/tmedwards/tweegoA command-line compiler written in Go for Twine/Twee story formats. It allows developers to compile Twee source files into playable Twine stories, supporting Twee v3, Twee v1, and Twee2 notations. Tweego provides extensive CLI flags for configuring output modes, story formats, and encoding, and supports the TWEEGO_PATH environment variable for managing story format search paths.
What's inside Tweego
- Tweego is a free, open-source command line compiler for Twine/Twee story formats. It is written in Go and allows developers to compile Twee source files into playable Twine formats via the command line.
Use the `Start` passage to define the entry point
masterBy default, Tweego uses a passage named
Startas the first normal passage displayed to the player.To override this behavior, you can either:
- Set the
startproperty within theStoryDatapassage. - Use the command line option
-s NAMEor--start=NAMEduring compilation.
Note: All special passage names are case-sensitive.
- Set the
How Tweego searches for story formats
masterWhen executed, Tweego searches for story formats in the following order:
- Program directory: The
storyformatsor.storyformatsfolders located where the Tweego binary resides. - User's home directory: The
storyformatsor.storyformatsfolders in the user's home directory (determined by$HOMEor OS defaults). - Current working directory: The
storyformatsor.storyformatsfolders in the directory from which you are running Tweego. - Environment variable: Any directories specified in the
TWEEGO_PATHvariable.
Legacy Support: Tweego also checks
story-formats,storyFormats, andtargetsduring steps 1–3, but it is strongly encouraged to use the standardstoryformatsor.storyformatsnames.- Program directory: The
Configure project settings with the `StoryData` passage
masterThe
StoryDatapassage is used to specify basic project settings via a JSON chunk.Core Properties (All formats)
ifid(string, Required): The project's unique Interactive Fiction IDentifier. If omitted, Tweego will automatically generate one and provide instructions on how to copy it into your chunk.start(string, Optional): The name of the starting passage. Defaults to theStartpassage if omitted.
Twine 2-style Properties
format(string, Optional): The name of the story format (e.g.,SugarCube,Harlowe,Chapbook,Snowman).format-version(string, Optional): The version of the story format following Semantic Versioning (e.g.,2.30.0). Tweego will attempt to use the greatest version that matches the specifiedmajorversion.
Important JSON Rules
- Property names must be double-quoted.
- Do not include a trailing comma after the last property.
- The chunk is a JSON object, not a JavaScript object literal.
:: StoryData { "ifid": "D674C58C-DEFA-4F70-B7A2-27742230C0FC", "format": "SugarCube", "format-version": "2.30.0", "start": "My Starting Passage" }Understand Tweego configuration precedence
masterTweego configuration settings follow a cascading hierarchy. If a setting is defined in multiple places, the one lower in this list takes precedence:
- Program defaults: The built-in fallback values.
- Environment variables: System-level settings.
- Story configuration: Settings defined within the story itself (see
StoryDatadocumentation). - Command line: Options passed directly when running the Tweego command.
To begin using Tweego, the only strictly necessary configuration step is ensuring it can find your story formats.
Understand Twee notation versions
masterTweego supports multiple Twee notations used to arrange stories into passages. Passages consist of a name, optional attributes (tags/metadata), and content.
- Twee v3: The current official notation. It supports tags, metadata (JSON), and name escaping. This is the recommended format for new files.
- Twee v1: A legacy official notation and a compatible subset of v3. It lacks metadata support and name escaping. Use only for Twine 1 interoperability.
- Twee2: An unofficial notation used by the largely abandoned Twee2 compiler. It includes an optional position block but lacks v3 features.
Tweego Compatibility Note: Tweego compiles v3 and v1 by default. To compile unofficial Twee2 files, you must either use the
.tw2or.twee2file extensions, or use the--twee2-compatCLI flag. It is strongly recommended to avoid Twee2 unless absolutely necessary.Convert Twee2 files to Twee v3
masterYou can convert files using the Twee2 notation to the Twee v3 notation using the
-d(dump) flag.If the source file uses a non-standard extension (like
.tw2), use the following syntax:tweego -d -o <output_file.twee> <input_file.tw2>If the Twee2 file already uses standard extensions (like
.twor.twee), you must include the--twee2-compatflag to ensure correct processing during conversion.# For .tw2 files tweego -d -o twee_v3_file.twee twee2_file.tw2 # For standard .tw or .twee files using Twee2 notation tweego --twee2-compat -d -o twee_v3_file.twee twee2_file.tweeBuild Tweego from source
masterTo build Tweego from source, you must have Go (version ≥v1.13) and Git installed on your system. Follow these steps to clone, fetch dependencies, and compile the binary.
# 1. Clone the repository git clone https://github.com/tmedwards/tweego.git # 2. Enter the directory cd tweego # 3. Switch to your desired branch (master for stable, develop for development) git checkout master # 4. Fetch dependencies go get # 5. Compile and install to your GOPATH/bin go installInstall Tweego via precompiled binaries
masterYou can download precompiled binaries for multiple operating systems in both 32-bit and 64-bit versions. These are available on the official Tweego website.
Download from: http://www.motoslave.net/tweego/Avoid processing unwanted files during compilation
masterTo prevent Tweego from attempting to compile files that are not source code (such as images or notes), ensure they are located in directories outside of the path passed to the
tweegocommand.A recommended directory structure is to keep assets in an
images/directory and source files in asrc/directory, then pass only thesrcdirectory to the CLI.Example structure:
project_directory/ images/ src/tweego -o project.html srcWrite passages using Twee v3 notation
masterIn Twee v3, a passage declaration must be a single line containing these components in order:
- Start Token:
::(required). - Passage Name: (required).
- Tags Block:
[tag1 tag2](optional). A space-separated list of tags inside square brackets. - Metadata Block: An inline JSON chunk containing optional properties like
positionandsize(optional).
The passage content begins on the line immediately following the declaration.
Escaping Rules: If passage or tag names contain delimiters like
[,],{, or}, you must escape them with a backslash (\). To include a literal backslash, escape it as\\.Tip: Avoid using delimiters or link markup separators (
|,->,<-) in names to prevent the need for escaping.:: A passage with no tags Content of the "A passage with no tags" passage. :: A tagged passage with three tags [alfa bravo charlie] {"position":"860,401"} Content of the "A tagged passage with three tags" passage.- Start Token:
Basic Tweego CLI usage
masterTweego is a command-line tool used to compile Twee source files into HTML or archives, or to decompile HTML/archives back into source code. The basic syntax is:
tweego [options] sources…sourcescan be individual files or directories. When a directory is provided, Tweego recursively searches it for all supported file types.tweego [options] sources…