-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectBuilder.cpp
148 lines (107 loc) · 4.79 KB
/
ProjectBuilder.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "ProjectBuilder.h"
#include <cstdio>
#include <filesystem>
#include <thread>
#include "App.h"
#include "ConsoleApp.h"
#include "Content.h"
#include "Libdragon.h"
#include "ThreadCommand.h"
#include "generated/generated.h"
#include "static/static.h"
void create_project_thread(App *app, std::string project_folder) {
app->project.project_settings.project_directory = project_folder;
// create folder if it doesn't exist
const std::filesystem::path project_path(project_folder);
if (!std::filesystem::exists(project_path)) {
console.AddLog("Creating project folder...");
std::filesystem::create_directories(project_path);
}
console.AddLog("Running 'libdragon init' at '%s'...", project_folder.c_str());
if (!Libdragon::InitSync(app)) {
console.AddLog("[error] Failed to initialize libdragon.");
return;
}
console.AddLog("Libdragon initialized.");
console.AddLog("Adding/Removing starting files...");
std::filesystem::path old_main_c_file(project_folder + "/src/main.c");
if (std::filesystem::exists(old_main_c_file)) {
std::filesystem::remove(old_main_c_file);
}
std::filesystem::path vscode_path(project_folder + "/.vscode");
if (!std::filesystem::exists(vscode_path)) {
std::filesystem::create_directories(vscode_path);
}
ProjectBuilder::GenerateStaticFiles(project_folder);
// this file should not be touched later
create_static_file(project_folder + "/Makefile_custom.mk", makefile_custom_mk);
console.AddLog("Adding libdragon-extensions...");
if (!Libdragon::GitSubmoduleAddSync(app,
"https://github.com/stefanmielke/libdragon-extensions.git",
"libs/libdragon-extensions")) {
console.AddLog("[error] Error adding libdragon-extensions. Please add it manually later.");
}
console.AddLog("Creating project settings file...");
ProjectSettings default_project_settings(app);
default_project_settings.project_directory = project_folder;
default_project_settings.SaveToDisk();
console.AddLog("Project settings file created.");
console.AddLog("Project creation complete.");
app->OpenProject(project_folder);
}
void ProjectBuilder::Create(App *app, std::string project_folder) {
std::thread(create_project_thread, app, project_folder).detach();
}
void create_build_files(App *app) {
std::filesystem::remove_all(app->project.project_settings.project_directory + "/build");
generate_game_gen_h(app->project);
generate_makefile_gen(app->project);
std::string setup_path(app->project.project_settings.project_directory + "/src/setup.gen.c");
generate_setup_gen_c(setup_path, app->project.project_settings);
std::string change_scene_path(app->project.project_settings.project_directory +
"/src/scenes/change_scene.gen.c");
generate_change_scene_gen_c(change_scene_path, app->project);
generate_scene_gen_files(app->project);
Content::CreateSprites(app->engine_settings, app->project.project_settings,
app->project.images);
Content::CreateSounds(app->engine_settings, app->project.project_settings, app->project.sounds);
Content::CreateGeneralFiles(app->engine_settings, app->project.project_settings,
app->project.general_files);
Content::CreateFonts(app->engine_settings, app->project.project_settings, app->project.fonts);
Content::CreateTiledMaps(app->engine_settings, app->project.project_settings,
app->project.tiled_maps);
Content::CreateLDtkMaps(app->engine_settings, app->project.project_settings,
app->project.ldtk_maps);
std::string path_to_content_script(app->project.project_settings.project_directory +
"/.ngine/pipeline/content_pipeline_end.term");
if (std::filesystem::exists(path_to_content_script)) {
console.AddLog("-- Custom content pipeline script starts --");
std::ifstream content_end_script(path_to_content_script);
std::string line;
while (std::getline(content_end_script, line)) {
char command[500];
snprintf(command, 500, "%s", line.c_str());
ThreadCommand::QueueCommand(line);
}
content_end_script.close();
console.AddLog("-- Custom content pipeline script ends --");
}
}
void ProjectBuilder::Build(App *app) {
create_build_files(app);
Libdragon::Build(app);
}
void ProjectBuilder::Rebuild(App *app) {
Libdragon::CleanSync(app);
create_build_files(app);
Libdragon::Build(app);
}
void ProjectBuilder::GenerateStaticFiles(const std::string &project_folder) {
std::filesystem::create_directories(project_folder + "/.vscode");
std::filesystem::create_directories(project_folder + "/src/scenes");
create_static_file(project_folder + "/.vscode/c_cpp_properties.json", vs_code_cpp_properties);
create_static_file(project_folder + "/.clang-format", clang_format);
create_static_file(project_folder + "/.gitignore", gitignore);
create_static_file(project_folder + "/src/main.s.c", main_s_c);
create_static_file(project_folder + "/src/scenes/change_scene.s.h", change_scene_s_h);
}