Skip to content

Commit 6354580

Browse files
committed
Camera config loading
1 parent a0978b4 commit 6354580

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

src/editor/JulGameEditor/Components/CameraWindow.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,20 @@ function show_camera_window(this::CameraWindow)
9898
# CImGui.ColorEdit4("Background Color", Ref(color_r), Ref(color_g), Ref(color_b), Ref(color_a))
9999
# this.camera.backgroundColor = (color_r, color_g, color_b, color_a)
100100
CImGui.PopItemWidth()
101-
102-
@cstatic color=Cfloat[114/255, 144/255, 154/255, 200/255] backup_color=Cfloat[0,0,0,0] saved_palette_init=true saved_palette=fill(ImVec4(0,0,0,0), 32) alpha_preview=true alpha_half_preview=true drag_and_drop=true options_menu=true hdr=false begin
101+
color = (Cfloat(this.camera.backgroundColor[1]/255), Cfloat(this.camera.backgroundColor[2]/255), Cfloat(this.camera.backgroundColor[3]/255), Cfloat(this.camera.backgroundColor[4]/255))
102+
colorCfloat = Cfloat[color[1], color[2], color[3], color[4]]
103+
@cstatic alpha_preview=true alpha_half_preview=true drag_and_drop=true options_menu=true hdr=false begin
103104
show_help_marker("Right-click on the individual color widget to show options.")
104105
CImGui.SameLine()
105106
misc_flags = (hdr ? CImGui.ImGuiColorEditFlags_HDR : 0) | (drag_and_drop ? 0 : CImGui.ImGuiColorEditFlags_NoDragDrop) | (alpha_half_preview ? CImGui.ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? CImGui.ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : CImGui.ImGuiColorEditFlags_NoOptions)
106107
misc_flags |= CImGui.ImGuiColorEditFlags_AlphaBar
107108

108109
CImGui.Text("Color widget RGBA:")
109-
CImGui.ColorEdit4("Background##2", color, CImGui.ImGuiColorEditFlags_DisplayRGB | misc_flags)
110+
CImGui.ColorEdit4("Background##2", colorCfloat, CImGui.ImGuiColorEditFlags_DisplayRGB | misc_flags)
110111
if CImGui.IsItemEdited()
111112
println("Color changed to: ", color)
112113
# update the camera background color rgba
113-
this.camera.backgroundColor = (UInt8(round(color[1]*255)), UInt8(round(color[2]*255)), UInt8(round(color[3]*255)), UInt8(round(color[4]*255)))
114+
this.camera.backgroundColor = (UInt8(round(colorCfloat[1]*255)), UInt8(round(colorCfloat[2]*255)), UInt8(round(colorCfloat[3]*255)), UInt8(round(colorCfloat[4]*255)))
114115
end
115116
CImGui.SetColorEditOptions(CImGui.ImGuiColorEditFlags_Float | CImGui.ImGuiColorEditFlags_HDR | CImGui.ImGuiColorEditFlags_PickerHueWheel)
116117
end # @cstatic

src/editor/JulGameEditor/Editor.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,12 @@ module Editor
166166
if confirmation_dialog(currentDialog) == "ok" && currentSceneName != ""
167167
if currentSceneMain === nothing
168168
currentSceneMain = load_scene(currentScenePath, renderer)
169-
currentSceneMain.scene.camera = gameCamera
170-
#TODO: currentSceneMain.cameraBackgroundColor = (50, 50, 50)
169+
gameCamera = currentSceneMain.scene.camera
170+
cameraWindow.camera = gameCamera
171171
else
172172
JulGame.change_scene(String(currentSceneName))
173+
gameCamera = currentSceneMain.scene.camera
174+
cameraWindow.camera = gameCamera
173175
end
174176
end
175177
elseif currentDialog[] == "New Scene"

src/engine/SceneManagement/SceneBuilder.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module SceneBuilderModule
114114
scene = deserialize_scene(joinpath(BasePath, "scenes", this.scene))
115115
MAIN.scene.entities = scene[1]
116116
MAIN.scene.uiElements = scene[2]
117+
MAIN.scene.camera = scene[3]
117118

118119
for uiElement in MAIN.scene.uiElements
119120
if "$(typeof(uiElement))" == "JulGame.UI.TextBoxModule.Textbox" && !uiElement.isWorldEntity
@@ -190,6 +191,8 @@ module SceneBuilderModule
190191
end
191192
end
192193

194+
MAIN.scene.camera = scene[3]
195+
193196
for entity in MAIN.scene.entities
194197
if entity.persistentBetweenScenes #TODO: Verify if the entity is in it's first scene. If it is, don't skip the scripts.
195198
continue

src/engine/SceneManagement/SceneLoader.jl

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module SceneLoaderModule
4949
JulGame.MAIN = JulGame.Main(Float64(1.0))
5050
#println("Loading scene $sceneFileName from $projectPath")
5151
scene = Scene("$sceneFileName", "$projectPath")
52-
52+
5353
SceneBuilderModule.load_and_prepare_scene(;this=scene)
5454

5555
return MAIN
@@ -69,25 +69,7 @@ module SceneLoaderModule
6969
7070
"""
7171
function get_project_path_from_full_scene_path(scenePath::String)
72-
projectPath = ""
73-
dirArray = length(split(scenePath, "/")) > 1 ? split(scenePath, "/") : split(scenePath, "\\")
74-
counter = 1
75-
for dir in dirArray
76-
if counter >= length(dirArray)-1
77-
continue
78-
elseif counter == 1
79-
projectPath = "$dir\\"
80-
else
81-
projectPath = joinpath(projectPath, dir)
82-
end
83-
counter += 1
84-
end
85-
86-
if startswith(projectPath, "\\/")
87-
projectPath = projectPath[2:end]
88-
end
89-
90-
return projectPath
72+
return dirname(dirname(scenePath))
9173
end
9274

9375
export get_scene_file_name_from_full_scene_path

src/engine/SceneManagement/SceneReader.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module SceneReaderModule
22
using JSON3
33
using ...AnimatorModule
44
using ...AnimationModule
5+
using ...CameraModule
56
using ...ColliderModule
67
using ...CircleColliderModule
78
using ...EntityModule
@@ -87,20 +88,25 @@ module SceneReaderModule
8788
end
8889

8990
for entity in entities
90-
if haskey(childParentDict, string(entity.id))
91-
parentId = childParentDict[string(entity.id)]
92-
for e in entities
93-
if string(e.id) == string(parentId)
94-
entity.parent = e
95-
end
91+
if haskey(childParentDict, string(entity.id))
92+
parentId = childParentDict[string(entity.id)]
93+
for e in entities
94+
if string(e.id) == string(parentId)
95+
entity.parent = e
9696
end
9797
end
98+
end
9899
end
99-
100100
uiElements = deserialize_ui_elements(json.UIElements)
101-
101+
camera = Camera(Vector2(500,500), Vector2f(),Vector2f(), C_NULL)
102+
if haskey(json, "Camera")
103+
camera = Camera(Vector2(json.Camera.size.x, json.Camera.size.y), Vector2f(json.Camera.position.x, json.Camera.position.y), Vector2f(json.Camera.offset.x, json.Camera.offset.y), C_NULL)
104+
camera.backgroundColor = (json.Camera.backgroundColor.r, json.Camera.backgroundColor.g, json.Camera.backgroundColor.b, json.Camera.backgroundColor.a)
105+
end
106+
102107
push!(res, entities)
103108
push!(res, uiElements)
109+
push!(res, camera)
104110
return res
105111
catch e
106112
@error string(e)

0 commit comments

Comments
 (0)