update mini view, add migration system

This commit is contained in:
Nitwel 2024-01-22 16:54:15 +01:00
parent 721c0de4ba
commit 7c5f549462
10 changed files with 147 additions and 25 deletions

View File

@ -1,9 +1,8 @@
[gd_scene load_steps=7 format=3 uid="uid://bsx12q23v8apy"]
[gd_scene load_steps=6 format=3 uid="uid://bsx12q23v8apy"]
[ext_resource type="Script" path="res://content/system/hands/hands.gd" id="1_c4f76"]
[ext_resource type="PackedScene" uid="uid://c0kow4g10wolq" path="res://assets/models/hands_steam/right_hand.glb" id="1_uekbj"]
[ext_resource type="PackedScene" uid="uid://dt4ksvogfctkr" path="res://assets/models/hands_steam/left_hand.glb" id="2_n73lt"]
[ext_resource type="PackedScene" uid="uid://bexxngoxcegul" path="res://content/system/armband/armband.tscn" id="3_ck75s"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dopke"]
radius = 0.001
@ -43,7 +42,7 @@ transform = Transform3D(1, -7.45058e-09, -2.22045e-16, 7.45058e-09, 1, 0, 0, 0,
shape = SubResource("CapsuleShape3D_dopke")
[node name="ThumbTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928487, 0.0498668, 0.0560917, -0.112777)
transform = Transform3D(0.937246, 0.0284254, -0.347508, 0.0184905, 0.991216, 0.130949, 0.348178, -0.129157, 0.928488, 0.0498668, 0.0560917, -0.112777)
bone_name = "Thumb_Tip_L"
bone_idx = 4
use_external_skeleton = true
@ -53,7 +52,7 @@ external_skeleton = NodePath("../left_hand/Armature_001/Skeleton3D")
gizmo_extents = 0.02
[node name="MiddleTip" type="BoneAttachment3D" parent="XRHandLeft"]
transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996576, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653567, 0.032112, 0.00654224, -0.171612)
transform = Transform3D(0.0812012, -0.650531, -0.755125, 0.996577, 0.064817, 0.051326, 0.0155558, -0.756708, 0.653568, 0.032112, 0.00654224, -0.171612)
bone_name = "Middle_Tip_L"
bone_idx = 14
use_external_skeleton = true
@ -81,9 +80,6 @@ collision_mask = 8
transform = Transform3D(1, 1.05818e-16, 4.75779e-13, -2.32831e-10, 1, -1.77636e-14, -4.97946e-12, 1.77636e-15, 1, -7.7486e-07, 1.33878e-09, -0.030436)
shape = SubResource("BoxShape3D_1pxrt")
[node name="Armband" parent="XRHandLeft/AnimatableBody3D" instance=ExtResource("3_ck75s")]
transform = Transform3D(0.5, -8.74228e-08, 0, 8.74228e-08, 0.5, 0, 0, 0, 0.5, 0, 5.00223e-14, 0.11)
[node name="RemoteTransform3D" type="RemoteTransform3D" parent="XRHandLeft"]
remote_path = NodePath("../AnimatableBody3D")
@ -98,7 +94,7 @@ hand_skeleton = NodePath("right_hand/Armature/Skeleton3D")
transform = Transform3D(1, 0, 4.7579e-13, 0, 1, 0, -1.34149e-12, 1.77636e-15, 1, 0, 0, 0)
[node name="IndexTip" type="BoneAttachment3D" parent="XRHandRight"]
transform = Transform3D(0.19221, 0.669966, 0.717078, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345978, -0.164767, -0.0355401)
transform = Transform3D(0.19221, 0.669966, 0.717079, -0.091543, -0.715277, 0.69282, 0.977075, -0.19881, -0.0761527, -0.0345977, -0.164767, -0.0355401)
bone_name = "Index_Tip_R"
bone_idx = 9
use_external_skeleton = true

View File

@ -12,6 +12,14 @@ var mini_view: bool = false:
mini_view = value
update_mini_view()
var target_size: float = 1.0
func _physics_process(delta):
levels.scale.x = lerp(levels.scale.x, target_size, 10.0 * delta)
levels.scale.y = lerp(levels.scale.y, target_size, 10.0 * delta)
levels.scale.z = lerp(levels.scale.z, target_size, 10.0 * delta)
func create_room(room_name: String, level: int) -> RoomType:
if editing_room != null:
editing_room.editable = false
@ -134,9 +142,7 @@ func update_mini_view():
else:
levels.position = Vector3(0, 0, 0)
levels.scale.x = 0.2 if mini_view else 1.0
levels.scale.y = 0.2 if mini_view else 1.0
levels.scale.z = 0.2 if mini_view else 1.0
target_size = 0.1 if mini_view else 1.0
for room in get_rooms(0):
room.state_machine.change_to("Mini" if mini_view else "View")

View File

@ -33,12 +33,6 @@ func remove_corner(index: int):
get_corner(index).queue_free()
get_edge(index).queue_free()
func _save():
return {
"corners": wall_corners.get_children().map(func(corner): return corner.position),
"name": name
}
func get_aabb():
if wall_corners.get_child_count() == 0:
return AABB()
@ -58,6 +52,11 @@ func get_aabb():
return AABB(to_global(min_pos), to_global(max_pos) - to_global(min_pos))
func _save():
return {
"corners": wall_corners.get_children().map(func(corner): return corner.position),
"name": name
}
func _load(data):
await ready

View File

@ -11,7 +11,7 @@ func _on_enter():
if corner_count < 3:
return
room_height = room.get_corner(0).global_position.y
room_height = room.room_ceiling.position.y
room.wall_mesh.visible = true
room.ceiling_mesh.visible = true

View File

@ -5,11 +5,12 @@ const Notification = preload("res://content/ui/components/notification/notificat
@onready var nav_view = $AnimationContainer/Navigation/View
@onready var nav_edit: Button3D = $AnimationContainer/Navigation/Edit
@onready var menu_edit: Node3D = $AnimationContainer/Content/EditMenu
@onready var nav_room = $AnimationContainer/Navigation/Room
@onready var menu_room: Node3D = $AnimationContainer/Content/RoomMenu
@onready var nav_automate = $AnimationContainer/Navigation/Automate
@onready var nav_settings = $AnimationContainer/Navigation/Settings
@onready var menu_view: Node3D = $AnimationContainer/Content/ViewMenu
@onready var menu_edit: Node3D = $AnimationContainer/Content/EditMenu
@onready var menu_room: Node3D = $AnimationContainer/Content/RoomMenu
@onready var menu_settings: Node3D = $AnimationContainer/Content/SettingsMenu
@onready var menu_root = $AnimationContainer
@ -89,7 +90,7 @@ func _is_valid_nav(nav):
func _nav_to_menu(nav):
match nav:
nav_view:
return null
return menu_view
nav_edit:
return menu_edit
nav_room:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=16 format=3 uid="uid://c3kdssrmv84kv"]
[gd_scene load_steps=17 format=3 uid="uid://c3kdssrmv84kv"]
[ext_resource type="Script" path="res://content/ui/menu/menu.gd" id="1_ng4u3"]
[ext_resource type="Material" uid="uid://bnwimm214q67g" path="res://assets/materials/sec-500.material" id="2_0x5at"]
@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://crrb0l3ekuotj" path="res://content/ui/menu/edit/edit_menu.tscn" id="4_r2raj"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="5_w4i01"]
[ext_resource type="ArrayMesh" uid="uid://cbqhhnknyium2" path="res://assets/immersive_home_panels/immersive_home_panels.obj" id="7_f4u4o"]
[ext_resource type="PackedScene" uid="uid://ddpxthb414unp" path="res://content/ui/menu/view/view_menu.tscn" id="8_71pkg"]
[ext_resource type="PackedScene" uid="uid://c01gkeldvjwtr" path="res://content/ui/menu/room/room_menu.tscn" id="10_u4i1x"]
[ext_resource type="PackedScene" uid="uid://c6r4higceibif" path="res://content/ui/menu/settings/settings_menu.tscn" id="11_7wm6b"]
@ -225,6 +226,9 @@ visible = false
[node name="SettingsMenu" parent="AnimationContainer/Content" instance=ExtResource("11_7wm6b")]
visible = false
[node name="ViewMenu" parent="AnimationContainer/Content" instance=ExtResource("8_71pkg")]
visible = false
[node name="NotifyPlace" type="Marker3D" parent="AnimationContainer"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.2, 0, -0.05)
gizmo_extents = 0.02

View File

@ -0,0 +1,12 @@
extends Node3D
@onready var mini_view = $Content/MiniView
@onready var background = $Background
func _ready():
background.visible = false
mini_view.on_button_down.connect(func():
House.body.mini_view = !House.body.mini_view
)

View File

@ -0,0 +1,21 @@
[gd_scene load_steps=4 format=3 uid="uid://ddpxthb414unp"]
[ext_resource type="Script" path="res://content/ui/menu/view/view_menu.gd" id="1_hxajx"]
[ext_resource type="PackedScene" uid="uid://bsjqdvkt0u87c" path="res://content/ui/components/button/button.tscn" id="2_qan1b"]
[sub_resource type="BoxMesh" id="BoxMesh_qr3bi"]
size = Vector3(0.3, 0.01, 0.3)
[node name="ViewMenu" type="Node3D"]
script = ExtResource("1_hxajx")
[node name="Background" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.15, 0, 0.15)
mesh = SubResource("BoxMesh_qr3bi")
[node name="Content" type="Node3D" parent="."]
[node name="MiniView" parent="Content" instance=ExtResource("2_qan1b")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, 0, 0.03)
label = "view_comfy"
icon = true

View File

@ -6,6 +6,8 @@ signal loaded()
signal unloaded()
var is_loaded := false
var export_config = ConfigFile.new()
var export_config_path = "res://export_presets.cfg"
func clear():
await _clear_save_tree(get_tree().root.get_node("Main"))
@ -25,11 +27,14 @@ func save():
var save_tree = _generate_save_tree(get_tree().root.get_node("Main"))
var json_text = JSON.stringify(save_tree)
var json_text = JSON.stringify({
"version": "1.0.0",
"tree": save_tree
})
save_file.store_line(json_text)
func load():
await clear()
await clear()
if HomeApi.has_connected() == false:
return
@ -42,7 +47,15 @@ func load():
return
var json_text = save_file.get_line()
var save_tree = JSON.parse_string(json_text)
var save_data = JSON.parse_string(json_text)
save_data = migrate(save_data)
if save_data == null:
save()
return
var save_tree = save_data["tree"]
if save_tree == null:
return
@ -56,6 +69,72 @@ func load():
loaded.emit()
is_loaded = true
func migrate(data: Dictionary):
var migration_version = data["migration"]
var migrations = load_migrations()
if migration_version == null || migrations == {}:
return null
var migration_keys = migrations.keys().sort()
for key in migration_keys:
if is_migration_newer(migration_version, key):
var migration = migrations[key]
data = migration.migrate(data)
data["migration"] = key
return data
func is_migration_newer(version, new_version):
var version_split = version.split(".")
var new_version_split = new_version.split(".")
for i in range(0, 3):
if int(version_split[i]) > int(new_version_split[i]):
return false
elif int(version_split[i]) < int(new_version_split[i]):
return true
return false
func load_migrations():
var migrations = {}
var migrations_dir := DirAccess.open("res://lib/migrations")
if migrations == null:
return {}
migrations_dir.list_dir_begin()
var file_name = migrations_dir.get_next()
while file_name != "":
if file_name.ends_with(".gd"):
var version = file_name.substr(0, -3)
migrations[version] = load("res://lib/migrations/%s" % file_name)
file_name = migrations_dir.get_next()
migrations_dir.list_dir_end()
return migrations
func get_version():
var config_error = export_config.load(export_config_path)
if config_error != OK:
return null
var version = export_config.get_value("preset.1.options", "version/name")
if version == null:
return null
return version
func _clear_save_tree(node: Node):
for child in node.get_children():
await _clear_save_tree(child)

View File

@ -0,0 +1,4 @@
extends Object
static func migrate(data: Dictionary):
return data