earwax.story.play_level module

Provides the StoryLevel class.

class earwax.story.play_level.PlayLevel(game: Game, world_context: StoryContext, cursor_sound: Optional[earwax.sound.Sound] = None, inventory: List[earwax.story.world.RoomObject] = NOTHING, reverb: Optional[GlobalFdnReverb] = None, object_ambiances: Dict[str, List[earwax.ambiance.Ambiance]] = NOTHING, object_tracks: Dict[str, List[earwax.track.Track]] = NOTHING)

Bases: earwax.level.Level

A level that can be used to play a story.

Instances of this class can only play stories, not edit them.

Variables:
  • world_context – The context that contains the world, and the state for this story.
  • action_sounds – The sounds which were started by object actions.
  • cursor_sound – The sound that plays when moving through objects and ambiances.
  • inventory – The list of Roomobject instances that the player is carrying.
  • reverb – The reverb object for the current room.
  • object_ambiances – The ambiances for a all objects in the room, excluding those in the players’ inventory.
  • object_tracks – The tracks for each object in the current room, excluding those objects that are in the player’s inventory.
actions_menu(obj: earwax.story.world.RoomObject, menu_action: Optional[earwax.story.world.WorldAction] = None) → None

Show a menu of object actions.

Parameters:
  • obj – The object which the menu will be shown for.
  • menu_action – The action which will be used instead of the default actions_action.
activate() → None

Activate the currently focussed object.

build_inventory() → None

Build the player inventory.

This method should be performed any time state changes.

cycle_category(direction: int) → Generator[None, None, None]

Cycle through information categories.

cycle_object(direction: int) → None

Cycle through objects.

do_action(action: earwax.story.world.WorldAction, obj: Union[earwax.story.world.RoomObject, earwax.story.world.RoomExit], pan: bool = True) → None

Actually perform an action.

Parameters:
  • action – The action to perform.
  • obj

    The object that owns this action.

    If this value is of type RoomObject, and its position value is not None, then the action sound will be panned accordingly..

  • pan – If this value evaluates to False, then regardless of the obj value, no panning will be performed.
drop_object(obj: earwax.story.world.RoomObject) → Callable[[], None]

Return a callable that can be used to drop an object.

drop_object_menu() → None

Push a menu that can be used to drop an object.

get_gain(type: earwax.track.TrackTypes, multiplier: float) → float

Return the proper gain.

get_objects() → List[earwax.story.world.RoomObject]

Return a list of objects that the player can see.

This method will exclude objects which are in the as yet unimplemented player inventory.

The resulting list will be sorted with Python’s sorted builtin.

inventory_menu() → None

Show the inventory menu.

main_menu() → Generator[None, None, None]

Return to the main menu.

next_category() → Generator[None, None, None]

Next information category.

next_object() → None

Go to the next object.

object

Return the object from self.state.

object_menu(obj: earwax.story.world.RoomObject) → Callable[[], None]

Return a callable which shows the inventory menu for an object.

objects_menu(objects: List[earwax.story.world.RoomObject], func: Callable[[earwax.story.world.RoomObject], Callable[[], None]], title: str) → None

Push a menu of objects.

on_pop() → None

Stop all the action sounds.

on_push() → None

Set the initial room.

The room is the world from the state object, rather than the initial_room.

pause() → None

Pause All the currently-playing room sounds.

perform_action(obj: earwax.story.world.RoomObject, action: earwax.story.world.WorldAction) → Callable[[], None]

Return a function that will perform an object action.

This method is used by actions_menu() to allow the player to trigger object actions.

The inner method performs the following actions:

  • Shows the action message to the player.
  • Plays the action sound. If obj has coordinates, the sound will be
    heard at those coordinates.
  • Pops the level to remove the actions menu from the stack.
Parameters:
  • obj – The object which has the action.
  • action – The action which should be performed.
play_action_sound(sound: str, position: Optional[earwax.point.Point] = None) → None

Play an action sound.

Parameters:
  • sound – The filename of the sound to play.
  • position

    The position of the owning object.

    If this value is None, the sound will not be panned.

play_cursor_sound(position: Optional[earwax.point.Point]) → None

Play and set the cursor sound.

play_object_ambiances(obj: earwax.story.world.RoomObject) → None

Play all the ambiances for the given object.

Parameters:obj – The object whose ambiances will be played.
previous_category() → Generator[None, None, None]

Previous information category.

previous_object() → None

Go to the previous object.

save_state() → None

Save the current state.

set_room(room: earwax.story.world.WorldRoom) → None

Move to a new room.

state

Return the current state.

stop_action_sounds() → None

Stop all action sounds.

stop_object_ambiances(obj: earwax.story.world.RoomObject) → None

Stop all the ambiances for the given object.

Parameters:obj – The object whose ambiances will be stopped.
take_object(obj: earwax.story.world.RoomObject) → None

Take an object.

use_exit(x: earwax.story.world.RoomExit) → None

Use the given exit.

This method is called by the activate() method.

Parameters:x – The exit to use.
use_object(obj: earwax.story.world.RoomObject) → Callable[[], None]

Return a callable that can be used to use an object.

use_object_menu() → None

Push a menu that allows using an object.

world

Get the attached world.