Peoplemon  0.1.0
Peoplemon 3 game source documentation
OwnedMove.hpp
Go to the documentation of this file.
1 #ifndef CORE_PEOPLEMON_OWNEDMOVE_HPP
2 #define CORE_PEOPLEMON_OWNEDMOVE_HPP
3 
4 #include <BLIB/Serialization.hpp>
6 
7 namespace core
8 {
9 namespace pplmn
10 {
17 struct OwnedMove {
20 
22  unsigned int curPP;
23 
25  unsigned int maxPP;
26 
31  OwnedMove();
32 
38  OwnedMove(MoveId id);
39 
45  void restorePP(int pp);
46 };
47 
48 } // namespace pplmn
49 } // namespace core
50 
51 namespace bl
52 {
53 namespace serial
54 {
55 namespace binary
56 {
58 
59 template<>
61  using IdSerializer = Serializer<core::pplmn::MoveId>;
62 
63  static bool serialize(OutputStream& output, const OwnedMove& v) {
64  if (!IdSerializer::serialize(output, v.id)) return false;
65  if (!output.write<std::uint8_t>(v.curPP)) return false;
66  if (!output.write<std::uint8_t>(v.maxPP)) return false;
67  return true;
68  }
69 
70  static bool deserialize(InputStream& input, OwnedMove& v) {
71  if (!IdSerializer::deserialize(input, v.id)) return false;
72  std::uint8_t t;
73  if (!input.read<std::uint8_t>(t)) return false;
74  v.curPP = t;
75  if (!input.read<std::uint8_t>(t)) return false;
76  v.maxPP = t;
77  return true;
78  }
79 
80  static std::size_t size(const OwnedMove& v) {
81  return IdSerializer::size(v.id) + sizeof(std::uint8_t) * 2;
82  }
83 };
84 
85 } // namespace binary
86 
87 template<>
88 struct SerializableObject<core::pplmn::OwnedMove> : public SerializableObjectBase {
91 
92  SerializableField<1, Move, Id> id;
93  SerializableField<2, Move, unsigned int> curPP;
94  SerializableField<3, Move, unsigned int> maxPP;
95 
97  : SerializableObjectBase("OwnedMove")
98  , id("id", *this, &Move::id, SerializableFieldBase::Required{})
99  , curPP("pp", *this, &Move::curPP, SerializableFieldBase::Required{})
100  , maxPP("maxPP", *this, &Move::maxPP, SerializableFieldBase::Required{}) {}
101 };
102 
103 } // namespace serial
104 } // namespace bl
105 
106 #endif
MoveId
The id of a move.
Definition: MoveId.hpp:16
Core classes and functionality for both the editor and game.
bl::serial::json::Serializer< Player > Serializer
Definition: Player.cpp:27
Represents a move owned by a peoplemon.
Definition: OwnedMove.hpp:17
void restorePP(int pp)
Restores some pp to the move.
Definition: OwnedMove.cpp:18
unsigned int maxPP
The pp to restore to. Increased max pp is stored here.
Definition: OwnedMove.hpp:25
unsigned int curPP
The current pp of the move.
Definition: OwnedMove.hpp:22
OwnedMove()
Creates an empty Unknown move with 0 pp.
Definition: OwnedMove.cpp:8
MoveId id
The id of the move.
Definition: OwnedMove.hpp:19
static bool serialize(OutputStream &output, const OwnedMove &v)
Definition: OwnedMove.hpp:63
static bool deserialize(InputStream &input, OwnedMove &v)
Definition: OwnedMove.hpp:70
Serializer< core::pplmn::MoveId > IdSerializer
Definition: OwnedMove.hpp:61
static std::size_t size(const OwnedMove &v)
Definition: OwnedMove.hpp:80
SerializableField< 2, Move, unsigned int > curPP
Definition: OwnedMove.hpp:93
SerializableField< 3, Move, unsigned int > maxPP
Definition: OwnedMove.hpp:94