-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
79 lines (64 loc) · 2.79 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.IO;
using DemonCastle.Editor;
using DemonCastle.Editor.FileInfo;
using DemonCastle.Game;
using DemonCastle.Game.SetupScreen;
using DemonCastle.ProjectFiles.Projects.Data;
using DemonCastle.ProjectFiles.Projects.Resources;
using DemonCastle.ProjectSelection;
using Godot;
namespace DemonCastle;
public partial class Main : Control {
protected GameSetup? GameSetup { get; set; }
protected EditorSpace? EditorSpace { get; set; }
public override void _Ready() {
base._Ready();
LoadProjectMenuView();
InputActions.RegisterActions();
var arguments = new CliArguments();
var projectPath = arguments.ProjectPath;
if (projectPath == null) return;
var projectResources = new ProjectResources(Path.GetDirectoryName(projectPath) ?? throw new DirectoryNotFoundException());
var project = projectResources.GetProject(projectPath);
LoadPlayProjectView(projectResources, project);
}
private void LoadProjectMenuView() {
ClearChildren();
GetWindow().Mode = Window.ModeEnum.Windowed;
GetWindow().Title = "DemonCastle";
ProjectSelectionMenu projectSelectionMenu;
AddChild(projectSelectionMenu = new ProjectSelectionMenu());
projectSelectionMenu.SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect, margin: 5);
projectSelectionMenu.ProjectRun += LoadPlayProjectView;
projectSelectionMenu.ProjectEdit += LoadEditProjectView;
}
protected void LoadPlayProjectView(ProjectResources resources, ProjectInfo project) {
ClearChildren();
GetWindow().Mode = Window.ModeEnum.Maximized;
GetWindow().Title = $"DemonCastle - {project.Name}";
GameRunner gameRunner;
AddChild(gameRunner = new GameRunner(resources, project));
gameRunner.SetAnchorsPreset(LayoutPreset.FullRect);
}
private void LoadEditProjectView(ProjectResources resources, ProjectInfo project) {
ClearChildren();
GetWindow().Mode = Window.ModeEnum.Maximized;
GetWindow().Title = $"DemonCastle - {project.Name}";
var projectPreferences = LoadProjectPreferences(resources);
AddChild(EditorSpace = new EditorSpace(resources, project, projectPreferences));
EditorSpace.GoToProjectMenu += LoadProjectMenuView;
}
private static ProjectPreferencesInfo LoadProjectPreferences(ProjectResources resources) {
var root = resources.GetRoot();
var preferencesFile = root.GetFile(".demoncastle/preferences.json");
if (!preferencesFile.FileExists()) {
preferencesFile.CreateFile("{}");
}
return ProjectPreferencesInfo.Load(preferencesFile, resources);
}
private void ClearChildren() {
foreach (var child in GetChildren()) {
child.QueueFree();
}
}
}