straker / kontra

A lightweight JavaScript gaming micro-library, optimized for js13kGames.
https://straker.github.io/kontra/
MIT License
969 stars 98 forks source link

Support of other level designers #273

Open UnbrandedTech opened 2 years ago

UnbrandedTech commented 2 years ago

I've been sporadically working on a game and trying to keep it as lightweight as possible so I can learn how game systems work under the hood.

Started to design some levels using LDTK and noticed that the only level designer integration KontaJS has is Tiled.

I've spent some time making an LDTK engine using Kontra core. Is there an appetite for an Engine abstraction that can be used for Tiled, LDTK, Ogmo, and anything under the sun?

straker commented 2 years ago

I'm unfamiliar with LDTK, but an abstraction to load different level editor JSON files seems interesting. The main issue is that the TileEngine was built around Tiled data structure. If supporting different level editors can be modular, that would probably be the best solution.

UnbrandedTech commented 2 years ago

Here's the doc for the LDTK JSON schema if you are curious. I'll see what I can do and throw a PR up for an engine abstraction (class TiledEngine extends Engine, class LDTKEngine extends Engine, etc...) when I get some free time.

ghost commented 2 years ago

Hi there, any progress on this? Asking because i would like to contribute for the Ogmo part i'm currently trying to use for my maps. Its pretty easy for really simple maps, but it has some downsides to be used properly.

As i figured out, to get started you just need some hints/tips to get the TileEngine rendering your map. However, to get more out of it (using objects and the entities defined in the map), you have to extend the TileEngine, though.

Is there anything i can contribute to get this issue going?

Greetings

straker commented 2 years ago

I haven't work on this yet. If you'd like to help I think what we need is an abstract TileEngine class that can bridge the different level editor data, then individual TileEngines for each editor that extends the abstract class and fills in support the editor.

ghost commented 2 years ago

OK, i had some time to look at the TileEngine. I think it's simple enough and should stay with the functionality. I would only move some parts of the code into functions (dirty check, visible, opacity, tileset selection while _r()).

The only thing a have struggle with is the assets loading. With any used TilemapEditor you have different formats and maybe want to load the assets differently. I would use a TileEngine.TilesetLoader() or TileEngine.DataLoader() rather then secretly us a global from window. Maybe someone is using a custom assetsLoader, or they should explicitly use load, loadData, etc.

That is based only on what i could check with the Tiled, Ogmo and LDtk Editors.

Each of them has unique ways to do stuff, but all are needing the values you have defined in the TileEngine (sometimes named differently). With just moving some of the parts in functions we can have a simple tilemap based rendering without the more complex stuff, but also be able to extends the class TileEngine for the heavy features of the named Editors and many other tools in the wild.

The 2 parts i've to think about:

straker commented 2 years ago

Thanks for looking into it. Asset loading is tricky since I didn't want to create a dependency from TileEngine to the asset loader (no way to tree-shake that out). So I used the secret window object to avoid that problem. I think having a function load them directly would create a direct dependency even if you didn't need to load that stuff.

Other than that I think what you said sounds good.

straker commented 1 year ago

So I'm taking a look at this and there's some major differences between Tiled and LDtk formats / capabilities that I'm not sure if I could make the two work the exact same. Here's the list of differences that I noticed:

The multiple maps per file and layers defining grid size are both significant differences that I'm not sure how best to handle them. It'll probably mean that the LDtk Engine has more functionality than the Tiled Engine? But I'm not sure yet.