Skip to content

Commit

Permalink
Core : New project from template, populate config
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrno committed May 7, 2024
1 parent aa40860 commit e9e6617
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 43 deletions.
Binary file modified build/bin/vortex
Binary file not shown.
2 changes: 1 addition & 1 deletion main/include/vortex.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace VortexMaker
VORTEX_API void AddModuleToProject(const std::string &module_name);

VORTEX_API void CreateProject(const std::string &name, const std::string &path);
VORTEX_API void CreateProject(const std::string &name, const std::string &author, const std::string &description, const std::string &path, const std::string &template_name);
VORTEX_API void CreateProject(const std::string &name, const std::string &author, const std::string &version, const std::string &description, const std::string &path, const std::string &template_name);

VORTEX_API void InstallContentOnSystem(const std::string &directory);

Expand Down
23 changes: 10 additions & 13 deletions main/src/templates/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ VORTEX_API void VortexMaker::InstallTemplateOnSystem(const std::string &director
std::string description = json_data["description"].get<std::string>();
std::string author = json_data["author"].get<std::string>();

//std::string origin_path = path.substr(0, path.find_last_of("/"));
// std::string origin_path = path.substr(0, path.find_last_of("/"));
modules_path += "/" + name + "." + version;

VortexMaker::LogInfo("Core", "Installing the module " + name + "...");
Expand Down Expand Up @@ -52,22 +52,19 @@ VORTEX_API void VortexMaker::InstallTemplate(const std::string &name, const std:
// TODO : Search modules registered in project first (if the project have include_system_templates == false)
// Search modules registered in project first
/*...*/
for(auto tem : ctx.IO.sys_templates)

for (auto tem : ctx.IO.sys_templates)
{
if(tem->m_name == name)
if (tem->m_name == name)
{
VortexMaker::LogInfo("Core", "Installing the template \"" + name + "\" ...");

VortexMaker::LogInfo("Core", "Installing the template \"" + name + "\" ...");
std::string cmd = "tar -xvf " + tem->m_path + tem->m_tarball + " --strip-components=1 " + " -C " + path;
std::cout << cmd << std::endl;
system(cmd.c_str());

std::string cmd = "tar -xvf " + tem->m_path + tem->m_tarball + " --strip-components=1 " + " -C " + path;
std::cout << cmd << std::endl;
system(cmd.c_str());

// Puis reprendre le ficheir vortex.condfig et l'overrider

// Puis reprendre le ficheir vortex.condfig et l'overrider
}

}

/*// Search the template registered in the system environment (if not findeed in the system and if the project can see env template)
Expand Down Expand Up @@ -102,7 +99,7 @@ VORTEX_API void VortexMaker::InstallTemplate(const std::string &name, const std:
// TODO : Call Deploy function of the template
std::string cmd = "tar -xvf " + module_path +
std::string cmd = "tar -xvf " + module_path +
// Get the target directory of installation (path)
// Take the tarball, and uncompress it into destination
Expand Down
23 changes: 21 additions & 2 deletions main/src/vortex/project/create_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,31 @@ void VortexMaker::CreateProject(const std::string& name, const std::string& path
}
}

VORTEX_API void VortexMaker::CreateProject(const std::string &name, const std::string &author, const std::string &description, const std::string &path, const std::string &template_name)
VORTEX_API void VortexMaker::CreateProject(const std::string &name, const std::string &author, const std::string &version, const std::string &description, const std::string &path, const std::string &template_name)
{
VortexMaker::createFolderIfNotExists(path);
VortexMaker::InstallTemplate(template_name, path);

std::string version = VORTEX_VERSION;
std::string vortex_version = VORTEX_VERSION;


std::string config_file = path + "/vortex.config";

// Load JSON data from the project configuration file
auto config_data = VortexMaker::DumpJSON(config_file);

// Project with the old name exists, update its information
config_data["project"]["name"] = name;
config_data["project"]["compatibleWith"] = vortex_version;
config_data["project"]["version"] = version;
config_data["project"]["author"] = author;
config_data["project"]["description"] = description;


// Write the updated JSON data back to the file
std::ofstream output(config_file);
output << config_data.dump(4); // Use pretty print with indentation of 4 spaces
output.close();

// Creating and populating JSON data for vortex.config
/*
Expand Down
3 changes: 3 additions & 0 deletions tools/editor/app/core/ProjectSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,13 @@ void ProjectSettings::Update()
{
std::string oldname = this->ctx->name;

std::string vortex_version = VORTEX_VERSION;

nlohmann::json toolchainData;
toolchainData["project"]["name"] = this->current_save->name;
toolchainData["project"]["author"] = this->current_save->author;
toolchainData["project"]["description"] = this->current_save->description;
toolchainData["project"]["compatibleWith"] = vortex_version;
toolchainData["project"]["type"] = this->current_save->type;
toolchainData["project"]["version"] = this->current_save->version;
toolchainData["project"]["include_system_templates"] = this->current_save->include_system_templates;
Expand Down
61 changes: 34 additions & 27 deletions tools/launcher/app/core/ProjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ static void logo(const std::string &path, int index, int total)
std::shared_ptr<UIKit::Image> _icon = std::make_shared<UIKit::Image>(w, h, UIKit::ImageFormat::RGBA, data);
logos.push_back(_icon);
VX_FREE(data);
ImTextureID addIcon = logos[index]->GetImGuiTextureID(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
textures.push_back(addIcon);

ImTextureID addIcon = logos[index]->GetImGuiTextureID(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
textures.push_back(addIcon);
}

if (index <= textures.size())
Expand Down Expand Up @@ -163,27 +162,26 @@ void ProjectManager::OnImGuiRender()
}

{
ImGuiID _id = ImGui::GetID("TEXT_");
ImGui::BeginChild(_id, ImVec2(0, 100), true);
float oldsize = ImGui::GetFont()->Scale;
ImGui::GetFont()->Scale *= 1.3;
ImGui::PushFont(ImGui::GetFont());
ImGuiID _id = ImGui::GetID("TEXT_");
ImGui::BeginChild(_id, ImVec2(0, 100), true);
float oldsize = ImGui::GetFont()->Scale;
ImGui::GetFont()->Scale *= 1.3;
ImGui::PushFont(ImGui::GetFont());

ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.8f), this->ctx->IO.sys_projects[row]->name.c_str());
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.8f), this->ctx->IO.sys_projects[row]->name.c_str());

ImGui::GetFont()->Scale = oldsize;
ImGui::PopFont();
ImGui::GetFont()->Scale = oldsize;
ImGui::PopFont();

ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), "Last opened ");
ImGui::SameLine();
ImGui::Text(this->ctx->IO.sys_projects[row]->lastOpened.c_str());
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), "Last opened ");
ImGui::SameLine();
ImGui::Text(this->ctx->IO.sys_projects[row]->lastOpened.c_str());

ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), "Author(s) ");
ImGui::SameLine();
ImGui::Text(this->ctx->IO.sys_projects[row]->author.c_str());
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), "Author(s) ");
ImGui::SameLine();
ImGui::Text(this->ctx->IO.sys_projects[row]->author.c_str());

ImGui::EndChild();

ImGui::EndChild();
}

if (ImGui::Button("Open"))
Expand Down Expand Up @@ -214,11 +212,19 @@ void ProjectManager::OnImGuiRender()
{
{
ImGui::BeginChild("LOGO_", ImVec2(70, 70), true);
if (!project_templates[i]->m_logo_path.empty())
try
{
logo(project_templates[i]->m_logo_path, i, project_templates.size());
}

if (!project_templates[i]->m_logo_path.empty())
{
logo(project_templates[i]->m_logo_path, i, project_templates.size());
}
}
catch (std::exception e)
{
std::cout << e.what() << std::endl;
sleep(5);
}
ImGui::EndChild();
ImGui::SameLine();
}
Expand Down Expand Up @@ -266,7 +272,8 @@ void ProjectManager::OnImGuiRender()
strncpy(buf, s.c_str(), sizeof(buf) - 1);

static char name[128] = "UnknowName";
static char desc[128];
static char desc[128] = "My project description !";
static char version[128] = "1.0.0";
static char auth[128] = "you";
static bool open = true;
{
Expand Down Expand Up @@ -304,6 +311,7 @@ void ProjectManager::OnImGuiRender()
ImGui::InputText("Name", name, 128);
ImGui::InputText("Description", desc, 128);
ImGui::InputText("Authors", auth, 128);
ImGui::InputText("Version", version, 128);

ImGui::Separator();
float oldsize = ImGui::GetFont()->Scale;
Expand All @@ -316,14 +324,14 @@ void ProjectManager::OnImGuiRender()
ImGui::SameLine();
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), selected_template_object->m_proper_name.c_str());
ImGui::Text("Description : ");
ImGui::SameLine();
ImGui::SameLine();
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), selected_template_object->m_description.c_str());
ImGui::Separator();

ImGui::Checkbox("Open the project after creation", &open);
std::string path = s + name;

ImGui::Text("This new project will be install in "); // Fix path and allow project creation + fix core dumped
ImGui::Text("This new project will be install in "); // Fix path and allow project creation + fix core dumped
ImGui::SameLine();
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), path.c_str());

Expand All @@ -333,10 +341,9 @@ void ProjectManager::OnImGuiRender()
}
ImGui::SameLine();


if (ImGui::ImageButtonWithText(addIcon, "Create", ImVec2(this->m_RefreshIcon->GetWidth(), this->m_RefreshIcon->GetHeight())))
{
VortexMaker::CreateProject(name, auth, desc, path, selected_template_object->m_name);
VortexMaker::CreateProject(name, auth, version, desc, path, selected_template_object->m_name);
}
ImGui::EndChild();
}
Expand Down

0 comments on commit e9e6617

Please sign in to comment.