Oxygine  1
2g game engine
Serialize.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "core/Object.h"
4 #include "pugixml/pugixml.hpp"
5 #include "res/ResAnim.h"
6 #include "res/ResFont.h"
7 #include "utils/stringUtils.h"
8 
9 namespace oxygine
10 {
11  class creator
12  {
13  public:
14  virtual spActor create(const char* type) const;
15  virtual Resource* getResource(const char* id) const {return 0;}
16  virtual ResAnim* getResAnim(const char* id) const {return safeCast<ResAnim*>(getResource(id));}
17  virtual AnimationFrame getFrame(const char* id, int col, int row) const {ResAnim* rs = getResAnim(id); if (rs) return rs->getFrame(col, row); return AnimationFrame();}
18  virtual ResFont* getResFont(const char* id) const {return safeCast<ResFont*>(getResource(id));}
19  };
20 
22  {
23  serializedata() : withChildren(true) {}
24  pugi::xml_node node;
25  bool withChildren;
26  };
27 
29  {
30  pugi::xml_node node;
31  const creator* factory;
32 
33  static spActor deser(pugi::xml_node node, const creator* factory);
34  };
35 
37  {
38  pugi::xml_node node;
39  spActor root;
40 
41  static void link(pugi::xml_node node, spActor root);
42  };
43 
44 
45  inline void setAttrV2(pugi::xml_node node, const char* name, const Vector2& v, const Vector2& def)
46  {
47  if (v == def)
48  return;
49  char str[255];
50  safe_sprintf(str, "%g,%g", v.x, v.y);
51  node.append_attribute(name).set_value(str);
52  }
53 
54 
55  template<class T>
56  void setAttr(pugi::xml_node node, const char* name, T v, T def)
57  {
58  if (v == def)
59  return;
60  node.append_attribute(name).set_value(v);
61  }
62 }
Definition: Serialize.h:28
Definition: ResFont.h:8
Definition: AnimationFrame.h:28
Definition: Serialize.h:21
–oxgl-end–!
Definition: Actor.h:14
Definition: Resource.h:10
Definition: ResAnim.h:13
Definition: Serialize.h:11