]> git.localhorst.tv Git - l2e.git/commitdiff
added type description of PartyLayout
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 9 Sep 2012 12:31:07 +0000 (14:31 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 9 Sep 2012 12:31:07 +0000 (14:31 +0200)
src/battle/PartyLayout.cpp
src/battle/PartyLayout.h

index 6389327528bd77df1e4c233147b2d5ad51609d93..ad0a54877c6b3c53e9266ea76cdeaa5c869cd2e4 100644 (file)
@@ -7,6 +7,44 @@
 
 #include "PartyLayout.h"
 
+#include "../loader/TypeDescription.h"
+
+using geometry::Vector;
+using loader::FieldDescription;
+using loader::TypeDescription;
+using std::vector;
+
 namespace battle {
 
+Vector<int> PartyLayout::CalculatePosition(int index, int width, int height) const {
+       assert(index >= 0 && index < numPositions);
+       return Vector<int>(
+                       positions[index].X() * width / 255,
+                       positions[index].Y() * height / 223
+                       );
+}
+
+void PartyLayout::CalculatePositions(int width, int height, vector<Vector<int> > &dest) const {
+       dest.clear();
+       dest.reserve(numPositions);
+       for (int i(0); i < numPositions; ++i) {
+               dest.push_back(Vector<int>(
+                               positions[i].X() * width / 255,
+                               positions[i].Y() * height / 223
+                               ));
+       }
+}
+
+
+void PartyLayout::CreateTypeDescription() {
+       PartyLayout p;
+       TypeDescription &td(TypeDescription::CreateOrGet("PartyLayout"));
+
+       td.SetSize(sizeof(PartyLayout));
+
+       int vectorId(TypeDescription::GetTypeId("Vector"));
+
+       td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), vectorId, true, true));
+}
+
 }
index 1d72aa8ad483bc8fadeafc6cf62a16d41fea5971..b2454f2cba18bcbcd8b8f9588fb8f2c931bf0de8 100644 (file)
@@ -19,37 +19,24 @@ namespace battle {
 class PartyLayout {
 
 public:
-       PartyLayout() { }
+       PartyLayout() : positions(0), numPositions(0) { }
 
 public:
-       std::vector<geometry::Vector<Uint8> >::size_type NumPositions() const { return positions.size(); }
-       template<class U>
-       void CalculatePositions(U width, U height, std::vector<geometry::Vector<U> > &dest) const {
-               dest.clear();
-               dest.reserve(positions.size());
-               for (std::vector<geometry::Vector<Uint8> >::const_iterator i(positions.begin()), end(positions.end()); i != end; ++i) {
-                       dest.push_back(geometry::Vector<U>(
-                                       i->X() * width / 255,
-                                       i->Y() * height / 223
-                                       ));
-               }
-       }
-       template<class U>
-       geometry::Vector<U> CalculatePosition(std::vector<geometry::Vector<Uint8> >::size_type index, U width, U height) const {
-               assert(index >= 0 && index < positions.size());
-               return geometry::Vector<U>(
-                               positions[index].X() * width / 255,
-                               positions[index].Y() * height / 223
-                               );
-       }
+       std::vector<geometry::Vector<int> >::size_type NumPositions() const { return numPositions; }
+       void CalculatePositions(int width, int height, std::vector<geometry::Vector<int> > &dest) const;
+       geometry::Vector<int> CalculatePosition(int index, int width, int height) const;
 
 public:
-       void AddPosition(const geometry::Vector<Uint8> &p) {
-               positions.push_back(p);
+       void SetPositions(const geometry::Vector<int> *p, int num) {
+               positions = p;
+               numPositions = num;
        }
 
+       static void CreateTypeDescription();
+
 private:
-       std::vector<geometry::Vector<Uint8> > positions;
+       const geometry::Vector<int> *positions;
+       int numPositions;
 
 };