The_Dark_Side_of_Earth/vines_petals/vine_node.gd

40 lines
1 KiB
GDScript

class_name VineNode extends Node2D
@export var vine : Vine
@export var location : Vector2 :
set(new_loc):
location = Global.vec_mod(new_loc, Grid.num_collumns, true)
@export var offset : Vector2
@export var depth : int
func _get(property: StringName) -> Variant:
if property == "position":
update_position()
return position
if property == "global_position":
update_position()
return global_position
return null
func _set(property: StringName, value: Variant) -> bool:
if property == "global_position":
location = Grid.get_location_from_world_pos(value)
offset = Grid.get_offset_from_world_pos(value)
update_position()
return true
if property == "position":
update_position()
return false
return false
func update_position():
global_position = Grid.get_world_position(location, offset)
func _enter_grid() -> void:
update_position()
func _init(_vine = null, _location = Vector2.ZERO, _offset = Vector2.ZERO, _depth = 0):
vine = _vine
location = _location
offset = _offset
depth = _depth