main.gd
· 5.2 KiB · GDScript3
Raw
Playground
# warning-ignore-all:return_value_discarded
extends HBoxContainer
class_name ChitinousCanrival
const event_player_scene = preload("res://scenes/ui/EventPlayer.tscn")
@onready var MinigameHandler := %MinigameHandler as MinigameHandler
@onready var TravelButtons := %TravelButtons as TravelButtons
@onready var EventPlayerContainer := %EventPlayerContainer as EventPlayerContainer
@onready var InventoryMenu := %InventoryMenu as InventoryMenu
@onready var SettingsMenu := %SettingsMenu as SettingsMenu
@onready var SaveMenu := %SaveMenu as SaveMenu
@onready var ChoicePanel := %ChoicePanel as Choice
@onready var StatusPanel := %StatusPanel as StatusPanel
@onready var Blackout := %BlackoutPanel as BlackoutPanel
var _current_sequence: String = ""
func _ready() -> void:
randomize()
MusicState.change_bg(MusicState.BACKGROUND_THEME)
ExploreState.set_start_time()
ExploreState._set_location(SimpleState.state.explore.location)
TravelButtons.set_button_disabled(SimpleState.state.explore.location)
SaveState.save_loaded.connect(_on_save_loaded)
EventPlayerContainer.minigame_started.connect(_on_minigame_started)
MinigameHandler.minigame_finished.connect(_on_minigame_finished)
StatusPanel.inventory_button_toggled.connect(_on_inventory_button_toggled)
StatusPanel.settings_button_toggled.connect(_on_settings_button_toggled)
StatusPanel.save_button_toggled.connect(_on_save_button_toggled)
InventoryMenu.visibility_changed.connect(_on_menu_visibility_changed)
SaveMenu.visibility_changed.connect(_on_menu_visibility_changed)
SaveMenu.closed.connect(StatusPanel.saving_closed)
SettingsMenu.visibility_changed.connect(_on_menu_visibility_changed)
SettingsMenu.closed.connect(StatusPanel.settings_closed)
TravelButtons.waited.connect(_on_wait_button_pressed)
ChoicePanel.options_shown.connect(_on_options_shown)
ChoicePanel.options_cleared.connect(_on_options_cleared)
ExploreState.trap_triggered.connect(_on_trap_triggered)
ExploreState.event_triggered.connect(_on_event_triggered)
ExploreState.event_trigger_forced.connect(_on_event_trigger_forced)
ExploreState.revisited.connect(_on_revisited)
ExploreState.wandered.connect(_on_wandered)
ExploreState.item_selected.connect(_on_item_selected)
ExploreState.masturbated.connect(_on_masturbated)
if not MemoryState.has_seen("00-intro/00-premise"):
InventoryState.add_trap("intro")
EventPlayerContainer.run("00-intro/00-premise")
if not SimpleState.state.sequence.current_sequence != "None":
EventPlayerContainer.restore_from_state()
await Blackout.fade_in()
func _on_revisited(event: String) -> void:
EventPlayerContainer.run(event)
func _on_wandered(where: String) -> void:
EventPlayerContainer.run("01-location/%s/wander" % where)
func _on_item_selected(what: String) -> void:
StatusPanel.inventory_closed()
EventPlayerContainer.run("items/%s" % what)
func _on_save_loaded(title) -> void:
if not title:
await Blackout.fade_out()
EventPlayerContainer.hard_stop()
ChoicePanel.clear_options()
if SimpleState.state.sequence.current_sequence != "NONE":
EventPlayerContainer.restore_from_state()
else:
EventPlayerContainer.hide()
await Blackout.fade_in()
func _on_minigame_started(minigame: String, initial_state: Dictionary) -> void:
MinigameHandler.play_minigame(minigame, initial_state)
func _on_minigame_finished(result) -> void:
EventPlayerContainer.minigame_finished(result)
func _on_inventory_button_toggled(pressed: bool) -> void:
InventoryMenu.visible = pressed
if pressed:
SettingsMenu.visible = false
StatusPanel.settings_closed()
SaveMenu.visible = false
StatusPanel.saving_closed()
func _on_settings_button_toggled(pressed: bool) -> void:
SettingsMenu.visible = pressed
if pressed:
InventoryMenu.visible = false
StatusPanel.inventory_closed()
SaveMenu.visible = false
StatusPanel.saving_closed()
func _on_save_button_toggled(pressed: bool) -> void:
SaveMenu.visible = pressed
if pressed:
InventoryMenu.visible = false
StatusPanel.inventory_closed()
SettingsMenu.visible = false
StatusPanel.settings_closed()
func _on_menu_visibility_changed() -> void:
EventPlayerContainer.set_input_disabled(any_menu_open())
ChoicePanel.visible = !any_menu_open() and ChoicePanel.active
func _on_wait_button_pressed() -> void:
await Blackout.fade_out()
ExploreState.wait()
await Blackout.fade_in()
func _on_options_shown() -> void:
ChoicePanel.visible = !any_menu_open() and ChoicePanel.active
func _on_options_cleared() -> void:
ChoicePanel.hide()
await get_tree().process_frame
func _on_trap_triggered(_trap_name: String, event: String) -> void:
EventPlayerContainer.run(event)
func _on_event_triggered(event, entry: String = "intro") -> void:
EventPlayerContainer.run(event, entry)
func _on_event_trigger_forced(event, entry: String) -> void:
if event == "NONE":
EventPlayerContainer._on_scene_ended()
ChoicePanel.clear_options()
else:
EventPlayerContainer._on_sequence_changed(event, entry)
func _on_masturbated() -> void:
EventPlayerContainer.run("masturbations/init")
func any_menu_open() -> bool:
return InventoryMenu.visible \
or SettingsMenu.visible \
or SaveMenu.visible
| 1 | # warning-ignore-all:return_value_discarded |
| 2 | extends HBoxContainer |
| 3 | class_name ChitinousCanrival |
| 4 | |
| 5 | const event_player_scene = preload("res://scenes/ui/EventPlayer.tscn") |
| 6 | |
| 7 | @onready var MinigameHandler := %MinigameHandler as MinigameHandler |
| 8 | @onready var TravelButtons := %TravelButtons as TravelButtons |
| 9 | @onready var EventPlayerContainer := %EventPlayerContainer as EventPlayerContainer |
| 10 | @onready var InventoryMenu := %InventoryMenu as InventoryMenu |
| 11 | @onready var SettingsMenu := %SettingsMenu as SettingsMenu |
| 12 | @onready var SaveMenu := %SaveMenu as SaveMenu |
| 13 | @onready var ChoicePanel := %ChoicePanel as Choice |
| 14 | @onready var StatusPanel := %StatusPanel as StatusPanel |
| 15 | @onready var Blackout := %BlackoutPanel as BlackoutPanel |
| 16 | |
| 17 | var _current_sequence: String = "" |
| 18 | |
| 19 | func _ready() -> void: |
| 20 | randomize() |
| 21 | |
| 22 | MusicState.change_bg(MusicState.BACKGROUND_THEME) |
| 23 | |
| 24 | ExploreState.set_start_time() |
| 25 | ExploreState._set_location(SimpleState.state.explore.location) |
| 26 | TravelButtons.set_button_disabled(SimpleState.state.explore.location) |
| 27 | |
| 28 | SaveState.save_loaded.connect(_on_save_loaded) |
| 29 | EventPlayerContainer.minigame_started.connect(_on_minigame_started) |
| 30 | MinigameHandler.minigame_finished.connect(_on_minigame_finished) |
| 31 | |
| 32 | StatusPanel.inventory_button_toggled.connect(_on_inventory_button_toggled) |
| 33 | StatusPanel.settings_button_toggled.connect(_on_settings_button_toggled) |
| 34 | StatusPanel.save_button_toggled.connect(_on_save_button_toggled) |
| 35 | |
| 36 | InventoryMenu.visibility_changed.connect(_on_menu_visibility_changed) |
| 37 | |
| 38 | SaveMenu.visibility_changed.connect(_on_menu_visibility_changed) |
| 39 | SaveMenu.closed.connect(StatusPanel.saving_closed) |
| 40 | |
| 41 | SettingsMenu.visibility_changed.connect(_on_menu_visibility_changed) |
| 42 | SettingsMenu.closed.connect(StatusPanel.settings_closed) |
| 43 | |
| 44 | TravelButtons.waited.connect(_on_wait_button_pressed) |
| 45 | |
| 46 | ChoicePanel.options_shown.connect(_on_options_shown) |
| 47 | ChoicePanel.options_cleared.connect(_on_options_cleared) |
| 48 | |
| 49 | ExploreState.trap_triggered.connect(_on_trap_triggered) |
| 50 | ExploreState.event_triggered.connect(_on_event_triggered) |
| 51 | ExploreState.event_trigger_forced.connect(_on_event_trigger_forced) |
| 52 | ExploreState.revisited.connect(_on_revisited) |
| 53 | ExploreState.wandered.connect(_on_wandered) |
| 54 | ExploreState.item_selected.connect(_on_item_selected) |
| 55 | ExploreState.masturbated.connect(_on_masturbated) |
| 56 | |
| 57 | if not MemoryState.has_seen("00-intro/00-premise"): |
| 58 | InventoryState.add_trap("intro") |
| 59 | EventPlayerContainer.run("00-intro/00-premise") |
| 60 | |
| 61 | if not SimpleState.state.sequence.current_sequence != "None": |
| 62 | EventPlayerContainer.restore_from_state() |
| 63 | |
| 64 | await Blackout.fade_in() |
| 65 | |
| 66 | |
| 67 | func _on_revisited(event: String) -> void: |
| 68 | EventPlayerContainer.run(event) |
| 69 | |
| 70 | |
| 71 | func _on_wandered(where: String) -> void: |
| 72 | EventPlayerContainer.run("01-location/%s/wander" % where) |
| 73 | |
| 74 | |
| 75 | func _on_item_selected(what: String) -> void: |
| 76 | StatusPanel.inventory_closed() |
| 77 | EventPlayerContainer.run("items/%s" % what) |
| 78 | |
| 79 | func _on_save_loaded(title) -> void: |
| 80 | if not title: |
| 81 | await Blackout.fade_out() |
| 82 | |
| 83 | EventPlayerContainer.hard_stop() |
| 84 | ChoicePanel.clear_options() |
| 85 | |
| 86 | if SimpleState.state.sequence.current_sequence != "NONE": |
| 87 | EventPlayerContainer.restore_from_state() |
| 88 | else: |
| 89 | EventPlayerContainer.hide() |
| 90 | |
| 91 | await Blackout.fade_in() |
| 92 | |
| 93 | |
| 94 | func _on_minigame_started(minigame: String, initial_state: Dictionary) -> void: |
| 95 | MinigameHandler.play_minigame(minigame, initial_state) |
| 96 | |
| 97 | |
| 98 | func _on_minigame_finished(result) -> void: |
| 99 | EventPlayerContainer.minigame_finished(result) |
| 100 | |
| 101 | |
| 102 | func _on_inventory_button_toggled(pressed: bool) -> void: |
| 103 | |
| 104 | InventoryMenu.visible = pressed |
| 105 | |
| 106 | if pressed: |
| 107 | SettingsMenu.visible = false |
| 108 | StatusPanel.settings_closed() |
| 109 | |
| 110 | SaveMenu.visible = false |
| 111 | StatusPanel.saving_closed() |
| 112 | |
| 113 | |
| 114 | func _on_settings_button_toggled(pressed: bool) -> void: |
| 115 | SettingsMenu.visible = pressed |
| 116 | |
| 117 | if pressed: |
| 118 | InventoryMenu.visible = false |
| 119 | StatusPanel.inventory_closed() |
| 120 | |
| 121 | SaveMenu.visible = false |
| 122 | StatusPanel.saving_closed() |
| 123 | |
| 124 | |
| 125 | func _on_save_button_toggled(pressed: bool) -> void: |
| 126 | SaveMenu.visible = pressed |
| 127 | |
| 128 | if pressed: |
| 129 | InventoryMenu.visible = false |
| 130 | StatusPanel.inventory_closed() |
| 131 | |
| 132 | SettingsMenu.visible = false |
| 133 | StatusPanel.settings_closed() |
| 134 | |
| 135 | |
| 136 | func _on_menu_visibility_changed() -> void: |
| 137 | EventPlayerContainer.set_input_disabled(any_menu_open()) |
| 138 | ChoicePanel.visible = !any_menu_open() and ChoicePanel.active |
| 139 | |
| 140 | |
| 141 | func _on_wait_button_pressed() -> void: |
| 142 | await Blackout.fade_out() |
| 143 | ExploreState.wait() |
| 144 | await Blackout.fade_in() |
| 145 | |
| 146 | |
| 147 | func _on_options_shown() -> void: |
| 148 | ChoicePanel.visible = !any_menu_open() and ChoicePanel.active |
| 149 | |
| 150 | |
| 151 | func _on_options_cleared() -> void: |
| 152 | ChoicePanel.hide() |
| 153 | await get_tree().process_frame |
| 154 | |
| 155 | |
| 156 | func _on_trap_triggered(_trap_name: String, event: String) -> void: |
| 157 | EventPlayerContainer.run(event) |
| 158 | |
| 159 | |
| 160 | func _on_event_triggered(event, entry: String = "intro") -> void: |
| 161 | EventPlayerContainer.run(event, entry) |
| 162 | |
| 163 | |
| 164 | func _on_event_trigger_forced(event, entry: String) -> void: |
| 165 | if event == "NONE": |
| 166 | EventPlayerContainer._on_scene_ended() |
| 167 | ChoicePanel.clear_options() |
| 168 | else: |
| 169 | EventPlayerContainer._on_sequence_changed(event, entry) |
| 170 | |
| 171 | |
| 172 | func _on_masturbated() -> void: |
| 173 | EventPlayerContainer.run("masturbations/init") |
| 174 | |
| 175 | |
| 176 | func any_menu_open() -> bool: |
| 177 | return InventoryMenu.visible \ |
| 178 | or SettingsMenu.visible \ |
| 179 | or SaveMenu.visible |
| 180 |