43 lines
1.3 KiB
GDScript3
43 lines
1.3 KiB
GDScript3
|
|
extends Node3D
|
||
|
|
class_name MapLogic
|
||
|
|
|
||
|
|
signal onCollision
|
||
|
|
|
||
|
|
signal missionLost
|
||
|
|
|
||
|
|
@export var debugObj: PackedScene
|
||
|
|
@export var pathPivot: Node3D
|
||
|
|
@export var drawDebugCubesPathfinding:= false
|
||
|
|
|
||
|
|
@export var pathfindingGridLoader: PathfindingGridLoader
|
||
|
|
var astar : AStar2D
|
||
|
|
|
||
|
|
@export var playerStartPos: Vector3 = Vector3(0,0,0)
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
if pathfindingGridLoader: pathfindingGridLoader.loadGrid()
|
||
|
|
onCollision.emit() #TODO: REMOVE THIS LATER ITS ONLY HERE TO STOP A WARNING
|
||
|
|
|
||
|
|
func looseMission() -> void:
|
||
|
|
missionLost.emit()
|
||
|
|
|
||
|
|
|
||
|
|
func finishAstarSetup() -> void: ##Run this in process or physics process of the child map class
|
||
|
|
if pathfindingGridLoader:
|
||
|
|
if pathfindingGridLoader.loading_done:
|
||
|
|
astar = pathfindingGridLoader.astar
|
||
|
|
print(astar.get_point_count())
|
||
|
|
pathfindingGridLoader.queue_free()
|
||
|
|
|
||
|
|
if drawDebugCubesPathfinding: #Only for debugging
|
||
|
|
for point in astar.get_point_ids():
|
||
|
|
var point_position: Vector2 = astar.get_point_position(point)
|
||
|
|
addObject(debugObj,pathPivot,Vector3(point_position.x,0.2,point_position.y))
|
||
|
|
|
||
|
|
func addObject(AddedObject:PackedScene, Parent: Node, Position: Vector3, Rotation: Vector3= Vector3(0,0,0)):
|
||
|
|
var obj = AddedObject.instantiate()
|
||
|
|
Parent.add_child(obj)
|
||
|
|
obj.position = Position
|
||
|
|
obj.rotation = Rotation
|
||
|
|
return obj
|