Skip to content
Draft
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
1 change: 1 addition & 0 deletions scenes/dev/dev_archipelago.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ position = Vector2(0, 64)

[node name="TemplateElder" parent="OnTheGround/Elders" unique_id=1625796178 node_paths=PackedStringArray("abandon_point") instance=ExtResource("11_ui3i3")]
position = Vector2(481, 1107)
quest_directory = "res://scenes/dev/level_design/"
abandon_point = NodePath("SpawnPoint")

[node name="SpawnPoint" parent="OnTheGround/Elders/TemplateElder" unique_id=1656237801 instance=ExtResource("18_elr7o")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: The Threadbare Authors
# SPDX-License-Identifier: MPL-2.0
~ start
if optional_collectible_item:
Ulysses Thriftweed: If you go East, you can get out of here.
Ulysses Thriftweed: If you go through the cave up North, there's another thread you can collect first, if you're feeling brave.
else:
Ulysses Thriftweed: I hope now you've learned to stop picking your nose.
=> END

~ wow
Ulysses Thriftweed: You run THAT fast?
=> END
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[remap]

importer="dialogue_manager"
importer_version=15
type="Resource"
uid="uid://b1ywwu7aese02"
path="res://.godot/imported/optional_threads.dialogue-f583759440f80634b369fea5863492be.tres"

[deps]

source_file="res://scenes/dev/level_design/optional_threads/optional_threads.dialogue"
dest_files=["res://.godot/imported/optional_threads.dialogue-f583759440f80634b369fea5863492be.tres"]

[params]

defaults=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Node2D

@onready var optional_collectible_item: CollectibleItem = %OptionalCollectibleItem


func _ready() -> void:
optional_collectible_item.tree_exiting.connect(func(): optional_collectible_item = null)

Check warning on line 7 in scenes/dev/level_design/optional_threads/optional_threads.gd

View workflow job for this annotation

GitHub Actions / Build for web

(UNTYPED_DECLARATION): Function "<anonymous lambda>()" has no static return type.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b4muk3fixh36l
237 changes: 237 additions & 0 deletions scenes/dev/level_design/optional_threads/optional_threads.tscn

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions scenes/dev/level_design/optional_threads/quest.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="Quest" format=3 uid="uid://pdpqinul8nu5"]

[ext_resource type="Script" uid="uid://dts1hwdy3phin" path="res://scenes/menus/storybook/components/quest.gd" id="1_cjuqo"]

[resource]
script = ExtResource("1_cjuqo")
title = "Optional Threads"
description = "Shows how to add an optional thread to a scene."
first_scene = "uid://cplmo457h47p8"
threads_to_collect = 2
metadata/_custom_type_script = "uid://dts1hwdy3phin"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[ext_resource type="Script" uid="uid://be7lr8ty24cix" path="res://scenes/game_elements/props/collectible_item/components/collectible_item.gd" id="1_7ff3m"]
[ext_resource type="Script" uid="uid://du8wfijr35r35" path="res://scenes/game_elements/props/interact_area/interact_area.gd" id="2_1kegn"]
[ext_resource type="Shader" uid="uid://cj250ayvmpwf3" path="res://scenes/game_elements/props/collectible_item/components/collectible_item.gdshader" id="4_hhgm5"]
[ext_resource type="AudioStream" uid="uid://bhgpds38q0j4r" path="res://assets/third_party/sounds/collectibles/MemoryCollectable.ogg" id="5_hhgm5"]
[ext_resource type="AudioStream" uid="uid://38xwdjm46478" path="res://assets/third_party/sounds/collectibles/CollectibleAppear.ogg" id="5_oh62b"]

Expand Down Expand Up @@ -294,6 +295,11 @@ _data = {
&"reveal": SubResource("Animation_qy0vu")
}

[sub_resource type="ShaderMaterial" id="ShaderMaterial_md2w2"]
resource_local_to_scene = true
shader = ExtResource("4_hhgm5")
shader_parameter/intensity = 0.0

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_hhgm5"]
radius = 9.0
height = 28.0
Expand Down Expand Up @@ -322,6 +328,7 @@ libraries/ = SubResource("AnimationLibrary_8dm1m")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1620327010]
visible = false
modulate = Color(1, 1, 1, 0)
material = SubResource("ShaderMaterial_md2w2")

[node name="CollectedSound" type="AudioStreamPlayer" parent="." unique_id=420528907]
unique_name_in_owner = true
Expand All @@ -333,6 +340,7 @@ stream = ExtResource("5_oh62b")
bus = &"SFX"

[node name="StaticBody2D" type="StaticBody2D" parent="." unique_id=9475262]
collision_layer = 16
collision_mask = 0

[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1204681631]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extends SceneLink

## [InventoryItem] provided by this collectible when interacted with.
@export var item: InventoryItem:
get = _get_item,
set = _set_item

@export_category("Dialogue")
Expand All @@ -30,6 +31,13 @@ extends SceneLink
## The dialogue title from where [member collected_dialogue] will start.
@export var dialogue_title: StringName = ""

var _ghost := false:
set(new_value):
_ghost = new_value
# TODO: effect is ugly
var sm := sprite_2d.material as ShaderMaterial
sm.set_shader_parameter("intensity", 0.25 if _ghost else 0.0)

@onready var interact_area: InteractArea = $InteractArea
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var sprite_2d: Sprite2D = $Sprite2D
Expand All @@ -52,11 +60,19 @@ func _get_configuration_warnings() -> PackedStringArray:
return warnings


func _get_item() -> InventoryItem:
# Replace anonymous resource stored in scene file with separately-stored resource.
# Can be removed when we don't expect to have to rewrite any new quests being merged.
if item and item.is_built_in():
item = InventoryItem.with_type(item.type)
return item


func _set_item(new_value: InventoryItem) -> void:
item = new_value

if sprite_2d:
sprite_2d.texture = item.get_world_texture() if item else null
sprite_2d.texture = item.world_texture if item else null

if interact_area:
interact_area.action = "Collect " + item.type_name() if item else "Collect"
Expand All @@ -73,6 +89,14 @@ func _ready() -> void:
if Engine.is_editor_hint():
return

# Collected in previous run.................? or in this run..............................?
if GameState.global.inventory.has(item, self) or GameState.quest.inventory.has(item, self):
if next_scene:
# Need to keep it because this is how we link scenes together.
_ghost = true
else:
queue_free()

interact_area.interaction_started.connect(self._on_interacted)


Expand Down Expand Up @@ -102,7 +126,8 @@ func _on_interacted(player: Player, _from_right: bool) -> void:
animation_player.play("collected")
await animation_player.animation_finished

GameState.quest.inventory.add_collected_item(item)
if not _ghost:
GameState.quest.inventory.add_collected_item(item, self)

if collected_dialogue:
DialogueManager.show_dialogue_balloon(collected_dialogue, dialogue_title, [self, player])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 KingToot
// SPDX-License-Identifier: CC0-1.0
// https://godotshaders.com/shader/dithering-screen-door-transparency/
shader_type canvas_item;

uniform float intensity: hint_range(0.0, 1.0, 0.05) = 0.0;

const mat4 THRESHOLD_MATRIX = mat4(
vec4(1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0),
vec4(13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0),
vec4(4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0),
vec4(16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0));

void fragment() {
vec2 uv = UV / TEXTURE_PIXEL_SIZE;
COLOR.a *= step(0.0, THRESHOLD_MATRIX[int(uv.x) % 4][int(uv.y) % 4] - intensity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cj250ayvmpwf3
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@


func _has_magical_thread_of_type(type: InventoryItem.ItemType) -> bool:
for item: InventoryItem in GameState.quest.inventory.items:
if item.type == type:
for ci: CollectedItem in GameState.quest.inventory.items:
if ci.item.type == type:
return true
return false

Expand Down Expand Up @@ -81,7 +81,7 @@

loom_offering_animation_player.play(&"loom_offering")
await loom_offering_animation_player.animation_finished
GameState.quest.inventory.clear_inventory()
GameState.global.inventory.merge(GameState.quest.inventory)

play_cinematic.emit()

Expand All @@ -103,7 +103,9 @@
if not GameState.quest:
return false

return true

if GameState.quest.quest.threads_to_collect <= 0:

Check warning on line 108 in scenes/game_elements/props/eternal_loom/components/eternal_loom.gd

View workflow job for this annotation

GitHub Actions / Build for web

(UNREACHABLE_CODE): Unreachable code (statement after return) in function "is_item_offering_possible()".
return false

return GameState.quest.inventory.items.size() >= GameState.quest.quest.threads_to_collect
2 changes: 2 additions & 0 deletions scenes/globals/game_state/global_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ signal helper_changed

@export var helper: HelperCharacterState

@export var inventory: InventoryState = InventoryState.new()

## Quests that were started & abandoned without being completed, keyed by
## [member Resource.resource_path] of each [Quest].
## Captures the [QuestState] and [PerSceneState] at point, so that the player
Expand Down
26 changes: 26 additions & 0 deletions scenes/globals/game_state/inventory/collected_item.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SPDX-FileCopyrightText: The Threadbare Authors
# SPDX-License-Identifier: MPL-2.0
class_name CollectedItem
extends Resource

@export var item: InventoryItem
@export var source_scene: String
@export var source_node: NodePath


static func make(an_item: InventoryItem, a_source_node: Node = null) -> CollectedItem:
var ci := new()
ci.item = an_item
var current_scene := (Engine.get_main_loop() as SceneTree).current_scene
ci.source_scene = current_scene.scene_file_path
if a_source_node:
ci.source_node = current_scene.get_path_to(a_source_node)
return ci


func matches(that: CollectedItem) -> bool:
return (
self.item == that.item
and self.source_scene == that.source_scene
and self.source_node == that.source_node
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cvmcbvc6skodh
13 changes: 13 additions & 0 deletions scenes/globals/game_state/inventory/imagination.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[gd_resource type="Resource" script_class="InventoryItem" format=3 uid="uid://cchnv5pn6fa8e"]

[ext_resource type="Texture2D" uid="uid://wyiamtqmp4gk" path="res://assets/first_party/collectibles/imagination.png" id="1_f7k4n"]
[ext_resource type="Script" uid="uid://bgmwplmj3bfls" path="res://scenes/globals/game_state/inventory/inventory_item.gd" id="2_mhd08"]
[ext_resource type="Texture2D" uid="uid://6bf8rum68wq3" path="res://assets/first_party/collectibles/world_imagination.png" id="3_vln5c"]

[resource]
script = ExtResource("2_mhd08")
type = 1
color = Color(0.969, 0.792, 0, 1)
hud_texture = ExtResource("1_f7k4n")
world_texture = ExtResource("3_vln5c")
metadata/_custom_type_script = "uid://bgmwplmj3bfls"
44 changes: 14 additions & 30 deletions scenes/globals/game_state/inventory/inventory_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,26 @@ enum ItemType {
MEMORY,
IMAGINATION,
SPIRIT,
NONE,
}

const COLORS_PER_TYPE: Dictionary[ItemType, Color] = {
ItemType.MEMORY: Color(0.459, 0.867, 0.0, 1.0),
ItemType.IMAGINATION: Color(0.969, 0.792, 0.0, 1.0),
ItemType.SPIRIT: Color(0.929, 0.0, 0.0, 1.0)
}

const HUD_TEXTURES: Dictionary[ItemType, Texture2D] = {
ItemType.MEMORY: preload("uid://brspc1u02oawt"),
ItemType.IMAGINATION: preload("uid://wyiamtqmp4gk"),
ItemType.SPIRIT: preload("uid://c4fefrg0tfkpl")
}

const WORLD_TEXTURES: Dictionary[ItemType, Texture2D] = {
ItemType.MEMORY: preload("uid://5wscjc8yqqts"),
ItemType.IMAGINATION: preload("uid://6bf8rum68wq3"),
ItemType.SPIRIT: preload("uid://cepg1o3ihp055")
}

@export var type: ItemType
@export var color: Color
@export var hud_texture: Texture2D
@export var world_texture: Texture2D


func get_hud_texture() -> Texture2D:
return HUD_TEXTURES[type]


func get_world_texture() -> Texture2D:
return WORLD_TEXTURES[type]


# TODO: can we eliminate this?
static func with_type(a_type: ItemType) -> InventoryItem:
var item := new()
item.type = a_type
return item
match a_type:
ItemType.MEMORY:
return load("res://scenes/globals/game_state/inventory/memory.tres")
ItemType.IMAGINATION:
return load("res://scenes/globals/game_state/inventory/imagination.tres")
ItemType.SPIRIT:
return load("res://scenes/globals/game_state/inventory/spirit.tres")
_:
push_error("Unknown ItemType %d" % a_type)
return null


func type_name() -> String:
Expand Down
12 changes: 12 additions & 0 deletions scenes/globals/game_state/inventory/memory.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="InventoryItem" format=3 uid="uid://ck0wbckgm5un8"]

[ext_resource type="Texture2D" uid="uid://brspc1u02oawt" path="res://assets/first_party/collectibles/memory.png" id="1_kqroc"]
[ext_resource type="Script" uid="uid://bgmwplmj3bfls" path="res://scenes/globals/game_state/inventory/inventory_item.gd" id="2_5x7xc"]
[ext_resource type="Texture2D" uid="uid://5wscjc8yqqts" path="res://assets/first_party/collectibles/world_memory.png" id="3_t6yoc"]

[resource]
script = ExtResource("2_5x7xc")
color = Color(0.459, 0.867, 0, 1)
hud_texture = ExtResource("1_kqroc")
world_texture = ExtResource("3_t6yoc")
metadata/_custom_type_script = "uid://bgmwplmj3bfls"
13 changes: 13 additions & 0 deletions scenes/globals/game_state/inventory/spirit.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[gd_resource type="Resource" script_class="InventoryItem" format=3 uid="uid://c44l6x4e7sfx3"]

[ext_resource type="Texture2D" uid="uid://c4fefrg0tfkpl" path="res://assets/first_party/collectibles/spirit.png" id="1_puqvu"]
[ext_resource type="Script" uid="uid://bgmwplmj3bfls" path="res://scenes/globals/game_state/inventory/inventory_item.gd" id="2_glbdd"]
[ext_resource type="Texture2D" uid="uid://cepg1o3ihp055" path="res://assets/first_party/collectibles/world_spirit.png" id="3_45k8j"]

[resource]
script = ExtResource("2_glbdd")
type = 2
color = Color(0.929, 0, 0, 1)
hud_texture = ExtResource("1_puqvu")
world_texture = ExtResource("3_45k8j")
metadata/_custom_type_script = "uid://bgmwplmj3bfls"
Loading
Loading