summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-20 15:27:31 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-20 15:27:31 +0100
commit5dbee173b961792b42596cb792a50624555cc41b (patch)
tree2e6d82e2c3fefd13584730aecd42a3d3fc14f105
parent81156d180847bf9ba502a25e546723f234d0e2c9 (diff)
src, senery, serialize: implement z offset
-rw-r--r--scenery/furniture/table1.json16
-rw-r--r--serialize/anim.cpp11
-rw-r--r--src/anim.hpp1
-rw-r--r--src/entity.cpp6
-rw-r--r--src/entity.hpp4
5 files changed, 19 insertions, 19 deletions
diff --git a/scenery/furniture/table1.json b/scenery/furniture/table1.json
index c7c922db..f90600a3 100644
--- a/scenery/furniture/table1.json
+++ b/scenery/furniture/table1.json
@@ -8,16 +8,12 @@
}
],
"ground": "960 x 540",
- "name": "n"
+ "name": "n",
+ "z-offset": "0 x 32"
},
{
"mirror-from": "n",
- "name": "w",
- "offset": [
- 0,
- 0,
- 0
- ]
+ "name": "w"
},
{
"frames": [
@@ -33,11 +29,7 @@
{
"mirror-from": "s",
"name": "e",
- "offset": [
- 0,
- 0,
- 0
- ]
+ "z-offset": "0 x 32"
}
],
"nframes": 1,
diff --git a/serialize/anim.cpp b/serialize/anim.cpp
index 8d867489..4effc375 100644
--- a/serialize/anim.cpp
+++ b/serialize/anim.cpp
@@ -46,6 +46,8 @@ static void to_json(nlohmann::json& j, const anim_group& val)
j["ground"] = val.ground;
if (val.offset != def.offset)
j["offset"] = val.offset;
+ if (val.z_offset != def.z_offset)
+ j["z-offset"] = val.z_offset;
}
static void from_json(const nlohmann::json& j, anim_group& val)
@@ -54,13 +56,18 @@ static void from_json(const nlohmann::json& j, anim_group& val)
val.name = j["name"];
fm_soft_assert(!val.name.isEmpty());
if (j.contains("mirror-from"))
+ {
+ fm_soft_assert(!j.contains("frames"));
val.mirror_from = j["mirror-from"];
+ }
else
val.frames = j["frames"];
if (j.contains("ground"))
val.ground = j["ground"];
if (j.contains("offset"))
val.offset = j["offset"];
+ if (j.contains("z-offset"))
+ val.z_offset = j["z-offset"];
}
static void to_json(nlohmann::json& j, const anim_def& val)
@@ -109,7 +116,7 @@ using namespace floormat;
namespace nlohmann {
-void adl_serializer<floormat::anim_scale>::to_json(json& j, const floormat::anim_scale val)
+void adl_serializer<floormat::anim_scale>::to_json(json& j, const anim_scale val)
{
switch (val.type)
{
@@ -126,7 +133,7 @@ void adl_serializer<floormat::anim_scale>::to_json(json& j, const floormat::anim
}
}
-void adl_serializer<floormat::anim_scale>::from_json(const json& j, floormat::anim_scale& val)
+void adl_serializer<anim_scale>::from_json(const json& j, anim_scale& val)
{
fm_soft_assert(j.is_array());
fm_soft_assert(j.size() == 2);
diff --git a/src/anim.hpp b/src/anim.hpp
index fe455128..4b7b6bc8 100644
--- a/src/anim.hpp
+++ b/src/anim.hpp
@@ -26,6 +26,7 @@ struct anim_group final
std::vector<anim_frame> frames;
Vector2ui ground; // for use in anim-crop-tool only
Vector3b offset;
+ Vector2b z_offset;
};
enum class anim_scale_type : unsigned char { invalid, ratio, fixed, };
diff --git a/src/entity.cpp b/src/entity.cpp
index 971b532d..1b54117d 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -48,15 +48,15 @@ entity::~entity() noexcept
float entity::ordinal() const
{
- return ordinal(coord.local(), offset);
+ return ordinal(coord.local(), offset, atlas->group(r).z_offset);
}
-float entity::ordinal(local_coords xy, Vector2b offset) const
+float entity::ordinal(local_coords xy, Vector2b offset, Vector2b z_offset) const
{
constexpr auto inv_tile_size = 1.f/TILE_SIZE2;
constexpr float width = TILE_MAX_DIM+1;
auto offset_ = ordinal_offset(offset);
- auto vec = Vector2(xy) + offset_*inv_tile_size;
+ auto vec = Vector2(xy) + offset_*inv_tile_size + Vector2(z_offset)*inv_tile_size;
return vec[1]*width + vec[0];
}
diff --git a/src/entity.hpp b/src/entity.hpp
index 75e06ba8..f2f6c65b 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -54,7 +54,7 @@ struct entity
virtual Vector2 ordinal_offset(Vector2b offset) const = 0;
float ordinal() const;
- float ordinal(local_coords xy, Vector2b offset) const;
+ float ordinal(local_coords xy, Vector2b offset, Vector2b z_offset) const;
struct chunk& chunk() const;
size_t index() const;
@@ -75,7 +75,7 @@ struct entity
bool is_dynamic() const;
bool can_rotate(rotation new_r);
bool can_move_to(Vector2i delta);
- [[nodiscard]] size_t move_to(size_t i, Vector2i delta, rotation new_r);
+ size_t move_to(size_t i, Vector2i delta, rotation new_r);
protected:
entity(object_id id, struct chunk& c, const entity_proto& proto);