summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/scenery-editor.cpp43
-rw-r--r--editor/scenery-editor.hpp17
-rw-r--r--editor/scenery-json.cpp14
-rw-r--r--editor/tile-editor.cpp7
4 files changed, 42 insertions, 39 deletions
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp
index c8f9f910..612bfb78 100644
--- a/editor/scenery-editor.cpp
+++ b/editor/scenery-editor.cpp
@@ -15,37 +15,33 @@ scenery_editor::scenery_editor() noexcept
void scenery_editor::set_rotation(rotation_ r)
{
- _selected.frame.r = r;
+ if (_selected.proto.atlas)
+ {
+ (void)_selected.proto.atlas->group(r);
+ _selected.proto.frame.r = r;
+ }
}
rotation_ scenery_editor::rotation() const
{
- return _selected.frame.r;
+ return _selected.proto.frame.r;
}
void scenery_editor::next_rotation()
{
- // todo
- auto r_1 = (rotation_t)_selected.frame.r + 1;
- auto rot = (rotation_)r_1;
- if (rot >= rotation_COUNT)
- rot = (rotation_)0;
- _selected.frame.r = rot;
+ if (auto& proto = _selected.proto; proto.atlas)
+ proto.frame.r = proto.atlas->next_rotation_from(proto.frame.r);
}
void scenery_editor::prev_rotation()
{
- if (_selected.frame.r == (rotation_)0)
- _selected.frame.r = (rotation_)((rotation_t)rotation_COUNT - 1);
- else
- _selected.frame.r = (rotation_)((rotation_t)_selected.frame.r - 1);
+ if (auto& proto = _selected.proto; proto.atlas)
+ proto.frame.r = proto.atlas->prev_rotation_from(proto.frame.r);
}
-//return atlas == _selected.atlas && r == _selected.s.r && frame == _selected.s.frame;
-
-void scenery_editor::select_tile(const scenery_proto& proto)
+void scenery_editor::select_tile(const scenery_& s)
{
- _selected = proto;
+ _selected = s;
}
void scenery_editor::clear_selection()
@@ -53,26 +49,19 @@ void scenery_editor::clear_selection()
_selected = {};
}
-const scenery_proto& scenery_editor::get_selected()
+auto scenery_editor::get_selected() -> const scenery_&
{
return _selected;
}
bool scenery_editor::is_atlas_selected(const std::shared_ptr<anim_atlas>& atlas) const
{
- return _selected.atlas == atlas;
-}
-
-bool scenery_editor::is_item_selected(const scenery_proto& proto) const
-{
- return _selected == proto;
+ return atlas == _selected.proto.atlas;
}
-void scenery_editor::load_atlases()
+bool scenery_editor::is_item_selected(const scenery_& s) const
{
- _atlases.clear();
- for (StringView str : loader.anim_atlas_list())
- _atlases[str] = loader.anim_atlas(str);
+ return s.name == _selected.name && s.proto.atlas == _selected.proto.atlas;
}
} // namespace floormat
diff --git a/editor/scenery-editor.hpp b/editor/scenery-editor.hpp
index b461fd0c..521353fa 100644
--- a/editor/scenery-editor.hpp
+++ b/editor/scenery-editor.hpp
@@ -2,7 +2,7 @@
#include "src/scenery.hpp"
#include <map>
#include <memory>
-#include <Corrade/Containers/StringView.h>
+#include <Corrade/Containers/String.h>
namespace floormat {
@@ -10,7 +10,10 @@ struct anim_atlas;
struct scenery_editor final
{
- using frame_t = scenery::frame_t;
+ struct scenery_ {
+ String name, descr;
+ scenery_proto proto;
+ };
scenery_editor() noexcept;
@@ -19,17 +22,17 @@ struct scenery_editor final
void next_rotation();
void prev_rotation();
- void select_tile(const scenery_proto& proto);
+ void select_tile(const scenery_& s);
void clear_selection();
- const scenery_proto& get_selected();
+ const scenery_& get_selected();
bool is_atlas_selected(const std::shared_ptr<anim_atlas>& atlas) const;
- bool is_item_selected(const scenery_proto& proto) const;
+ bool is_item_selected(const scenery_& s) const;
private:
void load_atlases();
- std::map<StringView, std::shared_ptr<anim_atlas>> _atlases;
- scenery_proto _selected;
+ std::map<String, scenery_> _atlases;
+ scenery_ _selected;
};
} // namespace floormat
diff --git a/editor/scenery-json.cpp b/editor/scenery-json.cpp
new file mode 100644
index 00000000..a6756512
--- /dev/null
+++ b/editor/scenery-json.cpp
@@ -0,0 +1,14 @@
+#include "scenery-editor.hpp"
+#include "serialize/scenery.hpp"
+#include "loader/loader.hpp"
+
+namespace floormat {
+
+void scenery_editor::load_atlases()
+{
+ _atlases.clear();
+ for (auto& s : loader.sceneries())
+ _atlases[s.name] = scenery_{s.name, s.descr, s.proto};
+}
+
+} // namespace floormat
diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp
index 4ae54d86..d944f47f 100644
--- a/editor/tile-editor.cpp
+++ b/editor/tile-editor.cpp
@@ -4,23 +4,20 @@
#include "keys.hpp"
#include "loader/loader.hpp"
#include "random.hpp"
-#include "serialize/json-helper.hpp"
-#include "serialize/tile-atlas.hpp"
#include <Corrade/Containers/PairStl.h>
#include <Corrade/Utility/Path.h>
namespace floormat {
-tile_editor::tile_editor(editor_mode mode, StringView name) : _name{ name}, _mode{ mode}
+tile_editor::tile_editor(editor_mode mode, StringView name) : _name{name}, _mode{ mode}
{
load_atlases();
}
void tile_editor::load_atlases()
{
- using atlas_array = std::vector<std::shared_ptr<tile_atlas>>;
const auto filename = _name + ".json";
- for (auto& atlas : json_helper::from_json<atlas_array>(Path::join(loader_::IMAGE_PATH, filename)))
+ for (const auto& atlas : loader.tile_atlases(filename))
{
const auto [name, _ext] = Path::splitExtension(atlas->name());
auto& [_, vec] = _permutation;