Scenarios and actions#

A scenario defines how a scene evolves through time; see Fictional interfaces for more information about scenes. In order to achieve this goal, it is composed of three elements:

  • An ending time, which defines at which time the scenario ends.

  • An ending type, which defines how the scene should behave once the scenario ends.

  • A set of actions, each accompagnied with a time relative to the start of the play.

In the scope of this project, such a scenario is represented using the pyfingerd.fiction.FingerScenario class. This class can load its data using two methods: programatically, or using a scenario file.

Note that this section doesn’t cover how to write scenarios, only a definition of scenarios; see Writing a scenario for pyfingerd for this use.

Scenarios as code#

For defining a scenario using code, you are to use the pyfingerd.fiction.FingerScenario.add() method with actions inheriting from pyfingerd.fiction.FingerAction, and define both the pyfingerd.fiction.FingerScenario.ending_type() and pyfingerd.fiction.FingerScenario.duration() properties.

For example:

from datetime import timedelta
from pyfingerd.fiction import *

scenario = FingerScenario()
scenario.ending_type = FingerScenario.EndingType.FREEZE
scenario.duration = 60

scenario.add(
    FingerUserCreationAction(
        login="root",
        home="/home/root",
    ),
    '-1m',
)

scenario.add(
    FingerUserLoginAction(
        login="root",
    ),
    timedelta(seconds=5),
)

Scenario files#

Scenarios can also be defined as TOML files, loaded using the pyfingerd.fiction.FingerScenario.load() static method which produce pyfingerd.fiction.FingerScenario instances.

These files describe actions as point in times where something happen. Every action has a time offset, using a TOML array section ([[something]]), and properties describing what’s happening. Endings are represented as specific actions.

Time offsets are represented the following way:

-?(<weeks>w)?(<days>[jd])?(<hours>h)?(<minutes>m)?(<seconds>s)?

Where negative times, starting with a dash (-), are the initial situation, what is supposed to have happened before the beginning.

For example, -1w5d2h means “1 week, 5 days and 2 hours before the origin” and 2j means “2 days after the origin”. So if we want to make an action that takes place 5 seconds after the origin, the first line of the action will be the following one:

[[5s]]

All actions have a type represented by the type property, and other properties depending on the type. The actions are described in the subsections below.