Skip to content

Commit

Permalink
Add voice narrator PoC, #83
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Dec 21, 2023
1 parent aab3dfb commit df68c87
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
Binary file added assets/voice/english/unit_lost.ogg
Binary file not shown.
19 changes: 19 additions & 0 deletions assets/voice/english/unit_lost.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://b00ul3tn2orom"
path="res://.godot/imported/unit_lost.ogg-38319176087d516ec9e73412b4e4d6d2.oggvorbisstr"

[deps]

source_file="res://assets/voice/english/unit_lost.ogg"
dest_files=["res://.godot/imported/unit_lost.ogg-38319176087d516ec9e73412b4e4d6d2.oggvorbisstr"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4
10 changes: 10 additions & 0 deletions source/match/MatchConstants.gd
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,13 @@ class Units:
const MOVING_UNIT_RADIUS_MAX_M = 1.0
const EMPTY_SPACE_RADIUS_SURROUNDING_STRUCTURE_M = MOVING_UNIT_RADIUS_MAX_M * 2.5
const STRUCTURE_CONSTRUCTING_SPEED = 0.3 # progress [0.0..1.0] per second


class VoiceNarrator:
enum Events {
UNIT_LOST,
}

const EVENT_TO_ASSET_MAPPING = {
Events.UNIT_LOST: preload("res://assets/voice/english/unit_lost.ogg"),
}
8 changes: 7 additions & 1 deletion source/match/players/human/Human.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://dh8dedilkhuoy"]
[gd_scene load_steps=5 format=3 uid="uid://dh8dedilkhuoy"]

[ext_resource type="Script" path="res://source/match/players/human/Human.gd" id="1_7iu1j"]
[ext_resource type="Script" path="res://source/match/players/human/UnitActionsController.gd" id="1_m624e"]
[ext_resource type="PackedScene" uid="uid://q5w474dvts3f" path="res://source/match/players/human/StructurePlacementHandler.tscn" id="2_bbqrb"]
[ext_resource type="Script" path="res://source/match/players/human/VoiceNarratorController.gd" id="4_ljr74"]

[node name="Human" type="Node3D"]
script = ExtResource("1_7iu1j")
Expand All @@ -12,3 +13,8 @@ color = Color(0.4, 0.694118, 1, 1)

[node name="UnitActionsController" type="Node" parent="."]
script = ExtResource("1_m624e")

[node name="VoiceNarratorController" type="Node" parent="."]
script = ExtResource("4_ljr74")

[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="VoiceNarratorController"]
17 changes: 17 additions & 0 deletions source/match/players/human/VoiceNarratorController.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends Node

@onready var _player = find_child("AudioStreamPlayer")


func _ready():
MatchSignals.unit_died.connect(_on_unit_died)


func _handle_event(event):
_player.stream = Constants.Match.VoiceNarrator.EVENT_TO_ASSET_MAPPING[event]
_player.play()


func _on_unit_died(unit):
if unit.is_in_group("controlled_units"):
_handle_event(Constants.Match.VoiceNarrator.Events.UNIT_LOST)

0 comments on commit df68c87

Please sign in to comment.