Skip to content

Commit

Permalink
Merge pull request #125 from Nitwel/entity_menu
Browse files Browse the repository at this point in the history
Add entities back to mini view + batch edit entities + palm shortcuts
  • Loading branch information
Nitwel authored Apr 17, 2024
2 parents 039f990 + 1f2ca1e commit 9f2cb27
Show file tree
Hide file tree
Showing 38 changed files with 533 additions and 186 deletions.
14 changes: 8 additions & 6 deletions app/assets/materials/switch_off.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://co2ishj2hx57p"
path="res://.godot/imported/switch_off.png-c31f6b401a5d3d7cba3c9d0f2c8b28fe.ctex"
path.s3tc="res://.godot/imported/switch_off.png-c31f6b401a5d3d7cba3c9d0f2c8b28fe.s3tc.ctex"
path.etc2="res://.godot/imported/switch_off.png-c31f6b401a5d3d7cba3c9d0f2c8b28fe.etc2.ctex"
metadata={
"vram_texture": false
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}

[deps]

source_file="res://assets/materials/switch_off.png"
dest_files=["res://.godot/imported/switch_off.png-c31f6b401a5d3d7cba3c9d0f2c8b28fe.ctex"]
dest_files=["res://.godot/imported/switch_off.png-c31f6b401a5d3d7cba3c9d0f2c8b28fe.s3tc.ctex", "res://.godot/imported/switch_off.png-c31f6b401a5d3d7cba3c9d0f2c8b28fe.etc2.ctex"]

[params]

compress/mode=0
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
Expand All @@ -31,4 +33,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
detect_3d/compress_to=0
7 changes: 6 additions & 1 deletion app/content/entities/button/button.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
extends Entity

const Entity = preload("../entity.gd")
const Entity = preload ("../entity.gd")

@onready var button = $Button

func _ready():
super()

icon.value = "radio_button_checked"

var stateInfo = await HomeApi.get_state(entity_id)

if stateInfo == null:
Expand All @@ -32,3 +34,6 @@ func set_state(state):
else:
button.icon = false
button.label = name

func quick_action():
HomeApi.set_state(entity_id, "pressed")
2 changes: 1 addition & 1 deletion app/content/entities/button/button.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[sub_resource type="BoxShape3D" id="BoxShape3D_um5pa"]
size = Vector3(0.0700684, 0.011734, 0.0703125)

[node name="Button" type="StaticBody3D" groups=["entity"]]
[node name="Button" type="StaticBody3D"]
script = ExtResource("1_ja7lt")

[node name="Button" parent="." instance=ExtResource("1_r4tef")]
Expand Down
6 changes: 3 additions & 3 deletions app/content/entities/camera/camera.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
extends Entity

const Entity = preload("../entity.gd")
const Entity = preload ("../entity.gd")

@export var view_width = 0.15

@onready var view = $View
@onready var http_request = $HTTPRequest
@onready var mesh = $MeshInstance3D


# Called when the node enters the scene tree for the first time.
func _ready():
super()

icon.value = "photo_camera"

var stateInfo = await HomeApi.get_state(entity_id)

set_state(stateInfo)
Expand All @@ -36,7 +37,6 @@ func set_state(stateInfo):

if stateInfo["attributes"].has("entity_picture"):
load_image(stateInfo["attributes"]["entity_picture"])


func load_image(url: String):
http_request.request("http://192.168.33.33:8123" + url)
Expand Down
2 changes: 1 addition & 1 deletion app/content/entities/camera/camera.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ size = Vector2(0.15, 0.15)
[sub_resource type="BoxShape3D" id="BoxShape3D_te0pn"]
size = Vector3(0.15, 0.15, 0.01)

[node name="Camera" type="StaticBody3D" groups=["entity"]]
[node name="Camera" type="StaticBody3D" ]
script = ExtResource("1_htxq3")

[node name="View" type="Sprite3D" parent="."]
Expand Down
2 changes: 2 additions & 0 deletions app/content/entities/entity.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extends StaticBody3D

var entity_id: String
var icon = R.state("question_mark")
var icon_color = R.state(Color(1, 1, 1, 1))

func _ready():
var movable = get_node("Movable")
Expand Down
106 changes: 64 additions & 42 deletions app/content/entities/light/light.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extends Entity

const Entity = preload("../entity.gd")
const color_wheel_img := preload("res://assets/canvas.png")
const Entity = preload ("../entity.gd")
const color_wheel_img := preload ("res://assets/canvas.png")

@export var color_off = Color(0.23, 0.23, 0.23)
@export var color_on = Color(1.0, 0.85, 0.0)

@onready var animation: AnimationPlayer = $AnimationPlayer
@onready var lightbulb = $Lightbulb
@onready var slider: Slider3D = $Slider
@onready var color_wheel = $ColorWheel
@onready var color_puck = $ColorWheel/Puck
Expand All @@ -17,105 +17,127 @@ const color_wheel_img := preload("res://assets/canvas.png")

var state = true
var brightness = 0 # 0-255
var color = color_on
var color_supported = false

# Called when the node enters the scene tree for the first time.
func _ready():
super()


icon.value = "lightbulb"
var stateInfo = await HomeApi.get_state(entity_id)
set_state(stateInfo["state"] == "on")
set_state(stateInfo["state"] == "on", stateInfo["attributes"])

if stateInfo.has("attributes") && stateInfo["attributes"].has("effect_list") && stateInfo["attributes"]["effect_list"].size() > 0:
if stateInfo["attributes"].has("effect") && stateInfo["attributes"]["effect"] != null:
if stateInfo.has("attributes")&&stateInfo["attributes"].has("effect_list")&&stateInfo["attributes"]["effect_list"].size() > 0:
if stateInfo["attributes"].has("effect")&&stateInfo["attributes"]["effect"] != null:
mode_label.text = stateInfo["attributes"]["effect"]

mode_next.on_button_down.connect(func():
var index = stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"])
if index == -1:
index = 0
var index=stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"])
if index == - 1:
index=0
else:
index = (index + 1) % stateInfo["attributes"]["effect_list"].size()
index=(index + 1) % stateInfo["attributes"]["effect_list"].size()

mode_label.text = stateInfo["attributes"]["effect_list"][index]
mode_label.text=stateInfo["attributes"]["effect_list"][index]

HomeApi.set_state(entity_id, "on", {"effect": stateInfo["attributes"]["effect_list"][index]})
)

mode_before.on_button_down.connect(func():
var index = stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"])
if index == -1:
index = 0
var index=stateInfo["attributes"]["effect_list"].find(stateInfo["attributes"]["effect"])
if index == - 1:
index=0
else:
index = (index - 1) % stateInfo["attributes"]["effect_list"].size()
index=(index - 1) % stateInfo["attributes"]["effect_list"].size()

mode_label.text = stateInfo["attributes"]["effect_list"][index]
mode_label.text=stateInfo["attributes"]["effect_list"][index]

HomeApi.set_state(entity_id, "on", {"effect": stateInfo["attributes"]["effect_list"][index]})
)
else:
remove_child(modes)


if stateInfo.has("attributes") && stateInfo["attributes"].has("supported_color_modes") && stateInfo["attributes"]["supported_color_modes"].has("rgb"):
if stateInfo.has("attributes")&&stateInfo["attributes"].has("supported_color_modes")&&stateInfo["attributes"]["supported_color_modes"].has("rgb"):
color_wheel.get_node("Clickable").on_press_down.connect(func(event: EventPointer):
var target_point = color_wheel.to_local(event.ray.get_collision_point())
var target_point=color_wheel.to_local(event.ray.get_collision_point())

var delta = Vector2(target_point.x, target_point.z) * (1.0 / 0.08)
var delta=Vector2(target_point.x, target_point.z) * (1.0 / 0.08)
if delta.length() > 1:
delta = delta.normalized()
delta=delta.normalized()

print("delta", delta)

var color = color_wheel_img.get_image().get_pixel((delta.x * 0.5 + 0.5) * 1000, (delta.y * 0.5 + 0.5) * 1000)
var color=color_wheel_img.get_image().get_pixel((delta.x * 0.5 + 0.5) * 1000, (delta.y * 0.5 + 0.5) * 1000)

color_puck.material_override.albedo_color = color
color_puck.position = Vector3(target_point.x, color_puck.position.y, target_point.z)
print("color", color)

var attributes = {
color_puck.material_override.albedo_color=color
color_puck.position=Vector3(target_point.x, color_puck.position.y, target_point.z)

var attributes={
"rgb_color": [int(color.r * 255), int(color.g * 255), int(color.b * 255)],
}

HomeApi.set_state(entity_id, "on", attributes)
set_state(state, attributes)
)
color_supported = true
else:
remove_child(color_wheel)

await HomeApi.watch_state(entity_id, func(new_state):
if (new_state["state"] == "on") == state:
return
set_state(new_state["state"] == "on")
set_state(new_state["state"] == "on", new_state["attributes"])
)

slider.on_value_changed.connect(func(new_value):
var value = new_value / 100 * 255
var value=new_value / 100 * 255
HomeApi.set_state(entity_id, "on" if state else "off", {"brightness": int(value)})
set_state(state, value)
set_state(state, {"brightness": value})
)

func set_state(new_state: bool, new_brightness = null):
if state == false && new_state == false:
func set_state(new_state: bool, attributes={}):
if state == false&&new_state == false:
return

state = new_state
brightness = new_brightness

if attributes.has("brightness"):
brightness = attributes["brightness"]

if attributes.has("rgb_color")&&attributes["rgb_color"] != null:
color = Color(attributes["rgb_color"][0] / 255.0, attributes["rgb_color"][1] / 255.0, attributes["rgb_color"][2] / 255.0, 1)

var tween = create_tween()

var target_color = color_off

if state:
if brightness == null:
animation.speed_scale = 1
animation.play_backwards("light")
target_color = color if color_supported else color_on
else:
var duration = animation.get_animation("light").length
animation.speed_scale = 0
animation.seek(lerpf(0, duration, 1 - (brightness / 255.0)), true)
else:
animation.speed_scale = 1
animation.play("light")
target_color = color_off.lerp(color if color_supported else color_on, brightness / 255.0)

icon_color.value = target_color
tween.tween_property(lightbulb, "material_override:albedo_color", target_color, 0.3)

func _on_click(event):
if event.target == self:
var attributes = {}

if !state && brightness != null:
if !state&&brightness != null:
attributes["brightness"] = int(brightness)

HomeApi.set_state(entity_id, "on" if !state else "off", attributes)
set_state(!state, brightness)
set_state(!state, attributes)

func quick_action():
var attributes = {}

if !state&&brightness != null:
attributes["brightness"] = int(brightness)

HomeApi.set_state(entity_id, "on" if !state else "off", attributes)
set_state(!state, attributes)
52 changes: 5 additions & 47 deletions app/content/entities/light/light.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://cw86rc42dv2d8"]
[gd_scene load_steps=15 format=3 uid="uid://cw86rc42dv2d8"]

[ext_resource type="Script" path="res://content/entities/light/light.gd" id="1_ykxy3"]
[ext_resource type="Script" path="res://content/functions/movable.gd" id="4_4sfxb"]
Expand All @@ -12,43 +12,6 @@
[sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"]
radius = 0.05

[sub_resource type="Animation" id="Animation_afofi"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("CSGCombiner3D:material_override:albedo_color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 0.85098, 0, 1)]
}

[sub_resource type="Animation" id="Animation_7o31s"]
resource_name = "light"
length = 0.3
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("CSGCombiner3D:material_override:albedo_color")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.3),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 0.85098, 0, 1), Color(0.231373, 0.231373, 0.231373, 1)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_8a76q"]
_data = {
"RESET": SubResource("Animation_afofi"),
"light": SubResource("Animation_7o31s")
}

[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_k3ob2"]
points = PackedVector3Array(0, -0.005, -0.08, -0.00784652, -0.005, -0.0796241, 0, 0.005, -0.08, 0.00783085, -0.005, -0.0796241, -0.00784652, 0.005, -0.0796241, -0.0156147, -0.005, -0.0784651, 0.00783085, 0.005, -0.0796241, 0.0155991, -0.005, -0.0784651, -0.0156147, 0.005, -0.0784651, -0.0232263, -0.005, -0.0765701, 0.0155991, 0.005, -0.0784651, 0.0232106, -0.005, -0.0765701, -0.0232263, 0.005, -0.0765701, -0.0306186, -0.005, -0.0739233, 0.0232106, 0.005, -0.0765701, 0.030603, -0.005, -0.0739233, -0.0306186, 0.005, -0.0739233, -0.0377134, -0.005, -0.070556, 0.030603, 0.005, -0.0739233, 0.0376977, -0.005, -0.070556, -0.0377134, 0.005, -0.070556, -0.0444479, -0.005, -0.0665309, 0.0376977, 0.005, -0.070556, 0.0444323, -0.005, -0.0665309, -0.0444479, 0.005, -0.0665309, -0.0507596, -0.005, -0.0618481, 0.0444323, 0.005, -0.0665309, 0.0507439, -0.005, -0.0618481, -0.0507596, 0.005, -0.0618481, -0.0565701, -0.005, -0.0565701, 0.0507439, 0.005, -0.0618481, 0.0565544, -0.005, -0.0565701, -0.0565701, 0.005, -0.0565701, -0.0618481, -0.005, -0.0507596, 0.0565544, 0.005, -0.0565701, 0.0618324, -0.005, -0.0507596, -0.0618481, 0.005, -0.0507596, -0.0665309, -0.005, -0.0444479, 0.0618324, 0.005, -0.0507596, 0.0665153, -0.005, -0.0444479, -0.0665309, 0.005, -0.0444479, -0.070556, -0.005, -0.0377134, 0.0665153, 0.005, -0.0444479, 0.0705403, -0.005, -0.0377134, -0.070556, 0.005, -0.0377134, -0.0739233, -0.005, -0.0306186, 0.0705403, 0.005, -0.0377134, 0.0739076, -0.005, -0.0306186, -0.0739233, 0.005, -0.0306186, -0.0765701, -0.005, -0.0232263, 0.0739076, 0.005, -0.0306186, 0.0765544, -0.005, -0.0232263, -0.0765701, 0.005, -0.0232263, -0.0784651, -0.005, -0.0156147, 0.0765544, 0.005, -0.0232263, 0.0784495, -0.005, -0.0156147, -0.0784651, 0.005, -0.0156147, -0.0796241, -0.005, -0.00784652, 0.0784495, 0.005, -0.0156147, 0.0796085, -0.005, -0.00784652, -0.0796241, 0.005, -0.00784652, -0.08, -0.005, 0, 0.0796085, 0.005, -0.00784652, 0.08, -0.005, 0, -0.08, 0.005, 0, -0.0796241, -0.005, 0.00783085, 0.08, 0.005, 0, 0.0796085, -0.005, 0.00783085, -0.0796241, 0.005, 0.00783085, -0.0784651, -0.005, 0.0155991, 0.0796085, 0.005, 0.00783085, 0.0784495, -0.005, 0.0155991, -0.0784651, 0.005, 0.0155991, -0.0765701, -0.005, 0.0232106, 0.0784495, 0.005, 0.0155991, 0.0765544, -0.005, 0.0232106, -0.0765701, 0.005, 0.0232106, -0.0739233, -0.005, 0.030603, 0.0765544, 0.005, 0.0232106, 0.0739076, -0.005, 0.030603, -0.0739233, 0.005, 0.030603, -0.070556, -0.005, 0.0376977, 0.0739076, 0.005, 0.030603, 0.0705403, -0.005, 0.0376977, -0.070556, 0.005, 0.0376977, -0.0665309, -0.005, 0.0444323, 0.0705403, 0.005, 0.0376977, 0.0665153, -0.005, 0.0444323, -0.0665309, 0.005, 0.0444323, -0.0618481, -0.005, 0.0507439, 0.0665153, 0.005, 0.0444323, 0.0618324, -0.005, 0.0507439, -0.0618481, 0.005, 0.0507439, -0.0565701, -0.005, 0.0565544, 0.0618324, 0.005, 0.0507439, 0.0565544, -0.005, 0.0565544, -0.0565701, 0.005, 0.0565544, -0.0507596, -0.005, 0.0618324, 0.0565544, 0.005, 0.0565544, 0.0507439, -0.005, 0.0618324, -0.0507596, 0.005, 0.0618324, -0.0444479, -0.005, 0.0665153, 0.0507439, 0.005, 0.0618324, 0.0444323, -0.005, 0.0665153, -0.0444479, 0.005, 0.0665153, -0.0377134, -0.005, 0.0705403, 0.0444323, 0.005, 0.0665153, 0.0376977, -0.005, 0.0705403, -0.0377134, 0.005, 0.0705403, -0.0306186, -0.005, 0.0739076, 0.0376977, 0.005, 0.0705403, 0.030603, -0.005, 0.0739076, -0.0306186, 0.005, 0.0739076, -0.0232263, -0.005, 0.0765544, 0.030603, 0.005, 0.0739076, 0.0232106, -0.005, 0.0765544, -0.0232263, 0.005, 0.0765544, -0.0156147, -0.005, 0.0784495, 0.0232106, 0.005, 0.0765544, 0.0155991, -0.005, 0.0784495, -0.0156147, 0.005, 0.0784495, -0.00784652, -0.005, 0.0796085, 0.0155991, 0.005, 0.0784495, 0.00783085, -0.005, 0.0796085, -0.00784652, 0.005, 0.0796085, 0, -0.005, 0.08, 0.00783085, 0.005, 0.0796085, 0, 0.005, 0.08)

Expand All @@ -67,7 +30,7 @@ top_radius = 0.01
bottom_radius = 0.01
height = 0.005

[node name="Light" type="StaticBody3D" groups=["entity"]]
[node name="Light" type="StaticBody3D"]
collision_mask = 0
script = ExtResource("1_ykxy3")

Expand All @@ -80,26 +43,21 @@ script = ExtResource("5_oh4jg")
[node name="Movable" type="Node" parent="."]
script = ExtResource("4_4sfxb")

[node name="CSGCombiner3D" type="CSGCombiner3D" parent="."]
[node name="Lightbulb" type="CSGCombiner3D" parent="."]
transform = Transform3D(1, 9.69949e-05, 0.000589194, -9.77749e-05, 0.999999, 0.00135802, -0.000589065, -0.00135808, 0.999999, 0, 0, 0)
material_override = ExtResource("5_50gph")

[node name="CSGSphere3D" type="CSGSphere3D" parent="CSGCombiner3D"]
[node name="CSGSphere3D" type="CSGSphere3D" parent="Lightbulb"]
radius = 0.05
radial_segments = 36
rings = 12

[node name="CSGCylinder3D" type="CSGCylinder3D" parent="CSGCombiner3D"]
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="Lightbulb"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0485739, 0)
radius = 0.02
height = 0.03
sides = 36

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_8a76q")
}

[node name="Slider" parent="." instance=ExtResource("6_mhjlm")]
transform = Transform3D(1.91069e-15, 4.37114e-08, 1, 1, -4.37114e-08, 0, 4.37114e-08, 1, -4.37114e-08, 0.08, 0, 0)
max = 100.0
Expand Down
Loading

0 comments on commit 9f2cb27

Please sign in to comment.