33 lines
969 B
GDScript
33 lines
969 B
GDScript
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)
|
|
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
|