clean sticker code
This commit is contained in:
parent
2da91253a7
commit
e51b395664
1 changed files with 19 additions and 14 deletions
|
@ -8,7 +8,12 @@ class_name Sticker extends Area2D
|
||||||
## and for the sprites.
|
## and for the sprites.
|
||||||
|
|
||||||
#region Exported variables
|
#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")
|
@export_group("Nodes")
|
||||||
## The look of the object. If it's multiple sprites, they should be under one main sprite
|
## The look of the object. If it's multiple sprites, they should be under one main sprite
|
||||||
@export var WorldSprite:Sprite2D
|
@export var WorldSprite:Sprite2D
|
||||||
|
@ -19,6 +24,9 @@ class_name Sticker extends Area2D
|
||||||
set(new_area):
|
set(new_area):
|
||||||
if(new_area != self):
|
if(new_area != self):
|
||||||
DetectionArea = new_area
|
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:
|
else:
|
||||||
printerr("DetectionArea cannot be the sticker itself")
|
printerr("DetectionArea cannot be the sticker itself")
|
||||||
@export_group("Material")
|
@export_group("Material")
|
||||||
|
@ -46,6 +54,8 @@ func _get_configuration_warnings():
|
||||||
return ["This node should have a parent"]
|
return ["This node should have a parent"]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
collision_layer = 2
|
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
|
# 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)
|
print("area exited",area)
|
||||||
detected_zones.erase(area)
|
detected_zones.erase(area)
|
||||||
|
|
||||||
func _process(_delta):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
## When the sticker is released
|
## When the sticker is released
|
||||||
func on_released(_CastResult:Array=[]):
|
func on_released(_CastResult:Array=[]):
|
||||||
|
@ -108,14 +115,16 @@ func on_released(_CastResult:Array=[]):
|
||||||
Grabbed = false
|
Grabbed = false
|
||||||
#Need a traceresult to know if it should stay in the stickerstate or be released in the world
|
#Need a traceresult to know if it should stay in the stickerstate or be released in the world
|
||||||
if(detected_solids.size()==0):
|
if(detected_solids.size()==0):
|
||||||
get_parent().top_level = false
|
updateStickerMode(false)
|
||||||
disable_ChildNodes_collisions(false)
|
|
||||||
update_ChildNodes_visibilty(true)
|
|
||||||
Sticker_mode = false
|
|
||||||
on_unhover() #security,but i don't like it
|
on_unhover() #security,but i don't like it
|
||||||
get_parent().reparent(MapManager.current_scene.get_child(0))
|
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():
|
func on_click():
|
||||||
print(self," clicked")
|
print(self," clicked")
|
||||||
|
@ -147,12 +156,8 @@ func on_unhover():
|
||||||
|
|
||||||
|
|
||||||
func on_grab(_offset:Vector2=Vector2(0.0,0.0)):
|
func on_grab(_offset:Vector2=Vector2(0.0,0.0)):
|
||||||
Sticker_mode = true
|
updateStickerMode(true)
|
||||||
|
|
||||||
get_parent().top_level = true
|
|
||||||
get_parent().reparent(MapManager)
|
get_parent().reparent(MapManager)
|
||||||
update_ChildNodes_visibilty(false)
|
|
||||||
disable_ChildNodes_collisions(true)
|
|
||||||
Grabbed = true
|
Grabbed = true
|
||||||
|
|
||||||
func update_ChildNodes_visibilty(_visible:bool=true):
|
func update_ChildNodes_visibilty(_visible:bool=true):
|
||||||
|
|
Loading…
Reference in a new issue