Merge pull request #19 from Nitwel/testing
Improve Interaction and Entities
This commit is contained in:
commit
6bac3640c1
|
@ -1,13 +1,15 @@
|
|||
extends StaticBody3D
|
||||
|
||||
@export var entity_id = "switch.plug_printer_2"
|
||||
@onready var sprite: AnimatedSprite3D = $Icon
|
||||
@onready var animation: AnimationPlayer = $AnimationPlayer
|
||||
@export var color_off = Color(0.23, 0.23, 0.23)
|
||||
@export var color_on = Color(1.0, 0.85, 0.0)
|
||||
|
||||
@onready var shape = $CSGCombiner3D
|
||||
@onready var rod_top = $RodTop
|
||||
@onready var rod_bottom = $RodBottom
|
||||
@onready var slider_knob = $Knob
|
||||
var state = false
|
||||
var brightness = 0 # 0-255
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
@ -20,20 +22,38 @@ func _ready():
|
|||
set_state(new_state["state"] == "on")
|
||||
)
|
||||
|
||||
func set_state(state: bool):
|
||||
func set_state(state: bool, brightness = null):
|
||||
print("set_state ", state, brightness)
|
||||
self.state = state
|
||||
self.brightness = brightness
|
||||
|
||||
if state:
|
||||
animation.play_backwards("light")
|
||||
if brightness == null:
|
||||
shape.material_override.albedo_color = color_on
|
||||
else:
|
||||
shape.material_override.albedo_color = color_off.lerp(color_on, brightness / 255.0)
|
||||
else:
|
||||
animation.play("light")
|
||||
shape.material_override.albedo_color = color_off
|
||||
|
||||
|
||||
|
||||
func _on_click(event):
|
||||
if event.target == self:
|
||||
HomeAdapters.adapter.set_state(entity_id, "on" if !state else "off")
|
||||
set_state(!state)
|
||||
var attributes = {}
|
||||
|
||||
if !state && brightness != null:
|
||||
attributes["brightness"] = int(brightness)
|
||||
|
||||
HomeAdapters.adapter.set_state(entity_id, "on" if !state else "off", attributes)
|
||||
set_state(!state, brightness)
|
||||
else:
|
||||
_on_clickable_on_click(event)
|
||||
|
||||
func _on_press_move(event):
|
||||
if event.target != self:
|
||||
_on_clickable_on_click(event)
|
||||
|
||||
|
||||
func _on_request_completed():
|
||||
pass
|
||||
|
||||
|
@ -51,4 +71,5 @@ func _on_clickable_on_click(event):
|
|||
|
||||
slider_knob.position = new_pos
|
||||
|
||||
HomeAdapters.adapter.set_state(entity_id, "on" if state else "off", {"brightness_pct": int(ratio * 100)})
|
||||
HomeAdapters.adapter.set_state(entity_id, "on" if state else "off", {"brightness": int(ratio * 255)})
|
||||
set_state(state, ratio * 255)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=14 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="Texture2D" uid="uid://b72vsbcvqqxg7" path="res://assets/materials/swich_on.png" id="2_6gn2e"]
|
||||
|
@ -7,7 +7,7 @@
|
|||
[ext_resource type="Material" uid="uid://vce66e7sbc3n" path="res://content/entities/light/light_on.tres" id="5_50gph"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_ukj14"]
|
||||
radius = 0.06
|
||||
radius = 0.05
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_ldpuo"]
|
||||
animations = [{
|
||||
|
@ -23,22 +23,6 @@ animations = [{
|
|||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[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="Animation" id="Animation_afofi"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
|
@ -66,6 +50,22 @@ tracks/1/keys = {
|
|||
"values": [Vector3(0, 0.0492394, -0.0903599)]
|
||||
}
|
||||
|
||||
[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"),
|
||||
|
@ -73,18 +73,22 @@ _data = {
|
|||
}
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_j3pn3"]
|
||||
top_radius = 0.002
|
||||
bottom_radius = 0.002
|
||||
top_radius = 0.004
|
||||
bottom_radius = 0.004
|
||||
height = 0.1
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_tysib"]
|
||||
height = 0.1
|
||||
radius = 0.006
|
||||
radius = 0.01
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_13uml"]
|
||||
albedo_color = Color(0.231373, 0.239216, 0.231373, 1)
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_s8215"]
|
||||
top_radius = 0.004
|
||||
bottom_radius = 0.004
|
||||
height = 0.002
|
||||
material = SubResource("StandardMaterial3D_13uml")
|
||||
top_radius = 0.006
|
||||
bottom_radius = 0.006
|
||||
height = 0.004
|
||||
|
||||
[node name="Light" type="StaticBody3D"]
|
||||
script = ExtResource("1_ykxy3")
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:9a91a5382c57467807e4afe3a1d52a1ce762977812c0ed7822b73bf440f32b35
|
||||
size 263
|
||||
oid sha256:ebf5147aa65e1f7aad1fee303f502e0ffce7e8863187b0e2a68377f38a0f3997
|
||||
size 248
|
||||
|
|
|
@ -6,11 +6,19 @@ extends StaticBody3D
|
|||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
var stateInfo = await HomeAdapters.adapter.get_state(entity_id)
|
||||
label.text = stateInfo["state"]
|
||||
set_text(stateInfo)
|
||||
|
||||
await HomeAdapters.adapter.watch_state(entity_id, func(new_state):
|
||||
label.text = new_state["state"]
|
||||
set_text(new_state)
|
||||
)
|
||||
|
||||
func _on_click(event):
|
||||
pass
|
||||
func set_text(stateInfo):
|
||||
var text = stateInfo["state"]
|
||||
|
||||
if stateInfo["attributes"]["friendly_name"] != null:
|
||||
text = stateInfo["attributes"]["friendly_name"] + "\n" + text
|
||||
|
||||
if stateInfo["attributes"].has("unit_of_measurement") && stateInfo["attributes"]["unit_of_measurement"] != null:
|
||||
text += " " + stateInfo["attributes"]["unit_of_measurement"]
|
||||
|
||||
label.text = text
|
||||
|
|
|
@ -13,7 +13,11 @@ script = ExtResource("1_57ac8")
|
|||
shape = SubResource("SphereShape3D_r20gc")
|
||||
|
||||
[node name="Label" type="Label3D" parent="."]
|
||||
text = "some text"
|
||||
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
|
||||
pixel_size = 0.001
|
||||
text = "some text
|
||||
"
|
||||
font_size = 80
|
||||
|
||||
[node name="Movable" type="Node" parent="."]
|
||||
script = ExtResource("2_fpq5q")
|
||||
|
|
|
@ -6,11 +6,13 @@ var hit_node := Node3D.new()
|
|||
|
||||
func _on_grab_down(event):
|
||||
event.controller.add_child(hit_node)
|
||||
hit_node.global_position = get_parent().global_position
|
||||
hit_node.global_transform = get_parent().global_transform
|
||||
|
||||
func _on_grab_move(event):
|
||||
get_parent().global_position = hit_node.global_position
|
||||
get_parent().global_rotation = hit_node.global_rotation
|
||||
get_parent().global_transform = hit_node.global_transform
|
||||
|
||||
func _on_grab_up(event):
|
||||
event.controller.remove_child(hit_node)
|
||||
|
||||
func _get_configuration_warnings() -> PackedStringArray:
|
||||
var warnings := PackedStringArray()
|
||||
|
|
|
@ -23,20 +23,19 @@ func _handle_move():
|
|||
return
|
||||
|
||||
var distance = ray.get_collision_point().distance_to(_click_point)
|
||||
var collider = ray.get_collider()
|
||||
|
||||
if distance > 0.02:
|
||||
if _moved || distance > 0.02:
|
||||
if _is_pressed:
|
||||
_call_fn(collider, "_on_press_move")
|
||||
_call_fn(_last_collided, "_on_press_move")
|
||||
_moved = true
|
||||
if _is_grabbed:
|
||||
_call_fn(collider, "_on_grab_move")
|
||||
_call_fn(_last_collided, "_on_grab_move")
|
||||
_moved = true
|
||||
|
||||
func _handle_enter_leave():
|
||||
var collider = ray.get_collider()
|
||||
|
||||
if collider == _last_collided:
|
||||
if collider == _last_collided || _is_grabbed || _is_pressed:
|
||||
return
|
||||
|
||||
_call_fn(collider, "_on_ray_enter")
|
||||
|
@ -61,22 +60,20 @@ func _on_button_pressed(button):
|
|||
_call_fn(collider, "_on_grab_down")
|
||||
|
||||
func _on_button_released(button):
|
||||
var collider = ray.get_collider()
|
||||
|
||||
if collider == null:
|
||||
if _last_collided == null:
|
||||
return
|
||||
|
||||
match button:
|
||||
"trigger_click":
|
||||
if _is_pressed:
|
||||
if _moved == false:
|
||||
_call_fn(collider, "_on_click")
|
||||
_call_fn(collider, "_on_press_up")
|
||||
_call_fn(_last_collided, "_on_click")
|
||||
_call_fn(_last_collided, "_on_press_up")
|
||||
_is_pressed = false
|
||||
_moved = false
|
||||
"grip_click":
|
||||
if _is_grabbed:
|
||||
_call_fn(collider, "_on_grab_up")
|
||||
_call_fn(_last_collided, "_on_grab_up")
|
||||
_is_grabbed = false
|
||||
_moved = false
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ var request_timeout := 10.0
|
|||
|
||||
var url := "ws://192.168.33.33:8123/api/websocket"
|
||||
var token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIzZjQ0ZGM2N2Y3YzY0MDc1OGZlMWI2ZjJlNmIxZjRkNSIsImlhdCI6MTY5ODAxMDcyOCwiZXhwIjoyMDEzMzcwNzI4fQ.K6ydLUC-4Q7BNIRCU1nWlI2s6sg9UCiOu-Lpedw2zJc"
|
||||
|
||||
# var url := "wss://8ybjhqcinfcdyvzu.myfritz.net:8123/api/websocket"
|
||||
# var token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjNjU0ZDE3NDc2ZGM0NzU1OGY5NjIzMmM5ZjdjYzE2YSIsImlhdCI6MTY5OTgyMzcxOCwiZXhwIjoyMDE1MTgzNzE4fQ.XHlfnXUd16HaV9XjYrxzuNg23nFFeoEsIsaMVXwRkd8"
|
||||
|
||||
var LOG_MESSAGES := false
|
||||
|
||||
var authenticated := false
|
||||
|
|
Loading…
Reference in New Issue
Block a user