summary refs log tree commit diff stats
path: root/tools/mapedit/src/map.h
blob: 46e579028261939399bc18e982d394c221eb9a57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef MAP_H
#define MAP_H

#include <string>
#include <exception>
#include <utility>
#include <list>
#include <memory>
#include <wx/treectrl.h>

class MapObject;
class World;
class MapeditFrame;

class MapLoadException: public std::exception
{
  public:
    MapLoadException(std::string mapname) : mapname(mapname) {}
    
    virtual const char* what() const throw()
    {
      return ("An error occured loading map " + mapname).c_str();
    }
    
  private:
    std::string mapname;
};

class MapWriteException: public std::exception
{
  public:
    MapWriteException(std::string mapname) : mapname(mapname) {}
    
    virtual const char* what() const throw()
    {
      return ("An error occured writing map " + mapname).c_str();
    }
    
  private:
    std::string mapname;
};

struct MapObjectEntry {
  MapObject* object;
  std::pair<int, int> position;
  
  bool operator==(MapObjectEntry& other) const
  {
    return (object == other.object) && (position == other.position);
  }
  
  bool operator!=(MapObjectEntry& other) const
  {
    return (object != other.object) && (position != other.position);
  }
};

class Map {
  public:
    Map(int id, World* world);
    Map(const Map& map);
    Map(Map&& map);
    ~Map();
    Map& operator= (Map other);
    friend void swap(Map& first, Map& second);
    
    enum class MoveType {
      Wall,
      Wrap,
      Warp,
      ReverseWarp
    };
    
    static std::list<MoveType> listMoveTypes();
    static std::string stringForMoveType(MoveType type);
    static bool moveTypeTakesMap(MoveType type);
    static std::string shortForMoveType(MoveType type);
    static MoveType moveTypeForShort(std::string str);
    
    int getID() const;
    std::string getTitle() const;
    int getTileAt(int x, int y) const;
    const std::list<std::shared_ptr<MapObjectEntry>>& getObjects() const;
    wxTreeItemId getTreeItemId() const;
    std::list<std::shared_ptr<Map>> getChildren() const;
    bool getExpanded() const;
    World* getWorld() const;
    bool getHidden() const;
    MoveType getLeftMoveType() const;
    MoveType getRightMoveType() const;
    MoveType getUpMoveType() const;
    MoveType getDownMoveType() const;
    int getLeftMoveMapID() const;
    int getRightMoveMapID() const;
    int getUpMoveMapID() const;
    int getDownMoveMapID() const;
    
    void setTitle(std::string title, bool dirty = true);
    void setTileAt(int x, int y, int tile, bool dirty = true);
    void setMapdata(int* mapdata, bool dirty = true);
    void addObject(std::shared_ptr<MapObjectEntry> obj, bool dirty = true);
    void removeObject(std::shared_ptr<MapObjectEntry> obj, bool dirty = true);
    void setTreeItemId(wxTreeItemId id);
    void addChild(int id);
    void setExpanded(bool exp);
    void setHidden(bool hid);
    void setLeftMoveType(MoveType move, bool dirty = true);
    void setRightMoveType(MoveType move, bool dirty = true);
    void setUpMoveType(MoveType move, bool dirty = true);
    void setDownMoveType(MoveType move, bool dirty = true);
    void setLeftMoveMapID(int id, bool dirty = true);
    void setRightMoveMapID(int id, bool dirty = true);
    void setUpMoveMapID(int id, bool dirty = true);
    void setDownMoveMapID(int id, bool dirty = true);
    
  private:
    int id;
    World* world;
    std::list<std::shared_ptr<MapObjectEntry>> objects;
    int* mapdata;
    std::string title {"Untitled Map"};
    std::list<int> children;
    wxTreeItemId treeItemId;
    bool expanded = false;
    bool hidden = false;
    MoveType leftType = MoveType::Wall;
    MoveType rightType = MoveType::Wall;
    MoveType upType = MoveType::Wall;
    MoveType downType = MoveType::Wall;
    int leftMap = 0;
    int rightMap = 0;
    int upMap = 0;
    int downMap = 0;
};

class MapPtrCtr : public wxTreeItemData {
  public:
    Map* map;
  
    MapPtrCtr(Map* map) : map(map) {}
};

class MoveTypeCtr {
  public:
    Map::MoveType type;
    
    MoveTypeCtr(Map::MoveType type) : type(type) {}
};

#endif