diff --git a/.gitattributes b/.gitattributes index 58b703f..b2873f7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,3 +13,4 @@ *.gltf filter=lfs diff=lfs merge=lfs -text *.obj filter=lfs diff=lfs merge=lfs -text *.mtl filter=lfs diff=lfs merge=lfs -text +*.wav filter=lfs diff=lfs merge=lfs -text diff --git a/assets/sound/click.wav b/assets/sound/click.wav new file mode 100644 index 0000000..df21c13 --- /dev/null +++ b/assets/sound/click.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:373cde6b402bd106fea9260b833a429e496caaf500d3b7186bed2fd36b0c6b01 +size 17452 diff --git a/assets/sound/click.wav.import b/assets/sound/click.wav.import new file mode 100644 index 0000000..e15034a --- /dev/null +++ b/assets/sound/click.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://k1xeit7qyqlq" +path="res://.godot/imported/click.wav-e8a30ec71317fecc836e787d9d63b4a3.sample" + +[deps] + +source_file="res://assets/sound/click.wav" +dest_files=["res://.godot/imported/click.wav-e8a30ec71317fecc836e787d9d63b4a3.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/assets/sound/spawn.wav b/assets/sound/spawn.wav new file mode 100644 index 0000000..8f5bb9e --- /dev/null +++ b/assets/sound/spawn.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4dbe8aa4dcfb16741a9439283d0ceeeb83b7153c26f8cab421d381676b8e51b5 +size 38780 diff --git a/assets/sound/spawn.wav.import b/assets/sound/spawn.wav.import new file mode 100644 index 0000000..5ba1847 --- /dev/null +++ b/assets/sound/spawn.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://ducbejs36cuim" +path="res://.godot/imported/spawn.wav-144efb9acab2ae0dd785e23bcaa07433.sample" + +[deps] + +source_file="res://assets/sound/spawn.wav" +dest_files=["res://.godot/imported/spawn.wav-144efb9acab2ae0dd785e23bcaa07433.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_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/content/raycast.gd b/content/raycast.gd index 4551aa1..7cf25d2 100644 --- a/content/raycast.gd +++ b/content/raycast.gd @@ -2,6 +2,7 @@ extends Node3D @onready var _controller := XRHelpers.get_xr_controller(self) @export var ray: RayCast3D +@export var timespan_click = 200.0 # Called when the node enters the scene tree for the first time. func _ready(): @@ -11,6 +12,7 @@ func _ready(): var _last_collided: Object = null var _is_pressed := false var _is_grabbed := false +var _time_pressed := 0.0 var _moved := false var _click_point := Vector3.ZERO @@ -19,18 +21,17 @@ func _physics_process(delta): _handle_move() func _handle_move(): - if _is_pressed == false && _is_grabbed == false: + var time_passed = Time.get_ticks_msec() - _time_pressed + if time_passed <= timespan_click || (_is_pressed == false && _is_grabbed == false): return - var distance = ray.get_collision_point().distance_to(_click_point) + _moved = true - if _moved || distance > 0.02: - if _is_pressed: - _call_fn(_last_collided, "_on_press_move") - _moved = true - if _is_grabbed: - _call_fn(_last_collided, "_on_grab_move") - _moved = true + if _is_pressed: + _call_fn(_last_collided, "_on_press_move") + + if _is_grabbed: + _call_fn(_last_collided, "_on_grab_move") func _handle_enter_leave(): var collider = ray.get_collider() @@ -52,6 +53,7 @@ func _on_button_pressed(button): match button: "trigger_click": _is_pressed = true + _time_pressed = Time.get_ticks_msec() _click_point = ray.get_collision_point() _call_fn(collider, "_on_press_down") "grip_click": diff --git a/content/ui/components/button/button.gd b/content/ui/components/button/button.gd index 8be1f4a..960eef3 100644 --- a/content/ui/components/button/button.gd +++ b/content/ui/components/button/button.gd @@ -21,6 +21,7 @@ var active: bool = false : return active @onready var animation_player: AnimationPlayer = $AnimationPlayer +@onready var click_sound: AudioStreamPlayer = $ClickSound func _ready(): if initial_active: @@ -34,6 +35,7 @@ func _on_click(_event): return active = !active + AudioPlayer.play_effect("click") return { "active": active @@ -46,6 +48,7 @@ func _on_press_down(_event): if toggleable: return + AudioPlayer.play_effect("click") animation_player.play("down") func _on_press_up(_event): diff --git a/content/ui/menu/edit/edit_menu.gd b/content/ui/menu/edit/edit_menu.gd index 2c31730..89adbfe 100644 --- a/content/ui/menu/edit/edit_menu.gd +++ b/content/ui/menu/edit/edit_menu.gd @@ -121,11 +121,13 @@ func _on_entity_click(entity_name): if entity_name == "#back": selected_device = null page = last_device_page + AudioPlayer.play_effect("click") render() return var type = entity_name.split(".")[0] print(type) + AudioPlayer.play_effect("spawn") if type == "switch": var switch = Switch.instantiate() diff --git a/content/ui/menu/room/room_menu.gd b/content/ui/menu/room/room_menu.gd index 57c448e..b97d934 100644 --- a/content/ui/menu/room/room_menu.gd +++ b/content/ui/menu/room/room_menu.gd @@ -39,12 +39,17 @@ func _ready(): ) func generate_mesh(): + var corner_count = wall_corners.get_child_count() + + if corner_count < 3: + return + var st = SurfaceTool.new() var wall_up = Vector3.UP * 3 st.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP) - for i in range(wall_corners.get_child_count()): + for i in range(corner_count): var corner = get_corner(i) print(corner.position, " ", corner.position + wall_up) diff --git a/lib/globals/audio_player.gd b/lib/globals/audio_player.gd new file mode 100644 index 0000000..83cb8a5 --- /dev/null +++ b/lib/globals/audio_player.gd @@ -0,0 +1,15 @@ +extends AudioStreamPlayer + +var click_sound = preload("res://assets/sound/click.wav") +var spawn_sound = preload("res://assets/sound/spawn.wav") + +func _ready(): + volume_db = -18 + +func play_effect(sound): + if sound == "click": + stream = click_sound + elif sound == "spawn": + stream = spawn_sound + + play() diff --git a/project.godot b/project.godot index 79aa4f7..26e7232 100644 --- a/project.godot +++ b/project.godot @@ -20,6 +20,7 @@ config/icon="res://assets/logo.png" XRToolsUserSettings="*res://addons/godot-xr-tools/user_settings/user_settings.gd" Request="*res://lib/globals/request.gd" HomeAdapters="*res://lib/globals/home_adapters.gd" +AudioPlayer="*res://lib/globals/audio_player.gd" [editor_plugins]