Static Interactive Fiction Generator
Project description
Grimoire
Grimoire is a Python library to create interactive fiction. What makes Grimoire unique is that it pre-renders all possible choices and simply outputs linked HTML files.
Installation
pip install grimoire-if
Usage
Check out some examples.
Your story begins
Begin by instantiating a Grimoire app.
from grimoire import Grimoire
app = Grimoire()
Then create our stories initial page.
@app.page
def start(state):
state['name'] = 'Grimoire'
return f"Hello, {state['name']}!", state
You can render our (rather boring) story right now by calling the app's render method.
app.render()
Grimoire added all the html files (in this case only the index.html file) into the site/ directory.
You can optionally pass a state class when creating your app.
@datalass
class State:
name: Optional[str] = None
app = Grimoire(state=State)
@app.start
def start(state):
state.name = 'Grimoire'
return f"Hello, {state.name}!", state
Grimoire uses hype to render html and you can use it in your render functions.
from hype import *
@app.start
def start(state):
state.name = 'Grimoire'
return H1(f"Hello, {state.name}!"), state
Choose your own destiny
Let's add some options.
@app.option(start, "Next")
def next(state):
return P("We're really moving now!"), state
Try rendering again. If you reload the index.html file, you should now see a link (Next) that brings you to the next page.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for grimoire_if-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e1787c8d281a08cccdb6b4eadc883ff8241046cbe08717bee2704d107489605 |
|
MD5 | 7d3b85dc2e2f640b589b57c48d390b0e |
|
BLAKE2b-256 | 5d7d980c9d511779e8b5c3ab031d15f51a24057f793cb2dc59cb1f3e8933d210 |