Fixed up a couple things, first steps towards a location manager
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
class_name cLocation
|
||||
|
||||
var locationGraph = Global.locations
|
||||
|
||||
var locationGraph: Dictionary
|
||||
var location: Dictionary
|
||||
var locationID: String
|
||||
|
||||
var id: int
|
||||
var name: String
|
||||
var connections: Array
|
||||
|
||||
@@ -18,14 +17,12 @@ var yoshida = enemyTemplate.duplicate()
|
||||
var akers = enemyTemplate.duplicate()
|
||||
var flesher = enemyTemplate.duplicate()
|
||||
|
||||
func _init(id: String):
|
||||
# Set immediate values
|
||||
locationID = id
|
||||
print(locationGraph)
|
||||
print(id)
|
||||
location = locationGraph.get(id)
|
||||
func _init(locationID: int, graph: Dictionary):
|
||||
locationGraph = graph
|
||||
id = locationID
|
||||
|
||||
# Set Fields
|
||||
location = locationGraph.get(str(id))
|
||||
|
||||
name = location.get("name")
|
||||
connections = location.get("connections")
|
||||
|
||||
|
||||
75
Scripts/Gameplay/Location/cLocationManager.gd
Normal file
75
Scripts/Gameplay/Location/cLocationManager.gd
Normal file
@@ -0,0 +1,75 @@
|
||||
class_name cLocationManager
|
||||
extends Node
|
||||
|
||||
var locationsJSON: Dictionary
|
||||
var locations: Array
|
||||
|
||||
enum eCharacter {
|
||||
CONSTRUCT,
|
||||
YOSHIDA,
|
||||
AKERS,
|
||||
FLESHER
|
||||
}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _init() -> void:
|
||||
print("Init location manager")
|
||||
locationsJSON = Global.loadJSON("res://Data/locations.json")
|
||||
|
||||
_cache()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func _cache() -> void:
|
||||
var location: cLocation
|
||||
for l in locationsJSON:
|
||||
location = cLocation.new(int(l), locationsJSON)
|
||||
locations.append(location)
|
||||
|
||||
func setLocationByID(character: eCharacter, currentLocationID: int, newLocationID: int) -> void:
|
||||
|
||||
pass
|
||||
|
||||
func setLocationBy(character: eCharacter, currentLocation: cLocation, newLocation: cLocation) -> void:
|
||||
|
||||
pass
|
||||
|
||||
func getCharacterLocation(character: eCharacter) -> cLocation:
|
||||
|
||||
return null
|
||||
|
||||
func clearLocation(character: eCharacter) -> void:
|
||||
|
||||
pass
|
||||
|
||||
# Mainly for the flesher enemy
|
||||
# Will pick a random location, has the option to exclude locations which are not connected
|
||||
# If the office is picked, it will by default roll back to the hangar to prevent an unfair death
|
||||
func randomLocation(
|
||||
currentLocation: int = 0,
|
||||
teleport: bool = false,
|
||||
allowOffice: bool = false,
|
||||
) -> cLocation:
|
||||
if teleport:
|
||||
var location: cLocation = locations[currentLocation]
|
||||
var validLocations = location.connections
|
||||
|
||||
return validLocations.pick_random()
|
||||
else:
|
||||
var location: cLocation = locations.pick_random()
|
||||
if not allowOffice && location.id == 0: location = locations[1]
|
||||
return location
|
||||
|
||||
func canMove(currentLocation: int, newLocation: int) -> bool:
|
||||
var locationA: cLocation = locations[currentLocation]
|
||||
var locationB: cLocation = locations[newLocation]
|
||||
|
||||
if locationB.connections.has(locationA.id):
|
||||
return true
|
||||
else:
|
||||
return false
|
||||
|
||||
func getLocation(location: int) -> cLocation:
|
||||
return locations[location]
|
||||
1
Scripts/Gameplay/Location/cLocationManager.gd.uid
Normal file
1
Scripts/Gameplay/Location/cLocationManager.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b8wog1q54q3nj
|
||||
Reference in New Issue
Block a user