/** The added word is invalid in term of position (horizontally) but it does not exist in the dictionary *\author Abdallah */ void test_horizontal_invalid () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag //Testing horizontal "to" t1 = new_tile('t'); t2 = new_tile('w'); t3 = new_tile('o'); t4 = new_tile ('x'); board[7][7] = &t1; board[7][8] = &t2; board[7][9] = &t3; board[7][6] = &t4; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score); }
/** * A word placed but not passing by the central square * \author Abdallah */ void test_invalid4() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag t1 = new_tile('g'); t2 = new_tile('o'); t3 = new_tile('o'); t4 = new_tile ('d'); board[7][8] = &t1; board[7][9] = &t2; board[7][10] = &t3; board[7][11] = &t4; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score); printf("Invalid placement \n"); }
/** The added word is valid in term of position (vertically) and exists in the dictionary *\author Abdallah */ void test_vertical_valid () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag //Testing horizontal "to" t1 = new_tile('l'); t2 = new_tile('o'); t3 = new_tile('s'); t4 = new_tile ('e'); board[7][7] = &t1; board[8][7] = &t2; board[9][7] = &t3; board[10][7] = &t4; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score); printf("The word added to the board is %s\n",str [0] ); }
/** * nth play where the board is in a valid state that can occur after one or more plays the added tiles are valid and pass by a triple word square * \author Abdallah */ void test_nth_valid3() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('c'); t2 = new_tile('l'); t3 = new_tile('a'); t8 = new_tile('n'); t4 = new_tile ('o'); t5 = new_tile('v'); t6 = new_tile('a'); t7 = new_tile('l'); t9 = new_tile('o'); t10 = new_tile ('n'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t8; board_prev[6][10] = &t4; board_prev[6][11] = &t5; board_prev[6][12] = &t6; board_prev[6][13] = &t7; board [7][7] = &t1; board [7][8] = &t2; board [7][9] = &t3; board [7][10] = &t8; board [6][10] = &t4; board [6][11] = &t5; board [6][12] = &t6; board [6][13] = &t7; board[7][13] = &t9; board[7][14] = &t10; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected added score is 8\nL(1) + O (1) =2 \n( O(1) + N (1) )*3 = 6\n"); }
/** @brief add_tile * * @todo: document this function */ void Tileset::add_tile(const std::string& path) { Tile::ptr new_tile(new Tile(path, transparent_colour_)); new_tile->load(); tiles_.push_back(new_tile); }
static unsigned int add_tile(unsigned int i, int x, int y, int w, int h) { int j = 0; if ((chk_host(i)) && (j = new_tile())) { /* Set a default display configuration. */ tile[j] = default_tile; /* The rectangle defines viewport size and default ortho projection. */ tile[j].pix_x = tile[j].win_x = x; tile[j].pix_y = tile[j].win_y = y; tile[j].pix_w = tile[j].win_w = w; tile[j].pix_h = tile[j].win_h = h; /* Include this tile in the host and in the total display. */ host[i].tile[host[i].n++] = j; bound_display(); } return j; }
/** * second play is tested over first play * the second play adds 3 words to the board by amending tiles to the existing word to form 3 new words *\author Abdallah */ void test_second_valid3() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('h'); t2 = new_tile('a'); t3 = new_tile('s'); t4 = new_tile ('r'); t5 = new_tile('e'); t6 = new_tile('m'); t7 = new_tile('d'); board_prev[7][7] = &t1; board_prev[8][7] = &t2; board_prev[9][7] = &t3; board[7][7] = &t1; board[8][7] = &t2; board[9][7] = &t3; board[6][8] = &t4; board[7][8] = &t5; board[8][8] = &t6; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected value : 21\nR(1)*2 + E(1) + M(3)*2 = 9\nH(4) + E (1) =5 \nA(1) + M(3)*2 = 7\n"); }
/** * second play is tested over first play * the second play adds a word that exists in the dictionary but is nor properly connected *\author Abdallah */ void test_second_invalid2() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('h'); t2 = new_tile('a'); t3 = new_tile('s'); t4 = new_tile ('r'); t5 = new_tile('e'); t6 = new_tile('m'); t7 = new_tile('d'); board_prev[7][7] = &t1; board_prev[8][7] = &t2; board_prev[9][7] = &t3; board[7][7] = &t1; board[8][7] = &t2; board[9][7] = &t3; board[6][1] = &t4; board[7][1] = &t5; board[8][1] = &t6; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); }
/** * nth play where the board is in a valid state that can occur after one or more plays the added tiles are valid and pass by a double word square * \author Abdallah */ void test_nth_valid2() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('c'); t2 = new_tile('l'); t3 = new_tile('a'); t8 = new_tile('n'); t4 = new_tile ('n'); t5 = new_tile('o'); t6 = new_tile('n'); t7 = new_tile('e'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t8; board_prev[8][10] = &t5; board_prev[9][10] = &t6; board [7][7] = &t1; board [7][8] = &t2; board [7][9] = &t3; board [7][10] = &t8; board[8][10] = &t5; board[9][10] = &t6; board[10][10] = &t7; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected added score is 8\n"); }
static unsigned int new_tile(void) { unsigned int i; void *v; if ((i = vec_add(tile, sizeof (struct tile)))) { memset(tile +i, 0, sizeof (struct tile)); return i; } if ((v = vec_gro(tile, sizeof (struct tile)))) { tile = (struct tile *) v; return new_tile(); } return 0; }
/** * second play is tested over first play * the second play adds 4 words to the board by amending tiles to the existing word to form 4 new words * this give me a huge error but from the analysis I can assume it is from the part when the the char is changed to int and vice versa because if the tenth is changed from 1 to 0 the answer would be correct *\author Abdallah */ void test_second_valid4() { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('h'); t2 = new_tile('a'); t3 = new_tile('i'); t8 = new_tile('r'); t4 = new_tile ('r'); t5 = new_tile('e'); t6 = new_tile('m'); t7 = new_tile('s'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t8; board [7][7] = &t1; board [7][8] = &t2; board [7][9] = &t3; board [7][10] = &t8; board[8][6] = &t4; board[8][7] = &t5; board[8][8] = &t6; board[8][9] = &t7; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected value is 10 + 5 + 7 + 2 = 24 \n"); }
/** * @brief Convenience method to construct a logical tile wrapping a tile group. * @param tile_group Tile group to be wrapped. * * @return Logical tile wrapping tile group. */ LogicalTile *LogicalTileFactory::WrapTileGroup( const std::shared_ptr<storage::TileGroup> &tile_group) { std::unique_ptr<LogicalTile> new_tile(new LogicalTile()); const int position_list_idx = 0; new_tile->AddPositionList( CreateIdentityPositionList(tile_group->GetActiveTupleCount())); // Construct schema. std::vector<catalog::Schema> &schemas = tile_group->GetTileSchemas(); PELOTON_ASSERT(schemas.size() == tile_group->NumTiles()); for (unsigned int i = 0; i < schemas.size(); i++) { auto base_tile_ref = tile_group->GetTileReference(i); for (oid_t col_id = 0; col_id < schemas[i].GetColumnCount(); col_id++) { new_tile->AddColumn(base_tile_ref, col_id, position_list_idx); } } return new_tile.release(); }
/** * @brief Convenience method to construct a logical tile wrapping a tile group. * @param tile_group Tile group to be wrapped. * * @return Logical tile wrapping tile group. */ LogicalTile *LogicalTileFactory::WrapTileGroup( const std::shared_ptr<storage::TileGroup> &tile_group) { std::unique_ptr<LogicalTile> new_tile(new LogicalTile()); const int position_list_idx = 0; new_tile->AddPositionList( CreateIdentityPositionList(tile_group->GetActiveTupleCount())); // Construct schema. unsigned int num_tiles = tile_group->NumTiles(); for (unsigned int i = 0; i < num_tiles; i++) { auto base_tile_ref = tile_group->GetTileReference(i); auto schema = base_tile_ref->GetSchema(); for (oid_t col_id = 0; col_id < schema->GetColumnCount(); col_id++) { new_tile->AddColumn(base_tile_ref, col_id, position_list_idx); } } return new_tile.release(); }
/** * @brief Convenience method to construct a logical tile wrapping base tiles. * @param base_tiles Base tiles to be represented as a logical tile. * * @return Pointer to newly created logical tile. */ LogicalTile *LogicalTileFactory::WrapTiles( const std::vector<std::shared_ptr<storage::Tile>> &base_tile_refs) { PELOTON_ASSERT(base_tile_refs.size() > 0); // TODO ASSERT all base tiles have the same height. std::unique_ptr<LogicalTile> new_tile(new LogicalTile()); // First, we build a position list to be shared by all the tiles. const oid_t position_list_idx = 0; new_tile->AddPositionList(CreateIdentityPositionList( base_tile_refs[0].get()->GetActiveTupleCount())); for (unsigned int i = 0; i < base_tile_refs.size(); i++) { // Next, we construct the schema. int column_count = base_tile_refs[i].get()->GetColumnCount(); for (int col_id = 0; col_id < column_count; col_id++) { new_tile->AddColumn(base_tile_refs[i], col_id, position_list_idx); } } // Drop reference because we created the base tile return new_tile.release(); }
/** * second play is tested over a valid first play word * the second play adds two words to the board by amending tiles to the existing word to form 2 new words \author Abdallah */ void test_second_valid2 () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; t1 = new_tile('f'); t2 = new_tile('i'); t3 = new_tile('l'); t4 = new_tile ('l'); t5 = new_tile('s'); t6 = new_tile('a'); t7 = new_tile('d'); board_prev[7][7] = &t1; board_prev[7][8] = &t2; board_prev[7][9] = &t3; board_prev[7][10] = &t4; board[7][7] = &t1; board[7][8] = &t2; board[7][9] = &t3; board[7][10] = &t4; board[7][11] = &t5; board[8][11] = &t6; board[9][11] = &t7; printf("Board before second play\n"); display_board (board_prev); printf("Board after second play\n"); display_board (board); check_board ( board , board_prev , str , &temp_score ); printf("Expected added value : 14\n F (4) + I (1) + L (1) + L (1) + S (1)*2 = 9 \n s (1)*2 + A (1) + D (2) = 5\n"); temp_score = 0; }
void TileSetData::AddTile(const std::string &path, const uint8_t flags){ Tile new_tile(path, flags); tiles_.push_back(new_tile); }
/** This takes all the visible layers, and merges them into one, leaving the old layers in tact (but invisible) */ afx_msg void CLayerView::OnFlattenVisibleLayers() { unsigned int i; std::vector<sLayer> layers; // get a list of the visible layers for (i = 0; i < (unsigned int)m_Map->GetNumLayers(); i++) { if (m_Map->GetLayer(i).IsVisible()) { layers.push_back(m_Map->GetLayer(i)); } } if (!(layers.size() >= 1)) { MessageBox("No layers are visible!", "No layers are visible", MB_OK); return; } else if (layers.size() == 1) { return; } int result = MessageBox("Flatten all visible layers?", "Flatten Layers", MB_YESNOCANCEL | MB_ICONQUESTION | MB_DEFBUTTON3); if (result != IDYES) { return; } int width = 0; int height = 0; // find the size of the image we're going to create for (i = 0; i < layers.size(); i++) { if (layers[i].GetWidth() > width) { width = layers[i].GetWidth(); } if (layers[i].GetHeight() > height) { height = layers[i].GetHeight(); } } if (width <= 0 || height <= 0) return; sLayer new_layer; new_layer.SetName("flattened_layer"); new_layer.Resize(width, height); sTileset& tileset = m_Map->GetTileset(); sTile new_tile(tileset.GetTileWidth(), tileset.GetTileHeight()); std::vector<int> blended_tile_indexes; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { new_tile.Clear(); blended_tile_indexes.clear(); for (unsigned int i = 0; i < layers.size(); ++i) { if (y < layers[i].GetHeight() && x < layers[i].GetWidth()) { sTile& tile = tileset.GetTile(layers[i].GetTile(x, y)); bool is_empty = true; for (int iy = 0; iy < tile.GetHeight(); ++iy) { for (int ix = 0; ix < tile.GetWidth(); ++ix) { if (tile.GetPixel(ix, iy).alpha != 0) { is_empty = false; break; } } } if (is_empty == false) { blended_tile_indexes.push_back(layers[i].GetTile(x, y)); BlendImage(new_tile.GetWidth(), new_tile.GetHeight(), tile.GetWidth(), tile.GetHeight(), new_tile.GetPixels(), tile.GetPixels()); } } } if (blended_tile_indexes.size() == 1) { new_layer.SetTile(x, y, blended_tile_indexes[0]); } else { int tile_index = -1; // make the tile fully opaque new_tile.SetAlpha(255, true); // see if the new_tile already exists within the tileset for (int i = 0; i < tileset.GetNumTiles(); ++i) { if (tileset.GetTile(i) == new_tile) { tile_index = i; break; } } if (tile_index == -1) { tile_index = tileset.GetNumTiles(); tileset.AppendTiles(1); tileset.GetTile(tile_index) = new_tile; } new_layer.SetTile(x, y, tile_index); } } } // turn the layers that were visible off for (i = 0; i < layers.size(); i++) { m_Map->GetLayer(i).SetVisible(false); } m_Map->AppendLayer(new_layer); Invalidate(); m_Handler->LV_MapChanged(); }
/** The added word is valid in term of position (horizontally) exists in the dictionary *\author Abdallah */ void test_horizontal_valid () { tile * board [max_rc] [max_rc]; new_board(board); tile * board_prev [max_rc] [max_rc]; new_board (board_prev); bag real_bag, inhand_bag; tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15; real_bag = new_real_bag();//initializing the real bag inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag //tested word:holocrystalline, longest possible (15 letters) t1 = new_tile('h'); t2 = new_tile('o'); t3 = new_tile('l'); t4 = new_tile ('o'); t5 = new_tile('c'); t6 = new_tile('r'); t7 = new_tile('y'); t8 = new_tile ('s'); t9 = new_tile('t'); t10 = new_tile('a'); t11= new_tile('l'); t12= new_tile ('l'); t13= new_tile ('i'); t14= new_tile ('n'); t15= new_tile ('e'); board[7][0] = &t1; board[7][1] = &t2; board[7][2] = &t3; board[7][3] = &t4; board[7][4] = &t5; board[7][5] = &t6; board[7][6] = &t7; board[7][7] = &t8; board[7][8] = &t9; board[7][9] = &t10; board[7][10] = &t11; board[7][11] = &t12; board[7][12] = &t13; board[7][13] = &t14; board[7][14] = &t15; display_board(board); display_bag (inhand_bag); char new_word [word_len]; check_board ( board , board_prev , str , & temp_score ); printf("The word added to the board is %s\n",str [0] ); }
bool Engine::LoadLevel( std::string Filename ) { std::string level_folder = Filename; size_t clear_begin; for( clear_begin = level_folder.size() - 1; clear_begin >= 0; --clear_begin ) { if( level_folder.at( clear_begin ) == '/' || level_folder.at( clear_begin ) == '\\' ) { ++clear_begin; break; } } level_folder.erase( clear_begin ); // Load the level TiXmlDocument level_document; if( !level_document.LoadFile( Filename ) ) { return false; } // Obtain the root element & verify its name TiXmlElement *level_root = level_document.RootElement(); if( level_root == nullptr || level_root->Value() != "map" ) { return false; } // Root Attributes std::string level_orientation; unsigned int level_width; unsigned int level_height; unsigned int level_tile_width; unsigned int level_tile_height; // Root Attribute Verification if( level_root->Attribute( "orientation" ) == nullptr || level_root->Attribute( "width" ) == nullptr || level_root->Attribute( "height" ) == nullptr || level_root->Attribute( "tilewidth" ) == nullptr || level_root->Attribute( "tileheight" ) == nullptr ) { return false; } // Root Attribute Processing level_orientation = level_root->Attribute( "orientation" ); level_width = atoi( level_root->Attribute( "width" ) ); level_height = atoi( level_root->Attribute( "height" ) ); level_tile_width = atoi( level_root->Attribute( "tilewidth" ) ); level_tile_height = atoi( level_root->Attribute( "tileheight" ) ); if( level_orientation != "isometric" && level_orientation != "orthogonal" ) { return false; } m_level_orientation = level_orientation; // Level Properties if( level_root->FirstChild( "properties" ) == nullptr || level_root->FirstChild( "properties" )->ToElement() == nullptr ) { return false; } TiXmlElement *level_properties = level_root->FirstChild( "properties" )->ToElement(); for( TiXmlNode *level_property_node = level_properties->FirstChild( "property" ); level_property_node != nullptr; level_property_node = level_properties->IterateChildren( "property", level_property_node ) ) { if( level_property_node->ToElement() == nullptr ) { return false; } // Property Attributes std::string property_name; std::string property_value; // Property Attribute Verification if( level_property_node->ToElement()->Attribute( "name" ) == nullptr || level_property_node->ToElement()->Attribute( "value" ) == nullptr) { return false; } // Property Attribute Processing property_name = level_property_node->ToElement()->Attribute( "name" ); property_value = level_property_node->ToElement()->Attribute( "value" ); m_level_properties[ property_name ] = property_value; } std::map< unsigned int, TileInfo > tile_list; // Tilesets for( TiXmlNode *level_tileset_node = level_root->FirstChild( "tileset" ); level_tileset_node != nullptr; level_tileset_node = level_root->IterateChildren( "tileset", level_tileset_node ) ) { if( level_tileset_node->ToElement() == nullptr ) { return false; } // Tileset Attributes unsigned int first_gid; std::string source; unsigned int tile_width; unsigned int tile_height; unsigned int spacing = 0; unsigned int margin = 0; // Tileset Attribute (and Child!) Verification if( level_tileset_node->ToElement()->Attribute( "firstgid" ) == nullptr || level_tileset_node->ToElement()->Attribute( "tilewidth" ) == nullptr || level_tileset_node->ToElement()->Attribute( "tileheight" ) == nullptr || ( level_tileset_node->ToElement()->Attribute( "source" ) == nullptr && ( level_tileset_node->ToElement()->FirstChild( "image" ) == nullptr || level_tileset_node->ToElement()->FirstChild( "image" )->ToElement() == nullptr || level_tileset_node->ToElement()->FirstChild( "image" )->ToElement()->Attribute( "source" ) == nullptr ) ) ) { return false; } // Tileset Attribute Processing first_gid = atoi( level_tileset_node->ToElement()->Attribute( "firstgid" ) ); tile_width = atoi( level_tileset_node->ToElement()->Attribute( "tilewidth" ) ); tile_height = atoi( level_tileset_node->ToElement()->Attribute( "tileheight" ) ); if( level_tileset_node->ToElement()->Attribute( "spacing" ) != nullptr ) { spacing = atoi( level_tileset_node->ToElement()->Attribute( "spacing" ) ); } if( level_tileset_node->ToElement()->Attribute( "margin" ) != nullptr ) { margin = atoi( level_tileset_node->ToElement()->Attribute( "margin" ) ); } if( level_tileset_node->ToElement()->Attribute( "source" ) != nullptr ) { source = level_folder + level_tileset_node->ToElement()->Attribute( "source" ); //! @todo TSX Parsing return false; } else { // Process the tileset source = level_folder + level_tileset_node->ToElement()->FirstChild( "image" )->ToElement()->Attribute( "source" ); sf::IntRect temp_rect; unsigned int tile_gid = first_gid; unsigned int tileset_width = GetTexture( source )->GetWidth(); unsigned int tileset_height = GetTexture( source )->GetHeight(); //! @todo Support Transparency (a slight issue with SFML) temp_rect.Width = tile_width; temp_rect.Height = tile_height; // Process tiles for( unsigned int x = margin; x <= temp_rect.Width - tile_width - margin; x += tile_width + spacing ) { for( unsigned int y = margin; y <= temp_rect.Height - tile_height - margin; y += tile_height + spacing ) { temp_rect.Left = x; temp_rect.Top = y; TileInfo new_tile; new_tile.filename = source; new_tile.gid = tile_gid; new_tile.region = temp_rect; tile_list[ new_tile.gid ] = new_tile; ++tile_gid; } } } } m_layers.clear(); // Layers & Object Groups for( TiXmlNode *level_layer_node = level_root->FirstChild(); level_layer_node != nullptr; level_layer_node = level_root->IterateChildren( level_layer_node ) ) { if( level_layer_node->ToElement() == nullptr ) { return false; } if( level_layer_node->Value() != "layer" && level_layer_node->Value() != "objectgroup" ) { continue; } if( level_layer_node->Value() == "layer" ) { Layer new_layer; unsigned int tile_num = 0; // Layer Attributes //! @todo Support Layer Names //! @todo Support Layer Opacity //! @todo Support Tile Flipping //! @todo Support Layer Properties // Data Processing if( level_layer_node->ToElement()->FirstChild( "data" ) == nullptr || level_layer_node->ToElement()->FirstChild( "data" )->ToElement() == nullptr ) { return false; } TiXmlElement *level_layer_data = level_layer_node->ToElement()->FirstChild( "data" )->ToElement(); std::string encoding; std::string compression; if( level_layer_data->Attribute( "encoding" ) != nullptr ) { encoding = level_layer_data->Attribute( "encoding" ); } if( level_layer_data->Attribute( "compression" ) != nullptr ) { compression = level_layer_data->Attribute( "compression" ); } if( compression == "gzip" ) { return false; // gzip is unsupported due to the developer's unfortunate choice to use the GPL. } if( compression == "zlib" ) { //! @todo zlib translation return false; } if( encoding == "base64" ) { //! @todo Base64 translation return false; } else if( encoding == "csv" ) { //! @todo CSV translation return false; } else { for( TiXmlNode *level_layer_tile_node = level_layer_data->FirstChild( "tile" ); level_layer_tile_node != nullptr; level_layer_tile_node = level_layer_data->IterateChildren( "tile", level_layer_tile_node ) ) { if( level_layer_tile_node->ToElement() == nullptr || level_layer_tile_node->ToElement()->Attribute( "gid" ) == nullptr ) { return false; } // Process New Tile unsigned int tile_gid = atoi( level_layer_tile_node->ToElement()->Attribute( "gid" ) ); std::shared_ptr< Object > new_tile( reinterpret_cast< Object* >( new Tile ) ); sf::Sprite new_tile_sprite( *( GetTexture( tile_list[ tile_gid ].filename ).get() ), tile_list[ tile_gid ].region ); // Calculate Tile Position if( level_orientation == "orthogonal" ) { unsigned int tile_x_index = tile_num % level_width; unsigned int tile_y_index = ( tile_num - tile_x_index ) / level_width; sf::Vector2f tile_pos; tile_pos.x = tile_x_index * level_tile_width; tile_pos.y = tile_y_index * level_tile_height; new_tile_sprite.SetPosition( tile_pos ); } if( level_orientation == "isometric" ) { unsigned int tile_x_index = tile_num % level_width; unsigned int tile_y_index = ( tile_num - tile_x_index ) / level_width; unsigned int total_width = level_width * level_tile_width; unsigned int total_height = level_height * level_tile_height; sf::Vector2f tile_pos; tile_pos.x = static_cast< float >( total_width + level_tile_width * ( tile_x_index - tile_y_index - 1 ) ) / 2.f; tile_pos.y = static_cast< float >( level_tile_height * ( tile_x_index + tile_y_index ) ) / 2.f; new_tile_sprite.SetPosition( tile_pos ); } // Set up new tile reinterpret_cast< Tile* >( new_tile.get() )->m_tile = new_tile_sprite; new_layer.Add( new_tile ); ++tile_num; } } // Add Layer m_layers.push_back( new_layer ); } if( level_layer_node->Value() == "objectgroup" ) { Layer new_layer; // Layer Attributes //! @todo Support Object Group Names //! @todo Support Object Group Opacity and Visibility // Layer Properties //! @todo Support Object Group Properties // Object Processing for( TiXmlNode *level_object_node = level_layer_node->ToElement()->FirstChild( "object" ); level_object_node != nullptr; level_object_node = level_layer_node->ToElement()->IterateChildren( "object", level_object_node ) ) { if( level_object_node->ToElement() == nullptr ) { return false; } // Object Attributes float object_x; float object_y; float object_width; float object_height; std::string object_type( "" ); // Object Attribute Verification if( level_object_node->ToElement()->Attribute( "x" ) == nullptr || level_object_node->ToElement()->Attribute( "y" ) == nullptr ) { return false; } // Object Property Processing std::map< std::string, std::string > object_properties; TiXmlNode *level_object_properties = level_object_node->ToElement()->FirstChild( "properties" ); if( level_object_properties != nullptr && level_object_properties->ToElement() != nullptr ) { for( TiXmlNode *level_object_property = level_object_properties->ToElement()->FirstChild( "property" ); level_object_property != nullptr; level_object_property = level_object_properties->ToElement()->IterateChildren( "property", level_object_properties ) ) { if( level_object_property->ToElement() == nullptr ) { return false; } // Property Attributes std::string property_name; std::string property_value; // Property Attribute Verification if( level_object_property->ToElement()->Attribute( "name" ) == nullptr || level_object_property->ToElement()->Attribute( "value" ) == nullptr) { return false; } // Property Attribute Processing property_name = level_object_property->ToElement()->Attribute( "name" ); property_value = level_object_property->ToElement()->Attribute( "value" ); // Add the property object_properties[ property_name ] = property_value; } } // Object Attribute Processing object_x = atof( level_object_node->ToElement()->Attribute( "x" ) ); object_y = atof( level_object_node->ToElement()->Attribute( "y" ) ); if( level_object_node->ToElement()->Attribute( "type" ) != nullptr ) { object_type = level_object_node->ToElement()->Attribute( "type" ); } if( level_object_node->ToElement()->Attribute( "gid" ) != nullptr ) { object_width = tile_list[ atoi( level_object_node->ToElement()->Attribute( "gid" ) ) ].region.Width; object_height = tile_list[ atoi( level_object_node->ToElement()->Attribute( "gid" ) ) ].region.Height; } if( level_object_node->ToElement()->Attribute( "width" ) != nullptr ) { object_width = atof( level_object_node->ToElement()->Attribute( "width" ) ); } if( level_object_node->ToElement()->Attribute( "height" ) != nullptr ) { object_width = atof( level_object_node->ToElement()->Attribute( "height" ) ); } // Create & Add Object if( m_creators.find( object_type ) != m_creators.end() ) { new_layer.Add( m_creators[ object_type ]( object_x, object_y, object_width, object_height, object_properties ) ); } } // Add Layer m_layers.push_back( new_layer ); } } }