clean sticker code

This commit is contained in:
Lucas 2024-09-05 11:46:39 +02:00
parent 2da91253a7
commit e51b395664

View file

@ -8,7 +8,12 @@ class_name Sticker extends Area2D
## and for the sprites.
#region Exported variables
@export var Sticker_mode:bool = false
@export var Sticker_mode:bool = false:
set(value):
Sticker_mode = value
## TODO: preview the sticker in editor
if Engine.is_editor_hint():
updateStickerMode(value)
@export_group("Nodes")
## The look of the object. If it's multiple sprites, they should be under one main sprite
@export var WorldSprite:Sprite2D
@ -19,6 +24,9 @@ class_name Sticker extends Area2D
set(new_area):
if(new_area != self):
DetectionArea = new_area
## Detection shapes all in green
for _collisionsshapes in DetectionArea.get_children():
_collisionsshapes.debug_color = Color(0, 0.637, 0.392, 0.42)
else:
printerr("DetectionArea cannot be the sticker itself")
@export_group("Material")
@ -46,6 +54,8 @@ func _get_configuration_warnings():
return ["This node should have a parent"]
return []
func _init():
collision_layer = 2
# TODO: Stickerzone maybe will not need to check everything, and detection will be on the zone detection area only. maybe we want a fallback if sticker area and detection area are the same shape
@ -98,9 +108,6 @@ func _on_area_exited(area:Area2D):
print("area exited",area)
detected_zones.erase(area)
func _process(_delta):
pass
## When the sticker is released
func on_released(_CastResult:Array=[]):
@ -108,14 +115,16 @@ func on_released(_CastResult:Array=[]):
Grabbed = false
#Need a traceresult to know if it should stay in the stickerstate or be released in the world
if(detected_solids.size()==0):
get_parent().top_level = false
disable_ChildNodes_collisions(false)
update_ChildNodes_visibilty(true)
Sticker_mode = false
updateStickerMode(false)
on_unhover() #security,but i don't like it
get_parent().reparent(MapManager.current_scene.get_child(0))
## Change all parameters based on the mode
func updateStickerMode(stickerMode:bool):
get_parent().top_level = stickerMode
disable_ChildNodes_collisions(stickerMode)
update_ChildNodes_visibilty(!stickerMode)
Sticker_mode = stickerMode
func on_click():
print(self," clicked")
@ -147,12 +156,8 @@ func on_unhover():
func on_grab(_offset:Vector2=Vector2(0.0,0.0)):
Sticker_mode = true
get_parent().top_level = true
updateStickerMode(true)
get_parent().reparent(MapManager)
update_ChildNodes_visibilty(false)
disable_ChildNodes_collisions(true)
Grabbed = true
func update_ChildNodes_visibilty(_visible:bool=true):