- std::map<std::string,SerializablePtr> rootObj;
- std::map<std::string,SerializablePtr>::iterator it;
-
- if (!root->get(rootObj))
- {
- std::cerr << "error loading scene tilemap object" << std::endl;
- return;
- }
-
- long width = 1;
- long height = 1;
- std::vector< std::vector<Tilemap::Index> > indices;
-
- if ((it = rootObj.find("width")) != rootObj.end())
- {
- (*it).second->get(width);
- }
- else
- {
- std::cerr << "width is a required field of a tilemap" << std::endl;
- return;
- }
-
- std::vector<SerializablePtr> tiles;
-
- if ((it = rootObj.find("tiles")) != rootObj.end() &&
- (*it).second->get(tiles) &&
- tiles.size() % width == 0)
- {
- std::vector<SerializablePtr>::iterator jt;
- int w, h;
-
- height = tiles.size() / width;
- indices.resize(height);
-
- // the indices are stored upside-down in the scene file so that they
- // are easier to edit as text, so we'll need to load them last row
- // first
-
- for (h = height - 1, jt = tiles.begin(); jt != tiles.end(); --h)
- {
- std::vector<Tilemap::Index> row;
-
- for (w = 0; w < width && jt != tiles.end(); ++w, ++jt)
- {
- long index;
-
- if ((*jt)->get(index))
- {
- row.push_back(Tilemap::Index(index));
- }
- }
-
- indices[h] = row;
- }
- }
- else
- {
- std::cerr << "error loading tiles from tilemap object" << std::endl;
- return;
- }