Fixed SoundPlayer, implemented handgun shoot sound

remotes/1711660107545182331/update-godot-to-1852afb6b
unfa 2021-09-12 03:03:52 +02:00
parent 66586e1546
commit d1b8b5eb6b
19 changed files with 311 additions and 36 deletions

View File

@ -29,19 +29,20 @@ func _ready():
if debug:
print("SoundClip: ", SoundClip)
# determine the sound group name part
var group = SoundClip.left(SoundClip.rfind('_')).right(SoundClip.rfind('/') + 1)
var group = SoundClip.left(SoundClip.rfind('_') -2).right(SoundClip.rfind('/') + 1)
# determine the sound layer name part
var layer = SoundClip.right(SoundClip.rfind('01') + 1)
layer = layer.right(layer.rfind('_') + 1)
layer = layer.left(layer.rfind('.'))
if layer == "1": # sound without a layer defined will return "1", so let's take that as a "no layers defined in this sound"
layer = ""
else: # if the layers was specified the group will be incorrectly including the variant number, let's fix that
group = group.left(group.rfind('_'))
if debug:
print("group: ", group)
print("layer: ", layer)
if false: # temporarily disabled, needs work
# determine the sound layer name part
var layer = SoundClip.right(SoundClip.rfind('01') + 1)
layer = layer.right(layer.rfind('_') - 1)
layer = layer.left(layer.rfind('.') -2)
if layer == "1": # sound without a layer defined will return "1", so let's take that as a "no layers defined in this sound"
layer = ""
else: # if the layers was specified the group will be incorrectly including the variant number, let's fix that
group = group.left(group.rfind('_'))
if debug:
print("group: ", group)
print("layer: ", layer)
while true:
var file = dir.get_next()
@ -49,14 +50,18 @@ func _ready():
if file == "":
break
elif not file.begins_with(".") and file.begins_with(group) and file.ends_with(".wav"):
if layer.length() == 0: # no layer specified?
files.append(file)
if debug:
print("no layer specified - adding ", file)
elif file.find(layer) > -1: # chek if the file name contains the layer string
files.append(file)
if debug:
print("layer matches - adding ", file)
files.append(file)
# temporarily disabled, not sure what this does
# if layer.length() == 0: # no layer specified?
# files.append(file)
# if debug:
# print("no layer specified - adding ", file)
# elif file.find(layer) > -1: # chek if the file name contains the layer string
# files.append(file)
# if debug:
# print("layer matches - adding ", file)
dir.list_dir_end()
@ -64,7 +69,7 @@ func _ready():
print("files in list: \n", files)
for f in files:
var res_file = SFX_dir + f
var res_file = SFX_dir + '/' + f
var clip = load(res_file)
clips.append(clip)
if debug:
@ -94,10 +99,10 @@ func _ready():
print("voices: ", voices)
if AutoPlay:
play()
await play()
func pick_random():
assert(len(clips) > 0)
assert(len(clips) > 0, "SoundPlayer has no clips to choose from")
return randi() % len(clips)
@rpc(sync, reliable) func play():
@ -141,15 +146,13 @@ func pick_random():
player.play()
ready_to_play = false
await get_tree().create_timer(MinDelay)
ready_to_play = true
$Timer.start(MinDelay)
#$Timer.start(MinDelay)
# TODO implement final randomization algorithm
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Timer_timeout():
ready_to_play = true

View File

@ -11,9 +11,3 @@ unit_size = 6.0
attenuation_filter_cutoff_hz = 20000.0
attenuation_filter_db = 0.0
script = null
[node name="Timer" type="Timer" parent="."]
one_shot = true
script = null
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

View File

@ -0,0 +1 @@
/data/Projects/Games/Liblast/Game/Assets/SFX/Weapons_Handgun_Shot_01_B.wav

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://6yccg4ubjmbe"
path="res://.godot/imported/Weapons_HandgunShot_01.wav-20989e13c56dd99bf4e568e4ae12f4f6.sample"
[deps]
source_file="res://Assets/SFX/Weapons_HandgunShot_01.wav"
dest_files=["res://.godot/imported/Weapons_HandgunShot_01.wav-20989e13c56dd99bf4e568e4ae12f4f6.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1 @@
/data/Projects/Games/Liblast/Game/Assets/SFX/Weapons_Handgun_Shot_02_B.wav

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://h0u4vnv2y77"
path="res://.godot/imported/Weapons_HandgunShot_02.wav-37c5160399b274cf0ea3d0ab45f9539a.sample"
[deps]
source_file="res://Assets/SFX/Weapons_HandgunShot_02.wav"
dest_files=["res://.godot/imported/Weapons_HandgunShot_02.wav-37c5160399b274cf0ea3d0ab45f9539a.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1 @@
/data/Projects/Games/Liblast/Game/Assets/SFX/Weapons_Handgun_Shot_03_B.wav

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://5qeevn6lc5wv"
path="res://.godot/imported/Weapons_HandgunShot_03.wav-80199029f341d6fce04ac557c38714aa.sample"
[deps]
source_file="res://Assets/SFX/Weapons_HandgunShot_03.wav"
dest_files=["res://.godot/imported/Weapons_HandgunShot_03.wav-80199029f341d6fce04ac557c38714aa.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://citsx20hcjj8i"
path="res://.godot/imported/Weapons_Handgun_Shot_01_A.wav-af05584f8bdd05826f633b0bae9266f5.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_01_A.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_01_A.wav-af05584f8bdd05826f633b0bae9266f5.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://cw01fxbftb6m2"
path="res://.godot/imported/Weapons_Handgun_Shot_01_B.wav-26bd3367aa7092533af6a1575f449573.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_01_B.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_01_B.wav-26bd3367aa7092533af6a1575f449573.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://cxiy7p6qd7hyh"
path="res://.godot/imported/Weapons_Handgun_Shot_01_C.wav-e20fc9ab5bc5e45e2f01c53f06d10d28.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_01_C.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_01_C.wav-e20fc9ab5bc5e45e2f01c53f06d10d28.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://31brspxqnm2m"
path="res://.godot/imported/Weapons_Handgun_Shot_02_A.wav-455df0caf86109da1dcb7efe84ac77af.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_02_A.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_02_A.wav-455df0caf86109da1dcb7efe84ac77af.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://dmb6np7rl74ro"
path="res://.godot/imported/Weapons_Handgun_Shot_02_B.wav-9d4b25707ca3287c7aca1b5f7aa60623.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_02_B.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_02_B.wav-9d4b25707ca3287c7aca1b5f7aa60623.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://6vhom2o52hxv"
path="res://.godot/imported/Weapons_Handgun_Shot_02_C.wav-733620efc67379e2baf491923afe37ed.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_02_C.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_02_C.wav-733620efc67379e2baf491923afe37ed.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://rifvwjhspwi"
path="res://.godot/imported/Weapons_Handgun_Shot_03_A.wav-4f512678faf6c02f6a9df0be454eccf6.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_03_A.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_03_A.wav-4f512678faf6c02f6a9df0be454eccf6.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://b4vum2rgre10c"
path="res://.godot/imported/Weapons_Handgun_Shot_03_B.wav-d6b93d69ed7fdde5023b196bda63e604.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_03_B.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_03_B.wav-d6b93d69ed7fdde5023b196bda63e604.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,22 @@
[remap]
importer="wav"
type="AudioStreamSample"
uid="uid://c8mfb788nob6u"
path="res://.godot/imported/Weapons_Handgun_Shot_03_C.wav-92ef54943e8389416a7d5cb044461dda.sample"
[deps]
source_file="res://Assets/SFX/Weapons_Handgun_Shot_03_C.wav"
dest_files=["res://.godot/imported/Weapons_Handgun_Shot_03_C.wav-92ef54943e8389416a7d5cb044461dda.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -29,6 +29,8 @@ var impact_player = preload("res://Assets/Effects/ImpactBlood.tscn")
var ray = space_state.intersect_ray(from, to, [player])
$Handgun/SFX/Shoot.play()
var impact_vfx
if ray: # did we hit anything?
@ -97,4 +99,5 @@ var impact_player = preload("res://Assets/Effects/ImpactBlood.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
pass
# align the sound source with the head to produce balanced stereo
pass #$Handgun/SFX/Shoot.global_transform = camera.global_transform

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://bemrov0tiy08n"]
[gd_scene load_steps=5 format=3 uid="uid://bemrov0tiy08n"]
[ext_resource type="PackedScene" uid="uid://cajs6ugsr1efo" path="res://Assets/Weapons/Handgun/Handgun.gltf" id="1"]
[ext_resource type="Script" path="res://Assets/Weapons/Weapon.gd" id="2"]
[ext_resource type="PackedScene" uid="uid://c5cwnfuw4go1b" path="res://Assets/Audio/SoundPlayer.tscn" id="3_q0xp7"]
[sub_resource type="Animation" id="1"]
resource_name = "Default"
@ -43,4 +44,11 @@ autoplay = "Default"
anims/Default = SubResource( "1" )
blend_times = []
[node name="SFX" type="Node3D" parent="Handgun"]
script = null
[node name="Shoot" parent="Handgun/SFX" instance=ExtResource( "3_q0xp7" )]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0168038, 0.251726, 0.250185)
SoundClip = "res://Assets/SFX/Weapons_HandgunShot_01.wav"
[editable path="Handgun"]