Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch up to TMX Format as of Tiled 0.12 #25

Merged
merged 1 commit into from
May 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions src/TmxMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ namespace Tmx
, background_color()
, version(0.0)
, orientation(TMX_MO_ORTHOGONAL)
, render_order(TMX_RIGHT_DOWN)
, stagger_axis(TMX_SA_NONE)
, stagger_index(TMX_SI_NONE)
, width(0)
, height(0)
, tile_width(0)
, tile_height(0)
, next_object_id(0)
, hexside_length(0)
, layers()
, tile_layers()
, object_groups()
Expand Down Expand Up @@ -218,19 +222,22 @@ namespace Tmx
// Read the orientation
std::string orientationStr = mapElem->Attribute("orientation");

if (!orientationStr.compare("orthogonal"))
if (!orientationStr.compare("orthogonal"))
{
orientation = TMX_MO_ORTHOGONAL;
}
else if (!orientationStr.compare("isometric"))
else if (!orientationStr.compare("isometric"))
{
orientation = TMX_MO_ISOMETRIC;
}
else if (!orientationStr.compare("staggered"))
else if (!orientationStr.compare("staggered"))
{
orientation = TMX_MO_STAGGERED;
}

else if (!orientationStr.compare("hexagonal"))
{
orientation = TMX_MO_HEXAGONAL;
}

// Read the render order
if (mapElem->Attribute("renderorder"))
Expand All @@ -254,6 +261,41 @@ namespace Tmx
}
}

// Read the stagger axis
if (mapElem->Attribute("staggeraxis"))
{
std::string staggerAxisStr = mapElem->Attribute("staggeraxis");
if (!staggerAxisStr.compare("x"))
{
stagger_axis = TMX_SA_X;
}
else if (!staggerAxisStr.compare("y"))
{
stagger_axis = TMX_SA_Y;
}
}

// Read the stagger index
if (mapElem->Attribute("staggerindex"))
{
std::string staggerIndexStr = mapElem->Attribute("staggerindex");
if (!staggerIndexStr.compare("even"))
{
stagger_index = TMX_SI_EVEN;
}
else if (!staggerIndexStr.compare("odd"))
{
stagger_index = TMX_SI_ODD;
}
}

// read the hexside length
if (mapElem->IntAttribute("hexsidelength"))
{
hexside_length = mapElem->IntAttribute("hexsidelength");
}

// read all other attributes
const tinyxml2::XMLNode *node = mapElem->FirstChild();
while( node )
{
Expand Down
37 changes: 36 additions & 1 deletion src/TmxMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ namespace Tmx
TMX_MO_ISOMETRIC = 0x02,

// This map is an isometric staggered map.
TMX_MO_STAGGERED = 0x03
TMX_MO_STAGGERED = 0x03,

// This map is an hexagonal staggered map.
TMX_MO_HEXAGONAL = 0x04
};

//-------------------------------------------------------------------------
Expand All @@ -83,6 +86,26 @@ namespace Tmx
TMX_LEFT_UP= 0x03
};

//-------------------------------------------------------------------------
// The stagger axis for the map. (only applies to hexagonal maps)
//-------------------------------------------------------------------------
enum MapStaggerAxis
{
TMX_SA_NONE = 0x00, // if the map is not hexagonal
TMX_SA_X = 0x01,
TMX_SA_Y = 0x02
};

//-------------------------------------------------------------------------
// The stagger index for the map. (applies to hexagonal AND isometric staggered maps)
//-------------------------------------------------------------------------
enum MapStaggerIndex
{
TMX_SI_NONE = 0x00, // if the map is not hexagonal
TMX_SI_EVEN = 0x01,
TMX_SI_ODD = 0x02
};

//-------------------------------------------------------------------------
// This class is the root class of the parser.
// It has all of the information in regard to the TMX file.
Expand Down Expand Up @@ -123,6 +146,12 @@ namespace Tmx
// Get the render order of the map.
Tmx::MapRenderOrder GetRenderOrder() const { return render_order; }

// Get the stagger axis of the map.
Tmx::MapStaggerAxis GetStaggerAxis() const { return stagger_axis; }

// Get the stagger index of the map.
Tmx::MapStaggerIndex GetStaggerIndex() const { return stagger_index; }

// Get the width of the map, in tiles.
int GetWidth() const { return width; }

Expand All @@ -138,6 +167,9 @@ namespace Tmx
// Get the next object id.
int GetNextObjectId() const { return next_object_id; }

// Get the hexside length.
int GetHexsideLength() const { return hexside_length; }

// Get the layer at a certain index.
const Tmx::Layer *GetLayer(int index) const { return layers.at(index); }

Expand Down Expand Up @@ -210,12 +242,15 @@ namespace Tmx
double version;
Tmx::MapOrientation orientation;
Tmx::MapRenderOrder render_order;
Tmx::MapStaggerAxis stagger_axis;
Tmx::MapStaggerIndex stagger_index;

int width;
int height;
int tile_width;
int tile_height;
int next_object_id;
int hexside_length;

std::vector< Tmx::Layer* > layers;
std::vector< Tmx::TileLayer* > tile_layers;
Expand Down
2 changes: 1 addition & 1 deletion src/TmxObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace Tmx

if (tempName) name = tempName;
if (tempType) type = tempType;

id = objectElem->IntAttribute("id");
x = objectElem->IntAttribute("x");
y = objectElem->IntAttribute("y");
Expand Down
29 changes: 23 additions & 6 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,29 @@ int main(int argc, char * argv[])
printf("error code: %d\n", map->GetErrorCode());
printf("error text: %s\n", map->GetErrorText().c_str());

system("PAUSE");

return map->GetErrorCode();
}

printf(" \n");
printf("====================================\n");
printf("Map\n");
printf("====================================\n");

printf("Version: %1.1f\n", map->GetVersion());
printf("Orientation: %d\n", map->GetOrientation());
if (!map->GetBackgroundColor().empty())
printf("Background Color (hex): %s\n",
map->GetBackgroundColor().c_str());
printf("Render Order: %d\n", map->GetRenderOrder());
if (map->GetStaggerAxis())
printf("Stagger Axis: %d\n", map->GetStaggerAxis());
if (map->GetStaggerIndex())
printf("Stagger Index: %d\n", map->GetStaggerIndex());
printf("Width: %d\n", map->GetWidth());
printf("Height: %d\n", map->GetHeight());
printf("Tile Width: %d\n", map->GetTileWidth());
printf("Tile Height: %d\n", map->GetTileHeight());

// Iterate through the tilesets.
for (int i = 0; i < map->GetNumTilesets(); ++i)
{
Expand All @@ -60,8 +78,9 @@ int main(int argc, char * argv[])
printf("Image Width: %d\n", tileset->GetImage()->GetWidth());
printf("Image Height: %d\n", tileset->GetImage()->GetHeight());
printf("Image Source: %s\n", tileset->GetImage()->GetSource().c_str());
printf("Transparent Color (hex): %s\n",
tileset->GetImage()->GetTransparentColor().c_str());
if (!tileset->GetImage()->GetTransparentColor().empty())
printf("Transparent Color (hex): %s\n",
tileset->GetImage()->GetTransparentColor().c_str());

if (tileset->GetTiles().size() > 0)
{
Expand Down Expand Up @@ -208,7 +227,5 @@ int main(int argc, char * argv[])

delete map;

system("PAUSE");

return 0;
}