summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-28 03:44:47 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-28 04:05:05 +0200
commit37215facfcecb3a4133a740d7fda57c0ef564395 (patch)
tree22e4da3a44314c75977438e9b65eeb9b6e452ded /editor
parentb8a295f01dbb82e19dce92fd3a2048d98554eb75 (diff)
w
Diffstat (limited to 'editor')
-rw-r--r--editor/imgui-raii.cpp14
-rw-r--r--editor/imgui-raii.hpp7
-rw-r--r--editor/inspect-types.cpp34
-rw-r--r--editor/inspect.cpp14
-rw-r--r--editor/tests-private.hpp14
-rw-r--r--editor/tests/hole-test.cpp98
-rw-r--r--editor/vobj-editor.cpp30
7 files changed, 192 insertions, 19 deletions
diff --git a/editor/imgui-raii.cpp b/editor/imgui-raii.cpp
index 8cae0818..b5997c7b 100644
--- a/editor/imgui-raii.cpp
+++ b/editor/imgui-raii.cpp
@@ -1,5 +1,6 @@
#include "imgui-raii.hpp"
#include "compat/assert.hpp"
+#include <cstdio>
#include <Corrade/Containers/StringView.h>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Color.h>
@@ -159,4 +160,17 @@ raii_wrapper begin_child(StringView name, const ImVec2& size, int flags, int win
return {&ImGui::EndChild};
}
+const char* label_left_(StringView label, char* buf, size_t buf_len, float width);
+
+const char* label_left_(StringView label, char* buf, size_t buf_len, float width)
+{
+ std::snprintf(buf, buf_len, "##%s", label.data());
+ float x = ImGui::GetCursorPosX();
+ ImGui::TextEx(label.data(), label.data() + label.size());
+ ImGui::SameLine();
+ ImGui::SetCursorPosX(x + width + ImGui::GetStyle().ItemInnerSpacing.x);
+ ImGui::SetNextItemWidth(-1);
+ return buf;
+}
+
} // namespace floormat::imgui
diff --git a/editor/imgui-raii.hpp b/editor/imgui-raii.hpp
index 63c749bb..59134deb 100644
--- a/editor/imgui-raii.hpp
+++ b/editor/imgui-raii.hpp
@@ -67,4 +67,11 @@ private:
float font_size;
};
+template<std::size_t N>
+const char* label_left(StringView label, char(&buf)[N], float width)
+{
+ const char* label_left_(StringView, char*, size_t, float);
+ return label_left_(label, static_cast<char*>(buf), N, width);
+}
+
} // namespace floormat::imgui
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp
index cb85f574..0968eeec 100644
--- a/editor/inspect-types.cpp
+++ b/editor/inspect-types.cpp
@@ -9,6 +9,7 @@
#include "src/chunk.hpp"
#include "src/critter.hpp"
#include "src/light.hpp"
+#include "src/hole.hpp"
#include <Corrade/Containers/ArrayViewStl.h>
#include <imgui.h>
@@ -140,6 +141,38 @@ template<> struct entity_accessors<door_scenery, inspect_intent_t>
}
};
+template<> struct entity_accessors<hole, inspect_intent_t>
+{
+ static constexpr auto accessors()
+ {
+ using E = Entity<hole>;
+ auto tuple0 = entity_accessors<object, inspect_intent_t>::accessors();
+ auto tuple = std::tuple{
+ E::type<uint8_t>::field{"height"_s,
+ &hole::height,
+ &hole::set_height,
+ [](const hole& x) { return x.flags.is_wall ? st::enabled : st::readonly; },
+ },
+ E::type<uint8_t>::field{"z-offset"_s,
+ &hole::z_offset,
+ &hole::set_z_offset,
+ [](const hole& x) { return x.flags.is_wall ? st::enabled : st::readonly; },
+ constantly(constraints::range<uint8_t>{0, tile_size_z}),
+ },
+ E::type<bool>::field{"on-render"_s,
+ [](const hole& x) { return x.flags.on_render; },
+ [](hole& x, bool value) { x.set_enabled(value, x.flags.on_physics); },
+ },
+ E::type<bool>::field{
+ "on-physics"_s,
+ [](const hole& x) { return x.flags.on_physics; },
+ [](hole& x, bool value) { x.set_enabled(x.flags.on_render, value); },
+ },
+ };
+ return std::tuple_cat(tuple0, tuple);
+ }
+};
+
template<typename, typename = void> struct has_anim_atlas : std::false_type {};
template<typename T>
@@ -318,6 +351,7 @@ bool inspect_object_subtype(object& x)
}
case object_type::critter: return inspect_type(static_cast<critter&>(x), inspect_intent_t{});
case object_type::light: return inspect_type(static_cast<light&>(x), inspect_intent_t{});
+ case object_type::hole: return inspect_type(static_cast<hole&>(x), inspect_intent_t{});
}
fm_warn_once("unknown object subtype '%d'", (int)type);
return false;
diff --git a/editor/inspect.cpp b/editor/inspect.cpp
index e7d8878a..349b5e3d 100644
--- a/editor/inspect.cpp
+++ b/editor/inspect.cpp
@@ -17,18 +17,6 @@ namespace floormat::entities {
namespace {
-template<std::size_t N>
-const char* label_left(StringView label, char(&buf)[N], size_t width)
-{
- std::snprintf(buf, N, "##%s", label.data());
- float x = ImGui::GetCursorPosX();
- ImGui::TextEx(label.data(), label.data() + label.size());
- ImGui::SameLine();
- ImGui::SetCursorPosX(x + (float)width + ImGui::GetStyle().ItemInnerSpacing.x);
- ImGui::SetNextItemWidth(-1);
- return buf;
-}
-
template<typename T> struct IGDT_;
template<> struct IGDT_<uint8_t> : std::integral_constant<int, ImGuiDataType_U8> {};
template<> struct IGDT_<int8_t> : std::integral_constant<int, ImGuiDataType_S8> {};
@@ -89,7 +77,7 @@ bool do_inspect_field(void* datum, const erased_accessor& accessor, field_repr r
should_disable = should_disable || !accessor.can_write();
[[maybe_unused]] auto disabler = begin_disabled(should_disable);
bool ret = false;
- const char* const label = label_left(accessor.field_name, buf, label_width);
+ const char* const label = label_left(accessor.field_name, buf, (float)label_width);
T value{};
accessor.read_fun(datum, accessor.reader, &value);
auto orig = value;
diff --git a/editor/tests-private.hpp b/editor/tests-private.hpp
index dc939878..d6a04cf5 100644
--- a/editor/tests-private.hpp
+++ b/editor/tests-private.hpp
@@ -32,7 +32,7 @@ protected:
enum class Test : uint32_t {
//todo add a speedometer overlay test
- none, path, raycast, region, walk, COUNT,
+ none, path, raycast, region, walk, hole, COUNT,
};
struct tests_data final : tests_data_
@@ -46,6 +46,7 @@ struct tests_data final : tests_data_
static Pointer<base_test> make_test_raycast();
static Pointer<base_test> make_test_region();
static Pointer<base_test> make_test_walk();
+ static Pointer<base_test> make_test_hole();
Pointer<base_test> current_test;
Test current_index = Test::none;
@@ -58,11 +59,12 @@ struct tests_data final : tests_data_
};
static constexpr test_tuple fields[] = {
- { "None"_s, Test::none, make_test_none, },
- { "Path search"_s, Test::path, make_test_path, },
- { "Raycasting"_s, Test::raycast, make_test_raycast },
- { "Region"_s, Test::region, make_test_region },
- { "Walking"_s, Test::walk, make_test_walk },
+ { "None"_s, Test::none, make_test_none, },
+ { "Path search"_s, Test::path, make_test_path, },
+ { "Raycasting"_s, Test::raycast, make_test_raycast },
+ { "Region"_s, Test::region, make_test_region },
+ { "Walking"_s, Test::walk, make_test_walk },
+ { "Hole"_s, Test::hole, make_test_hole },
};
};
diff --git a/editor/tests/hole-test.cpp b/editor/tests/hole-test.cpp
new file mode 100644
index 00000000..6cb60449
--- /dev/null
+++ b/editor/tests/hole-test.cpp
@@ -0,0 +1,98 @@
+#include "../tests-private.hpp"
+#include "compat/shared-ptr-wrapper.hpp"
+#include "src/tile-constants.hpp"
+#include "src/chunk-region.hpp"
+#include "src/object.hpp"
+#include "src/world.hpp"
+#include "../app.hpp"
+#include "../imgui-raii.hpp"
+#include "floormat/main.hpp"
+#include "src/critter.hpp"
+
+namespace floormat::tests {
+namespace {
+
+using namespace floormat::imgui;
+
+struct hole_test final : base_test
+{
+ ~hole_test() noexcept override = default;
+
+ bool handle_key(app& a, const key_event& e, bool is_down) override;
+ bool handle_mouse_click(app& a, const mouse_button_event& e, bool is_down) override;
+ bool handle_mouse_move(app& a, const mouse_move_event& e) override;
+ void draw_overlay(app& a) override;
+ void draw_ui(app& a, float menu_bar_height) override;
+ void update_pre(app& a, const Ns& dt) override;
+ void update_post(app&, const Ns&) override {}
+};
+
+bool hole_test::handle_key(app& a, const key_event& e, bool is_down)
+{
+ return false;
+}
+
+bool hole_test::handle_mouse_click(app& a, const mouse_button_event& e, bool is_down)
+{
+ return false;
+}
+
+bool hole_test::handle_mouse_move(app& a, const mouse_move_event& e)
+{
+ return false;
+}
+
+void hole_test::draw_overlay(app& a)
+{
+}
+
+void hole_test::draw_ui(app& a, float menu_bar_height)
+{
+ const auto& m = a.main();
+ const auto size_x = ImGui::GetWindowSize().x;
+ const auto window_size = ImVec2{size_x, size_x};
+ //const auto dpi = m.dpi_scale();
+ constexpr auto igcf = ImGuiChildFlags_None;
+ constexpr auto igwf = ImGuiWindowFlags_NoDecoration;
+
+ ImGui::NewLine();
+
+ char buf[32];
+
+ ImGui::LabelText("##test-area", "Test area");
+
+ ImGui::NewLine();
+ if (auto b1 = imgui::begin_child("Test area"_s, window_size, igcf, igwf))
+ {
+ const auto& win = *ImGui::GetCurrentWindow();
+ ImDrawList& draw = *win.DrawList;
+ }
+ ImGui::NewLine();
+
+ const auto label_width = ImGui::CalcTextSize("MMMM").x;
+
+ label_left("width", buf, label_width);
+ ImGui::NewLine();
+
+ label_left("height", buf, label_width);
+ ImGui::NewLine();
+
+ label_left("x", buf, label_width);
+ ImGui::NewLine();
+
+ label_left("y", buf, label_width);
+ ImGui::NewLine();
+
+ label_left("z", buf, label_width);
+ ImGui::NewLine();
+}
+
+void hole_test::update_pre(app& a, const Ns& dt)
+{
+}
+
+} // namespace
+
+Pointer<base_test> tests_data::make_test_hole() { return Pointer<hole_test>{InPlaceInit}; }
+
+} // namespace floormat::tests
diff --git a/editor/vobj-editor.cpp b/editor/vobj-editor.cpp
index e82c6d27..9eb36e39 100644
--- a/editor/vobj-editor.cpp
+++ b/editor/vobj-editor.cpp
@@ -1,6 +1,7 @@
#include "vobj-editor.hpp"
#include "src/world.hpp"
#include "src/light.hpp"
+#include "src/hole.hpp"
#include "loader/loader.hpp"
#include "loader/vobj-cell.hpp"
#include "app.hpp"
@@ -74,6 +75,8 @@ start: while (auto id = a.get_object_colliding_with_cursor())
#pragma clang diagnostic ignored "-Wweak-vtables"
#endif
+namespace {
+
struct light_factory final : vobj_factory
{
object_type type() const override;
@@ -98,6 +101,32 @@ std::shared_ptr<object> light_factory::make(world& w, object_id id, global_coord
return ret;
}
+struct hole_factory final : vobj_factory
+{
+ object_type type() const override;
+ const vobj_cell& info() const override;
+ std::shared_ptr<object> make(world& w, object_id id, global_coords pos) const override;
+};
+
+object_type hole_factory::type() const { return object_type::hole; }
+
+const vobj_cell& hole_factory::info() const
+{
+ constexpr auto NAME = "hole"_s;
+ static const vobj_cell& ret = loader.vobj(NAME);
+ fm_debug_assert(ret.name == NAME);
+ fm_debug_assert(ret.atlas != nullptr);
+ return ret;
+}
+
+std::shared_ptr<object> hole_factory::make(world& w, object_id id, global_coords pos) const
+{
+ auto ret = w.make_object<hole>(id, pos, hole_proto{});
+ return ret;
+}
+
+} // namespace
+
auto vobj_editor::make_vobj_type_map() -> std::map<String, vobj_>
{
constexpr auto add = [](auto& m, std::unique_ptr<vobj_factory>&& x) {
@@ -106,6 +135,7 @@ auto vobj_editor::make_vobj_type_map() -> std::map<String, vobj_>
};
std::map<String, vobj_> map;
add(map, std::make_unique<light_factory>());
+ add(map, std::make_unique<hole_factory>());
return map;
}