Giter Site home page Giter Site logo

Support Flipped Tiles about tileson HOT 3 CLOSED

ssbmtonberry avatar ssbmtonberry commented on August 16, 2024
Support Flipped Tiles

from tileson.

Comments (3)

SSBMTonberry avatar SSBMTonberry commented on August 16, 2024

Hey, @VictorJL !
This is probably related to features described in issue #9.

Due to issues with my arms I've been unable to code for the last two months, but I'm recovering 😊

I'll make this my top priority when I'm back. If you want to look into this yourself meanwhile, I suggest you look for differences related to what's described in #9 and look for the missing link in the related class.

Good luck 😊

from tileson.

SSBMTonberry avatar SSBMTonberry commented on August 16, 2024

@VictorJL: I see the feature you are asking about is something I have completely missed, and due to Tileson wrongfully parsing IDs as int and not uint32_t (or unsigned int), you'll have to convert an eventual ID to unsigned int first, then determine it using the example in the Tiled doc: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#tmx-tile-flipping

This will be implemented with actual flags so you'll not need to do this process yourself once this feature is done.

I am working on it as we speak, but I am sadly still in a recovery process on my arms, so I have a limited time I am able to code, but this my top priority right now. Will update this issue when it's done 🙂

from tileson.

SSBMTonberry avatar SSBMTonberry commented on August 16, 2024

@VictorJL : This feature should now be complete! It would be awesome if you could get the very latest version of Tileson and report if everything works as intended 😄 This should be compatible with tson::Object linked to tiles, tson::Tile and tson::TileObject (which is Tileson-only handling to easily resolve tile positions/drawing data).

Here is a copy/paste from one of the newest integration tests checking flipped tiles (to give you an idea how it works):

TEST_CASE( "Parse map - expect correct flip flags", "[parse][file][flip]" )
{
    tson::Tileson t;
    #ifndef DISABLE_CPP17_FILESYSTEM
    fs::path pathLocal {"../../content/test-maps/ultimate_test.json"};
    fs::path pathTravis {"../content/test-maps/ultimate_test.json"};
    fs::path pathToUse = (fs::exists(pathLocal)) ? pathLocal : pathTravis;
    #else
    std::string pathToUse = "../../content/test-maps/ultimate_test.json";
    #endif
    std::unique_ptr<tson::Map> map = t.parse({pathToUse});
    if(map->getStatus() == tson::ParseStatus::OK)
    {
        tson::Object *obj_ver_flip = map->getLayer("Object Layer")->firstObj("mario_ver_flip");
        tson::Object *obj_hor_flip = map->getLayer("Object Layer")->firstObj("mario_hor_flip");
        tson::Object *obj_all_flip = map->getLayer("Object Layer")->firstObj("mario_all_flipped");
        tson::Object *obj_no_flip = map->getLayer("Object Layer")->firstObj("mario_no_flip");

        tson::Tile *tile_ver_flip = map->getLayer("Main Layer")->getTileData(28, 15);
        tson::Tile *tile_hor_flip = map->getLayer("Main Layer")->getTileData(28, 14);
        tson::Tile *tile_diagvert_flip = map->getLayer("Main Layer")->getTileData(29, 15);
        tson::Tile *tile_diaghori_flip = map->getLayer("Main Layer")->getTileData(29, 14);
        tson::Tile *tile_no_flip = map->getLayer("Main Layer")->getTileData(25, 14);

        tson::TileObject *tileobj_hor_flip = map->getLayer("Main Layer")->getTileObject(28, 14);
        tson::TileObject *tileobj_diagvert_flip = map->getLayer("Main Layer")->getTileObject(29, 15);

        //Objects
        REQUIRE(obj_ver_flip != nullptr);
        REQUIRE(obj_ver_flip->hasFlipFlags(tson::TileFlipFlags::Vertically));
        REQUIRE(obj_hor_flip != nullptr);
        REQUIRE(obj_hor_flip->hasFlipFlags(tson::TileFlipFlags::Horizontally));
        REQUIRE(obj_all_flip != nullptr);
        REQUIRE(obj_all_flip->hasFlipFlags(tson::TileFlipFlags::Vertically | tson::TileFlipFlags::Horizontally));
        REQUIRE(obj_no_flip != nullptr);
        REQUIRE(obj_no_flip->hasFlipFlags(tson::TileFlipFlags::None));

        //Tiles
        REQUIRE(tile_ver_flip != nullptr);
        REQUIRE(tile_ver_flip->get<std::string>("name") == "cloudyboy");
        REQUIRE(tile_ver_flip->hasFlipFlags(tson::TileFlipFlags::Vertically));
        REQUIRE(tile_ver_flip->getId() == 3221225484); //Id including the flags
        REQUIRE(tile_ver_flip->getGid() == 12); //Id of the tile

        REQUIRE(tile_hor_flip != nullptr);
        REQUIRE(tile_hor_flip->get<std::string>("name") == "cloudyboy");
        REQUIRE(tile_hor_flip->hasFlipFlags(tson::TileFlipFlags::Horizontally));
        REQUIRE(tile_diagvert_flip != nullptr);
        REQUIRE(tile_diagvert_flip->get<std::string>("name") == "cloudyboy");
        REQUIRE(tile_diagvert_flip->hasFlipFlags(tson::TileFlipFlags::Vertically | tson::TileFlipFlags::Diagonally));
        REQUIRE(tile_diaghori_flip != nullptr);
        REQUIRE(tile_diaghori_flip->get<std::string>("name") == "cloudyboy");
        REQUIRE(tile_diaghori_flip->hasFlipFlags(tson::TileFlipFlags::Horizontally | tson::TileFlipFlags::Diagonally));
        REQUIRE(tile_no_flip != nullptr);
        REQUIRE(tile_no_flip->get<std::string>("name") == "cloudyboy");
        REQUIRE(tile_no_flip->hasFlipFlags(tson::TileFlipFlags::None));

        //TileObjects
        auto rect = tileobj_hor_flip->getDrawingRect();
        REQUIRE(tileobj_hor_flip != nullptr);
        REQUIRE(tileobj_hor_flip->getTile() != nullptr);
        REQUIRE(tileobj_hor_flip->getPositionInTileUnits() == tson::Vector2i(28, 14));
        REQUIRE(tileobj_hor_flip->getPosition() == tson::Vector2f(448, 224));
        REQUIRE(tileobj_hor_flip->getTile()->get<std::string>("name") == "cloudyboy");
        REQUIRE(tileobj_hor_flip->getTile()->hasFlipFlags(tson::TileFlipFlags::Horizontally));
        REQUIRE(tileobj_diagvert_flip != nullptr);
        REQUIRE(tileobj_diagvert_flip->getTile() != nullptr);
        REQUIRE(tileobj_diagvert_flip->getPositionInTileUnits() == tson::Vector2i(29, 15));
        REQUIRE(tileobj_diagvert_flip->getPosition() == tson::Vector2f(464, 240));
        REQUIRE(tileobj_diagvert_flip->getTile()->get<std::string>("name") == "cloudyboy");
        REQUIRE(tileobj_diagvert_flip->getTile()->hasFlipFlags(tson::TileFlipFlags::Vertically | tson::TileFlipFlags::Diagonally));
    }
    else
    {
        std::cout << "Ignored - " << map->getStatusMessage() << std::endl;
        REQUIRE(true);
    }
}

from tileson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.