techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/editor.c
diff options
context:
space:
mode:
Diffstat (limited to 'editor.c')
-rw-r--r--editor.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/editor.c b/editor.c
index 0a61ad3..2591cc1 100644
--- a/editor.c
+++ b/editor.c
@@ -67,6 +67,7 @@ typedef enum {
ED_CMD_NONE = -1,
ED_CMD_TIME,
ED_CMD_SPAWN_PREFAB,
+ ED_CMD_SPAWN_MODEL,
ED_CMD_CNT,
} EditorCommand;
@@ -4756,6 +4757,7 @@ panel_commands(Rect bounds, bool input) {
static const cstr names[ED_CMD_CNT] = {
[ED_CMD_TIME] = "Time of day",
[ED_CMD_SPAWN_PREFAB] = "Spawn prefab",
+ [ED_CMD_SPAWN_MODEL] = "Spawn model entity",
};
GuiPanel(bounds, "Command Menu");
@@ -4938,6 +4940,11 @@ panel_draw(EditorPanelContainer container) {
ed.focus_captured = false;
break;
+ case ED_CMD_SPAWN_MODEL:
+ asset_picker_open(ASSET_TAG_MODEL,
+ ASSET_PICK_MDL_ENT_CREATE);
+ break;
+
default:
break;
}
@@ -4962,9 +4969,36 @@ panel_draw(EditorPanelContainer container) {
}
break;
- case ASSET_PICK_MDL_ENT_CREATE:
- /* TODO: */
+ case ASSET_PICK_MDL_ENT_CREATE: {
+ Asset *asset = asset_get(key);
+ EditorAction action =
+ action_begin(ED_ACTION_CREATE, false);
+
+ u64 id = entity_id_from_pid(action.item[0].pid);
+ Entity *ent = entity_get(id);
+
+ ent->tr.pos = main_cam.cam.target;
+ ent->mdl = (ModelCmp){
+ .key = strdup(key),
+ .mdl = &asset->mdl,
+ .has = true,
+ .draw = true,
+ };
+
+ if (ent->name) {
+ free(ent->name);
+ }
+ ent->name = strdup(GetFileNameWithoutExt(key));
+
+ ed.sel_cnt = 1;
+ ed.sel_point = ent->tr.pos;
+ ed.sel_rot = ent->tr.rot;
+
+ action_commit(&action);
+ asset_picker_close();
+ ed.interact = ED_INTERACT_MOVE;
break;
+ }
case ASSET_PICK_MAT_TEX:
editor_set_material(key, asset_picker.mat_idx,