Popochiu

Inherits: Node

Description

Popochiu's core engine, responsible for the main game logic and systems. It is accessible from any game script as E (e.g. E.camera.shake()).

Provides core functionality for the game engine, plus access to some general-purpose feature: - Accessing the main camera and game settings. - Running sequential (and skippable) instruction queues. - Recording game events in a history log. - Handling game saves and loads. - Registering custom commands for the GUI. - Wrapping custom methods so they can be used inside a queue().

Use examples:

# Makes the player-controlled character say "Hi", wait a second, and then say another thing
E.queue([
    "Player: Hi",
    "...",
    "Player: I'm the character you can control!!!",
])
# Shake the camera with a strength of 2.0 for 3.0 seconds
E.camera.shake(2.0, 3.0)

Properties

Type Name Default
PopochiuAudioManager am null
Variant auto_continue_after -1.0
PopochiuClickable clicked null
PopochiuCommands commands null
Variant commands_map {
Variant current_command -1
Variant current_dialog_style settings.dialog_style
Variant cutscene_skipped false
PopochiuGraphicInterface gui null
Variant half_height 0.0
Variant half_width 0.0
Variant height 0.0
Variant history []
PopochiuClickable hovered null
Variant loaded_game {}
Variant playing_queue false
Variant scale Vector2.ONE
Variant settings PopochiuSettings.new()
float text_speed settings.text_speed
Variant width 0.0

Methods

Return Type Method
void add_history(data: Dictionary)
void command_fallback()
void cutscene(instructions: Array)
String get_command_name(command_id: int)
String get_current_command_name()
float get_half_height()
float get_half_width()
float get_height()
PopochiuClickable get_hovered()
Dictionary get_saves_descriptions()
String get_text(msg: String)
float get_width()
bool has_save()
void load_game(slot = 1)
void play_transition(anim_name: String, duration: float, mode: int) deprecated
void queue(instructions: Array, show_gui = true)
Callable queue_play_transition(anim_name: String, duration: float, mode: int) deprecated
Callable queue_wait(time = 1.0)
Callable queueable(node: Object, method: String, params = [], signal_name = "")
void register_command(id: int, command_name: String, fallback: Callable)
int register_command_without_id(command_name: String, fallback: Callable)
void save_game(slot = 1, description = "")
int saves_count()
void set_current_command(value: int)
void set_dialog_style(value: int)
void set_hovered(value: PopochiuClickable)
void set_text_speed(value: float)
void stop_camera_shake() deprecated
void wait(time = 1.0)

Signals


Signal Descriptions

await_stopped

signal await_stopped()

Sentinel signal that is never emitted. Awaiting it permanently suspends the current instruction chain, allowing new player interactions to take over (e.g. when the player clicks elsewhere while a character is walking to a PopochiuClickable).


command_selected

signal command_selected()

Emitted when current_command changes. Can be used to know the active command for the current GUI template.


dialog_style_changed

signal dialog_style_changed()

Emitted when the dialog style changes in PopochiuSettings.


game_load_started

signal game_load_started()

Emitted before a loaded game starts the transition to show the loaded data.


game_loaded

signal game_loaded(data: Dictionary)

Emitted by room_readied() when stored game data is loaded for the current room.


game_saved

signal game_saved()

Emitted after save_game() saves a file with the current game data.


language_changed

signal language_changed()

Emitted when the language changes in PopochiuSettings.


text_speed_changed

signal text_speed_changed()

Emitted when the text speed changes in PopochiuSettings.


Property Descriptions

am

var am : PopochiuAudioManager = null

Reference to the PopochiuAudioManager.


auto_continue_after

var auto_continue_after = -1.0

The number of seconds to wait before moving to the next dialog line (when playing dialog lines triggered inside a queue()).


clicked

var clicked : PopochiuClickable = null

Stores the last clicked PopochiuClickable for global access.


commands

var commands : PopochiuCommands = null

Reference to the current GUI commands script (e.g. NineVerbCommands, SierraCommands, or SimpleClickCommands).


commands_map

var commands_map = {

Maps command IDs to their names and fallback methods for the current GUI.


current_command

var current_command = -1
  • Setter: set_current_command

The ID of the current active command in the GUI. When this property changes, the command_selected signal is emitted.


current_dialog_style

var current_dialog_style = settings.dialog_style
  • Setter: set_dialog_style

The current dialog style used by the game. When this property changes, the dialog_style_changed signal is emitted.


cutscene_skipped

var cutscene_skipped = false

Whether the current cutscene was skipped by the player.


gui

var gui : PopochiuGraphicInterface = null

Reference to the PopochiuGraphicInterface.


half_height

var half_height = 0.0
  • Getter: get_half_height

height divided by 2.


half_width

var half_width = 0.0
  • Getter: get_half_width

width divided by 2.


height

var height = 0.0
  • Getter: get_height

The height, in pixels, of the game native resolution (that is get_viewport().get_visible_rect().end.y).


history

var history = []

Stores a list of game events (triggered actions and dialog lines). Each event is defined by a Dictionary.


hovered

var hovered : PopochiuClickable = null
  • Getter: get_hovered
  • Setter: set_hovered

Stores the last hovered PopochiuClickable for global access.


loaded_game

var loaded_game = {}

playing_queue

var playing_queue = false

Indicates if the game is playing a queue of instructions.


scale

var scale = Vector2.ONE

The scale value of the game. Defined by the native game resolution compared with (356, 200), which is the default game resolution defined by Popochiu.


settings

var settings = PopochiuSettings.new()

A reference to PopochiuSettings. Can be used to quickly access its members.


text_speed

var text_speed : float = settings.text_speed
  • Setter: set_text_speed

The text speed being used by the game. When this property changes, the text_speed_changed signal is emitted.


width

var width = 0.0
  • Getter: get_width

The width, in pixels, of the game native resolution (that is get_viewport().get_visible_rect().end.x).


Method Descriptions

add_history

func add_history(data: Dictionary) -> void

Adds an action, represented by data, to the history. The data dictionary can have one of these forms:

# To store the Look At interaction with the prop ToyCar:
{
    action = "look_at",
    target = "ToyCar"
}

or

# To store a dialog line said by the Popsy character
{
    character = "Popsy",
    text = "Hi. I said this and now it is recorded in the game's log!"
}

handle_command() and handle_command() store interactions with clickables and inventory items. on_dialog_line_started() stores dialog lines said by characters.


command_fallback

func command_fallback() -> void

Calls the fallback method registered for the current active GUI command. If no fallback method is registered, _command_fallback() is called.


cutscene

func cutscene(instructions: Array) -> void

Like queue(), but instructions can be skipped with the input action: popochiu-skip (see Project Settings... > Input Map). By default you can skip a cutscene with the [kbd]ESC[/kbd] key.


get_command_name

func get_command_name(command_id: int) -> String

Returns the name of the GUI command registered with command_id.


get_current_command_name

func get_current_command_name() -> String

Returns the name of the current active GUI command.


get_half_height

func get_half_height() -> float

get_half_width

func get_half_width() -> float

get_height

func get_height() -> float

get_hovered

func get_hovered() -> PopochiuClickable

get_saves_descriptions

func get_saves_descriptions() -> Dictionary

Gets the names of the saved games (the name given to the slot when the game is saved).


get_text

func get_text(msg: String) -> String

Returns msg translated to the current language if use_translations is enabled. Otherwise returns msg unchanged.


get_width

func get_width() -> float

has_save

func has_save() -> bool

Returns true if any saved game sessions exist in the game's save folder (user:// by default — open via Project > Open User Data Folder).


load_game

func load_game(slot = 1) -> void

Loads the game in the given slot.


play_transition

func play_transition(anim_name: String, duration: float, mode: int) -> void

Deprecated

Available in 2.1 - Will be removed in 2.2.

Plays the transition anim_name animation in the TransitionLayer with a duration in seconds with the specified mode.


queue

func queue(instructions: Array, show_gui = true) -> void

Executes an array of instructions one by one. show_gui determines whether the Graphic Interface reappears once all instructions have run.


queue_play_transition

func queue_play_transition(anim_name: String, duration: float, mode: int) -> Callable

Deprecated

Available in 2.1 - Will be removed in 2.2.

Plays the transition anim_name animation in the TransitionLayer with a duration in seconds with the specified mode. This method is intended to be used inside a queue() of instructions.


queue_wait

func queue_wait(time = 1.0) -> Callable

Creates a delay timer that lasts time seconds.

This method is intended to be used inside a queue() of instructions.


queueable

func queueable(node: Object, method: String, params = [], signal_name = "") -> Callable

Wraps a method on node so it can be used inside an array of instructions for queue(). Arguments for method can be passed as an array in params. By default the queued method waits for "completed", but it can wait for a different signal specified by signal_name. Examples:

# queue() will wait until $AnimationPlayer.animation_finished signal is emitted
E.queue([
    "Player: Ok. This is a queueable example",
    E.queueable($AnimationPlayer, "play", ["glottis_appears"], "animation_finished"),
    "Popsy: Hi Goddiu!",
    "Player: You're finally here!!!"
])

An example with a custom method:

# queue pauses until _make_glottis_appear.completed signal is emitted
func _ready() -> void:
E.queue([
    "Player: Ok. This is another queueable example",
    E.queueable(self, "_make_glottis_appear", [], "completed"),
    "Popsy: Hi Goddiu!",
    "Player: So... you're finally here!!!",
])

func _make_glottis_appear() -> void:
    $AnimationPlayer.play("make_glottis_appear")
    await $AnimationPlayer.animation_finished
    Globals.glottis_appeared = true
    await E.wait(1.0)

An example with a custom signal

# queue pauses until the "clicked" signal is emitted in the %PopupButton
# ---- In some prop ----
func on_click() -> void:
    E.queue([
        "Player: Ok. This is the last queueable example.",
        "Player: Promise!",
        E.queueable(%PopupButton, "_show_button", [], "clicked"),
        "Popsy: Are we done!?",
        "Player: Yup",
    ])

# ---- In the PopupButton node ----
signal clicked

func _show_button() -> void:
    $BtnPlay.show()

func _on_BtnPlay_pressed() -> void:
    await A.mx_mysterious_place.play()
    clicked.emit()

register_command

func register_command(id: int, command_name: String, fallback: Callable) -> void

Registers a GUI command identified by id, with name command_name and a fallback method to call when the interacted object has no implementation for the registered command.


register_command_without_id

func register_command_without_id(command_name: String, fallback: Callable) -> int

Registers a GUI command with just its name in command_name and a fallback method to call when the interacted object has no implementation for the registered command. Returns the auto-assigned id.


save_game

func save_game(slot = 1, description = "") -> void

Saves the current game state in a given slot with the name in description.


saves_count

func saves_count() -> int

Returns the number of saved game files in the game's save folder (user:// by default — open via Project > Open User Data Folder).


set_current_command

func set_current_command(value: int) -> void

set_dialog_style

func set_dialog_style(value: int) -> void

set_hovered

func set_hovered(value: PopochiuClickable) -> void

set_text_speed

func set_text_speed(value: float) -> void

stop_camera_shake

func stop_camera_shake() -> void

Deprecated

Now this is done by stop_shake().


wait

func wait(time = 1.0) -> void

Creates a delay timer that will last time seconds.