Skip to main content

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(start=True)
def start(state):
    state['name'] = 'Grimoire'
    return f"Hello, Grimoire!", 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.page(start=True)
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.page(start=True)
def start(state):
    state.name = 'Grimoire'
    return H1(f"Hello, {state.name}!"), state

Choose your own destiny

Let's add some options. We'll start by creating another page.

@app.page()
def next(state):
    return P("We're really moving now!"), state

Now go back to our first page and another argument, next. We'll import a helper function called link from grimoire.tempaltes to construct the link using the option argument.

from grimoire.templates import link


@app.page(start=True)
def start(state, next):
    state.name = 'Grimoire'
    return Div(
        H1(f"Hello, {state.name}!"),
        link('Next Page', next)
    ), state

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grimoire-if-0.0.7.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

grimoire_if-0.0.7-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page