Compare commits

...
22 changed files with 701 additions and 56 deletions
+9 -1
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3]
[gd_scene load_steps=19 format=3]
[ext_resource type="Script" path="res://scripts/game/game.gd" id="1_game"]
[ext_resource type="Script" path="res://scripts/presentation/map_renderer.gd" id="2_map"]
@@ -8,6 +8,8 @@
[ext_resource type="Script" path="res://scripts/infrastructure/audio_library.gd" id="6_audio"]
[ext_resource type="Script" path="res://scripts/presentation/event_presenter.gd" id="7_presenter"]
[ext_resource type="PackedScene" path="res://scenes/overlays/CombatFeedback.tscn" id="8_feedback"]
[ext_resource type="Script" path="res://scripts/presentation/door_chest_feedback.gd" id="31_door_chest_feedback"]
[ext_resource type="Script" path="res://scripts/presentation/loot_feedback.gd" id="32_loot_feedback"]
[ext_resource type="PackedScene" path="res://scenes/overlays/TargetingOverlay.tscn" id="9_targeting"]
[ext_resource type="PackedScene" path="res://scenes/overlays/SpellTargetingOverlay.tscn" id="10_spell_targeting"]
[ext_resource type="PackedScene" path="res://scenes/ui/LootPanel.tscn" id="11_loot"]
@@ -70,6 +72,12 @@ script = ExtResource("7_presenter")
[node name="CombatFeedback" parent="EventPresenter" instance=ExtResource("8_feedback")]
[node name="DoorChestFeedback" type="Node2D" parent="EventPresenter"]
script = ExtResource("31_door_chest_feedback")
[node name="LootFeedback" type="Node" parent="EventPresenter"]
script = ExtResource("32_loot_feedback")
[node name="World" type="Node2D" parent="."]
position = Vector2(32, 48)
@@ -0,0 +1,54 @@
class_name AudioImportManifest
extends Resource
## A deliberately small, Godot-native audio catalog.
##
## AudioLibrary only consumes AudioStream instances registered here. It never
## searches a user directory or asks an arbitrary file path to be decoded.
## A setup tool may construct this resource from assets already imported by
## Godot, then save it at USER_MANIFEST_PATH for the game to load.
const AMBIENCE_CONTEXTS := [&"exploration", &"combat", &"danger"]
const SFX_EVENTS := [&"attack_given", &"attack_received", &"menu_select", &"menu_cancel", &"item_use", &"death"]
const USER_AUDIO_DIRECTORY := "user://audio"
const USER_MANIFEST_PATH := "user://audio/audio_import_manifest.tres"
var ambience_streams: Dictionary = {}
var sfx_streams: Dictionary = {}
func register_ambience(context: StringName, stream: AudioStream) -> bool:
if not context in AMBIENCE_CONTEXTS or stream == null:
return false
ambience_streams[context] = stream
return true
func register_sfx(event: StringName, stream: AudioStream) -> bool:
if not event in SFX_EVENTS or stream == null:
return false
sfx_streams[event] = stream
return true
func ambience_for(context: StringName) -> AudioStream:
return ambience_streams.get(context) as AudioStream
func sfx_for(event: StringName) -> AudioStream:
return sfx_streams.get(event) as AudioStream
static func ensure_user_audio_directory() -> Error:
return DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(USER_AUDIO_DIRECTORY))
static func save_user_manifest(manifest: AudioImportManifest) -> Error:
if manifest == null:
return ERR_INVALID_PARAMETER
var directory_result := ensure_user_audio_directory()
if directory_result != OK:
return directory_result
return ResourceSaver.save(manifest, USER_MANIFEST_PATH)
static func load_user_manifest() -> AudioImportManifest:
if not FileAccess.file_exists(USER_MANIFEST_PATH):
return AudioImportManifest.new()
var resource := ResourceLoader.load(USER_MANIFEST_PATH, "AudioImportManifest", ResourceLoader.CACHE_MODE_IGNORE)
if resource is AudioImportManifest:
return resource as AudioImportManifest
return AudioImportManifest.new()
@@ -0,0 +1 @@
uid://bpu2ji542yhob
+105 -33
View File
@@ -1,30 +1,58 @@
class_name AudioLibrary
extends Node
const AudioImportManifestType = preload("res://scripts/infrastructure/audio_import_manifest.gd")
const AMBIENCE_CONTEXTS := ["exploration", "combat", "danger"]
const SFX_EVENTS := ["attack_given", "attack_received", "menu_select", "menu_cancel", "item_use", "death"]
const ADMITTED_EXTENSIONS := ["mp3", "ogg", "oga", "wav", "flac", "m4a", "opus"]
const DEFAULT_AUDIO_HOME := ".local/share/dcwascii"
const AMBIENCE_BUS := &"Ambience"
const SFX_BUS := &"SFX"
const DEFAULT_VOLUME_PERCENT := 100
const VOLUME_STEP_PERCENT := 10
var current_ambience_context := ""
var _audio_home_override := ""
var _manifest: AudioImportManifest
var _ambience_player: AudioStreamPlayer
var _sfx_player: AudioStreamPlayer
var _ambience_volume_percent := DEFAULT_VOLUME_PERCENT
var _sfx_volume_percent := DEFAULT_VOLUME_PERCENT
var _last_ambience_path := ""
var _last_sfx_path := ""
func _init(audio_home_override: String = "") -> void:
_audio_home_override = audio_home_override
func _init(manifest_or_legacy_root: Variant = null) -> void:
# The former API accepted an external directory override. Intentionally ignore
# it for compatibility: external paths are not a safe playback source.
if manifest_or_legacy_root is AudioImportManifest:
_manifest = manifest_or_legacy_root as AudioImportManifest
else:
_manifest = AudioImportManifestType.load_user_manifest()
func _ready() -> void:
_ensure_players()
func set_manifest(manifest: AudioImportManifest) -> void:
_manifest = manifest if manifest != null else AudioImportManifestType.new()
if current_ambience_context.is_empty():
_last_ambience_path = ""
else:
_set_ambience_stream(_manifest.ambience_for(StringName(current_ambience_context)))
func set_ambience_context(context: String) -> void:
if not context in AMBIENCE_CONTEXTS:
return
current_ambience_context = context
_last_ambience_path = _find_first_audio_file("audio", current_ambience_context)
_last_ambience_path = ""
_set_ambience_stream(_manifest.ambience_for(StringName(context)))
func play_sfx(event: String) -> void:
_last_sfx_path = ""
if not event in SFX_EVENTS:
return
_last_sfx_path = _find_first_audio_file("sfx", event)
_ensure_players()
var stream := _manifest.sfx_for(StringName(event))
_sfx_player.stream = stream
if stream != null:
_sfx_player.play()
func get_last_ambience_path() -> String:
return _last_ambience_path
@@ -32,34 +60,78 @@ func get_last_ambience_path() -> String:
func get_last_sfx_path() -> String:
return _last_sfx_path
func get_ambience_stream() -> AudioStream:
_ensure_players()
return _ambience_player.stream
func get_sfx_stream() -> AudioStream:
_ensure_players()
return _sfx_player.stream
func get_ambience_player() -> AudioStreamPlayer:
_ensure_players()
return _ambience_player
func get_sfx_player() -> AudioStreamPlayer:
_ensure_players()
return _sfx_player
func has_playable_ambience() -> bool:
return false
return get_ambience_stream() != null
func has_playable_sfx() -> bool:
return false
return get_sfx_stream() != null
func _audio_roots() -> Array[String]:
if not _audio_home_override.is_empty():
return [_audio_home_override]
var roots: Array[String] = []
var environment_root := OS.get_environment("DCW_AUDIO_HOME")
if not environment_root.is_empty():
roots.append(environment_root)
roots.append(OS.get_environment("HOME").path_join(DEFAULT_AUDIO_HOME))
return roots
func set_ambience_volume_percent(percent: int) -> void:
_ambience_volume_percent = clampi(percent, 0, 100)
_apply_volume(AMBIENCE_BUS, _ambience_volume_percent)
func _find_first_audio_file(kind: String, name: String) -> String:
for root in _audio_roots():
var directory_path := root.path_join(kind).path_join(name)
var directory := DirAccess.open(directory_path)
if directory == null:
continue
directory.list_dir_begin()
var entry := directory.get_next()
while not entry.is_empty():
if not directory.current_is_dir() and entry.get_extension().to_lower() in ADMITTED_EXTENSIONS:
directory.list_dir_end()
return directory_path.path_join(entry)
entry = directory.get_next()
directory.list_dir_end()
return ""
func set_sfx_volume_percent(percent: int) -> void:
_sfx_volume_percent = clampi(percent, 0, 100)
_apply_volume(SFX_BUS, _sfx_volume_percent)
func get_ambience_volume_percent() -> int:
return _ambience_volume_percent
func get_sfx_volume_percent() -> int:
return _sfx_volume_percent
func _set_ambience_stream(stream: AudioStream) -> void:
_ensure_players()
_ambience_player.stream = stream
if stream != null:
_ambience_player.play()
func _ensure_players() -> void:
if _ambience_player == null:
_ambience_player = AudioStreamPlayer.new()
_ambience_player.name = "AmbiencePlayer"
_ambience_player.bus = AMBIENCE_BUS
_ambience_player.finished.connect(_restart_ambience)
add_child(_ambience_player)
if _sfx_player == null:
_sfx_player = AudioStreamPlayer.new()
_sfx_player.name = "SfxPlayer"
_sfx_player.bus = SFX_BUS
add_child(_sfx_player)
_apply_volume(AMBIENCE_BUS, _ambience_volume_percent)
_apply_volume(SFX_BUS, _sfx_volume_percent)
func _restart_ambience() -> void:
if _ambience_player.stream != null:
_ambience_player.play()
func _apply_volume(bus_name: StringName, percent: int) -> void:
var bus_index := AudioServer.get_bus_index(bus_name)
if bus_index == -1:
bus_index = _ensure_bus(bus_name)
AudioServer.set_bus_volume_db(bus_index, linear_to_db(float(percent) / 100.0) if percent > 0 else -80.0)
func _ensure_bus(bus_name: StringName) -> int:
var existing_index := AudioServer.get_bus_index(bus_name)
if existing_index != -1:
return existing_index
AudioServer.add_bus()
var bus_index := AudioServer.bus_count - 1
AudioServer.set_bus_name(bus_index, bus_name)
return bus_index
@@ -0,0 +1,43 @@
class_name DoorChestFeedback
extends Node2D
const EFFECT_DURATION_MS := 160
const EFFECT_DURATION := float(EFFECT_DURATION_MS) / 1000.0
const DOOR_COLOR := Color(0.48, 0.8, 1.0, 1.0)
const CHEST_COLOR := Color(1.0, 0.8, 0.3, 1.0)
var _test_mode := false
var _last_feedback_state := {}
func _enter_tree() -> void:
_test_mode = "--test-mode" in OS.get_cmdline_user_args() and not Engine.is_editor_hint()
func set_test_mode_for_testing(enabled: bool) -> void:
_test_mode = enabled
func get_last_feedback_state() -> Dictionary:
return _last_feedback_state.duplicate()
func begin(event: GameEvent, presentation_kind: StringName) -> void:
var color := DOOR_COLOR if presentation_kind == &"door" else CHEST_COLOR
_last_feedback_state = {
"kind": presentation_kind,
"duration_ms": EFFECT_DURATION_MS,
"color": color,
}
if _test_mode:
return
var marker := Polygon2D.new()
marker.polygon = PackedVector2Array([Vector2(0, -10), Vector2(10, 0), Vector2(0, 10), Vector2(-10, 0)])
marker.color = color
marker.position = Vector2(event.cell) * Vector2(32, 32) + Vector2(16, 16)
if get_viewport() != null:
marker.position += get_viewport().get_visible_rect().size * 0.5
marker.z_index = 11
add_child(marker)
var tween := create_tween()
tween.set_parallel(true)
tween.tween_property(marker, "scale", Vector2(1.8, 1.8), EFFECT_DURATION)
tween.tween_property(marker, "modulate:a", 0.0, EFFECT_DURATION)
tween.chain().tween_callback(marker.queue_free)
await tween.finished
@@ -0,0 +1 @@
uid://dd8w2d6h57ult
+75 -1
View File
@@ -2,19 +2,37 @@ class_name EventPresenter
extends Node
signal event_presented(event: GameEvent)
signal presentation_started(presentation: PresentationEvent)
const CombatFeedbackType = preload("res://scripts/presentation/combat_feedback.gd")
const DoorChestFeedbackType = preload("res://scripts/presentation/door_chest_feedback.gd")
const LootFeedbackType = preload("res://scripts/presentation/loot_feedback.gd")
const PresentationEventType = preload("res://scripts/presentation/presentation_event.gd")
const COMBAT_COLOR := Color(1.0, 0.45, 0.45, 1.0)
const SPELL_COLOR := Color(0.72, 0.58, 1.0, 1.0)
const DEATH_COLOR := Color(1.0, 0.38, 0.34, 1.0)
var _queue: Array[GameEvent] = []
var _presenting := false
var _actor_lookup: Callable
@onready var _combat_feedback: CombatFeedback = get_node_or_null("CombatFeedback") as CombatFeedback
@onready var _door_chest_feedback: DoorChestFeedback = get_node_or_null("DoorChestFeedback") as DoorChestFeedback
@onready var _loot_feedback: LootFeedback = get_node_or_null("LootFeedback") as LootFeedback
func _ready() -> void:
if _combat_feedback == null:
_combat_feedback = CombatFeedbackType.new()
_combat_feedback.name = "CombatFeedback"
add_child(_combat_feedback)
if _door_chest_feedback == null:
_door_chest_feedback = DoorChestFeedbackType.new()
_door_chest_feedback.name = "DoorChestFeedback"
add_child(_door_chest_feedback)
if _loot_feedback == null:
_loot_feedback = LootFeedbackType.new()
_loot_feedback.name = "LootFeedback"
add_child(_loot_feedback)
func set_actor_lookup(actor_lookup: Callable) -> void:
_actor_lookup = actor_lookup
@@ -29,12 +47,38 @@ func pending_count() -> int:
func is_test_mode() -> bool:
return _combat_feedback != null and _combat_feedback.is_test_mode()
## Maps a semantic domain event to exactly one presentation event, or null when
## no visual feedback is appropriate. The source event stays immutable.
func map_event(event: GameEvent) -> PresentationEvent:
match event.kind:
&"melee", &"enemy_melee", &"damage_dealt", &"spell_damage_dealt", &"attack_started", &"attack_hit":
return PresentationEventType.new(event, &"combat", event.message, COMBAT_COLOR)
&"door_opened":
return PresentationEventType.new(event, &"door", event.message, DoorChestFeedback.DOOR_COLOR)
&"chest_opened":
return PresentationEventType.new(event, &"chest", event.message, DoorChestFeedback.CHEST_COLOR)
&"loot_dropped", &"loot_taken", &"item_picked_up":
return PresentationEventType.new(event, &"loot", event.message, LootFeedback.LOOT_COLOR)
&"trap_triggered", &"trap_discovered", &"trap_disarmed", &"trap_disarm_failed", &"trap_status_applied":
return PresentationEventType.new(event, &"trap", event.message, LootFeedback.TRAP_COLOR)
&"projectile_fired", &"spell_cast_started", &"spell_effect_applied":
return PresentationEventType.new(event, &"spell", event.message, SPELL_COLOR)
&"quest_started", &"quest_updated", &"quest_completed", &"quest_abandoned", &"quest_board_read":
return PresentationEventType.new(event, &"quest", event.message, LootFeedback.QUEST_COLOR)
&"enemy_defeated", &"actor_died", &"companion_died", &"run_ended", &"permadeath_run_retired":
return PresentationEventType.new(event, &"death", event.message, DEATH_COLOR)
_:
return null
func present_next() -> void:
if _presenting or _queue.is_empty():
return
_presenting = true
var event: GameEvent = _queue.pop_front()
if is_test_mode():
var test_presentation := map_event(event)
if test_presentation != null:
presentation_started.emit(test_presentation)
event_presented.emit(event)
_presenting = false
present_next()
@@ -42,7 +86,37 @@ func present_next() -> void:
_begin_feedback.call_deferred(event)
func _begin_feedback(event: GameEvent) -> void:
await _combat_feedback.begin(event, _actor_lookup)
var presentation := map_event(event)
if presentation != null:
presentation_started.emit(presentation)
await _present(presentation)
event_presented.emit(event)
_presenting = false
present_next()
func _present(presentation: PresentationEvent) -> void:
match presentation.kind:
&"combat", &"death":
await _combat_feedback.begin(presentation.source_event, _actor_lookup)
&"spell":
await _present_spell(presentation.source_event)
&"door", &"chest":
await _door_chest_feedback.begin(presentation.source_event, presentation.kind)
&"loot", &"trap", &"quest":
await _loot_feedback.begin(presentation.source_event, presentation.kind)
func _present_spell(event: GameEvent) -> void:
# A cast has no projectile until a target has been confirmed. This gives each
# spell event a brief, non-blocking cast flash instead of silently doing nothing.
if event.kind == &"spell_cast_started" or event.target_id.is_empty():
await get_tree().create_timer(0.12).timeout
return
await _combat_feedback.begin(event, _actor_lookup)
func get_feedback_metrics() -> Dictionary:
return {
"combat": _combat_feedback != null,
"door_chest": _door_chest_feedback != null,
"loot": _loot_feedback != null,
"mapped_kinds": 8,
}
+55
View File
@@ -0,0 +1,55 @@
class_name LootFeedback
extends Node
const EFFECT_DURATION_MS := 160
const EFFECT_DURATION := float(EFFECT_DURATION_MS) / 1000.0
const LOOT_COLOR := Color(1.0, 0.82, 0.32, 1.0)
const TRAP_COLOR := Color(1.0, 0.38, 0.34, 1.0)
const QUEST_COLOR := Color(0.55, 1.0, 0.67, 1.0)
var _test_mode := false
var _last_feedback_state := {}
func _enter_tree() -> void:
_test_mode = "--test-mode" in OS.get_cmdline_user_args() and not Engine.is_editor_hint()
func set_test_mode_for_testing(enabled: bool) -> void:
_test_mode = enabled
func get_last_feedback_state() -> Dictionary:
return _last_feedback_state.duplicate()
func begin(event: GameEvent, presentation_kind: StringName) -> void:
var color := _color_for(presentation_kind)
_last_feedback_state = {
"kind": presentation_kind,
"duration_ms": EFFECT_DURATION_MS,
"color": color,
}
if _test_mode:
return
var label := Label.new()
label.text = _label_for(event, presentation_kind)
label.modulate = color
label.position = Vector2(390, 80)
label.z_index = 20
add_child(label)
var tween := create_tween()
tween.set_parallel(true)
tween.tween_property(label, "position:y", label.position.y - 14.0, EFFECT_DURATION)
tween.tween_property(label, "modulate:a", 0.0, EFFECT_DURATION)
tween.chain().tween_callback(label.queue_free)
await tween.finished
func _color_for(presentation_kind: StringName) -> Color:
match presentation_kind:
&"trap": return TRAP_COLOR
&"quest": return QUEST_COLOR
_: return LOOT_COLOR
func _label_for(event: GameEvent, presentation_kind: StringName) -> String:
match presentation_kind:
&"loot": return "✦ LOOT SECURED"
&"trap": return "! TRAP"
&"quest": return "✦ QUEST UPDATED"
_: return event.message
@@ -0,0 +1 @@
uid://dolen1gstmp82
+15 -2
View File
@@ -10,6 +10,7 @@ var ui_scale := 1.0
var _selected_index := 0
var _waiting_for_rebind := false
var _bindings: Dictionary[StringName, Key] = {}
var _audio_library: AudioLibrary
var waiting_for_rebind: bool:
get:
@@ -24,6 +25,7 @@ func _ready() -> void:
func present() -> void:
visible = true
_waiting_for_rebind = false
_audio_library = get_node_or_null("../../AudioLibrary") as AudioLibrary
refresh()
func dismiss() -> void:
@@ -44,7 +46,15 @@ func handle_key(event: InputEventKey) -> bool:
_waiting_for_rebind = false
refresh()
return true
if event.keycode == KEY_UP:
if event.keycode == KEY_A and _audio_library != null:
_audio_library.set_ambience_volume_percent(_audio_library.get_ambience_volume_percent() - AudioLibrary.VOLUME_STEP_PERCENT)
elif event.keycode == KEY_Z and _audio_library != null:
_audio_library.set_ambience_volume_percent(_audio_library.get_ambience_volume_percent() + AudioLibrary.VOLUME_STEP_PERCENT)
elif event.keycode == KEY_S and _audio_library != null:
_audio_library.set_sfx_volume_percent(_audio_library.get_sfx_volume_percent() - AudioLibrary.VOLUME_STEP_PERCENT)
elif event.keycode == KEY_X and _audio_library != null:
_audio_library.set_sfx_volume_percent(_audio_library.get_sfx_volume_percent() + AudioLibrary.VOLUME_STEP_PERCENT)
elif event.keycode == KEY_UP:
_selected_index = posmod(_selected_index - 1, 3)
elif event.keycode == KEY_DOWN:
_selected_index = posmod(_selected_index + 1, 3)
@@ -67,7 +77,9 @@ func refresh() -> void:
return
var cursor := func(index: int) -> String: return "> " if index == _selected_index else " "
var contrast := "Renforcé" if _selected_index == 1 else "Standard"
body.text = "%sÉchelle UI : %d%%\n%sMarqueurs color-blind : %s\n%sRemapper Inventaire : %s\n\nFlèches — ajuster Entrée — sélectionner Échap / O — fermer" % [cursor.call(0), int(ui_scale * 100.0), cursor.call(1), contrast, cursor.call(2), OS.get_keycode_string(binding_for(&"inventory"))]
var ambience_volume := _audio_library.get_ambience_volume_percent() if _audio_library != null else 100
var sfx_volume := _audio_library.get_sfx_volume_percent() if _audio_library != null else 100
body.text = "%sÉchelle UI : %d%%\n%sMarqueurs color-blind : %s\n%sRemapper Inventaire : %s\n\nAmbiance : %d%% Effets sonores : %d%%\nA / Z — volume ambiance S / X — volume effets\nFlèches — ajuster Entrée — sélectionner Échap / O — fermer" % [cursor.call(0), int(ui_scale * 100.0), cursor.call(1), contrast, cursor.call(2), OS.get_keycode_string(binding_for(&"inventory")), ambience_volume, sfx_volume]
func _adjust_selected(direction: int) -> void:
if _selected_index == 0:
@@ -75,6 +87,7 @@ func _adjust_selected(direction: int) -> void:
ui_scale = SCALE_STEPS[clampi(index + direction, 0, SCALE_STEPS.size() - 1)]
_apply_scale()
func _apply_scale() -> void:
var hud := get_parent() as CanvasLayer
if hud == null:
@@ -0,0 +1,62 @@
class_name PresentationEvent
extends RefCounted
## A display-only, immutable translation of one authoritative GameEvent.
## Snapshot data belongs to this class, not an instance, so direct writes cannot
## create mutable instance state. Getter calls return a fresh source snapshot.
## RefCounted teardown cannot safely call script methods, so the static store is
## intentionally process-lifetime; entries contain only frozen presentation data.
const FORMER_BACKING_PROPERTIES := [
&"_backing_values",
&"_is_initialized",
&"_source_event",
&"_kind",
&"_notification",
&"_accent",
]
static var _snapshots: Dictionary[int, Dictionary] = {}
var source_event: GameEvent:
get:
return _copy_event(_snapshot()[&"source_event"] as GameEvent)
var kind: StringName:
get:
return _snapshot()[&"kind"] as StringName
var notification: String:
get:
return _snapshot()[&"notification"] as String
var accent: Color:
get:
return _snapshot()[&"accent"] as Color
func _init(source: GameEvent, presentation_kind: StringName, text: String = "", color: Color = Color.WHITE) -> void:
_snapshots[get_instance_id()] = {
&"source_event": _copy_event(source),
&"kind": presentation_kind,
&"notification": text if not text.is_empty() else source.message,
&"accent": color,
}
## Former fields are intentionally undeclared. _set absorbs legacy direct writes
## without creating per-instance storage or changing the captured snapshot.
func _set(property: StringName, _value: Variant) -> bool:
return property in FORMER_BACKING_PROPERTIES
func _snapshot() -> Dictionary:
return _snapshots.get(get_instance_id(), {}) as Dictionary
static func _copy_event(event: GameEvent) -> GameEvent:
return GameEvent.new(
event.turn,
event.floor,
event.kind,
event.payload,
event.message,
event.actor_id,
event.target_id,
event.cell,
)
@@ -0,0 +1 @@
uid://vgwy34xn5id7
+42
View File
@@ -0,0 +1,42 @@
# Task G3 — Safe Optional Audio Playback and Settings
## Scope
Implemented G3 exclusively in the Godot port worktree. No DCWASCII files were changed.
- Added `AudioImportManifest`, a typed Godot `Resource` catalog for the three supported ambience contexts and six supported SFX events. It provides the optional `user://audio` setup directory and accepts only registered `AudioStream` objects.
- Replaced `AudioLibrary`'s arbitrary external directory scan with manifest-only playback. The library now owns ambient/SFX `AudioStreamPlayer`s, routes them through separately named `Ambience` and `SFX` buses, loops available ambience, and remains silent when no registered stream exists.
- Preserved the old constructor's external-directory argument only as a harmless ignored compatibility value; it is no longer an audio decoding input. No runtime call inspects or loads arbitrary external audio files.
- Added keyboard-accessible volume controls to the existing Options panel: `A`/`Z` lower/raise ambience and `S`/`X` lower/raise SFX in ten-percent steps. Existing three-row arrow-key navigation and inventory rebinding behavior remains unchanged.
- Added manifest/playback unit coverage, external-file fail-closed coverage, safe directory-setup coverage, a real Game/Options E2E for volumes/buses/manifest playback, and updated prior no-audio tests to assert external WAV files stay ignored.
## Strict TDD evidence
1. Added `test_audio_playback.gd` and `test_audio_settings_e2e.gd` before production code.
2. After the normal Godot import prerequisite, both RED invocations failed at parse/collection time because `audio_import_manifest.gd`, `AudioLibrary.AMBIENCE_BUS`, and `AudioLibrary.SFX_BUS` did not exist. This establishes the requested missing-manifest/settings contract was red before implementation.
3. Implemented the manifest, manifest-only player path, audio buses, and option controls. Focused green verification passed:
- Audio unit suites: **6 / 6**, **33** assertions.
- Audio/no-audio/settings E2E suites: **3 / 3**, **25** assertions.
## Root-cause fixes found during verification
The original `AudioLibrary` enumerated files under an external home, retained their raw paths, and deliberately reported them unplayable. This neither implemented playback nor safely bounded decoder input. The fix removes that discovery route rather than adding a secondary guard: the only playback assignment is a typed `AudioStream` retrieved from `AudioImportManifest`; arbitrary user paths are ignored and no longer reported as discovered.
The first full verification also exposed a G2 navigation regression: adding two rows to the arrow-navigated option list changed the established two-Down/Enter sequence that opens inventory rebinding. The root cause was changing an existing navigation contract, not audio itself. The final UI keeps the original three-row navigation and adds audio controls as dedicated displayed keys (`A/Z`, `S/X`); the focused audio-settings and pre-existing full UI navigation E2E tests both pass.
## Final verification
`./scripts/verify.sh` completed successfully with Godot 4.5.0:
- Unit: **185 / 185** tests passed, **1,407** assertions.
- Integration: **11 / 11** tests passed, **59,470** assertions.
- E2E: **57 / 57** tests passed, **571** assertions, including safe no-audio and audio-settings end-to-end paths.
- Visual capture: passed.
- `artifacts/visual-check.png`: `dungeon_non_black_pixels=489308`, `visible_pixels=17524`, `explored_pixels=10438`, `explored_luminance=0.012`, `unknown_pixels=365325`, `unknown_luminance=0.001`.
- `artifacts/visual-check-exit.png`: `dungeon_non_black_pixels=489252`, `visible_pixels=17404`, `explored_pixels=17146`, `explored_luminance=0.012`, `unknown_pixels=439497`, `unknown_luminance=0.001`.
The standard GUT invalid-UID and Godot cleanup/resource warnings were emitted. There were no application parse errors, script errors, test failures, or visual verification failures.
## Git
All G3 sources, generated UIDs, tests, and this root report are committed locally in one commit. No push and no pull request were created.
+50
View File
@@ -0,0 +1,50 @@
extends GutTest
const GameScene = preload("res://scenes/Game.tscn")
const AudioImportManifest = preload("res://scripts/infrastructure/audio_import_manifest.gd")
var game: Game
func before_each() -> void:
game = GameScene.instantiate()
add_child_autofree(game)
await get_tree().process_frame
func test_options_control_audio_buses_and_imported_manifest_playback_without_external_files() -> void:
var audio = game.get_node("AudioLibrary") as AudioLibrary
var manifest := AudioImportManifest.new()
assert_true(manifest.register_ambience(&"combat", _silent_stream()))
assert_true(manifest.register_sfx(&"attack_given", _silent_stream()))
audio.set_manifest(manifest)
await _dispatch_key(KEY_O)
var options_panel := game.get_node("HUD/OptionsPanel") as OptionsPanel
assert_true(options_panel.visible)
assert_string_contains((options_panel.get_node("Body") as RichTextLabel).get_parsed_text(), "Ambiance")
await _dispatch_key(KEY_A)
await _dispatch_key(KEY_S)
assert_eq(audio.get_ambience_volume_percent(), 90)
assert_eq(audio.get_sfx_volume_percent(), 90)
audio.set_ambience_context("combat")
audio.play_sfx("attack_given")
assert_true(audio.has_playable_ambience())
assert_true(audio.has_playable_sfx())
assert_eq(audio.get_ambience_player().bus, AudioLibrary.AMBIENCE_BUS)
assert_eq(audio.get_sfx_player().bus, AudioLibrary.SFX_BUS)
func _dispatch_key(keycode: Key) -> void:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = true
game._unhandled_input(event)
await get_tree().process_frame
func _silent_stream() -> AudioStreamWAV:
var stream := AudioStreamWAV.new()
stream.format = AudioStreamWAV.FORMAT_16_BITS
stream.mix_rate = 44100
stream.stereo = false
stream.data = PackedByteArray([0, 0, 0, 0])
return stream
+1
View File
@@ -0,0 +1 @@
uid://b44wxq45xtuwp
+6 -11
View File
@@ -12,7 +12,7 @@ func before_each() -> void:
DirAccess.make_dir_recursive_absolute(empty_audio_home)
OS.set_environment("DCW_AUDIO_HOME", empty_audio_home)
game = GameScene.instantiate()
# Replace the scene library before ready to isolate both production search roots.
# Replace the scene library before ready to isolate the no-audio fallback.
var scene_audio := game.get_node("AudioLibrary")
var isolated_audio := AudioLibrary.new(empty_audio_home)
isolated_audio.name = "AudioLibrary"
@@ -43,18 +43,14 @@ func test_real_game_resolves_combat_with_empty_audio_home() -> void:
assert_false(audio.has_playable_ambience())
assert_false(audio.has_playable_sfx())
func test_external_nominal_and_invalid_wavs_do_not_affect_combat() -> void:
func test_external_wavs_do_not_affect_combat_or_become_playable() -> void:
var audio = game.get_node("AudioLibrary")
var nominal_path := empty_audio_home.path_join("audio/combat/silence.wav")
var nominal_path := empty_audio_home.path_join("audio/combat/external.wav")
var invalid_path := empty_audio_home.path_join("sfx/attack_given/truncated.wav")
DirAccess.make_dir_recursive_absolute(nominal_path.get_base_dir())
DirAccess.make_dir_recursive_absolute(invalid_path.get_base_dir())
var nominal_file := FileAccess.open(nominal_path, FileAccess.WRITE)
nominal_file.store_buffer(PackedByteArray([
82, 73, 70, 70, 36, 0, 0, 0, 87, 65, 86, 69, 102, 109, 116, 32,
16, 0, 0, 0, 1, 0, 1, 0, 68, 172, 0, 0, 136, 88, 1, 0,
2, 0, 16, 0, 100, 97, 116, 97, 0, 0, 0, 0,
]))
nominal_file.store_string("untrusted external WAV")
nominal_file.close()
var invalid_file := FileAccess.open(invalid_path, FileAccess.WRITE)
invalid_file.store_string("truncated WAV")
@@ -69,10 +65,9 @@ func test_external_nominal_and_invalid_wavs_do_not_affect_combat() -> void:
assert_eq(first_melee[0].kind, &"melee")
assert_eq(lethal_melee[1].kind, &"enemy_defeated")
assert_false(game.get_game_state().enemies.has(&"goblin"))
# Discovery remains diagnostic-only after combat; no external stream is playable.
audio.set_ambience_context("combat")
audio.play_sfx("attack_given")
assert_eq(audio.get_last_ambience_path(), nominal_path)
assert_eq(audio.get_last_sfx_path(), invalid_path)
assert_eq(audio.get_last_ambience_path(), "")
assert_eq(audio.get_last_sfx_path(), "")
assert_false(audio.has_playable_ambience())
assert_false(audio.has_playable_sfx())
@@ -0,0 +1,38 @@
extends GutTest
const GameScene = preload("res://scenes/Game.tscn")
const GameEvent = preload("res://scripts/domain/run/game_event.gd")
func test_real_game_scene_presents_one_ordered_feedback_event_for_each_major_domain_kind() -> void:
var game := GameScene.instantiate() as Game
add_child_autofree(game)
await get_tree().process_frame
var presenter := game.get_node("EventPresenter") as EventPresenter
var observed: Array[StringName] = []
presenter.presentation_started.connect(func(presentation: PresentationEvent) -> void:
observed.append(presentation.kind)
)
presenter.get_node("CombatFeedback").set_test_mode_for_testing(true)
presenter.get_node("DoorChestFeedback").set_test_mode_for_testing(true)
presenter.get_node("LootFeedback").set_test_mode_for_testing(true)
presenter.enqueue([
GameEvent.new(1, 0, &"damage_dealt", {"damage": 3}, "You strike.", &"player", &"goblin"),
GameEvent.new(1, 0, &"door_opened", {}, "Door opened.", &"player"),
GameEvent.new(1, 0, &"chest_opened", {}, "Chest opened.", &"player"),
GameEvent.new(1, 0, &"loot_taken", {}, "Loot taken.", &"player"),
GameEvent.new(1, 0, &"trap_triggered", {"damage": 1}, "Trap triggered.", &"player"),
GameEvent.new(1, 0, &"spell_cast_started", {}, "Spell cast.", &"player", &"goblin"),
GameEvent.new(1, 0, &"quest_started", {}, "Quest started.", &"player"),
GameEvent.new(1, 0, &"actor_died", {}, "Goblin defeated.", &"goblin", &"player"),
])
presenter.present_next()
await _wait_until_presented(observed, 8)
assert_eq(observed, [&"combat", &"door", &"chest", &"loot", &"trap", &"spell", &"quest", &"death"])
assert_eq(presenter.pending_count(), 0)
func _wait_until_presented(observed: Array[StringName], expected_count: int) -> void:
var deadline := Time.get_ticks_msec() + 2500
while observed.size() < expected_count and Time.get_ticks_msec() < deadline:
await get_tree().process_frame
@@ -0,0 +1 @@
uid://ng3wx4vhf7uk
+4 -8
View File
@@ -29,18 +29,14 @@ func test_unknown_requests_are_silent() -> void:
assert_false(library.has_playable_ambience())
assert_false(library.has_playable_sfx())
func test_nominal_and_invalid_wavs_are_discovered_but_never_playable() -> void:
func test_legacy_external_directory_override_is_ignored_and_invalid_wavs_stay_silent() -> void:
var root := ProjectSettings.globalize_path("user://s4-external-audio-library")
var nominal_path := root.path_join("audio/exploration/silence.wav")
var invalid_path := root.path_join("sfx/attack_given/not-a-wave.wav")
DirAccess.make_dir_recursive_absolute(nominal_path.get_base_dir())
DirAccess.make_dir_recursive_absolute(invalid_path.get_base_dir())
var nominal_file := FileAccess.open(nominal_path, FileAccess.WRITE)
nominal_file.store_buffer(PackedByteArray([
82, 73, 70, 70, 36, 0, 0, 0, 87, 65, 86, 69, 102, 109, 116, 32,
16, 0, 0, 0, 1, 0, 1, 0, 68, 172, 0, 0, 136, 88, 1, 0,
2, 0, 16, 0, 100, 97, 116, 97, 0, 0, 0, 0,
]))
nominal_file.store_string("this must not be loaded by the audio library")
nominal_file.close()
var invalid_file := FileAccess.open(invalid_path, FileAccess.WRITE)
invalid_file.store_string("this is not a WAV file")
@@ -51,7 +47,7 @@ func test_nominal_and_invalid_wavs_are_discovered_but_never_playable() -> void:
library.set_ambience_context("exploration")
library.play_sfx("attack_given")
assert_eq(library.get_last_ambience_path(), nominal_path)
assert_eq(library.get_last_sfx_path(), invalid_path)
assert_eq(library.get_last_ambience_path(), "")
assert_eq(library.get_last_sfx_path(), "")
assert_false(library.has_playable_ambience())
assert_false(library.has_playable_sfx())
+60
View File
@@ -0,0 +1,60 @@
extends GutTest
const AudioLibrary = preload("res://scripts/infrastructure/audio_library.gd")
const AudioImportManifest = preload("res://scripts/infrastructure/audio_import_manifest.gd")
func test_imported_manifest_maps_only_known_ambience_and_sfx_to_godot_streams() -> void:
var ambience_stream := _silent_stream()
var sfx_stream := _silent_stream()
var manifest := AudioImportManifest.new()
assert_true(manifest.register_ambience(&"combat", ambience_stream))
assert_true(manifest.register_sfx(&"attack_given", sfx_stream))
assert_false(manifest.register_ambience(&"unknown", ambience_stream))
assert_false(manifest.register_sfx(&"unknown", sfx_stream))
var library := AudioLibrary.new(manifest)
add_child_autofree(library)
library.set_ambience_context("combat")
library.play_sfx("attack_given")
assert_eq(library.get_ambience_stream(), ambience_stream)
assert_eq(library.get_sfx_stream(), sfx_stream)
assert_true(library.has_playable_ambience())
assert_true(library.has_playable_sfx())
assert_eq(library.get_ambience_player().bus, AudioLibrary.AMBIENCE_BUS)
assert_eq(library.get_sfx_player().bus, AudioLibrary.SFX_BUS)
func test_setup_creates_the_private_user_audio_directory_for_manifest_assets() -> void:
assert_eq(AudioImportManifest.ensure_user_audio_directory(), OK)
assert_true(DirAccess.dir_exists_absolute(ProjectSettings.globalize_path(AudioImportManifest.USER_AUDIO_DIRECTORY)))
var manifest := AudioImportManifest.new()
assert_true(manifest.register_sfx(&"menu_select", _silent_stream()))
assert_eq(manifest.sfx_for(&"menu_select").get_class(), "AudioStreamWAV")
assert_eq(manifest.ambience_for(&"combat"), null)
func test_unregistered_external_audio_file_is_never_decoded_or_playable() -> void:
var root := ProjectSettings.globalize_path("user://g3-unregistered-audio-%s" % Time.get_ticks_usec())
var wav_path := root.path_join("audio/combat/external.wav")
DirAccess.make_dir_recursive_absolute(wav_path.get_base_dir())
var file := FileAccess.open(wav_path, FileAccess.WRITE)
file.store_string("this must never be decoded by AudioLibrary")
file.close()
var library := AudioLibrary.new()
add_child_autofree(library)
library.set_ambience_context("combat")
library.play_sfx("attack_given")
assert_eq(library.get_ambience_stream(), null)
assert_eq(library.get_sfx_stream(), null)
assert_false(library.has_playable_ambience())
assert_false(library.has_playable_sfx())
func _silent_stream() -> AudioStreamWAV:
var stream := AudioStreamWAV.new()
stream.format = AudioStreamWAV.FORMAT_16_BITS
stream.mix_rate = 44100
stream.stereo = false
stream.data = PackedByteArray([0, 0, 0, 0])
return stream
+1
View File
@@ -0,0 +1 @@
uid://b7ftt2slt52b0
+76
View File
@@ -54,3 +54,79 @@ func _wait_for_presented_events(observed: Array[GameEvent], expected_count: int)
var deadline := Time.get_ticks_msec() + 1000
while observed.size() < expected_count and Time.get_ticks_msec() < deadline:
await get_tree().process_frame
func test_direct_former_backing_field_writes_are_absorbed_after_mapping() -> void:
var presenter := EventPresenter.new()
add_child_autofree(presenter)
var source := GameEvent.new(7, 2, &"damage_dealt", {"damage": 3}, "Goblin takes 3 damage.", &"player", &"goblin", Vector2i(6, 12))
var mapped: PresentationEvent = presenter.map_event(source)
var replacement := GameEvent.new(99, 9, &"actor_died", {"damage": 99}, "Replacement.")
# Former fields are undeclared. Leading underscores are not private in
# GDScript, so every legacy direct write must be absorbed by _set.
mapped._kind = &"death"
mapped._source_event = replacement
mapped._backing_values = {&"_kind": &"death"}
mapped._is_initialized = false
assert_eq(mapped.kind, &"combat")
assert_eq(mapped.notification, "Goblin takes 3 damage.")
assert_eq(mapped.accent, EventPresenter.COMBAT_COLOR)
assert_eq(mapped.source_event.kind, &"damage_dealt")
assert_eq(mapped.source_event.payload, {"damage": 3})
assert_eq(source.kind, &"damage_dealt")
assert_eq(source.payload, {"damage": 3})
assert_ne(mapped.source_event, replacement)
func test_mapping_captures_an_immutable_source_snapshot() -> void:
var presenter := EventPresenter.new()
add_child_autofree(presenter)
var source := GameEvent.new(7, 2, &"damage_dealt", {"damage": 3, "nested": {"critical": false}}, "Goblin takes 3 damage.", &"player", &"goblin", Vector2i(6, 12))
var mapped: PresentationEvent = presenter.map_event(source)
var exposed_snapshot := mapped.source_event
# The adapter captures source values at mapping time, including nested payload.
source.kind = &"actor_died"
source.payload["damage"] = 7
source.payload["nested"]["critical"] = true
# PresentationEvent only exposes getter-backed values. Assigning to locals or
# to a returned snapshot cannot change the adapter or authoritative event.
var reassigned_kind := mapped.kind
reassigned_kind = &"death"
var reassigned_notification := mapped.notification
reassigned_notification = "rewritten"
var reassigned_accent := mapped.accent
reassigned_accent = Color.BLACK
exposed_snapshot.kind = &"death"
exposed_snapshot.payload["damage"] = 99
exposed_snapshot.payload["nested"]["critical"] = true
assert_eq(mapped.kind, &"combat")
assert_eq(mapped.notification, "Goblin takes 3 damage.")
assert_eq(mapped.accent, EventPresenter.COMBAT_COLOR)
assert_eq(mapped.source_event.kind, &"damage_dealt")
assert_eq(mapped.source_event.payload, {"damage": 3, "nested": {"critical": false}})
assert_eq(source.kind, &"actor_died")
assert_eq(source.payload, {"damage": 7, "nested": {"critical": true}})
assert_ne(mapped.source_event, source)
assert_ne(mapped.source_event, exposed_snapshot)
func test_major_domain_event_kinds_each_map_to_one_named_presentation_event() -> void:
var presenter := EventPresenter.new()
add_child_autofree(presenter)
var expected := {
&"damage_dealt": &"combat",
&"door_opened": &"door",
&"chest_opened": &"chest",
&"loot_taken": &"loot",
&"trap_triggered": &"trap",
&"spell_cast_started": &"spell",
&"quest_started": &"quest",
&"actor_died": &"death",
}
for domain_kind: StringName in expected:
var mapped: PresentationEvent = presenter.map_event(GameEvent.new(1, 0, domain_kind))
assert_not_null(mapped, "%s should have presentation feedback" % domain_kind)
assert_eq(mapped.kind, expected[domain_kind], "%s should map once to its feedback kind" % domain_kind)