Git Product home page Git Product logo

ldtkloader's Introduction


๐Ÿ•น๏ธ Currently working on NasNas, a cross platform 2D game framework for C++ !

ldtkloader's People

Contributors

dontpanic5 avatar jpvanoosten avatar lucidsigma avatar madour avatar progrematic avatar scastd avatar surrealegg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ldtkloader's Issues

Undefined reference to...

I'm currently developing a game using sfml. While compiling the project, I get the following error:

g++ -g -I ../include -L ../lib ../src/*.cpp -lsfml-graphics -lsfml-window -lsfml-system -o main
C:\Users\Admin\AppData\Local\Temp\ccP5UqED.o: In function `main':
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:12: undefined reference to `ldtk::Project::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:20: undefined reference to `ldtk::Project::getWorld() const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:23: undefined reference to `ldtk::World::getLevel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:24: undefined reference to `ldtk::Level::getLayer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:26: undefined reference to `ldtk::Layer::allTiles() const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:30: undefined reference to `ldtk::Layer::getTileset() const'
C:\Users\Admin\Documents\Projects\test\bin/../src/main.cpp:39: undefined reference to `ldtk::Tile::getVertices() const'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:2: all] Error 1

For testing purposes I copied the example code (below) for sfml and I got the same error.

#include <SFML/Graphics.hpp>
#include <LDtkLoader/Project.hpp>

#include <iostream>

int main() {
    // declare a LDtk World
    ldtk::Project ldtk_project;

    // load the LDtk World from file
    try {
        ldtk_project.loadFromFile("assets/level.ldtk");
    }
    catch (std::exception& ex) {
        std::cerr << ex.what() << std::endl;
        return 1;
    }

    // get the world
    const auto& world = ldtk_project.getWorld();

    // get the level and the layer we want to render
    const auto& level = world.getLevel("Level");
    const auto& layer = level.getLayer("Ground");
    // get all the tiles in the Ground layer
    const auto& tiles_vector = layer.allTiles();

    // load the tileset texture
    sf::Texture tileset_texture;
    tileset_texture.loadFromFile("assets/"+layer.getTileset().path);


    // create the VertexArray that will store all the tiles
    sf::VertexArray tilemap;
    tilemap.resize(tiles_vector.size()*4);  // each tile has 4 vertices
    tilemap.setPrimitiveType(sf::PrimitiveType::Quads);
    int i = 0;
    for (const auto& tile : tiles_vector) {
        auto vertices = tile.getVertices();
        for (int j = 0; j < 4 ; ++j) {
            // set the position and texture coordinate of each vertex
            // flips are already done, you don't have to do it manually
            tilemap[i*4+j].position.x = vertices[j].pos.x;
            tilemap[i*4+j].position.y = vertices[j].pos.y;
            tilemap[i*4+j].texCoords.x = static_cast<float>(vertices[j].tex.x);
            tilemap[i*4+j].texCoords.y = static_cast<float>(vertices[j].tex.y);
        }
        i++;
    }

    // create the window and start the game loop
    sf::RenderWindow window;
    window.create(sf::VideoMode(level.size.x*4, level.size.y*4), "LDtkLoader - SFML");
    window.setFramerateLimit(60);

    sf::Event event{};
    while(window.isOpen()) {
        while(window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

        window.clear();

        // draw the tile map scaled x4
        sf::RenderStates states;
        states.transform.scale(4, 4);
        states.texture = &tileset_texture;
        window.draw(tilemap, states);

        window.display();
    }

    return 0;
}

How can I fix this?

Note
I'm compiling my project with make and g++, c++17. g++ -g -I ../include -L ../lib ../src/*.cpp -lsfml-graphics -lsfml-window -lsfml-system -o main

Can't parse LDtk 1.2.0

It seems that LDtk 1.2.0 removed the autoTilesetDefUid property from the layer defs. This causes LDtkLoader to break when parsing 1.2.0 levels:

m_auto_tileset(j["autoTilesetDefUid"].is_null() ? nullptr : &p->getTileset(j["autoTilesetDefUid"].get<int>()))

nlohmann/json requires that these keys exist. An assertion is thrown if it doesn't exist:

JSON_ASSERT(m_value.object->find(key) != m_value.object->end());

SDL Example does not build

cmake --build .
[14/17] Building CXX object examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o
FAILED: examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o 
/usr/bin/clang++  -I../examples/SDL/../../include -I../include -isystem /usr/include/SDL2  -MD -MT examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o -MF examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o.d -o examples/SDL/CMakeFiles/LDtkSDL.dir/main.cpp.o -c ../examples/SDL/main.cpp
../examples/SDL/main.cpp:10:17: error: no matching constructor for initialization of 'ldtk::World'
    ldtk::World world;
                ^
../examples/SDL/../../include/LDtkLoader/World.hpp:22:9: note: candidate constructor not viable: requires 1 argument, but 0 were provided
        World(const World&) = delete;
        ^
../examples/SDL/../../include/LDtkLoader/World.hpp:23:9: note: candidate constructor not viable: requires 1 argument, but 0 were provided
        World(World&&) = default;
        ^
../examples/SDL/../../include/LDtkLoader/World.hpp:56:9: note: candidate constructor not viable: requires 4 arguments, but 0 were provided
        World(const nlohmann::json& j, Project* p, const FileLoader& file_loader, bool external_levels);
        ^
../examples/SDL/main.cpp:14:15: error: no member named 'loadFromFile' in 'ldtk::World'
        world.loadFromFile("assets/level.ldtk");
        ~~~~~ ^
../examples/SDL/main.cpp:51:18: error: no member named 'position' in 'ldtk::Tile'
            tile.position.x, tile.position.y,
            ~~~~ ^
../examples/SDL/main.cpp:51:35: error: no member named 'position' in 'ldtk::Tile'
            tile.position.x, tile.position.y,
                             ~~~~ ^
../examples/SDL/main.cpp:56:18: error: no member named 'texture_position' in 'ldtk::Tile'
            tile.texture_position.x, tile.texture_position.y,
            ~~~~ ^
../examples/SDL/main.cpp:56:43: error: no member named 'texture_position' in 'ldtk::Tile'
            tile.texture_position.x, tile.texture_position.y,
                                     ~~~~ ^
6 errors generated.
[15/17] Building CXX object CMakeFiles/LDtkLoader.dir/src/World.cpp.o
ninja: build stopped: subcommand failed.

why do the examples use render textures?

hi there! in all the examples, the tilemaps are rendered on a render texture, which is then blown up to the screen's size.
but, why is it done like that?
why not just blow up the textures themselves in code, rather than drawing everything to a render texture, and then drawing that to the screen. im quite confused by this, and would love an explanation! thanks :D

No Way to Get List of All Entities

I see that there are calls to get entities by id/name in a layer and also the entity defs can be gotten by id/name.
But it seems like I would need to already know all the entities I need beforehand.
So if I get a ldtk file without prior knowledge of the entities it can have, there's no way to know what id/names to call.

How to parse intgrid and autotile layers?

Looking through examples and source code and theres not alot of documentation especially around autolayer and int grids.

Any chance of some documentation updates for it?

Loading external level files does not take world directory into account

World files with external levels stores paths to those levels that are relative to the world file itself. However, the current level loader simply passes the path as is, which means that trying to load any world with external levels that is not in the current working for the process directory will fail.

Update third party JSON.

nlohmann json recently got updated to 3.11.3, breaking compat with this library due to outdated included header.

Suggest either removing header or updating.

Compile error: "Cannot use 'throw' with exceptions disabled"

First of all, thanks for sharing this lib :)

For my project I set -fno-exceptions to avoid the use of noexception keyword in all functions,
I am getting this error when I try to compile LdtkLoader in my project.
to make it work I must eliminate all the throws in the optional.hpp file

Is there any possibility to remove the throws and replace them with something else without having to modify the original code?

Thanks!

Compile times, in particular external includes

Hey - cool library! I use it as a static library to keep the compile time of my main project small. Looking at the vcperf traces, it's still a bit of a sore spot in that regard. But I think it can be improved quite a bit:

An include of World.hpp takes ~800ms on my machine, 69% of which is json.hpp for example. That could be avoided with the use of its forward declarations for the necessary parameter I think. I'm sure there are other unnecessary includes but I didn't look into it in detail.

Thanks for writing this library.

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.