summaryrefslogtreecommitdiff
path: root/editor/editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor.cpp')
-rw-r--r--editor/editor.cpp39
1 files changed, 25 insertions, 14 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 2de4772..159a828 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -57,7 +57,7 @@ const char* const dbgCtrl_ImGui_Toggle = "debug-imgui-toggle";
// TODO editor state (scene vs level)
struct editor_master {
pke_scene *active_scene;
- pk_str target_scene_name;
+ pk_str target_scene_path;
bool shouldLoadScene = false;
bool shouldSaveScene = false;
} editor_mstr;
@@ -186,20 +186,29 @@ void PkeEditor_Tick(double delta) {
});
PkeThreads_Enqueue(threadPoolHandle, task);
}
- if (editor_mstr.shouldSaveScene && editor_mstr.active_scene->file_path.val) {
+ if (editor_mstr.shouldSaveScene && editor_mstr.active_scene) {
+ NULL_CHAR_ARR(file_path, 256);
editor_mstr.shouldSaveScene = false;
- Game_SaveSceneFile(editor_mstr.active_scene->file_path.val);
+ if (editor_mstr.active_scene->file_path.val) {
+ sprintf(file_path, "%.255s", editor_mstr.active_scene->file_path.val);
+ } else {
+ sprintf(file_path, "%.16s", editor_mstr.active_scene->name);
+ }
+ Game_SaveSceneFile(file_path);
shouldRebuildProjectDir = true;
}
- if (editor_mstr.target_scene_name.val != nullptr) {
+ if (editor_mstr.target_scene_path.val != nullptr) {
if (editor_mstr.active_scene != nullptr) {
pke_scene_remove(editor_mstr.active_scene->scene_handle);
}
ActiveCamera = &NullCamera;
- Game_LoadSceneFile(editor_mstr.target_scene_name.val);
- editor_mstr.active_scene = pke_scene_get_by_name(editor_mstr.target_scene_name.val);
- pk_delete<char>(editor_mstr.target_scene_name.val, editor_mstr.target_scene_name.reserved);
- editor_mstr.target_scene_name = {};
+ Game_LoadSceneFile(editor_mstr.target_scene_path.val);
+ std::filesystem::path p(editor_mstr.target_scene_path.val);
+ editor_mstr.active_scene = pke_scene_get_by_name(p.stem().c_str());
+ if (editor_mstr.active_scene) {
+ editor_mstr.active_scene->file_path = editor_mstr.target_scene_path;
+ }
+ editor_mstr.target_scene_path = {};
return;
}
@@ -305,7 +314,9 @@ void PkeEditor_Tick(double delta) {
while (entityInstancesToCreate.Count() > 0) {
EntityType *et = entityInstancesToCreate.Pop();
if (et->createInstanceCallback.func) {
- reinterpret_cast<void(*)()>(et->createInstanceCallback.func)();
+ // TODO function signature
+ // reinterpret_cast<void(*)()>(et->createInstanceCallback.func)();
+ fprintf(stderr, "[%s] Attempted to call EntityType::createInstanceCallback without a function signature", __FILE__);
} else {
EntityType_CreateGenericInstance(et, PkeLevel_Get(pkeSettings.rt.activeLevel), nullptr);
}
@@ -1606,11 +1617,11 @@ void BuildDirRecursive(const std::filesystem::directory_entry &de, fsEntry *dirF
void BuildProjectMenuRecursive(fsEntry &entry) {
if (entry.type == 1) {
if (ImGui::Selectable(entry.name, false, ImGuiSelectableFlags_AllowDoubleClick) && ImGui::IsMouseDoubleClicked(0)) {
- assert(editor_mstr.target_scene_name.val == nullptr);
- editor_mstr.target_scene_name.length = strlen(entry.name);
- editor_mstr.target_scene_name.reserved = editor_mstr.target_scene_name.length + 1;
- editor_mstr.target_scene_name.val = pk_new<char>(editor_mstr.target_scene_name.reserved);
- strcpy(editor_mstr.target_scene_name.val, entry.name);
+ assert(editor_mstr.target_scene_path.val == nullptr);
+ editor_mstr.target_scene_path.length = strlen(entry.name);
+ editor_mstr.target_scene_path.reserved = editor_mstr.target_scene_path.length + 1;
+ editor_mstr.target_scene_path.val = pk_new<char>(editor_mstr.target_scene_path.reserved);
+ strncpy(editor_mstr.target_scene_path.val, entry.name, editor_mstr.target_scene_path.reserved);
ActiveCamera = &NullCamera;
}
} else if (entry.type == 0) {