clean up and restructuring

This commit is contained in:
Nitwel 2024-05-22 18:38:28 +02:00
parent 61dee85aa3
commit 37bb550544
44 changed files with 281 additions and 280 deletions

View File

@ -48,8 +48,6 @@ func _ready():
)
func set_state(stateInfo):
print("Setting state: ", stateInfo)
if stateInfo == null:
view.texture = null
mesh.visible = true

View File

@ -9,5 +9,5 @@ func _ready():
if movable:
movable.on_moved.connect(func():
House.body.save_all_entities()
App.house.save_all_entities()
)

View File

@ -26,7 +26,7 @@ func _ready():
remove_child(chart_button)
chart_button.on_button_down.connect(func():
House.body.create_entity(entity_id, global_position, "line_chart")
App.house.create_entity(entity_id, global_position, "line_chart")
remove_child(chart_button)
)

View File

@ -22,8 +22,6 @@ func set_state(stateInfo):
if stateInfo == null:
return
print(stateInfo)
var state = stateInfo["state"]
var attributes = stateInfo["attributes"]
@ -39,7 +37,7 @@ func set_state(stateInfo):
animation.play("clear-night")
"cloudy":
weather_label.text = "Cloudy"
animation.play("cloudy")
animation.play("partly-cloudy-day")
"fog":
weather_label.text = "Fog"
animation.play("fog")

View File

@ -30426,8 +30426,7 @@ transform = Transform3D(0.28, 0, 0, 0, 0.28, 0, 0, 0, 0.28, -0.14, 0.01, 0)
pixel_size = 0.001
render_priority = 15
sprite_frames = SubResource("SpriteFrames_71wxj")
animation = &"sleet"
frame_progress = 0.689981
animation = &"partly-cloudy-day"
[node name="WeatherLabel" type="Label3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.05, 0.02, 0)

View File

@ -2,20 +2,19 @@ extends Node3D
const VoiceAssistant = preload ("res://content/system/assist/assist.tscn")
const environment_passthrough_material = preload ("res://assets/environment_passthrough.tres")
const Menu = preload ("res://content/ui/menu/menu.gd")
const OnboardingScene = preload ("res://content/ui/onboarding/onboarding.tscn")
@onready var environment: WorldEnvironment = $WorldEnvironment
@onready var camera: XRCamera3D = $XROrigin3D/XRCamera3D
@onready var controller_left = $XROrigin3D/XRControllerLeft
@onready var controller_right = $XROrigin3D/XRControllerRight
@onready var camera: XRCamera3D = %XRCamera3D
@onready var controller_left = %XRControllerLeft
@onready var controller_right = %XRControllerRight
@onready var house = $House
@onready var menu = $Menu
@onready var keyboard = $Keyboard
@onready var menu: Menu = $Menu
@onready var xr: XRToolsStartXR = $StartXR
var voice_assistant = null
func _ready():
# In case we're running on the headset, use the passthrough sky
if OS.get_name() == "Android":
# OS.request_permissions()
environment.environment = environment_passthrough_material
@ -25,51 +24,24 @@ func _ready():
create_voice_assistant()
controller_left.button_pressed.connect(func(name):
_emit_action(name, true, false)
)
controller_right.button_pressed.connect(func(name):
_emit_action(name, true, true)
)
controller_left.button_released.connect(func(name):
_emit_action(name, false, false)
)
controller_right.button_released.connect(func(name):
_emit_action(name, false, true)
)
remove_child(keyboard)
EventSystem.on_action_down.connect(func(action):
if action.name == "menu_button":
toggle_menu()
elif action.name == "by_button":
House.body.mini_view.small.value=!House.body.mini_view.small.value
)
EventSystem.on_focus_in.connect(func(event):
if keyboard.is_inside_tree():
return
add_child(keyboard)
keyboard.global_transform=menu.get_node("AnimationContainer/KeyboardPlace").global_transform
)
EventSystem.on_focus_out.connect(func(event):
if !keyboard.is_inside_tree():
return
remove_child(keyboard)
)
xr.xr_started.connect(func():
if HomeApi.has_connected() == false:
HomeApi.start()
)
HomeApi.on_connect.connect(func():
start_setup_flow.call_deferred()
)
func start_setup_flow():
var onboarding = OnboardingScene.instantiate()
add_child(onboarding)
await onboarding.tree_exited
if Store.house.state.rooms.size() == 0:
house.create_room("Room 1")
func create_voice_assistant():
if Store.settings.is_loaded() == false:
await Store.settings.on_loaded
@ -85,47 +57,37 @@ func create_voice_assistant():
voice_assistant.queue_free()
)
func toggle_menu():
menu.show_menu.value = !menu.show_menu.value
func _emit_action(name: String, value, right_controller: bool=true):
var event = EventAction.new()
event.name = name
event.value = value
event.right_controller = right_controller
match typeof(value):
TYPE_BOOL:
EventSystem.emit("action_down" if value else "action_up", event)
TYPE_FLOAT, TYPE_VECTOR2:
EventSystem.emit("action_value", event)
func _process(delta):
if OS.get_name() != "Android":
var camera_basis = camera.get_global_transform().basis
camera_basis.x.y = 0
camera_basis.z.y = 0
camera_basis.y = Vector3(0, 1, 0)
camera_basis.x = camera_basis.x.normalized()
camera_basis.z = camera_basis.z.normalized()
var movement = camera_basis * vector_key_mapping(KEY_D, KEY_A, KEY_S, KEY_W) * delta
camera.position += movement
controller_left.position += movement
controller_right.position += movement
_move_camera_pc(delta)
func _input(event):
# Debugging Features
if event is InputEventKey and Input.is_key_pressed(KEY_F10):
var vp = get_viewport()
vp.debug_draw = (vp.debug_draw + 1) % 5
if event is InputEventKey and Input.is_key_pressed(KEY_M):
toggle_menu()
menu.toggle_open()
func vector_key_mapping(key_positive_x: int, key_negative_x: int, key_positive_y: int, key_negative_y: int):
func _move_camera_pc(delta):
if OS.get_name() == "Android": return
var camera_basis = camera.get_global_transform().basis
camera_basis.x.y = 0
camera_basis.z.y = 0
camera_basis.y = Vector3(0, 1, 0)
camera_basis.x = camera_basis.x.normalized()
camera_basis.z = camera_basis.z.normalized()
var movement = camera_basis * _vector_key_mapping(KEY_D, KEY_A, KEY_S, KEY_W) * delta
camera.position += movement
controller_left.position += movement
controller_right.position += movement
func _vector_key_mapping(key_positive_x: int, key_negative_x: int, key_positive_y: int, key_negative_y: int):
var x = 0
var y = 0
if Input.is_physical_key_pressed(key_positive_y):

View File

@ -8,9 +8,9 @@
[ext_resource type="PackedScene" uid="uid://ctltchlf2j2r4" path="res://addons/xr-simulator/XRSimulator.tscn" id="5_3qc8g"]
[ext_resource type="PackedScene" uid="uid://biu66ihmvmku3" path="res://content/system/controller_right/controller_right.tscn" id="7_0b3tc"]
[ext_resource type="PackedScene" uid="uid://c3kdssrmv84kv" path="res://content/ui/menu/menu.tscn" id="8_du83w"]
[ext_resource type="PackedScene" uid="uid://lrehk38exd5n" path="res://content/system/keyboard/keyboard.tscn" id="9_e5n3p"]
[ext_resource type="PackedScene" uid="uid://cbemihbxkd4ll" path="res://content/system/house/house.tscn" id="9_np6mw"]
[ext_resource type="Script" path="res://lib/utils/screenshot.gd" id="12_e13ym"]
[ext_resource type="PackedScene" uid="uid://ds60i5n211hi3" path="res://content/system/miniature/miniature.tscn" id="12_lmxhs"]
[ext_resource type="PackedScene" uid="uid://bhyddd1f0ry1x" path="res://content/ui/onboarding/onboarding.tscn" id="12_uq2nj"]
[node name="Main" type="Node3D"]
@ -30,8 +30,10 @@ enable_passthrough = true
[node name="XROrigin3D" type="XROrigin3D" parent="."]
[node name="XRCamera3D" parent="XROrigin3D" instance=ExtResource("3_rj4ac")]
unique_name_in_owner = true
[node name="XRControllerLeft" parent="XROrigin3D" instance=ExtResource("2_2lraw")]
unique_name_in_owner = true
transform = Transform3D(0.999999, -1.39633e-11, 0, 9.48075e-12, 1, 0, 0, 0, 1, -0.355145, 0.550439, -0.477945)
[node name="IndexTip" parent="XROrigin3D/XRControllerLeft" index="4"]
@ -43,30 +45,25 @@ transform = Transform3D(0.967043, 0.24582, -0.0663439, -0.0663439, 0.494837, 0.8
[node name="MiddleTip" parent="XROrigin3D/XRControllerLeft" index="6"]
transform = Transform3D(0.98042, 0.196912, 0.00149799, 0.001498, -0.015065, 0.999885, 0.196912, -0.980305, -0.0150651, -0.00327212, -0.00771427, -0.176318)
[node name="Palm" parent="XROrigin3D/XRControllerLeft" index="7"]
transform = Transform3D(1, 3.12364e-06, -3.13861e-06, -3.12371e-06, 1, -1.97886e-05, 3.13854e-06, 1.97889e-05, 1, 0.0307807, -0.0419721, -0.0399505)
[node name="XRControllerRight" parent="XROrigin3D" instance=ExtResource("7_0b3tc")]
unique_name_in_owner = true
transform = Transform3D(0.999999, -1.39635e-11, 0, 1.31553e-10, 1, 0, 0, 0, 1, 0.336726, 0.575093, -0.437942)
[node name="XRSimulator" parent="." instance=ExtResource("5_3qc8g")]
min_camera_height = 0.01
xr_origin = NodePath("../XROrigin3D")
[node name="House" parent="." instance=ExtResource("9_np6mw")]
[node name="Miniature" parent="." instance=ExtResource("12_lmxhs")]
[node name="Menu" parent="." instance=ExtResource("8_du83w")]
transform = Transform3D(0.999999, -1.39633e-11, 0, 1.60657e-10, 1, -4.54747e-13, 0, 0, 0.999999, -0.0165677, 0.766337, -0.634317)
[node name="Keyboard" parent="." instance=ExtResource("9_e5n3p")]
transform = Transform3D(0.5, 5.24309e-05, 0.000144384, -0.000139169, 0.353553, 0.353553, -6.50204e-05, -0.353553, 0.353553, -0.0199266, 0.550784, -0.47368)
[node name="Rooms" type="Node3D" parent="."]
[node name="House" parent="." instance=ExtResource("9_np6mw")]
[node name="Onboarding" parent="." instance=ExtResource("12_uq2nj")]
transform = Transform3D(1, -1.39636e-11, 0, 4.42413e-11, 1, 0, 0, 0, 1, -0.576793, 0.820168, -0.60016)
[node name="Node" type="Node" parent="."]
[node name="Screenshot" type="Node" parent="."]
script = ExtResource("12_e13ym")
[editable path="XROrigin3D/XRControllerLeft"]

View File

@ -17,7 +17,6 @@ var effect: AudioEffectCapture
@onready var chat_user: Chat = $ChatUser
@onready var chat_assistant: Chat = $ChatAssistant
@onready var loader: Node3D = $Loader
@onready var camera = $"/root/Main/XROrigin3D/XRCamera3D"
var running := false
var voice_assistant: VoiceAssistant
@ -50,9 +49,9 @@ func _ready():
loader.visible=true
chat_user.visible=false
chat_assistant.visible=false
global_position=camera.global_position + camera.global_transform.basis.z * - 0.5
global_position=App.camera.global_position + App.camera.global_transform.basis.z * - 0.5
global_position.y *= 0.7
global_transform.basis=Basis.looking_at((camera.global_position - global_position) * - 1)
global_transform.basis=Basis.looking_at((App.camera.global_position - global_position) * - 1)
running=true
)

View File

@ -7,7 +7,7 @@ func _physics_process(_delta):
update_room()
func update_room():
var room = House.body.find_room_at(global_position)
var room = App.house.find_room_at(global_position)
if room != last_room:
if room:

View File

@ -5,9 +5,8 @@ const Initiator = preload ("res://lib/utils/pointer/initiator.gd")
const Finger = preload ("res://lib/utils/touch/finger.gd")
const Touch = preload ("res://lib/utils/touch/touch.gd")
const Collide = preload ("res://lib/utils/touch/collide.gd")
const Miniature = preload ("res://content/system/house/mini/miniature.gd")
const Miniature = preload ("res://content/system/miniature/miniature.gd")
@onready var main = $"/root/Main"
@onready var hand = $hand_l
@onready var hand_mesh = $hand_l/Armature/Skeleton3D/mesh_Hand_L
@onready var auto_hand = $AutoHandtracker
@ -35,6 +34,13 @@ var pressed = false
var grabbed = false
func _ready():
button_pressed.connect(func(action_name):
EventSystem.emit_action(action_name, true, false)
)
button_released.connect(func(action_name):
EventSystem.emit_action(action_name, false, false)
)
_setup_hand()
@ -43,7 +49,7 @@ func _process(_delta):
if quick_actions.is_inside_tree(): palm.remove_child(quick_actions)
return
if main.camera.global_transform.basis.z.dot(palm.global_transform.basis.x) > 0.85:
if App.camera.global_transform.basis.z.dot(palm.global_transform.basis.x) > 0.85:
if quick_actions.is_inside_tree() == false: palm.add_child(quick_actions)
else:
if quick_actions.is_inside_tree(): palm.remove_child(quick_actions)
@ -87,21 +93,21 @@ func _setup_hand():
)
mini_view_button.on_button_up.connect(func():
House.body.mini_view.small.value=!House.body.mini_view.small.value
App.miniature.small.value=!App.miniature.small.value
)
temperature_button.on_button_up.connect(func():
if House.body.mini_view.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.NONE
if App.miniature.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE:
App.miniature.heatmap_type.value=Miniature.HeatmapType.NONE
else:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.TEMPERATURE
App.miniature.heatmap_type.value=Miniature.HeatmapType.TEMPERATURE
)
humidity_button.on_button_up.connect(func():
if House.body.mini_view.heatmap_type.value == Miniature.HeatmapType.HUMIDITY:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.NONE
if App.miniature.heatmap_type.value == Miniature.HeatmapType.HUMIDITY:
App.miniature.heatmap_type.value=Miniature.HeatmapType.NONE
else:
House.body.mini_view.heatmap_type.value=Miniature.HeatmapType.HUMIDITY
App.miniature.heatmap_type.value=Miniature.HeatmapType.HUMIDITY
)
initiator.type = Initiator.Type.HAND_LEFT

View File

@ -5,9 +5,8 @@ const Initiator = preload ("res://lib/utils/pointer/initiator.gd")
const Finger = preload ("res://lib/utils/touch/finger.gd")
const Touch = preload ("res://lib/utils/touch/touch.gd")
const Collide = preload ("res://lib/utils/touch/collide.gd")
const Miniature = preload ("res://content/system/house/mini/miniature.gd")
const Miniature = preload ("res://content/system/miniature/miniature.gd")
@onready var main = $"/root/Main"
@onready var ray: RayCast3D = $Raycast
@onready var hand: Node3D = $hand_r
@onready var hand_mesh = $hand_r/Armature/Skeleton3D/mesh_Hand_R
@ -28,6 +27,14 @@ var pressed = false
var grabbed = false
func _ready():
button_pressed.connect(func(action_name):
EventSystem.emit_action(action_name, true, true)
)
button_released.connect(func(action_name):
EventSystem.emit_action(action_name, false, true)
)
func _setup_hand():
TouchManager.add_finger(Finger.Type.INDEX_RIGHT, $IndexTip/TouchArea)
collide = Collide.new(hand, hand_mesh, index_tip.get_node("Marker3D"))

View File

@ -16,8 +16,6 @@ var touched_enter = 0.0
var moved_ran = false
var touch_ran = false
var miniature = House.body.mini_view
func _ready():
R.effect(func(_arg):
label.text=entity.icon.value
@ -37,15 +35,15 @@ func _ready():
)
func _on_click(_event: EventPointer):
if entity.has_method("quick_action")&&miniature.entity_select.selection_active() == false:
if entity.has_method("quick_action")&&App.miniature.entity_select.selection_active() == false:
entity.quick_action()
snap_sound.play()
else:
miniature.entity_select.toggle(entity)
App.miniature.entity_select.toggle(entity)
func _on_press_move(_event: EventPointer):
if moved_ran: return
miniature.entity_select.toggle(entity)
App.miniature.entity_select.toggle(entity)
moved_ran = true
func _on_press_up(_event: EventPointer):
@ -58,15 +56,15 @@ func _on_touch_enter(_event: EventTouch):
func _on_touch_move(_event: EventTouch):
if touch_ran||Time.get_ticks_msec() - touched_enter < TOUCH_LONG: return
miniature.entity_select.toggle(entity)
App.miniature.entity_select.toggle(entity)
touch_ran = true
func _on_touch_leave(_event: EventTouch):
if touch_ran: return
if entity.has_method("quick_action")&&miniature.entity_select.selection_active() == false:
if entity.has_method("quick_action")&&App.miniature.entity_select.selection_active() == false:
snap_sound.play()
entity.quick_action()
else:
miniature.entity_select.toggle(entity)
App.miniature.entity_select.toggle(entity)

View File

@ -19,7 +19,7 @@ extends Node3D
edge.visible = !disabled
func _ready():
update_initial_positions()
update_initial_positions.call_deferred()
corner1.get_node("Movable").on_move.connect(func(position, rotation):
edge.align_to_corners(corner1.global_position, corner2.global_position)
@ -40,8 +40,11 @@ func _ready():
return corner1.position + delta_new_pos_corner1
func update_initial_positions():
if App.main.is_node_ready() == false:
await App.main.ready
edge.align_to_corners(corner1.global_position, corner2.global_position)
marker.global_transform = House.body.transform
marker.global_transform = App.house.transform
func get_new_transform():
marker.scale = Vector3(1, 1, 1)

View File

@ -50,8 +50,8 @@ func edit(door):
break
if existing_door != null:
room1 = House.body.find_room(existing_door.room1)
room2 = House.body.find_room(existing_door.room2)
room1 = App.house.find_room(existing_door.room1)
room2 = App.house.find_room(existing_door.room2)
room1_corner1 = WallCornerScene.instantiate()
room1_corner1.global_position = existing_door.room1_position1
@ -73,13 +73,13 @@ func edit(door):
room2_corner2.get_node("Clickable").on_grab_move.connect(_move_corner.bind(room2, room2_corner2))
add_child(room2_corner2)
for room in House.body.get_rooms(0):
for room in App.house.get_rooms():
if room != room1&&room != room2:
room.get_node("WallCollision/Clickable").on_click.connect(_add_corner.bind(room))
else:
room.get_node("WallCollision/Clickable").on_click.disconnect(_add_corner.bind(room))
for room in House.body.get_rooms(0):
for room in App.house.get_rooms():
if door != null:
room.get_node("WallCollision/Clickable").on_click.connect(_add_corner.bind(room))
else:

View File

@ -2,15 +2,12 @@ extends Node3D
const Room = preload ("./room/room.tscn")
const RoomType = preload ("./room/room.gd")
const Miniature = preload ("./mini/miniature.gd")
const Doors = preload ("./doors/doors.gd")
const AlignReference = preload ("./align_reference.gd")
@onready var levels = $Levels
@onready var collision_shape = $Levels/CollisionShape3D
@onready var rooms = $Rooms
@onready var align_reference: AlignReference = $AlignReference
@onready var mini_view: Miniature = $Levels/Miniature
@onready var doors: Doors = $Levels/Doors
@onready var doors: Doors = $Doors
var fixing_reference: bool = false
var editing_room: RoomType = null
@ -23,7 +20,7 @@ func _ready():
func update_house():
loaded.value = false
for old_room in get_rooms(0):
for old_room in get_rooms():
old_room.get_parent().remove_child(old_room)
old_room.queue_free()
@ -37,7 +34,7 @@ func update_house():
Store.house.save_local()
continue
create_room(new_room.name, 0)
create_room(new_room.name)
for entity_index in range(Store.house.state.entities.size()):
var entity = Store.house.state.entities[entity_index]
@ -53,7 +50,7 @@ func update_house():
loaded.value = true
func create_room(room_name: String, level: int) -> RoomType:
func create_room(room_name: String) -> RoomType:
var existing_room = Store.house.get_room(room_name)
if existing_room == null:
@ -66,7 +63,7 @@ func create_room(room_name: String, level: int) -> RoomType:
var room = Room.instantiate()
room.name = room_name
get_level(level).add_child(room)
rooms.add_child(room)
return room
@ -116,13 +113,13 @@ func is_editiong(room_name):
return editing_room != null&&editing_room.name == room_name
func find_room(room_name):
for room in get_rooms(0):
for room in get_rooms():
if room.name == room_name:
return room
return null
func find_room_at(entity_position: Vector3):
for room in get_rooms(0):
for room in get_rooms():
if room.has_point(entity_position):
return room
return null
@ -143,11 +140,8 @@ func rename_room(old_room: String, new_name: String):
save_all_entities()
Store.house.save_local()
func get_level(level: int):
return levels.get_child(level)
func get_level_aabb(level: int):
var rooms = get_level(level).get_children()
func get_rooms_aabb():
var rooms = get_rooms()
if rooms.size() == 0:
return AABB()
@ -168,8 +162,8 @@ func get_level_aabb(level: int):
return AABB(min_pos, max_pos - min_pos)
func get_rooms(level: int):
return get_level(level).get_children()
func get_rooms():
return rooms.get_children()
func create_entity(entity_id: String, entity_position: Vector3, type=null):
var room = find_room_at(entity_position)
@ -218,7 +212,7 @@ func fix_reference():
func save_reference():
if fixing_reference:
for room in get_rooms(0):
for room in get_rooms():
room.editable = true
var align_transform = align_reference.global_transform
@ -227,7 +221,7 @@ func save_reference():
align_reference.update_store()
for room in get_rooms(0):
for room in get_rooms():
room.editable = false
save_all_entities()
@ -241,7 +235,7 @@ func save_reference():
func save_all_entities():
Store.house.state.entities.clear()
for room in get_rooms(0):
for room in get_rooms():
for entity in room.get_node("Entities").get_children():
var entity_data = {
"id": entity.entity_id,

View File

@ -1,21 +1,16 @@
[gd_scene load_steps=5 format=3 uid="uid://cbemihbxkd4ll"]
[gd_scene load_steps=4 format=3 uid="uid://cbemihbxkd4ll"]
[ext_resource type="Script" path="res://content/system/house/house.gd" id="1_p8amj"]
[ext_resource type="PackedScene" uid="uid://jls16btb8nko" path="res://content/system/house/align_reference.tscn" id="3_e1tcn"]
[ext_resource type="PackedScene" uid="uid://c8nh8582vwc8u" path="res://content/system/house/doors/doors.tscn" id="4_bb3c2"]
[ext_resource type="PackedScene" uid="uid://ds60i5n211hi3" path="res://content/system/house/mini/miniature.tscn" id="4_qjbly"]
[node name="House" type="Node3D"]
script = ExtResource("1_p8amj")
[node name="Levels" type="Node3D" parent="."]
[node name="Level0" type="Node3D" parent="Levels"]
[node name="Miniature" parent="Levels" instance=ExtResource("4_qjbly")]
[node name="Doors" parent="Levels" instance=ExtResource("4_bb3c2")]
[node name="Rooms" type="Node3D" parent="."]
[node name="AlignReference" parent="." instance=ExtResource("3_e1tcn")]
visible = false
disabled = true
[node name="Doors" parent="." instance=ExtResource("4_bb3c2")]

View File

@ -20,9 +20,35 @@ var caps = false:
update_labels()
func _ready():
get_parent().remove_child.call_deferred(self)
_create_keys()
_prepare_keyboard_spawn()
_connect_key_events()
func _prepare_keyboard_spawn():
if Engine.is_editor_hint():
return
EventSystem.on_focus_in.connect(func(event):
if is_inside_tree():
return
App.main.add_child(self)
global_transform=App.menu.get_node("AnimationContainer/KeyboardPlace").global_transform
)
EventSystem.on_focus_out.connect(func(event):
if !is_inside_tree():
return
App.main.remove_child(self)
)
func _create_keys():
for row in key_list:
for key in row:
var key_node = create_key(key)
var key_node = _create_key(key)
keys.add_child(key_node)
if Engine.is_editor_hint():
@ -37,6 +63,7 @@ func _ready():
keys.columns = key_list[0].size()
func _connect_key_events():
if Engine.is_editor_hint():
return
@ -67,7 +94,7 @@ func _ready():
_emit_event("key_up", KEY_INSERT)
)
func create_key(key: Key):
func _create_key(key: Key):
var key_node = button_scene.instantiate()
key_node.label = EventKey.key_to_string(key, caps)

View File

@ -4,20 +4,17 @@ const DotScene = preload ("res://content/system/dot/dot.tscn")
const Entity = preload ("res://content/entities/entity.gd")
@onready var dots = $"../Small/Dots"
@onready var main = $"/root/Main"
var active_type = null
var editing = R.state([])
var group_entity = null
var house_small = null
func _ready():
await House.body.ready
await App.main.ready
# Update Group Entity
R.effect(func(_arg):
if house_small.value == false||editing.value.size() == 0:
if App.miniature.small.value == false||editing.value.size() == 0:
if group_entity != null:
remove_child(group_entity)
group_entity.queue_free()
@ -29,19 +26,19 @@ func _ready():
if entity_node is Movable:
entity_node.disabled=true
group_entity.transform=Transform3D().looking_at(to_local((main.camera.global_position)), Vector3.UP, true)
group_entity.transform=Transform3D().looking_at(to_local((App.camera.global_position)), Vector3.UP, true)
add_child(group_entity)
else:
HomeApi.groups.update_entities(group_entity.entity_id, editing.value.map(func(entity): return entity.entity_id))
)
var dots_disabled = R.computed(func(_arg):
return House.body.mini_view.small.value == false
return App.miniature.small.value == false
)
# Update Entities
R.effect(func(_arg):
if House.body.loaded.value == false:
if App.house.loaded.value == false:
return
if Store.house.state.entities.size() == 0:
@ -51,11 +48,11 @@ func _ready():
dots.remove_child(old_dot)
old_dot.free()
for room in House.body.get_rooms(0):
for room in App.house.get_rooms():
for entity in room.get_node("Entities").get_children():
var dot=DotScene.instantiate()
dot.position=House.body.to_local(entity.global_position)
dot.position=App.house.to_local(entity.global_position)
dot.entity=entity
dot.active=R.computed(func(_arg2):
return editing.value.has(entity)

View File

@ -1,7 +1,7 @@
[gd_resource type="ShaderMaterial" load_steps=3 format=3 uid="uid://bcfcough6ucvc"]
[ext_resource type="Shader" path="res://content/system/house/mini/mini_wall_shader.gdshader" id="1_sbr3e"]
[ext_resource type="Texture2D" uid="uid://bbuq4wn7e5o2q" path="res://content/system/house/mini/temp_gradient.tres" id="2_3lwi8"]
[ext_resource type="Shader" path="res://content/system/miniature/mini_wall_shader.gdshader" id="1_sbr3e"]
[ext_resource type="Texture2D" uid="uid://bbuq4wn7e5o2q" path="res://content/system/miniature/temp_gradient.tres" id="2_3lwi8"]
[resource]
render_priority = 0

View File

@ -11,7 +11,6 @@ const temperature_gradient = preload ("./temp_gradient.tres")
@onready var player = $Body/Small/Player
@onready var collision_shape = $Body/CollisionShape3D
@onready var entity_select = $Body/EntitySelect
@onready var main = $"/root/Main"
enum HeatmapType {
NONE = 0,
@ -39,7 +38,10 @@ func _ready():
wall_material.set_shader_parameter("data", [])
wall_material.set_shader_parameter("data_size", 0)
entity_select.house_small = small
EventSystem.on_action_down.connect(func(action):
if action.name == "by_button":
small.value=!small.value
)
if Store.house.is_loaded() == false:
await Store.house.on_loaded
@ -87,7 +89,7 @@ func _ready():
tween.set_parallel(true)
if small.value:
var aabb=House.body.get_level_aabb(0)
var aabb=App.house.get_level_aabb(0)
var height=aabb.size.y
aabb.position.y=- 0.03
@ -99,9 +101,8 @@ func _ready():
collision_shape.position=center * 0.1
entity_select.position=Vector3(0, height * 0.1 + 0.1, 0)
var camera=$"/root/Main/XROrigin3D/XRCamera3D"
var camera_position=camera.global_position
var camera_direction=- camera.global_transform.basis.z
var camera_position=App.camera.global_position
var camera_direction=- App.camera.global_transform.basis.z
camera_position.y *= 0.5
camera_direction.y=0
@ -119,10 +120,7 @@ func _ready():
# Update Walls
R.effect(func(_arg):
var show_map=heatmap_type.value != HeatmapType.NONE
var show_small=small.value
model.visible=show_map||show_small
model.visible=heatmap_type.value != HeatmapType.NONE||small.value
)
# Update Heatmap
@ -144,7 +142,7 @@ func _ready():
)
func _process(delta):
var cam_pos = main.camera.global_position
var cam_pos = App.camera.global_position
cam_pos.y += 0.1
player.mesh.height = cam_pos.y
player.position = Vector3(cam_pos.x, cam_pos.y / 2, cam_pos.z)
@ -157,7 +155,7 @@ func get_base_scale() -> Vector2:
func get_sensor_data():
var data_list = []
for room in House.body.get_rooms(0):
for room in App.house.get_rooms():
for entity in room.get_node("Entities").get_children():
if entity is SensorEntity:
var sensor = entity as SensorEntity
@ -165,14 +163,14 @@ func get_sensor_data():
if data == null:
continue
var sensor_pos = House.body.to_local(sensor.global_position)
var sensor_pos = App.house.to_local(sensor.global_position)
data_list.append(Vector4(sensor_pos.x, sensor_pos.y, sensor_pos.z, float(data)))
return data_list
func get_sensor_unit():
for room in House.body.get_rooms(0):
for room in App.house.get_rooms():
for entity in room.get_node("Entities").get_children():
if entity is SensorEntity:
var sensor = entity as SensorEntity

View File

@ -1,8 +1,8 @@
[gd_scene load_steps=7 format=3 uid="uid://ds60i5n211hi3"]
[ext_resource type="Script" path="res://content/system/house/mini/miniature.gd" id="1_b53yn"]
[ext_resource type="Script" path="res://content/system/miniature/miniature.gd" id="1_b53yn"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="2_x7oed"]
[ext_resource type="Script" path="res://content/system/house/mini/Entity.gd" id="3_tgpny"]
[ext_resource type="Script" path="res://content/system/miniature/entity_select.gd" id="3_tgpny"]
[sub_resource type="BoxShape3D" id="BoxShape3D_bckw3"]

View File

@ -73,7 +73,7 @@ func _ready():
trash_bin_large=false
trash_bin_visible=false
House.body.save_all_entities()
App.house.save_all_entities()
)
func _get_entity(node: Node):

View File

@ -20,7 +20,7 @@ func _ready():
entities_page.on_select_entity.connect(func(entity_name):
spawn_sound.play()
var entity=House.body.create_entity(entity_name, global_position)
var entity=App.house.create_entity(entity_name, global_position)
if typeof(entity) == TYPE_BOOL&&entity == false:
EventSystem.notify("Entity is not in Room", EventNotify.Type.INFO)

View File

@ -6,18 +6,15 @@ const Notification = preload ("res://content/ui/components/notification/notifica
@onready var open_sound = $OpenSound
@onready var close_sound = $CloseSound
@onready var notify_place = $AnimationContainer/NotifyPlace
@onready var main = $"/root/Main"
var show_menu = R.state(false)
func _ready():
await main.ready
main.remove_child(self)
App.main.remove_child(self)
R.effect(func(_arg):
if show_menu.value:
main.add_child(self)
App.main.add_child(self)
move_into_view()
animation_player.play_backwards("hide_menu")
open_sound.play()
@ -30,7 +27,12 @@ func _ready():
animation_player.animation_finished.connect(func(_animation):
if show_menu.value == false:
main.remove_child(self)
App.main.remove_child(self)
)
EventSystem.on_action_down.connect(func(action):
if action.name == "menu_button":
toggle_open()
)
EventSystem.on_notify.connect(func(event: EventNotify):
@ -44,8 +46,11 @@ func _ready():
notify_place.add_child(notification_node)
)
func toggle_open():
show_menu.value = !show_menu.value
func move_into_view():
var camera_transform = main.camera.global_transform
var camera_transform = App.camera.global_transform
camera_transform.origin -= camera_transform.basis.z * 0.5
global_transform = camera_transform

View File

@ -1,6 +1,6 @@
extends Node3D
const window_scene = preload("./window.tscn")
const window_scene = preload ("./window.tscn")
@onready var background = $Background
@ -8,7 +8,7 @@ func _ready():
background.visible = false
HomeApi.on_connect.connect(func():
# var rooms = House.body.get_rooms(0)
# var rooms = App.house.get_rooms(0)
# for room in rooms:
# var mesh = room.wall_mesh

View File

@ -45,20 +45,20 @@ func _ready():
door_button.on_button_up.connect(func():
if doors_map.selected_door.value == null:
var id=House.body.doors.add()
var id=App.house.doors.add()
editing_door.value=true
doors_map.selected_door.value=id
elif editing_door.value == false:
editing_door.value=true
House.body.doors.edit(doors_map.selected_door.value)
App.house.doors.edit(doors_map.selected_door.value)
else:
House.body.doors.save()
App.house.doors.save()
editing_door.value=false
)
delete_button.on_button_up.connect(func():
if doors_map.selected_door.value != null:
House.body.doors.delete(doors_map.selected_door.value)
App.house.doors.delete(doors_map.selected_door.value)
doors_map.selected_door.value=null
)

View File

@ -19,13 +19,13 @@ func _ready():
edit_button.on_button_down.connect(func():
if active:
House.body.save_reference()
App.house.save_reference()
else:
House.body.edit_reference()
active = !active
App.house.edit_reference()
active=!active
)
fix_button.on_button_down.connect(func():
House.body.fix_reference()
active = true
App.house.fix_reference()
active=true
)

View File

@ -46,8 +46,8 @@ func _ready():
EventSystem.notify("Name already taken", EventNotify.Type.WARNING)
return
House.body.create_room(room_name, 0)
House.body.edit_room(room_name)
App.house.create_room(room_name)
App.house.edit_room(room_name)
selected_room.value=room_name
editing_room.value=true
rooms_map.selectable.value=false
@ -56,17 +56,17 @@ func _ready():
rooms_map.selectable.value=!editing_room.value
if editing_room.value == false:
if !House.body.is_valid_room(selected_room.value):
if !App.house.is_valid_room(selected_room.value):
EventSystem.notify("Room was deleted as it had less than 3 corners.", EventNotify.Type.WARNING)
House.body.delete_room(selected_room.value)
App.house.delete_room(selected_room.value)
selected_room.value=null
return
if selected_room.value != null&&selected_room.value != input.text:
House.body.rename_room(selected_room.value, input.text)
App.house.rename_room(selected_room.value, input.text)
selected_room.value=input.text
House.body.edit_room(null)
App.house.edit_room(null)
else:
House.body.edit_room(selected_room.value)
App.house.edit_room(selected_room.value)
)

View File

@ -40,7 +40,6 @@ func _ready():
cursor_options.on_select.connect(func(option):
settings_store.cursor_style=option
settings_store.cursor_style=option
print("cursor_style", option)
Store.settings.save_local()
)

View File

@ -8,7 +8,7 @@
[ext_resource type="Texture2D" uid="uid://bl33klueufwja" path="res://assets/cursors/pointer.png" id="6_ypel5"]
[ext_resource type="Texture2D" uid="uid://churthrr24yhw" path="res://assets/cursors/old.png" id="7_un12x"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5amor"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_jrgbl"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("4_v4u0l")
@ -23,7 +23,7 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_i5pey"]
[sub_resource type="QuadMesh" id="QuadMesh_si7x8"]
size = Vector2(0.04, 0.04)
[sub_resource type="BoxShape3D" id="BoxShape3D_01skh"]
@ -34,7 +34,7 @@ size = Vector3(0.04, 0.04, 0.01)
resource_local_to_scene = true
size = Vector3(0.04, 0.04, 0.03)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_dsrxt"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_arcnd"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("4_v4u0l")
@ -49,7 +49,7 @@ shader_parameter/corner_radius = 0.2
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_7pl3m"]
[sub_resource type="QuadMesh" id="QuadMesh_ajawk"]
size = Vector2(0.04, 0.04)
[node name="FeaturesMenu" type="Node3D"]
@ -93,8 +93,8 @@ icon = true
toggleable = true
[node name="Panel3D" parent="CursorOptions/CircleCursor/Body" index="0"]
material_override = SubResource("ShaderMaterial_5amor")
mesh = SubResource("QuadMesh_i5pey")
material_override = SubResource("ShaderMaterial_jrgbl")
mesh = SubResource("QuadMesh_si7x8")
[node name="CollisionShape3D" parent="CursorOptions/CircleCursor/Body" index="1"]
shape = SubResource("BoxShape3D_01skh")
@ -126,8 +126,8 @@ icon = true
toggleable = true
[node name="Panel3D" parent="CursorOptions/RetroCursor/Body" index="0"]
material_override = SubResource("ShaderMaterial_dsrxt")
mesh = SubResource("QuadMesh_7pl3m")
material_override = SubResource("ShaderMaterial_arcnd")
mesh = SubResource("QuadMesh_ajawk")
[node name="CollisionShape3D" parent="CursorOptions/RetroCursor/Body" index="1"]
shape = SubResource("BoxShape3D_01skh")

View File

@ -6,11 +6,11 @@ extends Node3D
func _ready():
save.on_button_down.connect(func():
House.body.save_all_entities()
App.house.save_all_entities()
Store.house.save_local()
)
clear_save.on_button_down.connect(func():
Store.house.clear()
House.body.update_house()
App.house.update_house()
)

View File

@ -1,6 +1,6 @@
extends Node3D
const Miniature = preload ("res://content/system/house/mini/miniature.gd")
const Miniature = preload ("res://content/system/miniature/miniature.gd")
@onready var mini_view_button = $Content/MiniView
@onready var heat_map_button = $Content/HeatMap
@ -13,81 +13,79 @@ const Miniature = preload ("res://content/system/house/mini/miniature.gd")
func _ready():
background.visible = false
if !House.body.is_node_ready():
await House.body.ready
var mini_view = House.body.mini_view
if App.miniature.is_node_ready() == false:
await App.miniature.ready
mini_view_button.on_toggled.connect(func(active):
mini_view.small.value=active
App.miniature.small.value=active
)
heat_map_button.on_toggled.connect(func(active):
if active == false:
if mini_view.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE:
mini_view.heatmap_type.value=Miniature.HeatmapType.NONE
if App.miniature.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE:
App.miniature.heatmap_type.value=Miniature.HeatmapType.NONE
return
mini_view.heatmap_type.value=Miniature.HeatmapType.TEMPERATURE
App.miniature.heatmap_type.value=Miniature.HeatmapType.TEMPERATURE
)
humudity_map_button.on_toggled.connect(func(active):
if active == false:
if mini_view.heatmap_type.value == Miniature.HeatmapType.HUMIDITY:
mini_view.heatmap_type.value=Miniature.HeatmapType.NONE
if App.miniature.heatmap_type.value == Miniature.HeatmapType.HUMIDITY:
App.miniature.heatmap_type.value=Miniature.HeatmapType.NONE
return
mini_view.heatmap_type.value=Miniature.HeatmapType.HUMIDITY
App.miniature.heatmap_type.value=Miniature.HeatmapType.HUMIDITY
)
R.effect(func(_arg):
heat_map_button.active=mini_view.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE
humudity_map_button.active=mini_view.heatmap_type.value == Miniature.HeatmapType.HUMIDITY
heat_map_button.active=App.miniature.heatmap_type.value == Miniature.HeatmapType.TEMPERATURE
humudity_map_button.active=App.miniature.heatmap_type.value == Miniature.HeatmapType.HUMIDITY
)
min_slider.on_value_changed.connect(func(value):
if value >= mini_view.selected_scale.value.y:
min_slider.value=mini_view.selected_scale.value.y
if value >= App.miniature.selected_scale.value.y:
min_slider.value=App.miniature.selected_scale.value.y
return
mini_view.selected_scale.value.x=value
App.miniature.selected_scale.value.x=value
)
max_slider.on_value_changed.connect(func(value):
if value <= mini_view.selected_scale.value.x:
max_slider.value=mini_view.selected_scale.value.x
if value <= App.miniature.selected_scale.value.x:
max_slider.value=App.miniature.selected_scale.value.x
return
mini_view.selected_scale.value.y=value
App.miniature.selected_scale.value.y=value
)
R.effect(func(_arg):
min_slider.value=mini_view.selected_scale.value.x
max_slider.value=mini_view.selected_scale.value.y
min_slider.value=App.miniature.selected_scale.value.x
max_slider.value=App.miniature.selected_scale.value.y
)
# Update Slider
R.effect(func(_arg):
var minmax=mini_view.get_base_scale()
var minmax=App.miniature.get_base_scale()
min_slider.min=minmax.x
min_slider.max=minmax.y
max_slider.min=minmax.x
max_slider.max=minmax.y
var sensor_minmax=mini_view.get_sensor_scale()
var sensor_minmax=App.miniature.get_sensor_scale()
sensor_minmax.x=floor(sensor_minmax.x)
sensor_minmax.y=ceil(sensor_minmax.y)
mini_view.selected_scale.value=sensor_minmax
App.miniature.selected_scale.value=sensor_minmax
min_slider.value=sensor_minmax.x
max_slider.value=sensor_minmax.y
var unit=mini_view.get_sensor_unit()
var unit=App.miniature.get_sensor_unit()
min_slider.label_unit=unit
max_slider.label_unit=unit
)
R.bind(opacity_slider, "value", mini_view.opacity, opacity_slider.on_value_changed)
R.bind(opacity_slider, "value", App.miniature.opacity, opacity_slider.on_value_changed)

View File

@ -2,7 +2,6 @@ extends Node3D
@onready var getting_started_button = $GettingStartedButton
@onready var close_button = $CloseButton
@onready var camera = $"/root/Main/XROrigin3D/XRCamera3D"
var next_new_position = null
func _ready():
@ -30,11 +29,11 @@ func close():
queue_free()
func _slow_tick(delta):
var new_position = camera.global_position + camera.global_transform.basis.z * - 0.5
var new_position = App.camera.global_position + App.camera.global_transform.basis.z * - 0.5
if next_new_position.distance_to(new_position) > 0.2:
next_new_position = new_position
var new_direction = Basis.looking_at((camera.global_position - new_position) * - 1)
var new_direction = Basis.looking_at((App.camera.global_position - new_position) * - 1)
var tween = create_tween()
tween.set_parallel(true)

View File

@ -1,6 +1,5 @@
extends Node
const console_scene = preload ("res://content/ui/console.tscn")
@onready var main = $"/root/Main"
@onready var console = $"/root/Main/Console"

View File

@ -82,6 +82,19 @@ func notify(message: String, type:=EventNotify.Type.INFO):
event.type = type
emit("notify", event)
## Helper for emitting controller actions
func emit_action(name: String, value, right_controller: bool=true):
var event = EventAction.new()
event.name = name
event.value = value
event.right_controller = right_controller
match typeof(value):
TYPE_BOOL:
EventSystem.emit("action_down" if value else "action_up", event)
TYPE_FLOAT, TYPE_VECTOR2:
EventSystem.emit("action_value", event)
## Returns true when the node is focused
func is_focused(node: Node):
return _active_node == node

View File

@ -22,7 +22,6 @@ var api: Node
var reconnect_timer := Timer.new()
func _ready():
print("HomeApi ready")
start()
reconnect_timer.wait_time = 60

View File

@ -1,6 +0,0 @@
extends Node
## Shortcut to get the House node from the Main scene
const HouseClass = preload ("res://content/system/house/house.gd")
@onready var body: HouseClass = get_node_or_null("/root/Main/House")

16
app/lib/globals/main.gd Normal file
View File

@ -0,0 +1,16 @@
extends Node
const Main = preload ("res://content/main.gd")
const House = preload ("res://content/system/house/house.gd")
const Menu = preload ("res://content/ui/menu/menu.gd")
const Miniature = preload ("res://content/system/miniature/miniature.gd")
const ControllerLeft = preload ("res://content/system/controller_left/controller_left.gd")
const ControllerRight = preload ("res://content/system/controller_right/controller_right.gd")
@onready var main: Main = get_node_or_null("/root/Main")
@onready var house: House = get_node_or_null("/root/Main/House")
@onready var menu: Menu = get_node_or_null("/root/Main/Menu")
@onready var camera: XRCamera3D = get_node_or_null("/root/Main/XROrigin3D/XRCamera3D")
@onready var miniature: Miniature = get_node_or_null("/root/Main/Miniature")
@onready var controller_left: ControllerLeft = get_node_or_null("/root/Main/XROrigin3D/XRControllerLeft")
@onready var controller_right: ControllerRight = get_node_or_null("/root/Main/XROrigin3D/XRControllerRight")

View File

@ -17,8 +17,9 @@ func _init(hand: Node3D, hand_mesh: MeshInstance3D, tip: Node3D):
func _ready():
var body_container = Node3D.new()
body_container.name = "HandBodyContainer"
body_container.top_level = true
get_node("/root/Main/").add_child.call_deferred(body_container)
add_child(body_container)
tip_body = TipCollider.instantiate()
tip_body.global_position = tip.global_position

View File

@ -22,10 +22,10 @@ driver/enable_input=true
[autoload]
XRToolsUserSettings="*res://addons/godot-xr-tools/user_settings/user_settings.gd"
App="*res://lib/globals/main.gd"
HomeApi="*res://lib/globals/home_api.gd"
Store="*res://lib/globals/main_store.gd"
EventSystem="*res://lib/globals/event_system.gd"
House="*res://lib/globals/house_body.gd"
Request="*res://lib/globals/request.gd"
TouchManager="*res://lib/utils/touch/touch.gd"