summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-09-25 15:57:24 -0400
committerJonathan Bradley <jcb@pikum.xyz>2023-09-25 15:57:24 -0400
commitae11f06d5e804669c0138c9e263f937af94ac059 (patch)
treea46f1defea387c51dc5f6d7ba91e1c4ea0552113 /src
parent086fa2fa5fb8fe1ead980e136ce4aa5193b507a9 (diff)
create entity type via imgui popup - poor error handling
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp76
1 files changed, 75 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 184ca16..325b5e6 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -30,6 +30,8 @@ const char *PKE_FILE_ENTITY_TYPE_IMPORTER_GLTF_ACCESSOR_INDEX_INDEX = "Importer_
char consoleBuffer[consoleBufferCount][consoleLineLength];
long consoleBufferIndex = 0;
+bool shouldCreateEntityType = false;
+EntityType *entityTypeToCreate = nullptr;
void SerializeEntityType(std::ofstream &stream, const EntityType &et) {
char handleStr[19] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' };
@@ -185,6 +187,20 @@ void Game_Tick(double delta) {
* `EntitiesToBeRemoved` for all other ticks to use.
*/
ECS_Tick(delta);
+ if (shouldCreateEntityType) {
+ assert(entityTypeToCreate != nullptr);
+ assert(entityTypeToCreate != CAFE_BABE(EntityType));
+ assert(entityTypeToCreate->entityHandle == EntityHandle_MAX);
+ // TODO this needs to be more elegant
+ int64_t existingEntityTypeIndex = EntityType_FindByTypeCode(entityTypeToCreate->entityTypeCode);
+ if (existingEntityTypeIndex == -1) {
+ entityTypeToCreate->entityHandle = ECS_CreateEntity();
+ EntityType_Load(*entityTypeToCreate);
+ GlobalEntityTypes.Push(*entityTypeToCreate);
+ }
+ Pke_Delete<EntityType>(entityTypeToCreate);
+ shouldCreateEntityType = false;
+ }
}
void RecordImGuiEditorWrapper() {
@@ -273,19 +289,77 @@ void RecordImGuiEntityList() {
ImGui::End();
}
-void RecordImGuiSceneEditor() {
+void RecordImGuiModalCreateEntityType() {
+ if (ImGui::BeginPopupModal("CreateEntityType", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
+ static bool needsReset = true;
+ static char modelsDir[64];
+ static char modelFile[64];
+ static char entityTypeCode[32];
+ if (needsReset) {
+ memset(modelsDir, '\0', 64);
+ memset(modelFile, '\0', 64);
+ memset(entityTypeCode, '\0', 32);
+ entityTypeToCreate = Pke_New<EntityType>();
+ needsReset = false;
+ }
+
+ ImGui::InputText("Models Dir", modelsDir, 63);
+ ImGui::InputText("Model File", modelFile, 63);
+ ImGui::InputText("Entity Type Code", entityTypeCode, 31);
+ ImGui::InputScalar("Starting Instance Count", ImGuiDataType_U32, &entityTypeToCreate->startingInstanceCount);
+ ImGui::InputScalar("GLTF Import Index - Vertex", ImGuiDataType_S16, &entityTypeToCreate->Importer_GLTF.AccessorIndexVertex);
+ ImGui::InputScalar("GLTF Import Index - Normal", ImGuiDataType_S16, &entityTypeToCreate->Importer_GLTF.AccessorIndexNormal);
+ ImGui::InputScalar("GLTF Import Index - UV", ImGuiDataType_S16, &entityTypeToCreate->Importer_GLTF.AccessorIndexUV);
+ ImGui::InputScalar("GLTF Import Index - Index", ImGuiDataType_S16, &entityTypeToCreate->Importer_GLTF.AccessorIndexIndex);
+
+ ImGui::Separator();
+
+ if (ImGui::Button("Create")) {
+ // TODO some type of validation
+
+ char *sModelsDir = Pke_New<char>(strlen(modelsDir) + 1);
+ strncpy(sModelsDir, modelsDir, 63);
+ entityTypeToCreate->modelsDir = sModelsDir;
+
+ char *sModelFile = Pke_New<char>(strlen(modelFile) + 1);
+ strncpy(sModelFile, modelFile, 63);
+ entityTypeToCreate->modelFile = sModelFile;
+
+ char *sEntityTypeCode = Pke_New<char>(strlen(entityTypeCode) + 1);
+ strncpy(sEntityTypeCode, entityTypeCode, 31);
+ entityTypeToCreate->entityTypeCode = sEntityTypeCode;
+ shouldCreateEntityType = true;
+ needsReset = true;
+ ImGui::CloseCurrentPopup();
+ }
+ ImGui::SameLine();
+ if (ImGui::Button("Cancel")) {
+ ImGui::CloseCurrentPopup();
+ }
+
+ ImGui::EndPopup();
+ }
+}
+
+void RecordImGuiSceneEditor() {
{
if (!ImGui::Begin("SceneEditorEntityTypes", &pkeSettings.editorSettings.isShowingSceneEditor)) {
ImGui::End();
return;
}
+ if (ImGui::Button("Create Entity Type")) {
+ ImGui::OpenPopup("CreateEntityType");
+ }
if (ImGui::Button("Save")) {
SaveSceneFile("test.pstf");
}
if (ImGui::Button("Load")) {
LoadSceneFile("test.pstf");
}
+
+ RecordImGuiModalCreateEntityType();
+
ImGui::End();
}
}