void Map::loadLayer(FileParser &infile) { if (infile.key == "type") { // @ATTR layer.type|string|Map layer type. layers.resize(layers.size()+1); layers.back().resize(w); for (size_t i=0; i<layers.back().size(); ++i) { layers.back()[i].resize(h); } layernames.push_back(infile.val); if (infile.val == "collision") collision_layer = static_cast<int>(layernames.size())-1; } else if (infile.key == "format") { // @ATTR layer.format|string|Format for map layer, must be 'dec' if (infile.val != "dec") { infile.error("Map: The format of a layer must be 'dec'!"); logErrorDialog("Map: The format of a layer must be 'dec'!"); mods->resetModConfig(); Exit(1); } } else if (infile.key == "data") { // @ATTR layer.data|raw|Raw map layer data // layer map data handled as a special case // The next h lines must contain layer data. for (int j=0; j<h; j++) { std::string val = infile.getRawLine(); infile.incrementLineNum(); if (!val.empty() && val[val.length()-1] != ',') { val += ','; } // verify the width of this row int comma_count = 0; for (unsigned i=0; i<val.length(); ++i) { if (val[i] == ',') comma_count++; } if (comma_count != w) { infile.error("Map: A row of layer data has a width not equal to %d.", w); mods->resetModConfig(); Exit(1); } for (int i=0; i<w; i++) layers.back()[i][j] = static_cast<unsigned short>(popFirstInt(val)); } } else { infile.error("Map: '%s' is not a valid key.", infile.key.c_str()); } }