inkcpp_py

Python bindings for InkCPP https://github.com/JBenda/inkcpp

class IList(pybind11_builtins.pybind11_object):

Allows reading and editing inkcpp lists. !Only valid until next choose ore getline a runner referncing the corresponding global

def add(self, flag: str) -> None:

Add flag to list.

def remove(self, flag: str) -> None:

Remove flag from list

def contains(self, flag: str) -> bool:

Check if list contains the given flag

def flags_from(self, list_name: str) -> Iterator[IList.Flag]:

Rerutrns all flags contained in this list from a list of name list_name.

Use iter(List) to iterate over all flags.

class IList.Flag(pybind11_builtins.pybind11_object):

A list flag containing the name of the flag and the corresponding list

name: str

The flag

list_name: str

Name of the corresponding list

class Value(pybind11_builtins.pybind11_object):

A Value of a Ink Variable

Value(**kwds)

__init__(args, *kwargs) Overloaded function.

  1. __init__(self: inkcpp_py.Value, value: bool) -> None

  2. __init__(self: inkcpp_py.Value, value: int, type: inkcpp_py.Value.Type) -> None

Used to explicit set a Uint32 value. Type must be inkcpp_py.Value.Type.Uint32!

  1. __init__(self: inkcpp_py.Value, value: int) -> None

  2. __init__(self: inkcpp_py.Value, value: float) -> None

  3. __init__(self: inkcpp_py.Value, value: inkcpp_py.IList) -> None

  4. __init__(self: inkcpp_py.Value, value: str) -> None

Bool: ClassVar[Value.Type] = <Type.Bool: 0>
Uint32: ClassVar[Value.Type] = <Type.Uint32: 1>
Int32: ClassVar[Value.Type] = <Type.Int32: 2>
String: ClassVar[Value.Type] = <Type.String: 3>
Float: ClassVar[Value.Type] = <Type.Float: 4>
List: ClassVar[Value.Type] = <Type.List: 5>
type: Value.Type

Type contained in value

def as_list(self) -> IList:

If it contains a inkcpp_py.Value.Type.List, return it. Else throws AttributeError.

def as_int(self) -> int:

If value contains a inkcpp_py.Value.Type.Int32 or inkcpp_py.Value.Type.Uint32 return the int value. Else throws AttributeError

def as_bool(self) -> bool:

If value contains a inkcpp_py.Value.Type.Bool, return it. Else throws a AttributeError.

def as_str(self) -> str:

If value contains a inkcpp_py.Value.Type.String, return it. Else throws an AttributeError.

If you want convert it to a string use: str(value).

def as_float(self) -> float:

If value contains a inkcpp_py.Value.Type.Float, return it. Else throws an AttributeError.

class Value.Type(pybind11_builtins.pybind11_object):
Value.Type(value: int)

__init__(self: inkcpp_py.Value.Type, value: int) -> None

name: str

name(self: object) -> str

value: int

(arg0: inkcpp_py.Value.Type) -> int

Bool: ClassVar[Value.Type] = <Type.Bool: 0>
Uint32: ClassVar[Value.Type] = <Type.Uint32: 1>
Int32: ClassVar[Value.Type] = <Type.Int32: 2>
String: ClassVar[Value.Type] = <Type.String: 3>
Float: ClassVar[Value.Type] = <Type.Float: 4>
List: ClassVar[Value.Type] = <Type.List: 5>
class Snapshot(pybind11_builtins.pybind11_object):

Globals and all assoziatet runner stored for later restoration

def num_runners(self) -> int:

Number of different runners stored in snapshot

def write_to_file(self, filename: str) -> None:

Store snapshot in file.

def from_file(filename: str) -> Snapshot:

Load snapshot from file

def compile_json(input_file_name: str, output_file_name: str) -> None:

Converts a story.json file to a story.bin file used by inkcpp

class Choice(pybind11_builtins.pybind11_object):
def text(self) -> str:

Get choice printable content

def has_tags(self) -> bool:

if choices is tagged?

def num_tags(self) -> int:

Number of tags assigned to choice

def get_tag(self, index: int) -> str:

Get tag at index

def tags(self) -> list[str]:

Get all current assinged tags

class Globals(pybind11_builtins.pybind11_object):

Global variable store. Use globals[var_name] to read/write them.

def create_snapshot(self) -> Snapshot:

Creates a snapshot from the current state for later usage

def observe( self, name: str, callback: Callable[[Value, Value | None], NoneType]) -> None:

Start observing a variable.

Arguments:
  • name: name of the (global) variable to observe
  • callback: called when varibale changes with (new_value, old_value). old_value will be None when variable is initelized
class Runner(pybind11_builtins.pybind11_object):

Runtime logic for a story.

def create_snapshot(self) -> Snapshot:

Creates a snapshot from the current state for later usage.

This snapshot will also contain the global state. To reload:

>>> snapshot = old_runner.create_snapshot()
>>> story = Story.from_file("story.bin")
>>> runner = story.new_runner_from_snapshot(snapshot)
def can_continue(self) -> bool:

check if there is content left in story

def getline(self) -> str:

Get content of the next output line

def getall(self) -> str:

execute getline and append until inkcp_py.Runner.can_continue is false

def has_tags(self) -> bool:

Where there tags since last choice

def num_tags(self) -> int:

Number of tags currently stored

def get_tag(self, index: int) -> str:

Get Tag currently stored at index

def tags(self) -> list[str]:

Get all current assigned tags

def has_choices(self) -> bool:

Check if there is at least one open choice at the moment.

def get_choice(self, index: int) -> Choice:

Get current choice at index.

iter(inkcpp_py.Runner) returns a iterator over all current choices.

def num_choices(self) -> int:

Number of current open choices

def choose(self, index: int) -> None:

Select choice at index and continue.

def bind_void( self, function_name: str, function: Callable[[list[Value]], NoneType], lookaheadSafe: bool = False) -> None:

Bind function with void result

def bind( self, function_name: str, function: Callable[[list[Value]], Value], lookaheadSafe: bool = False) -> None:

Bind a function with return value

def move_to(self, path: str) -> bool:

Moves execution pointer to start of container desrcipet by the path

class Story(pybind11_builtins.pybind11_object):
def from_file(filename: str) -> Story:

Creates a new story from a .bin file.

Returns:

inkcpp_py.Story: a new story

def new_globals(self) -> Globals:

Creates new globals store for the current story.

def new_runner(self, globals: Globals = None) -> Runner:

Ceates a new runner.

Arguments:
  • globals: pass a global to use, else use a new inetrnal one.
Returns:

inkcpp_py.Runner: a newly created runner, initelized at start of story

def new_globals_from_snapshot(self, snapshot: Snapshot) -> Globals:

Loads a global store from a snapshot.

Returns:

inkcpp_py.Globals: a new global store with the same state then stored in the snapshot.

def new_runner_from_snapshot( self, snapshot: Snapshot, globals: Globals = None, runner_id: int = 0) -> Runner:

Reconstructs a runner from a snapshot.

Arguments:
  • snapshot: snapshot to load runner from.
  • globals: store used by this runner, else load the store from the file and use it. (created with inkcpp_py.Story.new_runner_from_snapshot)
  • runner_id: if multiple runners are stored in the snapshot, id of runner to reconstruct. (ids start at 0 and are dense)
Returns:

inkcpp_py.Runner: at same state as before