Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ func _ready() -> void:
var elder: Elder
if GameState.current_quest:
elder = _find_elder(GameState.current_quest)
elif elders:
# If the game was started from a specific scene (in the editor or
# via the #fragment in the web build), rather than by picking a
# quest from an elder, GameState.current_quest will be null.
# Pick any elder.
elder = elders[0]
else:
push_warning("incorporating_threads was set, but current_quest was null")
if elders:
# Pick any elder.
elder = elders.pick_random()
if elder:
await elder.congratulate_player()

Expand Down Expand Up @@ -71,4 +70,8 @@ func on_offering_succeeded() -> void:


func is_item_offering_possible() -> bool:
return GameState.items_collected().size() >= InventoryItem.ItemType.size()
return (
GameState.current_quest
and GameState.current_quest.threads_to_collect > 0
and GameState.items_collected().size() >= GameState.current_quest.threads_to_collect
Comment on lines +74 to +76
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

)
41 changes: 34 additions & 7 deletions scenes/globals/game_state/game_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ signal lives_changed(new_lives: int)

const GAME_STATE_PATH := "user://game_state.cfg"
const INVENTORY_SECTION := "inventory"
const INVENTORY_ITEMS_AMOUNT_KEY := "amount_of_items_collected"
const INVENTORY_ITEMS_KEY := "items_collected"
const QUEST_SECTION := "quest"
const QUEST_PATH_KEY := "resource_path"
const QUEST_CURRENTSCENE_KEY := "current_scene"
Expand Down Expand Up @@ -76,7 +76,10 @@ func _ready() -> void:
)
persist_progress = initial_scene_uid == main_scene_uid
if not persist_progress:
if current_scene:
guess_quest(current_scene.scene_file_path)
return

var err := _state.load(GAME_STATE_PATH)
if err != OK and err != ERR_FILE_NOT_FOUND:
push_error("Failed to load %s: %s" % [GAME_STATE_PATH, err])
Expand Down Expand Up @@ -109,6 +112,27 @@ func start_quest(quest: Quest) -> void:
_save()


## Guess which quest the given scene is part of, and set [member current_quest]
## accordingly. If the quest cannot be determined, unset [member current_quest].
## [br][br]
## This is for use when jumping to a particular scene during development (e.g.
## with F6 in the editor, the URL hash in the browser, or in future if we add a
## level selector). During normal gameplay it should not be used.
func guess_quest(scene_path_or_uid: String) -> void:
var scene_path := ResourceUID.ensure_path(scene_path_or_uid)
var dir_path := scene_path.get_base_dir()
while dir_path != "res://":
var quest_path := dir_path.path_join("quest.tres")
if ResourceLoader.exists(quest_path, "Resource"):
current_quest = ResourceLoader.load(quest_path) as Quest
prints("Guessed quest", current_quest.resource_path, "from scene", scene_path)
return

dir_path = dir_path.get_base_dir()

current_quest = null


## Set the scene path and [member current_spawn_point].
func set_scene(scene_path: String, spawn_point: NodePath = ^"") -> void:
if scene_path in TRANSIENT_SCENES:
Expand Down Expand Up @@ -227,8 +251,11 @@ func items_collected() -> Array[InventoryItem]:


func _update_inventory_state() -> void:
var amount: int = clamp(inventory.size(), 0, InventoryItem.ItemType.size())
_state.set_value(INVENTORY_SECTION, INVENTORY_ITEMS_AMOUNT_KEY, amount)
_state.set_value(
INVENTORY_SECTION,
INVENTORY_ITEMS_KEY,
inventory.map(func(i: InventoryItem) -> InventoryItem.ItemType: return i.type)
)


## Decrement the player's lives by 1. Does not go below 0.
Expand Down Expand Up @@ -287,11 +314,11 @@ func get_scene_to_restore() -> String:

## Restore the persisted state.
func restore() -> Dictionary:
var amount_in_state: int = _state.get_value(INVENTORY_SECTION, INVENTORY_ITEMS_AMOUNT_KEY, 0)
var amount: int = clamp(amount_in_state, 0, InventoryItem.ItemType.size())
inventory.clear()
for index in range(amount):
var item := InventoryItem.with_type(index)
for item_type: InventoryItem.ItemType in _state.get_value(
INVENTORY_SECTION, INVENTORY_ITEMS_KEY, []
):
var item := InventoryItem.with_type(item_type)
inventory.append(item)

if _state.has_section_key(QUEST_SECTION, QUEST_PATH_KEY):
Expand Down
4 changes: 2 additions & 2 deletions scenes/globals/scene_switcher/scene_switcher.gd
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ func _restore_from_hash() -> void:
# for testing or debugging.
GameState.persist_progress = false
GameState.clear()
# TODO: Try to look up the quest that the scene corresponds to
GameState.guess_quest(path)

# In theory, we might like to avoid switching scene if the specified
# scene is the default scene. In practice, that will not happen, and
# if it does, it's harmless enough.
change_to_file(path)
else:
print("Path ", path, " from URL hash ", url_hash, " is not a scene; ignoring")
prints("Path", path, "from URL hash", url_hash, "is not a scene; ignoring")


## On the web, update or clear the URL hash to indicate the current world.
Expand Down
5 changes: 5 additions & 0 deletions scenes/menus/storybook/components/quest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ enum Status {
## The path to the first scene of the quest.
@export_file("*.tscn") var first_scene: String

## The number of threads that the player collects in this quest - typically one
## at the end of each mini-game/challenge. This should match the number of
## [CollectibleItem]s in the quest.
@export_range(0, 6, 1, "suffix:threads") var threads_to_collect: int = 3

@export_group("Animation")

## An optional sprite frame library to show in the storybook page for this quest.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=33 format=4 uid="uid://d2ejk3qrh0fo3"]
[gd_scene load_steps=32 format=4 uid="uid://d2ejk3qrh0fo3"]

[ext_resource type="Script" uid="uid://dnp0tjloec2d7" path="res://scenes/game_logic/stealth_game_logic.gd" id="1_gqxgg"]
[ext_resource type="TileSet" uid="uid://oynx002hv8tl" path="res://tiles/water.tres" id="1_stmf1"]
Expand All @@ -19,7 +19,6 @@
[ext_resource type="AudioStream" uid="uid://bwif2oo6ymiu2" path="res://assets/third_party/sounds/characters/enemies/guard/TorchHit.ogg" id="10_f0rs2"]
[ext_resource type="SpriteFrames" uid="uid://d1k25io0tiiij" path="res://scenes/game_elements/characters/enemies/guard/components/storyvoretorch_frames_blue.tres" id="11_bc7ib"]
[ext_resource type="Script" uid="uid://c68oh8dtr21ti" path="res://scenes/game_logic/sequence_puzzle.gd" id="14_qhjva"]
[ext_resource type="Resource" uid="uid://c6npgkuhqql7" path="res://scenes/quests/lore_quests/quest_003/1_stealth_sequence_combo/components/collected.dialogue" id="15_00lb2"]
[ext_resource type="Script" uid="uid://ccc78coj2b1li" path="res://scenes/game_logic/sequence_puzzle_step.gd" id="15_aaq2u"]
[ext_resource type="PackedScene" uid="uid://ymcjwxrqt4e4" path="res://scenes/quests/lore_quests/quest_001/1_music_puzzle/components/musical_rock.tscn" id="15_lxyj7"]
[ext_resource type="AudioStream" uid="uid://byi3b8aywp6py" path="res://assets/third_party/nepalese_hand_bells/handBells-a3.ogg" id="17_qhjva"]
Expand All @@ -44,6 +43,7 @@ point_count = 4

[sub_resource type="Resource" id="Resource_idy4y"]
script = ExtResource("9_1l5nh")
type = 2
metadata/_custom_type_script = "uid://bgmwplmj3bfls"

[node name="StealthSequenceCombo" type="Node2D"]
Expand Down Expand Up @@ -237,7 +237,6 @@ position = Vector2(2429, 1936)
revealed = false
next_scene = "uid://dgt78lsdstjrl"
item = SubResource("Resource_idy4y")
collected_dialogue = ExtResource("15_00lb2")
metadata/patchwork_id = "b4d8599d3c834fa99ea2e23c1a05d61c"

[node name="InTheWater" type="Node2D" parent="."]
Expand Down
1 change: 1 addition & 0 deletions scenes/quests/lore_quests/quest_003/quest.tres
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ script = ExtResource("1_onpv7")
title = "Placeholder"
description = "A quest to hold scenes that don't yet have a permanent home."
first_scene = "uid://d2ejk3qrh0fo3"
threads_to_collect = 2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dialogue removed in this 1st commit was granting 2 threads (imagination, spirit). But yes I see that it wasn't updated when the ink_combat_round_6.tscn added a 4th thread. So the threads to collect are indeed 2.

metadata/_custom_type_script = "uid://dts1hwdy3phin"
7 changes: 7 additions & 0 deletions scenes/ui_elements/hud/hud.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ script = ExtResource("1_dwpju")

[node name="StoryQuestProgress" parent="." instance=ExtResource("1_7maed")]
unique_name_in_owner = true
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -144.0
offset_right = 0.0
offset_bottom = 128.0
grow_horizontal = 0
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ _data = {
[node name="ItemSlot" type="TextureRect"]
modulate = Color(0, 0, 0, 0.690196)
texture_filter = 6
custom_minimum_size = Vector2(32, 32)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@ const ITEM_SLOT: PackedScene = preload("uid://1mjm4atk2j6e")


func _ready() -> void:
if not GameState.current_quest:
push_warning("No current quest")
return

if GameState.current_quest.threads_to_collect == 0:
visible = false
return

# Add one slot for each item in the current quest
for _i: int in GameState.current_quest.threads_to_collect:
items_container.add_child(ITEM_SLOT.instantiate())

# On ready, the HUD is populated with the items that were collected so
# far in the quest.
var items_collected := GameState.items_collected()
for i: int in clamp(items_collected.size(), 0, InventoryItem.ItemType.size()):
for i: int in min(items_collected.size(), GameState.current_quest.threads_to_collect):
items_container.get_child(i).start_as_filled(items_collected[i])

# Then, when each new item is collected, it is added to the progress UI
GameState.item_collected.connect(self._on_item_collected)
GameState.item_consumed.connect(self._on_item_consumed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://cae10mh6roenk"]
[gd_scene load_steps=4 format=3 uid="uid://cae10mh6roenk"]

[ext_resource type="Texture2D" uid="uid://b00c4kiewn30t" path="res://assets/third_party/tiny-swords/UI/Banners/Banner_Horizontal.png" id="1_cikk2"]
[ext_resource type="Script" uid="uid://bvv51rbqbu78f" path="res://scenes/ui_elements/story_quest_progress/components/story_quest_progress.gd" id="2_hvmtc"]
[ext_resource type="PackedScene" uid="uid://1mjm4atk2j6e" path="res://scenes/ui_elements/story_quest_progress/components/item_slot/item_slot.tscn" id="3_mwl7j"]

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_hqnrr"]
content_margin_top = 32.0
Expand All @@ -18,32 +17,12 @@ axis_stretch_horizontal = 1
axis_stretch_vertical = 1

[node name="StoryQuestProgress" type="PanelContainer"]
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -216.0
offset_bottom = 128.0
grow_horizontal = 0
offset_right = 112.0
offset_bottom = 96.0
theme_override_styles/panel = SubResource("StyleBoxTexture_hqnrr")
script = ExtResource("2_hvmtc")

[node name="ItemsContainer" type="HBoxContainer" parent="."]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4

[node name="ItemSlot" parent="ItemsContainer" instance=ExtResource("3_mwl7j")]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
expand_mode = 2

[node name="ItemSlot2" parent="ItemsContainer" instance=ExtResource("3_mwl7j")]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
expand_mode = 2

[node name="ItemSlot3" parent="ItemsContainer" instance=ExtResource("3_mwl7j")]
custom_minimum_size = Vector2(32, 32)
layout_mode = 2
expand_mode = 2
Loading