From f9de58d9f7b7431e0a2ae02684d88a925f2987e9 Mon Sep 17 00:00:00 2001 From: CT1138 Date: Fri, 27 Mar 2026 16:32:52 -0700 Subject: [PATCH] Fixed up a couple things, first steps towards a location manager --- Scripts/Characters/NPC/npcConstruct.gd | 11 +-- Scripts/Characters/cCharacter.gd | 9 +-- Scripts/Gameplay/Camera/cCamera.gd | 22 +++--- Scripts/Gameplay/CommandLine/Commands/cam.gd | 7 +- Scripts/Gameplay/Location/cLocation.gd | 17 ++--- Scripts/Gameplay/Location/cLocationManager.gd | 75 +++++++++++++++++++ .../Gameplay/Location/cLocationManager.gd.uid | 1 + Scripts/cGame.gd | 7 +- global.gd | 10 +-- 9 files changed, 111 insertions(+), 48 deletions(-) create mode 100644 Scripts/Gameplay/Location/cLocationManager.gd create mode 100644 Scripts/Gameplay/Location/cLocationManager.gd.uid diff --git a/Scripts/Characters/NPC/npcConstruct.gd b/Scripts/Characters/NPC/npcConstruct.gd index 4bdcbef..3ed42ab 100644 --- a/Scripts/Characters/NPC/npcConstruct.gd +++ b/Scripts/Characters/NPC/npcConstruct.gd @@ -1,12 +1,11 @@ class_name npcConstruct extends cCharacter -var defaultRoom = 0 - signal location_changed(ai, old_location, new_location) signal state_changed(ai, old_state, new_state) var state: int = 0 + func advance_state() -> void: if state >= MAX_STATE: if reset_after_climax: @@ -14,11 +13,10 @@ func advance_state() -> void: else: state += 1 -func _ready(): - super._ready() +func _init(): + super._init() print("Construct Ready") - Global.game.night.hour_changed.connect(_on_hour_changed) func _on_hour_changed(hour: int): @@ -29,6 +27,8 @@ func _on_hour_changed(hour: int): func _process(delta: float) -> void: super._process(delta) + print("Construct: Processing") + print(state) match state: 0: pass # dormant @@ -38,6 +38,7 @@ func _process(delta: float) -> void: 4: pass 5: pass 6: pass + advance_state() if (randi_range(1, 20) > 10): stunted = true diff --git a/Scripts/Characters/cCharacter.gd b/Scripts/Characters/cCharacter.gd index f53aa9b..9d1029a 100644 --- a/Scripts/Characters/cCharacter.gd +++ b/Scripts/Characters/cCharacter.gd @@ -1,6 +1,5 @@ class_name cCharacter extends Node - # --- Parameters --- @export_range(0, 20) var ai_level := 10 @@ -9,6 +8,8 @@ extends Node @export var reset_after_climax := true @export var character_name := "template" +var default_room: cCamera = Global.game.cameras[0] + # --- Constants --- const MAX_STATE := 6 const DEBUG := true @@ -25,10 +26,7 @@ func move_to(room_id: int): current_room = room_id Global.rooms[current_room].add_enemy(self) -func _init(): - _ready() - -func _ready() -> void: +func _init() -> void: randomize() _set_next_interval() @@ -54,6 +52,7 @@ func try_move(delta: float) -> bool: return roll <= ai_level func _process(delta: float) -> void: + print("Test Character Script") if try_move(delta): if(stunted): stunted = false diff --git a/Scripts/Gameplay/Camera/cCamera.gd b/Scripts/Gameplay/Camera/cCamera.gd index 33bc158..cce50ec 100644 --- a/Scripts/Gameplay/Camera/cCamera.gd +++ b/Scripts/Gameplay/Camera/cCamera.gd @@ -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() diff --git a/Scripts/Gameplay/CommandLine/Commands/cam.gd b/Scripts/Gameplay/CommandLine/Commands/cam.gd index 4c2748e..edb9c02 100644 --- a/Scripts/Gameplay/CommandLine/Commands/cam.gd +++ b/Scripts/Gameplay/CommandLine/Commands/cam.gd @@ -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()) + diff --git a/Scripts/Gameplay/Location/cLocation.gd b/Scripts/Gameplay/Location/cLocation.gd index efca9c3..5ea0729 100644 --- a/Scripts/Gameplay/Location/cLocation.gd +++ b/Scripts/Gameplay/Location/cLocation.gd @@ -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") diff --git a/Scripts/Gameplay/Location/cLocationManager.gd b/Scripts/Gameplay/Location/cLocationManager.gd new file mode 100644 index 0000000..8279a54 --- /dev/null +++ b/Scripts/Gameplay/Location/cLocationManager.gd @@ -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] diff --git a/Scripts/Gameplay/Location/cLocationManager.gd.uid b/Scripts/Gameplay/Location/cLocationManager.gd.uid new file mode 100644 index 0000000..fbbd1e0 --- /dev/null +++ b/Scripts/Gameplay/Location/cLocationManager.gd.uid @@ -0,0 +1 @@ +uid://b8wog1q54q3nj diff --git a/Scripts/cGame.gd b/Scripts/cGame.gd index 0d2f5ba..790ca6d 100644 --- a/Scripts/cGame.gd +++ b/Scripts/cGame.gd @@ -2,7 +2,6 @@ class_name cGame var night: cNight var enemies: Dictionary = {} -var locations: Dictionary = {} var cameras: Array = [] var nightStarted = false @@ -11,8 +10,7 @@ var nightCompleted = false func make_cameras(): var camera for key in Global.cameras: - print(key) - camera = cCamera.new(key) + camera = cCamera.new(int(key)) cameras.append(camera) @@ -31,7 +29,6 @@ func make_enemies(): func _setup(): print("Setting up Game") night = cNight.new() - locations = Global.locations - + make_cameras() make_enemies() diff --git a/global.gd b/global.gd index bd66b96..f7f26be 100644 --- a/global.gd +++ b/global.gd @@ -4,17 +4,13 @@ var gameNight = 0 var stars = 0 var cameras -var locations -var cameraHelper var game: cGame +var locationManager: cLocationManager func _ready() -> void: cameras = loadJSON("res://Data/cameras.json") - locations = loadJSON("res://Data/locations.json") - - cameraHelper = hCamera.new() - cameraHelper.setup(cameras) - + locationManager = cLocationManager.new() + begin_game() func begin_game():