summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/vobj-editor.cpp58
-rw-r--r--editor/vobj-editor.hpp27
-rw-r--r--userconfig-sthalik@Windows-GNU.cmake1
3 files changed, 47 insertions, 39 deletions
diff --git a/editor/vobj-editor.cpp b/editor/vobj-editor.cpp
index 8687e107..82b36204 100644
--- a/editor/vobj-editor.cpp
+++ b/editor/vobj-editor.cpp
@@ -4,7 +4,7 @@
#include "src/world.hpp"
#include "src/light.hpp"
#include <array>
-#include <Corrade/Containers/ArrayView.h>
+#include <utility>
#include <Corrade/Containers/StringView.h>
#if defined __clang__ || defined __CLION_IDE__
@@ -13,12 +13,30 @@
namespace floormat {
-[[nodiscard]]
-std::shared_ptr<entity> make_vobj(world& w, entity_type type, object_id id, global_coords pos);
-
StringView vobj_factory::name() const { return info().name; }
StringView vobj_factory::descr() const { return info().descr; }
std::shared_ptr<anim_atlas> vobj_factory::atlas() const { return info().atlas; }
+vobj_factory::vobj_factory() = default;
+vobj_factory::~vobj_factory() noexcept = default;
+
+vobj_editor::vobj_::operator bool() const { return factory != nullptr; }
+vobj_editor::vobj_editor() = default;
+void vobj_editor::select_tile(const vobj_& type) { _selected = &type; }
+
+auto vobj_editor::get_type(StringView name) -> const vobj_&
+{
+ auto it = _types.find(name);
+ if (it != _types.cend())
+ return &it->second;
+ else
+ {
+ fm_warn_once("invalid vobj type '%s'", name.data());
+ return nullptr;
+ }
+}
+
+bool vobj_editor::is_item_selected(const vobj_& x) const { return _selected == &x; }
+bool vobj_editor::is_anything_selected() const { return _selected != nullptr; }
struct light_factory final : vobj_factory
{
@@ -40,31 +58,17 @@ struct light_factory final : vobj_factory
}
};
-template<typename T> struct factory_ { static constexpr const T value = {}; };
-
-static consteval auto make_factory_array()
+static auto make_vobj_type_map()
{
- const auto size = (1uz << entity_type_BITS)-1;
- std::array<const vobj_factory*, size> array = {};
- array[(unsigned)entity_type::light] = &factory_<light_factory>::value;
- return array;
+ constexpr auto add = [](auto& m, std::unique_ptr<vobj_factory>&& x) {
+ StringView name = x->name(), descr = x->descr();
+ m[name] = vobj_editor::vobj_{ name, descr, std::move(x) };
+ };
+ std::map<StringView, vobj_editor::vobj_> map;
+ add(map, std::make_unique<light_factory>());
+ return map;
}
-static constexpr auto factory_array = make_factory_array();
-const ArrayView<const vobj_factory* const> vobj_editor::_types = { factory_array.data(), factory_array.size() };
-
-const vobj_factory* vobj_editor::get_factory(entity_type type)
-{
- const auto idx = size_t(type);
- fm_debug_assert(idx < std::size(factory_array));
- const auto* ptr = factory_array[idx];
- if (!ptr)
- {
- fm_warn_once("invalid vobj type '%zu'", idx);
- return nullptr;
- }
- else
- return ptr;
-}
+const std::map<StringView, vobj_editor::vobj_> vobj_editor::_types = make_vobj_type_map();
} // namespace floormat
diff --git a/editor/vobj-editor.hpp b/editor/vobj-editor.hpp
index 573f00e3..cbe2ffb4 100644
--- a/editor/vobj-editor.hpp
+++ b/editor/vobj-editor.hpp
@@ -1,12 +1,11 @@
#pragma once
#include "src/entity-type.hpp"
#include <memory>
-//#include <Corrade/Containers/ArrayView.h>
+#include <map>
namespace Corrade::Containers {
template<typename T> class BasicStringView;
using StringView = BasicStringView<const char>;
-template<typename T> class ArrayView;
} // namespace Corrade::Containers
namespace floormat {
@@ -24,8 +23,8 @@ struct vobj_info;
struct vobj_factory
{
- constexpr vobj_factory() = default;
- virtual constexpr ~vobj_factory() noexcept;
+ vobj_factory();
+ virtual ~vobj_factory() noexcept;
virtual const vobj_info& info() const = 0;
virtual entity_type type() const = 0;
virtual std::shared_ptr<entity> make(world& w, object_id id, global_coords pos) const = 0;
@@ -35,24 +34,28 @@ struct vobj_factory
std::shared_ptr<anim_atlas> atlas() const;
};
-constexpr vobj_factory::~vobj_factory() noexcept {}; // NOLINT workaround gcc 12 bug #93413
-
#if defined __clang__ || defined __CLION_IDE__
#pragma clang diagnostic pop
#endif
struct vobj_editor final
{
+ struct vobj_ final {
+ StringView name, descr;
+ std::unique_ptr<vobj_factory> factory;
+ operator bool() const;
+ };
+
vobj_editor();
- void select_type(entity_type type);
+ void select_tile(const vobj_& type);
void clear_selection();
- [[nodiscard]] static const vobj_factory* get_factory(entity_type type);
- bool is_type_selected(entity_type type) const;
+ static const vobj_& get_type(StringView name);
+ bool is_item_selected(const vobj_& x) const;
bool is_anything_selected() const;
- static void place_tile(world& w, global_coords pos, const vobj_factory& factory);
+ static void place_tile(world& w, global_coords pos, const vobj_& x);
static auto cbegin() noexcept { return _types.cbegin(); }
static auto cend() noexcept { return _types.cend(); }
@@ -60,8 +63,8 @@ struct vobj_editor final
static auto end() noexcept { return _types.cend(); }
private:
- static const ArrayView<const vobj_factory* const> _types;
- const vobj_factory* _selected = nullptr;
+ static const std::map<StringView, vobj_> _types;
+ const vobj_* _selected = nullptr;
};
} // namespace floormat
diff --git a/userconfig-sthalik@Windows-GNU.cmake b/userconfig-sthalik@Windows-GNU.cmake
index 57e8ac72..32b41574 100644
--- a/userconfig-sthalik@Windows-GNU.cmake
+++ b/userconfig-sthalik@Windows-GNU.cmake
@@ -22,6 +22,7 @@ endif()
# for building submodule dependencies
function(fm-userconfig-external)
+ set(FLOORMAT_SUBMODULE-SDL2 1)
add_compile_options(
-Wno-ignored-attributes
-Wno-unused-function