-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScriptBuilder.cpp
50 lines (39 loc) · 1.43 KB
/
ScriptBuilder.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
#include "ScriptBuilder.h"
#include <filesystem>
#include <fstream>
#include "App.h"
#include "ConsoleApp.h"
#include "json.hpp"
#include "Libdragon.h"
#include "generated/generated.h"
bool ScriptBuilder::CreateScriptFile(const ProjectSettings &project_settings, const char *script_name) {
const std::string script_folder = project_settings.project_directory + "/src/scripts/";
const std::string script_json_folder = project_settings.project_directory + "/.ngine/scripts/";
std::filesystem::create_directories(script_folder);
std::filesystem::create_directories(script_json_folder);
{
std::string filepath = script_json_folder + script_name + ".script.json";
if (std::filesystem::exists(filepath)) {
console.AddLog("Script with the same name already exists.");
return false;
}
nlohmann::json json;
json["name"] = script_name;
std::ofstream file(filepath);
file << json.dump(4) << std::endl;
file.close();
}
{
std::string filepath = script_folder + script_name;
std::string header_name = filepath + ".script.h";
FILE *filestream = fopen(header_name.c_str(), "w");
fprintf(filestream, script_blank_gen_h, script_name, script_name, script_name, script_name);
fclose(filestream);
std::string c_name = filepath + ".script.c";
filestream = fopen(c_name.c_str(), "w");
fprintf(filestream, script_blank_gen_c, script_name, script_name, script_name, script_name,
script_name);
fclose(filestream);
}
return true;
}