legacy-of-the-ancient-questor/scripts/game/maps/MapContainer.gd

73 lines
1.6 KiB
GDScript

extends Node
var map:Map
var loading: bool
var newSpawnpoint
var newFacing
func _ready():
CommandDispatcher.LOAD_MAP.connect(loadMap)
func loadMap(newMapPath, spawnpoint, facing):
var newMap:Map
CommandDispatcher.PAUSE_PROCESSOR.emit()
loading = true
if (map != null):
map.queue_free()
GameManager.currentMap = newMapPath
ResourceLoader.load_threaded_request(GameManager.currentMap)
newSpawnpoint = spawnpoint
newFacing = facing
#map = load(newMapPath).instantiate()
#
#add_child(map)
#
#map.get_node("Entities").add_child(map.spawnPlayerAtPosition(spawnpoint, facing))
#
#GameManager.currentMap = newMapPath
#
#CommandDispatcher.WAIT_FOR_COMMAND.emit()
func _unhandled_key_input(event):
var direction
if (Input.is_action_pressed("ui_right")):
direction = Map.Direction.East
if (Input.is_action_pressed("ui_left")):
direction = Map.Direction.West
if (Input.is_action_pressed("ui_up")):
direction = Map.Direction.North
if (Input.is_action_pressed("ui_down")):
direction = Map.Direction.South
if (direction != null):
CommandDispatcher.PROCESS_COMMAND.emit(MoveCommand.new(direction))
func _process(delta: float) -> void:
if(loading):
if(ResourceLoader.load_threaded_get_status(GameManager.currentMap) == ResourceLoader.THREAD_LOAD_LOADED):
loading = false
map = ResourceLoader.load_threaded_get(GameManager.currentMap).instantiate()
call_deferred("add_child", map)
map.spawnPlayerAtPosition(newSpawnpoint, newSpawnpoint)
CommandDispatcher.LOAD_COMPLETE.emit()
CommandDispatcher.WAIT_FOR_COMMAND.emit()