summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/app.hpp1
-rw-r--r--editor/events.cpp1
-rw-r--r--editor/imgui.cpp12
-rw-r--r--editor/keys.hpp5
-rw-r--r--editor/save.cpp7
-rw-r--r--editor/update.cpp17
6 files changed, 32 insertions, 11 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index a2d036e4..776b0fcf 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -91,6 +91,7 @@ private:
void do_quicksave();
void do_quickload();
+ void do_new_file();
void draw_editor_pane(float main_menu_height);
void draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const std::shared_ptr<tile_atlas>& atlas);
diff --git a/editor/events.cpp b/editor/events.cpp
index 56d35bf9..426acac4 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -129,6 +129,7 @@ auto app::resolve_keybinding(int k_, int mods_) const -> std::tuple<key, int>
case SDLK_F5: return { key_quicksave, mods };
case SDLK_F9: return { key_quickload, mods };
case SDLK_q | CTRL: return { key_quit, mods };
+ case SDLK_n | CTRL: return { key_new_file, mods };
}
}
}
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 59196e6f..1b219561 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -39,9 +39,17 @@ float app::draw_main_menu()
ImGui::MenuItem("Close");
ImGui::Separator();
#endif
- bool do_quit = false;
+ bool do_new = false, do_quickload = false, do_quit = false;
+ ImGui::MenuItem("New", nullptr, &do_new);
+ ImGui::Separator();
+ ImGui::MenuItem("Load quicksave", nullptr, &do_quickload);
+ ImGui::Separator();
ImGui::MenuItem("Quit", "Ctrl+Q", &do_quit);
- if (do_quit)
+ if (do_new)
+ do_key(key_new_file, kmod_none);
+ else if (do_quickload)
+ do_key(key_quickload, kmod_none);
+ else if (do_quit)
do_key(key_quit, kmod_none);
}
if (auto b = begin_menu("Mode"))
diff --git a/editor/keys.hpp b/editor/keys.hpp
index b74d5557..1f56cb69 100644
--- a/editor/keys.hpp
+++ b/editor/keys.hpp
@@ -14,11 +14,14 @@ enum kmod : int {
enum key : unsigned {
key_noop,
key_camera_up, key_camera_left, key_camera_right, key_camera_down, key_camera_reset,
+ key_NO_REPEAT,
key_rotate_tile,
key_mode_none, key_mode_floor, key_mode_walls, key_mode_scenery,
+ key_GLOBAL,
+ key_new_file,
key_quit,
key_quicksave, key_quickload,
- key_COUNT, key_MIN = key_noop, key_NO_REPEAT = key_rotate_tile, key_GLOBAL = key_quit,
+ key_COUNT, key_MIN = key_noop,
};
} // namespace floormat
diff --git a/editor/save.cpp b/editor/save.cpp
index e3d917fa..c05f3e5f 100644
--- a/editor/save.cpp
+++ b/editor/save.cpp
@@ -48,4 +48,11 @@ void app::do_quickload()
fputs("done\n", stderr); fflush(stderr);
}
+void app::do_new_file()
+{
+ auto& w = M->world();
+ w = world{};
+ maybe_initialize_chunk_(chunk_coords{}, w[chunk_coords{}]);
+}
+
} // namespace floormat
diff --git a/editor/update.cpp b/editor/update.cpp
index 0de85536..5dd48868 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -15,16 +15,14 @@ void app::maybe_initialize_chunk_(const chunk_coords& pos, chunk& c)
constexpr auto N = TILE_MAX_DIM;
for (auto [x, k, pt] : c) {
-#if defined FM_NO_BINDINGS
- const auto& atlas = floor1;
+#if 1
+ const auto& atlas = _floor1;
#else
const auto& atlas = pt.x == N/2 || pt.y == N/2 ? _floor2 : _floor1;
#endif
x.ground() = { atlas, variant_t(k % atlas->num_tiles()) };
}
-#ifdef FM_NO_BINDINGS
- const auto& wall1 = floor1, wall2 = floor1;
-#endif
+#if 0
constexpr auto K = N/2;
c[{K, K }].wall_north() = { _wall1, 0 };
c[{K, K }].wall_west() = { _wall2, 0 };
@@ -33,6 +31,7 @@ void app::maybe_initialize_chunk_(const chunk_coords& pos, chunk& c)
c[{K+3, K+1}].scenery() = { scenery::door, _door, rotation::N, };
c[{ 3, 4 }].scenery() = { scenery::generic, _table, rotation::W, };
c[{K, K+1}].scenery() = { scenery::generic, _control_panel, rotation::N, scenery::frame_t{0}, pass_mode::pass };
+#endif
c.mark_modified();
}
@@ -88,7 +87,8 @@ void app::do_key(key k, int mods)
switch (k)
{
default:
- fm_warn("unhandled key: '%zu'", std::size_t(k));
+ if (k >= key_NO_REPEAT)
+ fm_warn("unhandled key: '%zu'", std::size_t(k));
return;
case key_rotate_tile:
if (auto* ed = _editor.current_tile_editor())
@@ -108,6 +108,8 @@ void app::do_key(key k, int mods)
return do_quicksave();
case key_quickload:
return do_quickload();
+ case key_new_file:
+ return do_new_file();
case key_quit:
return M->quit(0);
}
@@ -116,7 +118,7 @@ void app::do_key(key k, int mods)
void app::apply_commands(const key_set& keys)
{
using value_type = key_set::value_type;
- for (value_type i = key_NO_REPEAT; i < key_COUNT; i++)
+ for (value_type i = key_MIN; i < key_NO_REPEAT; i++)
if (const auto k = key(i); keys[k])
do_key(k, key_modifiers[i]);
}
@@ -138,7 +140,6 @@ void app::update(float dt)
apply_commands(keys);
update_world(dt);
do_camera(dt, keys, get_key_modifiers());
- update_cursor_tile(cursor.pixel);
clear_non_repeated_keys();
if (clickable_scenery* s = find_clickable_scenery(cursor.pixel))