Fixed up a couple things, first steps towards a location manager

This commit is contained in:
2026-03-27 16:32:52 -07:00
parent 7ba95c5949
commit f9de58d9f7
9 changed files with 111 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
class_name cCamera
var cam: Dictionary
var camID: String
var camID: int
var camGraph = Global.loadJSON("res://Data/cameras.json")
@@ -9,25 +9,23 @@ var name: String
var disabled: bool
var rendersChart: Dictionary
var renders: Dictionary
var locationID: String
var locationID: int
var location: cLocation
# Called when the node enters the scene tree for the first time.
func _init(id: String) -> void:
func _init(id: int) -> void:
camID = id
cam = camGraph[camID]
print("Setting up camera " + camID)
if not camGraph.has(str(camID)):
camID = 0
cam = camGraph[str(camID)]
name = cam.get("name")
disabled = cam.get("disabled")
rendersChart = cam.get("renders")
locationID = str( int( cam.get("location") ) )
location = cLocation.new(locationID)
print(name)
print(disabled)
print(rendersChart)
print(location)
locationID = int( cam.get("location") )
location = Global.locationManager.getLocation(id)
_loadRenders()

View File

@@ -19,10 +19,9 @@ func main(args: Array, context: Node) -> void:
if cam_id == -1:
context._print("Invalid camera ID or name: %s" % input_value)
return
var cam_name = Global.cameraHelper.getName(cam_id)
var newCam = cCamera.new(str(cam_id))
newCam._init(str(cam_id))
var new_camera: cCamera = Global.game.cameras[cam_id]
var cam_name = new_camera.name
context._print("Camera set to %s" % cam_name.capitalize())

View File

@@ -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")

View 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]

View File

@@ -0,0 +1 @@
uid://b8wog1q54q3nj