summaryrefslogtreecommitdiff
path: root/Objects/BuilderObject.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/BuilderObject.gd')
-rw-r--r--Objects/BuilderObject.gd45
1 files changed, 38 insertions, 7 deletions
diff --git a/Objects/BuilderObject.gd b/Objects/BuilderObject.gd
index 2be50da..91465bc 100644
--- a/Objects/BuilderObject.gd
+++ b/Objects/BuilderObject.gd
@@ -3,19 +3,28 @@ extends Node2D
var is_colliding = false
-var is_dragged = false
+var is_dragging = false
+var is_rotating = false
var mouse_offset = Vector2(0,0)
-var last_position = Vector2(0,0)
+var last_position = null
+var rotation_offset_angle = 0
+var last_rotation = 0
+
+# todo: if is focused via click, show rotation picker in edge
func _ready():
$CollisionShape.texture.width = $Area2D/CollisionShape2D.shape.size.x
func _process(_delta):
- if is_dragged:
+ if is_dragging:
position = get_global_mouse_position() + mouse_offset
+
+ if is_rotating:
+ var distance = position - get_global_mouse_position()
+ rotation = atan2(distance.y, distance.x) - rotation_offset_angle
func _on_area_2d_input_event(_viewport, event: InputEvent, _shape_idx):
@@ -30,16 +39,38 @@ func drag_start():
mouse_offset = position - get_global_mouse_position()
last_position = position
- is_dragged = true
+ is_dragging = true
func drag_end():
- if is_dragged and is_colliding:
- if last_position != Vector2(0,0):
+ if is_colliding:
+ if last_position:
position = last_position
else:
queue_free()
- is_dragged = false
+ is_dragging = false
+
+
+func _on_rotate_gui_input(event: InputEvent):
+ get_viewport().set_input_as_handled()
+
+ if event.is_action_pressed("rotate_start"):
+ rotate_start()
+ if event.is_action_released("rotate_start"):
+ rotate_end()
+
+
+func rotate_start():
+ var distance = position - get_global_mouse_position()
+ rotation_offset_angle = atan2(distance.y, distance.x) - rotation
+ last_rotation = rotation
+ is_rotating = true
+
+func rotate_end():
+ if is_colliding:
+ rotation = last_rotation
+
+ is_rotating = false
func _on_area_2d_area_entered(_area):