Tilemap Editor in LÖVE?

Show off your games, demos and other (playable) creations.
Post Reply
royalepoe
Prole
Posts: 1
Joined: Thu May 04, 2023 7:56 am

Tilemap Editor in LÖVE?

Post by royalepoe »

I'm currently trying to create a tilemap editor using LÖVE. I hated using things like Tiled etc cause I don't like having to shuffle files around and keep going in an out of different programs. Anyway I was wondering if anyone else has attempted something like this before? I plan on continuing with mine either way but it would be nice to see something to get some inspiration from.
User avatar
Hugues Ross
Citizen
Posts: 85
Joined: Fri Oct 22, 2021 9:18 pm
Location: Quebec
Contact:

Re: Tilemap Editor in LÖVE?

Post by Hugues Ross »

I think everybody and their aunt has tried that before, it's a pretty common topic. Anyway, here are a few relevant topics: Personally I just did this instead though, as someone who actually makes dev tools full-time for a living I think the best homebrew tool is the one that takes as little time out of your development budget while still providing what you need.
User avatar
darkfrei
Party member
Posts: 1181
Joined: Sat Feb 08, 2020 11:09 pm

Re: Tilemap Editor in LÖVE?

Post by darkfrei »

royalepoe wrote: Thu May 04, 2023 8:11 am I'm currently trying to create a tilemap editor using LÖVE. I hated using things like Tiled etc cause I don't like having to shuffle files around and keep going in an out of different programs. Anyway I was wondering if anyone else has attempted something like this before? I plan on continuing with mine either way but it would be nice to see something to get some inspiration from.
Maybe some exporter to .Lua?

Code: Select all

/*
 * Lua Exporter Plugin for Tiled Map Editor v1.0.0
 */

function luaExporterPlugin(map) {
    var file = new TextFile(map.filename.replace(/\.[^/.]+$/, "") + ".lua", TextWrite);

    var luaCode = "local map = {\n";

    luaCode += "width = " + map.width + ",\n";
    luaCode += "height = " + map.height + ",\n";
    luaCode += "tilewidth = " + map.tileWidth + ",\n";
    luaCode += "tileheight = " + map.tileHeight + ",\n";

    luaCode += "layers = {\n";

    for (var i = 0; i < map.layerCount; ++i) {
        var layer = map.layerAt(i);
        var layerName = layer.name;
        var layerType = layer.__proto__.toString().replace(/\[object (.*)\]/, "$1").toLowerCase();

        luaCode += "\t{\n";
        luaCode += "\t\tname = \"" + layerName + "\",\n";
        luaCode += "\t\ttype = \"" + layerType + "\",\n";
        luaCode += "\t\tdata = {";

        if (layerType === "tilelayer") {
            for (var y = 0; y < map.height; ++y) {
                luaCode += "\n\t\t\t";
                for (var x = 0; x < map.width; ++x) {
                    var tile = layer.cellAt(x, y);
                    luaCode += tile.tileId + 1;
                    if (x !== map.width - 1 || y !== map.height - 1) {
                        luaCode += ",";
                    }
                }
            }
        } else if (layerType === "objectgroup") {
            for (var j = 0; j < layer.objectCount; ++j) {
                var object = layer.objectAt(j);
                var objName = object.name;
                var objType = object.type;
                var objX = object.x;
                var objY = object.y;
                var objWidth = object.width;
                var objHeight = object.height;

                luaCode += "\n\t\t\t{\n";
                luaCode += "\t\t\t\tname = \"" + objName + "\",\n";
                luaCode += "\t\t\t\ttype = \"" + objType + "\",\n";
                luaCode += "\t\t\t\tx = " + objX + ",\n";
                luaCode += "\t\t\t\ty = " + objY + ",\n";
                luaCode += "\t\t\t\twidth = " + objWidth + ",\n";
                luaCode += "\t\t\t\theight = " + objHeight + "\n";
                luaCode += "\t\t\t}";

                if (j !== layer.objectCount - 1) {
                    luaCode += ",";
                }
            }
        }

        luaCode += "}\n";
        luaCode += "\t}";

        if (i !== map.layerCount - 1) {
            luaCode += ",";
        }

        luaCode += "\n";
    }

    luaCode += "}\n";
    luaCode += "}\n";

    file.write(luaCode);
    file.commit();
    file.close();
}

tiled.registerPlugin("LuaExporter", "Lua Exporter Plugin", luaExporterPlugin);
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
pauljessup
Party member
Posts: 355
Joined: Wed Jul 03, 2013 4:06 am

Re: Tilemap Editor in LÖVE?

Post by pauljessup »

I made this forever ago...

https://github.com/pauljessup/greentea

It still works in the latest love, though I do have to add an example on how to use it...the dropbox link I had before doesn't exist anymore, lol. Next time I'll just add it to the repo
Post Reply

Who is online

Users browsing this forum: No registered users and 45 guests