A comprehensive batteries-included template for creating text games in Twine with Sugarcube, designed to work seamlessly with AI agents.
Twine Template (TwT) is a project that aims to streamline the development of text-based games using Twine and Sugarcube. It provides a structured template that can be used with AI agents (in VSCode with Cline or Roo Code) to employ AI in writing Twine games and their presentation.
The template includes a demo game that showcases Twine/Sugarcube capabilities:
-
Variable Management & State Tracking
- Demonstrates
$awareness
and$loops
variables - Shows how to persist and update game state
- Examples of conditional content based on variables
- Demonstrates
-
Dynamic Content & Meta-Commentary
- Passages that evolve based on player progress
- Meta-narrative elements that respond to player actions
- Multiple paths with varying requirements
-
Modern Styling & Effects
- Custom CSS animations and transitions
- Responsive design for all devices
- Dark mode support
- Status displays and UI components
See the demo game in action, built and published with GitHub Actions - https://kerray.github.io/twine_template/
- Ready-to-use structure for Twine game development
- Built-in Tweego compiler for all major platforms
- VSCode integration with tasks for compiling and testing
- AI-friendly prompts for different development roles
- GitHub Actions for continuous integration and deployment
- Comprehensive documentation for both template development and game creation
- World building templates to help define your game world
- Cross-platform build system using Just and shell scripts
./src/
- Twine source files (*.tw), can be in subfolders./src/_media/
- Media files for the game./dist/
- Compiled game output./world/
- Game world information (worldbuilding, character sheets, etc.)./world/templates/
- Templates for world building documents./prompts/
- AI role prompts./bin/
- binaries for Tweego compiler and Just./docs/
- Documentation./memlog/
- Logs of completed work./scripts/
- Build and utility scripts./tests/
- Template tests./.github/workflows/
- GitHub Actions workflows
See INSTALL.md for detailed setup instructions - give it as prompt to an AI agent to help you set up this project properly.
Once you have the template set up:
-
Define your game world
- Copy the templates from
./world/templates/
to the./world/
directory - Fill in the world building documents with your game's details
cp ./world/templates/* ./world/
- Copy the templates from
-
Use AI to help develop your game
- Use the prompts (and update them - or have AI update them - for your needs!) in
./prompts/
directory to guide the AI in different aspects of game development - The AI will help you create content, implement mechanics, and style your game
- Use the prompts (and update them - or have AI update them - for your needs!) in
-
Build and test your game
- Use VSCode tasks or Just commands to build:
# Build the game ./just compile # Watch for changes just watch
- Open
./dist/index.html
in a web browser to test
- Use VSCode tasks or Just commands to build:
The template includes a comprehensive build system using Just and shell scripts:
The template follows a modular approach to dependencies:
-
Base Setup (Minimal):
- Just Tweego and Just command runner
- Sufficient for basic Twine game development
- No npm, Java, or other heavy dependencies
- Use
just install-deps
for this minimal setup
-
Testing Layer:
- Adds npm and Playwright
- Only installed when user explicitly needs testing capabilities
- Use
just install-tests
to set up
-
Cordova Browser Builds:
- Adds capabilities for browser app packaging
- Separate from mobile builds to keep dependencies minimal
-
Mobile Builds (work in progress):
- Adds Java for Android and Mac-specific requirements
- Heaviest dependency footprint
- Only installed when explicitly needed for mobile development
This approach ensures you only install what you need for your specific use case.
just compile
- Compiles the game to a single HTML file.just watch
- Watches for changes and recompiles the game file automaticallyjust clean
- Cleans the output directoryjust install-deps
- Installs core dependencies (Tweego, Sugarcube, etc.)just install-tests
- Installs test dependencies (npm, Playwright)just install-all
- Installs all dependencies including test dependenciesjust test
- Runs tests (without reinstalling test dependencies)
For automatically building mobile apps from compiled games with Cordova, see docs/Cordova_Integration.md
. Available commands:
just cordova-init
- Initializes the Cordova projectjust cordova-resources
- Generates Cordova resourcesjust cordova-android
- Builds the Android appjust cordova-ios
- Builds the iOS appjust cordova-windows
- Builds the Windows appjust cordova-browser
- Builds the Browser appjust setup-android
- Sets up the Android development environment
You can customize the build process with these variables:
OUTPUT_DIR
- Output directory (default:dist
)STORY_FORMAT
- Story format to use (default:sugarcube-2-37-3
)SRC_DIR
- Source directory (default:src
)TWEEGO_PATH
- Path to Tweego (automatically detected based on OS)
Example:
./just compile OUTPUT_DIR=custom-output STORY_FORMAT=harlowe-3
The ./scripts/
directory contains helper scripts:
build-game.sh
- Builds the gamedownload-just.sh
- Downloads Just binaries for different platforms and symlink just in root folderdownload-sugarcube.sh
- Downloads and sets up Sugarcube story formatdownload-tweego.sh
- Downloads and sets up Tweego compilerinstall-dependencies.sh
- Installs dependencies like ImageMagick
This template is designed to work with AI agents. The project includes several specialized AI roles defined in .roomodes
that help with different aspects of game development:
- Template Developer - For extending and improving the template itself
- Game Writer - For creating game content and narrative
- Web Developer - For styling and UI improvements
- Game Designer - For game mechanics and structure
Each role has specific capabilities and access restrictions to ensure focused development. See .roomodes
for detailed role definitions and capabilities.
The ./world/templates/
directory contains templates for defining your game world:
- World.md - Overview of the game world, setting, themes, and key locations
- Characters.md - Player character, main characters, supporting characters, and antagonists
- Items.md - Key items, collectibles, consumables, equipment, and currency
- Mechanics.md - Core mechanics, stats, inventory system, progression, and special systems
- Story.md - Main plot, story branches, endings, side stories, and story progression
The template includes several VSCode tasks to help with development:
- Compile Game - Compiles the game and outputs it to
./dist/index.html
- Watch and Compile - Watches for changes in the
./src/
directory and automatically recompiles - Test Compilation - Tests the compilation process without generating output
- Clean Output Directory - Cleans the output directory
- Install Dependencies - Installs required dependencies
The template includes a GitHub Actions workflow that:
- Compiles the game using Tweego
- Tests the compilation
- Builds mobile and desktop versions using Cordova
- Deploys the compiled game to GitHub Pages (conditionally based on repository settings)
The workflow is configured to use Just and provide artifacts for all platforms on GitHub, just as it would locally.
The template includes recommendations for VSCode extensions that enhance the development experience:
- Twine Language Tools - Syntax highlighting and language support for Twine files
- Live Server - Easily view the compiled HTML game
- ESLint - JavaScript linting
- Prettier - Code formatting
- Path Intellisense - Path autocompletion
- HTML CSS Support - Enhanced HTML and CSS support
- Markdown All in One - Enhanced Markdown editing
- Markdown Preview GitHub Styles - Preview Markdown files with GitHub styling
When you open the project in VSCode, you'll be prompted to install these recommended extensions.
This project uses a dual licensing approach:
-
Non-Commercial Use: GNU Affero General Public License v3.0
- Free to use, modify, and distribute
- Must keep source code open
- Changes must be shared under the same license
- See the LICENSE file for full terms
-
Commercial Use: Custom Commercial License
- Required for any commercial use including:
- Selling games created with this template
- Using this template in commercial products
- Incorporating this template into commercial services
- Contact the author to obtain a commercial license
- Ensures fair compensation while maintaining availability for non-commercial use
- Required for any commercial use including:
For more details, see the LICENSE file in the repository.
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch
git checkout -b feature/your-feature-name
- Make your changes
- Commit your changes
git commit -m "Add your feature description"
- Push to the branch
git push origin feature/your-feature-name
- Create a Pull Request
Please make sure your code follows the existing style and includes appropriate documentation.