diff --git a/data/maps/sample1.tmx b/data/maps/sample1.tmx index d3fbfdc..e67fef9 100644 --- a/data/maps/sample1.tmx +++ b/data/maps/sample1.tmx @@ -1,22 +1,25 @@ - + - + + + + eJzt0aENADAMA8Hsv0U7aXkVHks5cNzy36q6AAAAAABDTmN602ZdD33ym+iS2USb3Ca66LLd/7ku2TQBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAGQ9zDLk7 - + eJztmztvE0EURseh4Q0JUEIBDY8ECIgSJKDgFSBJTZAgBaEj1AgJKAgFzxpo7UgohIgy5A8QkQL4FTikAHrulfey15Nd74y9u0mY70if7F2vYmuO7p2ZtWNMa6YqxjynvKtkXAhKgX0swUfpfKXx/kb5bo07+/gJH6Xzi8b7N+Wj5YR9LMJH6bCP413GnKD8sXwswEfpSH0k+UC/Kp8d5GFnlF1d8fnVtL46TTmTkrMr+LnKpJ35Y5AylJLhNj8Hu9hHuZmSvSYMJ+34uEOZUZlW6Tf+TrJcSEY9/+5aROaPecrWruzrGfYxbpJ9fKDc9fwMN0y2i5B81D3nEF0f4mA8Cnx0Rh/VxDPy8N6jRqQ+pEb4cdrEjorwwR/rkeffXavIPRPX+ybsQ2pCHmei5+ylCB8h1IYgNeLq4wWlx8S1oXtVN+WV5/trH1wH60y4tSH4zuvs5GVCfF0wD0zsYDQ6fqgSmgvGt2fljdRIKPuMLKRnLXquffNC1wicNPCdR/JGzyMhzd+taGd/mBd2jYR03yqNdueRjXTtpiibO6gte+0buhe9P8zyoR3U6fhQpZEfpn03sray17wh968px/36wUrsIC3ipl0vIa95Bb3WalUjLj60l076WOi41IiPDzjpDPlepNV367aPz3TuUiXOvEl3soU9U7bBjxMu931tH72U7ZRuSk8luX7Y2QA99lEO89rawIkrshepp9RIko+jlH7KsRQfvVFtLJmGDzhxJ2u/nuRjkDJEGW7hQ2pDh52gf2Uj80hSz7pozRF632HvSbJ82F7gJhn5vVxajdhOspLlw3YDJ81Iz2r1/To7SVtPdeIDTpKRe1pZ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8iXeXSq7T44E9/42chcZD6y4Jvfqbb74GHUjn7rx/F74vnoVNt9cDlqK5Wsmken2u6Da1Ffr2TDPDrVdh/cjP5vVbJtHgAAf7g/z8X9eS7uz3Nxf56L+/Nc3J8DADDJnF/l4vwqF+dXuTi/ysX5VS7OrwAmxw8dtWaX - + @@ -24,11 +27,7 @@ - - - - - - + + diff --git a/data/textures/city_outside.png b/data/textures/city_outside.png new file mode 100644 index 0000000..419c7d4 Binary files /dev/null and b/data/textures/city_outside.png differ diff --git a/data/textures/city_outside.png.txt b/data/textures/city_outside.png.txt new file mode 100644 index 0000000..8a81cfc --- /dev/null +++ b/data/textures/city_outside.png.txt @@ -0,0 +1,70 @@ +CC-BY-SA 3.0, GPL 2.0, GPL 3.0 (https://opengameart.org/content/lpc-city-outside) +Original credit file follows: +city_outside.png += Stone floor bricks = + * By Tuomo Untinen += Stone floor bricks with water and Stone brick with deep water = + * Water from LPC made by Lanea Zimmerman (Sharm) + * Bricks by Tuomo Untinen += Brown windows = + * Hyptosis + * Plants by Tuomo Untinen += Cement stair tiles = + * Based on cement tiles in LPC made by Lanea Zimmerman (Sharm) += Doors = + * By Guido Bos += Blueish roof and red roof with tower tops= + * Based LPC made by Lanea Zimmerman (Sharm) + * Recoloration by Tuomo Untinen + * Clock by Tuomo Untinen += Red brick wall = + * From LPC made by Lanea Zimmerman (Sharm) + * Wall base by Tuomo Untinen += White wall = + * By Tuomo Untinen + * Wall base from cement tiles in LPC made by Lanea Zimmerman (Sharm) += White and blue roof = + * By Tuomo Untinen += Gray windows = + * By Tuomo Untinen += Gray brick wall = + * By Tuomo Untinen += Yellow brick wall = + * By Tuomo Untinen += Red banners and red flag = + * By Tuomo Untinen += Monk statues = + * Bright statue base is made by Johann C + * Statues are made by Johannes Sjölund += Obelisk = + * Obelisk base is made by Johann C + * Tuomo Untinen += Pedastal and sun clock = + * Tuomo Untinen += Well = + * Xenodora + * Wooden parts by Tuomo Untinen += Blueish gray brick floor tiles = + * By Tuomo Untinen + * Dark border is from Castle_2.png by Lanea Zimmerman (AKA Sharm) += Lamp post = + * Lanea Zimmerman + * William Thompson + * Animation done by Tuomo Untinen += Red chimney = + * Tuomo Untinen += Round flowerbeds = + * Tuomo Untinen + * Plant from Daniel Eddeland (http://opengameart.org/content/lpc-farming-tilesets-magic-animations-and-ui-elements) += Market place = + * Roof based on "Adobe Town Set" Artist: bluecarrot16 License: CC-BY 3.0 / GPL 3.0 / GPL 2.0 / OGA-BY 3.0 Please link to page on opengameart. Based on "[LPC] Adobe Building Set" Artist: Sharm (Lanea Zimmerman) Contributor: William.Thompsonj (William Thompson) License: CC-BY 3.0 / GPL 3.0 / GPL 2.0 / OGA-BY 3.0 http://opengameart.org/content/lpc-adobe-building-set + * Table top Based on LPC base tileset by Lanea Zimmerman (AKA Sharm) + * Plants,hammers, tongs and box from Daniel Eddeland (http://opengameart.org/content/lpc-farming-tilesets-magic-animations-and-ui-elements) + * Chest from LPC base tileset by Lanea Zimmerman (AKA Sharm) + * Rocks, papers and scissors by caeles. + * Dark green bottles by Tuomo Untinen + * Purple and green bottle from Hyptosis Mage city + * Kettle, pan and scoop by Lanea Zimmerman (AKA Sharm) + * Hanging cloths and sack by Tuomo Untinen += Boats = + * Daniel Eddeland (http://opengameart.org/content/lpc-farming-tilesets-magic-animations-and-ui-elements) diff --git a/src/sagotmx/tmx_struct.h b/src/sagotmx/tmx_struct.h index ff65574..4382843 100644 --- a/src/sagotmx/tmx_struct.h +++ b/src/sagotmx/tmx_struct.h @@ -10,7 +10,7 @@ It still has some limitations: * Only one (1) TileSet * No functions to actually change the tilemap -Compiles with g++ and requires C++11 support. +Compiles with g++ and requires C++11 support. Requirements: * zlib (http://www.zlib.net/) @@ -229,7 +229,7 @@ struct TileSet { }; struct TileLayerData { - std::string encoding; + std::string encoding; std::string compression; std::string payload; }; @@ -269,7 +269,7 @@ struct TileMap { int tilewidth=0; int tileheight=0; int nextobjectid = 0; - TileSet tileset; + std::vector tileset; std::vector layers; std::vector object_groups; }; @@ -351,7 +351,7 @@ inline TileMap string2tilemap(const std::string& tmx_content) { std::string tmx_parseable_content = tmx_content; rapidxml::xml_document<> doc; // character type defaults to char char* parsable_pointer = &tmx_parseable_content[0]; //Legal from C++11 and forward - doc.parse<0>(parsable_pointer); + doc.parse<0>(parsable_pointer); rapidxml::xml_node<> * root_node = doc.first_node("map"); setValueFromAttribute( root_node, "verion", m.version); setValueFromAttribute( root_node, "orientation", m.orientation); @@ -361,8 +361,10 @@ inline TileMap string2tilemap(const std::string& tmx_content) { setValueFromAttribute( root_node, "tilewidth", m.tilewidth); setValueFromAttribute( root_node, "tileheight", m.tileheight); setValueFromAttribute( root_node, "nextobjectid", m.nextobjectid); - const auto& tileset_node = getElement(root_node, "tileset"); - m.tileset = node2tileset(tileset_node); + //const auto& tileset_node = getElement(root_node, "tileset"); + for (rapidxml::xml_node<> * tileset_node = root_node->first_node("tileset"); tileset_node; tileset_node = tileset_node->next_sibling("tileset")) { + m.tileset.push_back(node2tileset(tileset_node)); + } for (rapidxml::xml_node<> * layer_node = root_node->first_node("layer"); layer_node; layer_node = layer_node->next_sibling("layer")) { TileLayer tl; setValueFromAttribute(layer_node, "name", tl.name); @@ -428,12 +430,21 @@ inline void xml_add_attribute(std::iostream& io, const char* name, int value) { } } -inline void xml_add_tileset(std::iostream& io, const TileMap& m) { - const auto& ts = m.tileset; +inline void xml_add_tileset(std::iostream& io, const TileMap& m, size_t tile_set_number) { + const auto& ts = m.tileset.at(tile_set_number); io << "\n"; + if (ts.source.length() > 0) { + xml_add_attribute(io, "source", ts.source); + } + else { + io << " name=\"" << ts.name << "\" tilewidth=\""<\n"; + if (ts.source.length() == 0) { + //Write image here + } + io << "\n"; } inline void xml_add_layer(std::iostream& io, const TileMap& m, size_t layer_number) { @@ -495,7 +506,9 @@ inline std::string tilemap2string(const TileMap& m) { xml_add_attribute(ret, "tileheight", m.tileheight); xml_add_attribute(ret, "nextobjectid", m.nextobjectid); ret << ">\n"; - xml_add_tileset(ret, m); + for (size_t i = 0; i < m.tileset.size(); ++i) { + xml_add_tileset(ret, m, i); + } for (size_t i = 0; i < m.layers.size(); ++i) { xml_add_layer(ret, m, i); } @@ -519,7 +532,11 @@ inline std::string tilemap2string(const TileMap& m) { */ inline void getTextureLocationFromGid(const TileMap& tm, int gid, std::string* imageFile, int* x, int* y, int* w, int* h ) { //Currently hardcoded to one tileset - const TileSet *ts = &(tm.tileset); + const TileSet *ts = nullptr; + if (tm.tileset.size() < 1) { + return; + } + ts = &(tm.tileset.at(0)); //TODO: Check this. Is "firstgid" from the tiledset related? gid--; //Gids starts at 1 by default while (ts->alternativeSource) { @@ -552,13 +569,13 @@ inline bool tileInBound(const TileMap& tm, int x, int y) { /** * This function tells the gid of the tile in a given location on a given map, on a given layer - * - * If the layer is corrupt or the coordinates out of bound then the behavior is unspecified. + * + * If the layer is corrupt or the coordinates out of bound then the behavior is unspecified. * It may return the wrong gid or throw a SagoTiledException - * + * * @param m The TileMap to look at. Required because the total size are located here * @param l The layer to look at - * @param x The X coordinate + * @param x The X coordinate * @param y The Y coordiante * @return The gid number of the given tile. Provided that X and Y are within the map limits */ diff --git a/src/saland/model/World.cpp b/src/saland/model/World.cpp index cf54bf9..0d3640d 100644 --- a/src/saland/model/World.cpp +++ b/src/saland/model/World.cpp @@ -148,7 +148,7 @@ void World::init(std::shared_ptr& world, const std::string& mapFileName std::string tmx_file = sago::GetFileContent(mapFileName); ts = sago::tiled::string2tileset(tsx_file); tm = sago::tiled::string2tilemap(tmx_file); - tm.tileset.alternativeSource = &ts; + tm.tileset.at(0).alternativeSource = &ts; init_physics(world); }