Camera system YAY!!!
This commit is contained in:
49
Scripts/Gameplay/Camera/cCamera.gd
Normal file
49
Scripts/Gameplay/Camera/cCamera.gd
Normal file
@@ -0,0 +1,49 @@
|
||||
class_name cCamera
|
||||
|
||||
var cam: Dictionary
|
||||
var camID: String
|
||||
|
||||
var camGraph = Global.loadJSON("res://Data/cameras.json")
|
||||
|
||||
var name: String
|
||||
var disabled: bool
|
||||
var rendersChart: Dictionary
|
||||
var renders: Dictionary
|
||||
var locationID: String
|
||||
var location: cLocation
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _init(id: String) -> void:
|
||||
camID = id
|
||||
cam = camGraph[camID]
|
||||
|
||||
print("Setting up camera " + 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)
|
||||
|
||||
_loadRenders()
|
||||
|
||||
func _loadRenders():
|
||||
renders = {}
|
||||
for key in rendersChart:
|
||||
var renderPath = rendersChart[key]
|
||||
|
||||
if renderPath == null or not FileAccess.file_exists(renderPath):
|
||||
push_error("Missing render: " + str(renderPath))
|
||||
continue
|
||||
|
||||
renders[key] = load(renderPath)
|
||||
|
||||
func getFeed() -> Texture2D:
|
||||
var hash = location.makeHash()
|
||||
if not renders.has(hash): return null
|
||||
|
||||
return renders[hash]
|
||||
1
Scripts/Gameplay/Camera/cCamera.gd.uid
Normal file
1
Scripts/Gameplay/Camera/cCamera.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bsxrimscxvjck
|
||||
53
Scripts/Gameplay/Camera/cCameraViewer.gd
Normal file
53
Scripts/Gameplay/Camera/cCameraViewer.gd
Normal file
@@ -0,0 +1,53 @@
|
||||
class_name cCameraViewer
|
||||
extends TextureRect
|
||||
|
||||
var defaultTexture: Texture2D
|
||||
|
||||
var activeCamera: cCamera = null
|
||||
var activeCameraID: int = -1
|
||||
var activeTexture: Texture2D = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
clearCamera()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if activeCamera == null:
|
||||
return
|
||||
|
||||
var newTexture = getCameraRender()
|
||||
if newTexture != activeTexture:
|
||||
activeTexture = newTexture
|
||||
renderCamera()
|
||||
|
||||
func setCamera(id: int) -> void:
|
||||
clearCamera()
|
||||
|
||||
activeCameraID = id
|
||||
activeCamera = Global.game.camera
|
||||
|
||||
renderCamera()
|
||||
|
||||
func renderCamera() -> void:
|
||||
if activeTexture == null:
|
||||
self.texture = defaultTexture
|
||||
else:
|
||||
self.texture = activeTexture
|
||||
|
||||
func clearCamera() -> void:
|
||||
activeCamera = null
|
||||
activeCameraID = -1
|
||||
activeTexture = defaultTexture
|
||||
renderCamera()
|
||||
|
||||
|
||||
func getCameraRender() -> Texture2D:
|
||||
if activeCamera == null:
|
||||
return defaultTexture
|
||||
|
||||
var feed = activeCamera.getFeed()
|
||||
|
||||
if feed == null:
|
||||
return defaultTexture
|
||||
|
||||
return feed
|
||||
1
Scripts/Gameplay/Camera/cCameraViewer.gd.uid
Normal file
1
Scripts/Gameplay/Camera/cCameraViewer.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://be6xuapep782t
|
||||
@@ -21,7 +21,8 @@ func main(args: Array, context: Node) -> void:
|
||||
return
|
||||
|
||||
var cam_name = Global.cameraHelper.getName(cam_id)
|
||||
|
||||
var newCam = cCamera.new(str(cam_id))
|
||||
newCam._init(str(cam_id))
|
||||
|
||||
context._print("Camera set to %s" % cam_name.capitalize())
|
||||
|
||||
print(Global.cameraHelper.id_to_name)
|
||||
print(Global.cameraHelper.name_to_id)
|
||||
|
||||
65
Scripts/Gameplay/Location/cLocation.gd
Normal file
65
Scripts/Gameplay/Location/cLocation.gd
Normal file
@@ -0,0 +1,65 @@
|
||||
class_name cLocation
|
||||
|
||||
var locationGraph = Global.locations
|
||||
|
||||
var location: Dictionary
|
||||
var locationID: String
|
||||
|
||||
var name: String
|
||||
var connections: Array
|
||||
|
||||
var enemyTemplate = {
|
||||
"present": false,
|
||||
"state": 0
|
||||
}
|
||||
|
||||
var construct = enemyTemplate.duplicate()
|
||||
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)
|
||||
|
||||
# Set Fields
|
||||
name = location.get("name")
|
||||
connections = location.get("connections")
|
||||
|
||||
func isPresent(character: String) -> bool:
|
||||
match character:
|
||||
"construct":
|
||||
return construct.get("present")
|
||||
"yoshida":
|
||||
return yoshida.get("present")
|
||||
"akers":
|
||||
return akers.get("present")
|
||||
"flesher":
|
||||
return flesher.get("present")
|
||||
return false
|
||||
|
||||
func getState(character: String) -> int:
|
||||
match character:
|
||||
"construct":
|
||||
return construct.get("state")
|
||||
"yoshida":
|
||||
return yoshida.get("state")
|
||||
"akers":
|
||||
return akers.get("state")
|
||||
"flesher":
|
||||
return flesher.get("state")
|
||||
return -1
|
||||
|
||||
func makeHash() -> String:
|
||||
var hash = ""
|
||||
var characters = ["construct", "yoshida", "akers", "flesher"]
|
||||
|
||||
for c in characters:
|
||||
if isPresent(c):
|
||||
hash += c[0]
|
||||
hash += str( getState(c) )
|
||||
|
||||
return hash
|
||||
1
Scripts/Gameplay/Location/cLocation.gd.uid
Normal file
1
Scripts/Gameplay/Location/cLocation.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cor2nfptbpmby
|
||||
Reference in New Issue
Block a user