Using the new MapGlobal at various parts and switched away from the Grid.resource

This commit is contained in:
awu
2025-12-30 23:38:56 +01:00
parent 858122b8a1
commit 6431603630
7 changed files with 64 additions and 68 deletions

View File

@@ -1,53 +1,16 @@
extends Node
@export var grid: Resource
@onready var _Map: Node = $Map
@onready var _Camera = $CameraController
# Units
var _UnitScene = preload("res://Scenes/Unit/unit.tscn")
var _Units: Array[Unit] = []
# MovingMarker
var _MovingMarkerScene = preload("res://Scenes/Unit/marker.tscn")
var _MovingMarker: Node2D = _MovingMarkerScene.instantiate()
#@export var mapSize: int = 15
@onready var UnitCamera: SmartCamera2D = $SmartCamera2D
@onready var GroundLayer: TileMapLayer = $Map/Ground
var aStarGrid: AStarGrid2D:
set(v): aStarGrid = v;
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
aStarGrid = MapGlobal.GenerateGridFromLayer($Map/Obstacles)
if $Player.is_node_ready():
$Player.setup($Map.getGrid())
$Player.setup(MapGlobal.GetGrid())
$GameBoard/Cursor.moved.connect($Player.setTarget)
$GameBoard/Cursor.accept_pressed.connect($Player.selectUnit)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _createUnit(pos: Vector2i):
var newUnit = _UnitScene.instantiate()
newUnit.set("_spawnPosition", pos)
_Units.append(newUnit as Unit)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("SetMarker"):
print("Action is SetMarker")
# _MovingMarker.global_position = _getMousePosition(event).position
_MovingMarker.position = GroundLayer.local_to_map(event.position)
_MovingMarker.show()
func selectUnitAt(cell: Vector2i):
pass
func _getScreenCenter():
return get_viewport().get_camera_2d().get_screen_center_position()
@@ -55,19 +18,5 @@ func _getScreenCenter():
func _getMousePosition(event: InputEvent):
return get_viewport().get_camera_2d().make_input_local(event)
#func prepareAStarGrid():
# var astarGrid = AStarGrid2D.new()
# astarGrid.cell_size = GroundLayer.tile_set.tile_size
# astarGrid.region = Rect2(Vector2.ZERO, ceil(get_viewport_rect().size / astarGrid.cell_size))
# astarGrid.update()
#
# for id in ObstacleLayer.get_used_cells():
# var data: TileData = ObstacleLayer.get_cell_tile_data(id)
# if data and data.get_custom_data('obstacle'):
# astarGrid.set_point_solid(id)
#
# %GridDisplay.grid = astarGrid
func get_cell_information(cell):
print(cell)