The_Dark_Side_of_Earth/utils/grid_node.gd

34 lines
969 B
GDScript3
Raw Normal View History

2025-10-21 17:54:43 +02:00
class_name GridNode extends Node2D
# Setting location and offset automatically adjusts position
@export var location : Vector2 :
set(new_loc):
location = Global.vec_mod(new_loc, Grid.num_collumns, true)
2025-10-21 17:54:43 +02:00
update_position()
@export var offset : Vector2 :
set(new_offset):
offset = new_offset
update_position()
@export var depth : int
# Setting the global position automatically adjusts location and offset
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
return false
# Generates position from location and offset
func update_position():
global_position = Grid.get_world_position(location, offset)
func _enter_grid() -> void:
update_position()
# Constructor for Grid Nodes
func _init(_location = Vector2.ZERO, _offset = Vector2.ZERO):
location = _location
offset = _offset