diff options
-rw-r--r-- | editor/scenery-editor.cpp | 1 | ||||
-rw-r--r-- | scenery/control-panel.json | 7 | ||||
-rw-r--r-- | serialize/anim.cpp | 27 | ||||
-rw-r--r-- | src/entity.cpp | 8 |
4 files changed, 22 insertions, 21 deletions
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index fd859db3..6cfe56bf 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -22,6 +22,7 @@ scenery_editor::scenery_editor() noexcept void scenery_editor::set_rotation(enum rotation r) { auto& s = _selected.proto; + s.offset = rotate_point(s.offset, s.r, r); s.bbox_offset = rotate_point(s.bbox_offset, s.r, r); s.bbox_size = rotate_size(s.bbox_size, s.r, r); s.r = r; diff --git a/scenery/control-panel.json b/scenery/control-panel.json index 2ef2e2f0..fa557b42 100644 --- a/scenery/control-panel.json +++ b/scenery/control-panel.json @@ -17,7 +17,12 @@ },
{
"mirror-from": "n",
- "name": "w"
+ "name": "w",
+ "offset": [
+ 0,
+ 0,
+ 22
+ ]
}
],
"nframes": 1,
diff --git a/serialize/anim.cpp b/serialize/anim.cpp index 7be6323b..4d19acbe 100644 --- a/serialize/anim.cpp +++ b/serialize/anim.cpp @@ -38,7 +38,10 @@ static void to_json(nlohmann::json& j, const anim_group& val) const anim_group def{}; j["name"] = val.name; - j["frames"] = val.frames; + if (val.mirror_from) + j["mirror-from"] = val.mirror_from; + else + j["frames"] = val.frames; if (val.ground != def.ground) j["ground"] = val.ground; if (val.offset != def.offset) @@ -50,7 +53,10 @@ static void from_json(const nlohmann::json& j, anim_group& val) val = {}; val.name = j["name"]; fm_soft_assert(!val.name.isEmpty()); - val.frames = j["frames"]; + if (j.contains("mirror-from")) + val.mirror_from = j["mirror-from"]; + else + val.frames = j["frames"]; if (j.contains("ground")) val.ground = j["ground"]; if (j.contains("offset")) @@ -159,22 +165,7 @@ void adl_serializer<anim_group>::to_json(json& j, const anim_group& val) to_json(j, val); } -void adl_serializer<anim_group>::from_json(const json& j, anim_group& val) -{ - using nlohmann::from_json; - if (j.contains("mirror-from")) - { - const anim_group def{}; - - val.name = j["name"]; - val.mirror_from = j["mirror-from"]; - if (val.offset != def.offset) - val.offset = j["offset"]; - } - else - from_json(j, val); -} - +void adl_serializer<anim_group>::from_json(const json& j, anim_group& val) { using nlohmann::from_json; from_json(j, val); } void adl_serializer<anim_def>::to_json(json& j, const anim_def& val) { using nlohmann::to_json; to_json(j, val); } void adl_serializer<anim_def>::from_json(const json& j, anim_def& val) { using nlohmann::from_json; from_json(j, val); } diff --git a/src/entity.cpp b/src/entity.cpp index 766b0093..41b22d5e 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -81,9 +81,10 @@ bool entity::can_rotate(global_coords coord, rotation new_r, rotation old_r, Vec { if (bbox_offset.isZero() && bbox_size[0] == bbox_size[1]) return true; + const auto offset_ = rotate_point(offset, old_r, new_r); const auto bbox_offset_ = rotate_point(bbox_offset, old_r, new_r); const auto bbox_size_ = rotate_size(bbox_size, old_r, new_r); - return can_move_to({}, coord, offset, bbox_offset_, bbox_size_); + return can_move_to({}, coord, offset_, bbox_offset_, bbox_size_); } bool entity::can_rotate(rotation new_r) @@ -94,7 +95,10 @@ bool entity::can_rotate(rotation new_r) void entity::rotate(size_t, rotation new_r) { fm_assert(atlas->check_rotation(new_r)); - set_bbox(offset, rotate_point(bbox_offset, r, new_r), rotate_size(bbox_size, r, new_r), pass); + auto offset_ = is_dynamic() ? rotate_point(offset, r, new_r) : offset; // todo add boolean for this condition + auto bbox_offset_ = rotate_point(bbox_offset, r, new_r); + auto bbox_size_ = rotate_size(bbox_size, r, new_r); + set_bbox(offset_, bbox_offset_, bbox_size_, pass); if (r != new_r && !is_dynamic()) c->mark_scenery_modified(); const_cast<rotation&>(r) = new_r; |