Compare commits

...

2 commits

Author SHA1 Message Date
af4bece554 Use global sounds system in end door 2025-03-08 16:33:05 -05:00
ba3306c04c Global Sounds system 2025-03-08 16:32:47 -05:00
18 changed files with 248 additions and 15 deletions

View file

@ -0,0 +1,17 @@
@tool
extends EditorPlugin
const GlobalSoundSelectorPlugin = preload("global_sound_selector_plugin.gd")
var global_sound_selector_plugin: EditorInspectorPlugin
func _enter_tree() -> void:
global_sound_selector_plugin = GlobalSoundSelectorPlugin.new()
add_inspector_plugin(global_sound_selector_plugin)
func _exit_tree() -> void:
remove_inspector_plugin(global_sound_selector_plugin)

View file

@ -0,0 +1 @@
uid://b6rylu4028qec

View file

@ -0,0 +1,46 @@
extends EditorProperty
var _dropdown_button := Button.new()
var _popup_menu := PopupMenu.new()
func _init() -> void:
_dropdown_button.pressed.connect(_show_popup)
_dropdown_button.icon = EditorInterface.get_editor_theme().get_icon("AudioStreamPlayer", "EditorIcons")
_popup_menu.index_pressed.connect(_on_sound_selected)
add_child(_dropdown_button)
add_child(_popup_menu)
add_focusable(_dropdown_button)
func _update_property() -> void:
var new_value: StringName = get_edited_object()[get_edited_property()]
_dropdown_button.text = new_value.capitalize()
func _show_popup() -> void:
var sounds = GlobalSounds.sounds.keys()
_popup_menu.clear()
for sound: StringName in sounds:
_popup_menu.add_icon_item(
EditorInterface.get_editor_theme().get_icon("AudioStreamPlayer", "EditorIcons"),
sound.capitalize()
)
var button_rect = _dropdown_button.get_global_rect()
_popup_menu.reset_size()
var popup_pos = button_rect.position + Vector2(DisplayServer.window_get_position())
_popup_menu.position = popup_pos
_popup_menu.min_size.x = button_rect.size.x
_popup_menu.popup()
func _on_sound_selected(index: int) -> void:
var sound = GlobalSounds.sounds.keys()[index]
_dropdown_button.grab_focus()
emit_changed(get_edited_property(), sound)

View file

@ -0,0 +1 @@
uid://bwr5g1ae4dxs4

View file

@ -0,0 +1,16 @@
extends EditorInspectorPlugin
const GlobalSoundSelector = preload("global_sound_selector.gd")
func _can_handle(object: Object) -> bool:
return true
func _parse_property(object: Object, type: Variant.Type, name: String, hint_type: PropertyHint, hint_string: String, usage_flags: int, wide: bool) -> bool:
if type == TYPE_STRING_NAME and hint_string == "global_sound":
add_property_editor(name, GlobalSoundSelector.new())
return true
else:
return false

View file

@ -0,0 +1 @@
uid://c3qk8q16lbsk6

View file

@ -0,0 +1,7 @@
[plugin]
name="Capri Tools"
description="Bespoke tools for Capri's systems that require an editor plugin to be nicer to use."
author="fogwaves"
version="0.1.0"
script="capri_tools.gd"

View file

@ -0,0 +1,18 @@
@tool
extends Node
@export_tool_button("Update Sounds") var _update_sounds_action = _update_sounds
@export var sounds: Dictionary[StringName, AudioStreamPlayer]
func play_sound(id: StringName) -> void:
var sound := sounds.get(id) as AudioStreamPlayer
sound.play()
func _update_sounds() -> void:
sounds.clear()
for node in get_children():
if node is AudioStreamPlayer:
sounds[node.name] = node
notify_property_list_changed()

View file

@ -0,0 +1 @@
uid://c1yco1xiqppw

View file

@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=3 uid="uid://cof2sm0drv2i"]
[ext_resource type="Script" uid="uid://c1yco1xiqppw" path="res://autoloads/global_sounds.gd" id="1_22s5s"]
[ext_resource type="AudioStream" uid="uid://sci5aqar0oyx" path="res://assets/audio/bgs/amb_sog.wav" id="2_3njyb"]
[ext_resource type="AudioStream" uid="uid://flc817bekeh6" path="res://assets/audio/sfx/level_win.ogg" id="3_pqonv"]
[node name="GlobalSounds" type="Node" node_paths=PackedStringArray("sounds")]
script = ExtResource("1_22s5s")
sounds = {
&"SoggyAmbience": NodePath("SoggyAmbience"),
&"WinSound": NodePath("WinSound")
}
[node name="SoggyAmbience" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_3njyb")
volume_db = -10.0
autoplay = true
bus = &"Background Sound"
[node name="WinSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("3_pqonv")
volume_db = -6.558
bus = &"Sound Effects"

View file

@ -28,7 +28,6 @@ enum ScaleMode {
ProjectSettings.get_setting("display/window/size/viewport_height")
)
@onready var win_sound = $WinSound
## The currently active scene.
##

View file

@ -1,18 +1,13 @@
extends Node2D
signal door_entered()
@export var next_map: PackedScene
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_area_2d_body_entered(body: Node2D) -> void:
func _on_player_detector_body_entered(body: Node2D) -> void:
if body is Player:
door_entered.emit()
SceneManager.current_scene = next_map.instantiate()
SceneManager.win_sound.play()

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://bhnse651bcybm"]
[gd_scene load_steps=5 format=3 uid="uid://bhnse651bcybm"]
[ext_resource type="Texture2D" uid="uid://bwq21el575t1g" path="res://assets/textures/door/door.png" id="1_4beu0"]
[ext_resource type="Script" uid="uid://b3ynfi0yyc7t5" path="res://objects/end_door/end_door.gd" id="1_ph88k"]
[ext_resource type="Script" uid="uid://cg3hwyafaokvs" path="res://scripts/global_sound_player/global_sound_player.gd" id="3_8mj78"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_qkffx"]
size = Vector2(16, 16)
@ -12,11 +13,18 @@ script = ExtResource("1_ph88k")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_4beu0")
[node name="Area2D" type="Area2D" parent="."]
[node name="PlayerDetector" type="Area2D" parent="."]
collision_mask = 16
monitorable = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerDetector"]
shape = SubResource("RectangleShape2D_qkffx")
debug_color = Color(0, 1, 0.701961, 0.419608)
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
[node name="GlobalSoundPlayer" type="Node" parent="."]
script = ExtResource("3_8mj78")
sound = &"WinSound"
metadata/_custom_type_script = "uid://cg3hwyafaokvs"
[connection signal="door_entered" from="." to="GlobalSoundPlayer" method="play"]
[connection signal="body_entered" from="PlayerDetector" to="." method="_on_player_detector_body_entered"]

View file

@ -19,6 +19,7 @@ config/icon="res://icon.svg"
SceneManager="*res://autoloads/scene_manager.tscn"
Levels="*res://autoloads/levels.tscn"
GlobalSounds="*res://autoloads/global_sounds.tscn"
[display]
@ -27,7 +28,7 @@ window/size/viewport_height=216
[editor_plugins]
enabled=PackedStringArray("res://addons/godot_state_charts/plugin.cfg")
enabled=PackedStringArray("res://addons/capri_tools/plugin.cfg", "res://addons/godot_state_charts/plugin.cfg")
[file_customization]

View file

@ -0,0 +1,11 @@
@tool
@icon("global_sound_player.svg")
class_name GlobalSoundPlayer
extends Node
@export_custom(0, "global_sound") var sound: StringName
func play() -> void:
GlobalSounds.play_sound(sound)

View file

@ -0,0 +1 @@
uid://cg3hwyafaokvs

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xml:space="preserve"
width="16"
height="16"
version="1.0"
viewBox="0 0 2.4 2.4"
id="svg2"
sodipodi:docname="global_sound_player.svg"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><defs
id="defs2" /><sodipodi:namedview
id="namedview2"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#505050"
inkscape:zoom="15.216732"
inkscape:cx="8.8718131"
inkscape:cy="5.0602193"
inkscape:window-width="1362"
inkscape:window-height="768"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg2" /><g
id="g2"
transform="matrix(0.80605275,0,0,0.8060853,0.50659596,0.52854067)"><path
fill="#e0e0e0"
d="M 1.252,0.15 A 0.1,0.1 0 0 0 1.17,0.18 L 0.6,0.75 H 0.318 C 0.225,0.75 0.15,0.817 0.15,0.9 v 0.6 c 0,0.083 0.075,0.15 0.168,0.15 H 0.6 L 1.17,2.22 C 1.236,2.287 1.35,2.24 1.35,2.146 V 0.256 A 0.106,0.106 0 0 0 1.252,0.15"
paint-order="markers stroke fill"
id="path1" /><path
fill="none"
stroke="#e0e0e0"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="0.165"
d="m 1.575,0.675 c 0.45,0.525 0,1.05 0,1.05 m 0.3,-1.35 c 0.675,0.825 0,1.65 0,1.65"
paint-order="markers stroke fill"
id="path2" /></g><path
fill="#e0e0e0"
d="M 0.72037825,0.2668907 A 0.15624453,0.15624453 0 0 1 0.94219887,0.48699299 L 0.7543543,0.67483756 A 0.31242343,0.31242343 0 1 0 0.53331471,0.45379798 Z M 0.31125971,0.78738817 A 0.07810586,0.07810586 0 0 0 0.4217014,0.89782983 L 0.89033658,0.42919465 A 0.07810586,0.07810586 0 0 0 0.77989482,0.31875299 Z M 0.47903114,0.95000455 A 0.15624457,0.15624457 0 0 1 0.25721047,0.72990217 L 0.44505509,0.5420576 a 0.31242343,0.31242343 0 1 0 0.22103958,0.22088342 z"
id="path1-0"
style="stroke-width:0.0781059" /></svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d228m7ctf8oxw"
path="res://.godot/imported/global_sound_player.svg-1b6f31c64d0990ab1d53b6cd3019a357.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://scripts/global_sound_player/global_sound_player.svg"
dest_files=["res://.godot/imported/global_sound_player.svg-1b6f31c64d0990ab1d53b6cd3019a357.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false