bug fixes and improvements

This commit is contained in:
Nitwel 2023-11-14 00:51:48 +01:00
parent 94eb0fec7f
commit 91bd0403c4
7 changed files with 69 additions and 32 deletions

View File

@ -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:
animation.play("light")
shape.material_override.albedo_color = color_off.lerp(color_on, brightness / 255.0)
else:
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)

View File

@ -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 = [{
@ -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")

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9a91a5382c57467807e4afe3a1d52a1ce762977812c0ed7822b73bf440f32b35
size 263
oid sha256:ebf5147aa65e1f7aad1fee303f502e0ffce7e8863187b0e2a68377f38a0f3997
size 248

View File

@ -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

View File

@ -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")

View File

@ -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()

View File

@ -60,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