From 7e9efc174a6a6100cdf65ad2dcc774cf612f17ad Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sun, 14 Aug 2022 19:46:10 +0000 Subject: [PATCH] Editor project --- source/engine/ed_project.c | 95 ++++++++++++++++++++++++++++++++++++++ source/engine/ed_project.h | 18 ++++++++ 2 files changed, 113 insertions(+) create mode 100644 source/engine/ed_project.c create mode 100644 source/engine/ed_project.h diff --git a/source/engine/ed_project.c b/source/engine/ed_project.c new file mode 100644 index 0000000..53e7481 --- /dev/null +++ b/source/engine/ed_project.c @@ -0,0 +1,95 @@ +#include "ed_project.h" + +#include "editor.h" + +void editor_init_project(struct gameproject *gp) +{ +/* + cur_project = gp; + DATA_PATH = strdup(gp->path); + stemlen = strlen(DATA_PATH); + findPrefabs(); + get_levels(); + get_all_files(); + */ +} + +void editor_make_project(char *path) +{ + FILE *f = path_open("w", "%s%s", path, "/project.yugh"); + cur_project = + (struct gameproject *) malloc(sizeof(struct gameproject)); + strncpy(cur_project->name, "New Game", 127); + strncpy(cur_project->path, path, 2048); + vec_add(projects, cur_project); + fwrite(cur_project, sizeof(*cur_project), 1, f); + fclose(f); + + editor_init_project(cur_project); + + editor_save_projects(); +} + +void editor_import_project(char *path) +{ + FILE *f = path_open("r", "%s%s", path, "/project.yugh"); + if (!f) + return; + + struct gameproject *gp = (struct gameproject *) malloc(sizeof(*gp)); + fread(gp, sizeof(*gp), 1, f); + fclose(f); + + vec_add(projects, gp); +} + +void editor_project_btn_gui(struct gameproject *gp) +{ +/* + if (ImGui::Button(gp->name)) + editor_init_project(gp); + + + ImGui::SameLine(); + ImGui::Text("%s", gp->path); + */ +} + +void editor_proj_select_gui() +{ +/* + ImGui::Begin("Project Select"); + + vec_walk(projects, (void (*)(void *)) &editor_project_btn_gui); + + ImGui::InputText("Project import path", setpath, MAXPATH); + ImGui::SameLine(); + if (ImGui::Button("Create")) { + editor_make_project(setpath); + } + ImGui::SameLine(); + if (ImGui::Button("Import")) { + editor_import_project(setpath); + } + + ImGui::End(); + */ +} + + +void editor_load_projects() +{ + FILE *f = fopen("projects.yugh", "r"); + if (!f) + return; + + vec_load(projects, f); + fclose(f); +} + +void editor_save_projects() +{ + FILE *f = fopen("projects.yugh", "w"); + vec_store(projects, f); + fclose(f); +} \ No newline at end of file diff --git a/source/engine/ed_project.h b/source/engine/ed_project.h new file mode 100644 index 0000000..3d92bee --- /dev/null +++ b/source/engine/ed_project.h @@ -0,0 +1,18 @@ +#ifndef ED_PROJECT_H +#define ED_PROJECT_H + +#include "config.h" + +struct gameproject { + char name[127]; + char path[MAXPATH]; +}; + +void editor_init_project(struct gameproject *gp); +void editor_save_projects(); +void editor_load_projects(); +void editor_proj_select_gui(); +void editor_import_project(char *path); +void editor_make_project(char *path); + +#endif \ No newline at end of file