summaryrefslogtreecommitdiffhomepage
path: root/src/character.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-18 00:08:33 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-18 00:08:33 +0100
commitc7a342d71ee93586b073a8e9c73b8ba6b621266f (patch)
tree4fd99ee3db670fe9933e023d18d74f50abf1311c /src/character.cpp
parent2640db18223b6a93140dd8fdc57d607d4b777f08 (diff)
a
Diffstat (limited to 'src/character.cpp')
-rw-r--r--src/character.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/character.cpp b/src/character.cpp
index 67b6ca72..9c69e061 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -51,17 +51,23 @@ constexpr auto arrows_to_dir(bool L, bool R, bool U, bool D)
} // namespace
-character::character(std::uint64_t id, struct chunk& c, entity_type type, const character_proto& proto) :
- entity{id, c, type, proto},
- name{proto.name},
- playable{proto.playable}
+character_proto::character_proto(const character_proto&) = default;
+character_proto::character_proto() = default;
+character_proto::~character_proto() noexcept = default;
+character_proto& character_proto::operator=(const character_proto&) = default;
+character::~character() = default;
+
+bool character_proto::operator==(const entity_proto& e0) const
{
- if (!atlas)
- atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH);
- entity::set_bbox_(offset, bbox_offset, Vector2ub(iTILE_SIZE2/2), pass);
-}
+ if (type != e0.type)
+ return false;
-character::~character() = default;
+ if (!entity_proto::operator==(e0))
+ return false;
+
+ const auto& s0 = static_cast<const character_proto&>(e0);
+ return name == s0.name && playable == s0.playable;
+}
int character::allocate_frame_time(float dt)
{
@@ -120,4 +126,25 @@ bool character::update(std::size_t i, float dt)
return true;
}
+character::operator character_proto() const
+{
+ character_proto ret;
+ static_cast<entity_proto&>(ret) = entity::operator entity_proto();
+ ret.name = name;
+ ret.playable = playable;
+ return ret;
+}
+
+character::character(std::uint64_t id, struct chunk& c, entity_type type, const character_proto& proto) :
+ entity{id, c, type, proto},
+ name{proto.name},
+ playable{proto.playable}
+{
+ if (!name)
+ name = "(Unnamed)"_s;
+ if (!atlas)
+ atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH);
+ entity::set_bbox_(offset, bbox_offset, Vector2ub(iTILE_SIZE2/2), pass);
+}
+
} // namespace floormat