2025-10-21 17:54:43 +02:00
|
|
|
class_name GridNode extends Node2D
|
2025-10-22 01:45:25 +02:00
|
|
|
|
|
|
|
|
# Setting location and offset automatically adjusts position
|
2025-10-21 16:06:16 +02:00
|
|
|
@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()
|
2025-10-21 16:06:16 +02:00
|
|
|
@export var depth : int
|
|
|
|
|
|
2025-10-22 01:45:25 +02:00
|
|
|
# Setting the global position automatically adjusts location and offset
|
2025-10-21 16:06:16 +02:00
|
|
|
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
|
|
|
|
|
|
2025-10-22 01:45:25 +02:00
|
|
|
# Generates position from location and offset
|
2025-10-21 16:06:16 +02:00
|
|
|
func update_position():
|
|
|
|
|
global_position = Grid.get_world_position(location, offset)
|
|
|
|
|
|
|
|
|
|
func _enter_grid() -> void:
|
|
|
|
|
update_position()
|
2025-10-03 11:31:45 +02:00
|
|
|
|
2025-10-22 01:45:25 +02:00
|
|
|
# Constructor for Grid Nodes
|
|
|
|
|
func _init(_location = Vector2.ZERO, _offset = Vector2.ZERO):
|
2025-10-21 16:06:16 +02:00
|
|
|
location = _location
|
|
|
|
|
offset = _offset
|
2025-10-22 03:04:15 +02:00
|
|
|
|
|
|
|
|
static func random_at(_location):
|
|
|
|
|
var rand_offset = Vector2(randf_range(60, 240), randf_range(90, 270))
|
|
|
|
|
return GridNode.new(_location, rand_offset)
|