Advice on making a level editor

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Lugen
Prole
Posts: 24
Joined: Mon Nov 10, 2014 8:36 am
Location: Sweden

Advice on making a level editor

Post by Lugen » Sun May 10, 2015 6:09 pm

So I'm thinking about making a level editor for my current project.

The problem
I would preferably like to have it as a stand-alone application (it's own main-file basically) but still sharing the same code-base as the game itself.
I'm not sure how to approach this with Love2d so any advice/tips/tricks would be very much appreciated.

Suggestions
  • One way I was thinking of would perhaps be to have the main-file for the game and editor in their own sub-folders in the game-folder but as far as I've read it doesn't seem you can do "require" on paths that are higher up in the folder hierarchy.
  • Another way could be to have the editor in a completely separate folder and somehow load all the shared stuff from the games' directory.
Feel free to chime as well if you have similar concerns. Perhaps this thread could become a go-to-place for getting started with making editors in Love2d, particularly in regards of what's mentioned above.

User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Advice on making a level editor

Post by s-ol » Sun May 10, 2015 6:23 pm

Lugen wrote:So I'm thinking about making a level editor for my current project.

The problem
I would preferably like to have it as a stand-alone application (it's own main-file basically) but still sharing the same code-base as the game itself.
I'm not sure how to approach this with Love2d so any advice/tips/tricks would be very much appreciated.

Suggestions
  • One way I was thinking of would perhaps be to have the main-file for the game and editor in their own sub-folders in the game-folder but as far as I've read it doesn't seem you can do "require" on paths that are higher up in the folder hierarchy.
  • Another way could be to have the editor in a completely separate folder and somehow load all the shared stuff from the games' directory.
Feel free to chime as well if you have similar concerns. Perhaps this thread could become a go-to-place for getting started with making editors in Love2d, particularly in regards of what's mentioned above.
You can "share" files between directories hard- and symlinks: http://www.havetheknowhow.com/Creating- ... Links.html
whichever you can use depends on the hard-drive format and your OS, but generally both should work. A hardlink basically means that both names on the filesystem point to the same contents, a symlink is like a reference to another filename. Either should work fine with löve; just make sure that the original file is in the game's .love in case you use symlinks.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end

User avatar
Lugen
Prole
Posts: 24
Joined: Mon Nov 10, 2014 8:36 am
Location: Sweden

Re: Advice on making a level editor

Post by Lugen » Tue May 12, 2015 10:34 am

S0lll0s wrote: You can "share" files between directories hard- and symlinks: http://www.havetheknowhow.com/Creating- ... Links.html
whichever you can use depends on the hard-drive format and your OS, but generally both should work. A hardlink basically means that both names on the filesystem point to the same contents, a symlink is like a reference to another filename. Either should work fine with löve; just make sure that the original file is in the game's .love in case you use symlinks.
Thanks for your reply. Interesting suggestion. Might be something I'll look into, particularly if one can hard-link entire folders.

jjmafiae
Party member
Posts: 1333
Joined: Tue Jul 24, 2012 8:22 am

Re: Advice on making a level editor

Post by jjmafiae » Tue May 12, 2015 12:21 pm

How I did my level editor for my game was to have an object system which draws and handles all the buildings and objects in my maps that system is pretty much identical in my standalone map editor and my game. After I have created my maps in my map editor they get saved to a file with a table serializer and love.filesystem when I then load up my game it loads the map file.

User avatar
Lugen
Prole
Posts: 24
Joined: Mon Nov 10, 2014 8:36 am
Location: Sweden

Re: Advice on making a level editor

Post by Lugen » Tue May 12, 2015 5:40 pm

jjmafiae wrote:How I did my level editor for my game was to have an object system which draws and handles all the buildings and objects in my maps that system is pretty much identical in my standalone map editor and my game. After I have created my maps in my map editor they get saved to a file with a table serializer and love.filesystem when I then load up my game it loads the map file.
Already got that covered. It's the file structure I'm mostly concerned about. So I assume you had your editor as its own project and simply duplicated whatever you needed from the game project folder?

Germanunkol
Party member
Posts: 710
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Advice on making a level editor

Post by Germanunkol » Tue May 12, 2015 7:57 pm

Two ways that come to mind:

Main file only chooses between running the game or the editor. You could even use a command-line switch for this (which would also work with .bat files, for example).
When, in the end, you want to distribute an .exe, you can simply change the main file to only load the game, then build your game.exe and then change it to only load the editor and build the editor.exe from it.

Code: Select all

- main.lua
- scripts
    - editor.lua
    - game.lua
    - other.lua
    - other2.lua
Second method would be:

Code: Select all

- main.lua  -- game's main.lua, starts game
- scripts
    - main.lua -- editor's main.lua, starts editor
    - other.lua
    - other2.lua

EDIT: Never mind. You can require from parent paths, which should work fine for your purposes:

Code: Select all

package.path = package.path .. ";../?.lua"    -- add the parent directory to the list of include dirs
package.path = package.path .. ";../scripts/?.lua"    -- add the scripts directory to the list of include dirs
require("common")  -- this could be in the parent directory or the scripts directory.

Code: Select all

- game
     - main.lua
- editor
     - main.lua
- scripts
     - common.lua
Last edited by Germanunkol on Tue May 12, 2015 8:05 pm, edited 2 times in total.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de

jjmafiae
Party member
Posts: 1333
Joined: Tue Jul 24, 2012 8:22 am

Re: Advice on making a level editor

Post by jjmafiae » Tue May 12, 2015 7:59 pm

Lugen wrote:
jjmafiae wrote:How I did my level editor for my game was to have an object system which draws and handles all the buildings and objects in my maps that system is pretty much identical in my standalone map editor and my game. After I have created my maps in my map editor they get saved to a file with a table serializer and love.filesystem when I then load up my game it loads the map file.
Already got that covered. It's the file structure I'm mostly concerned about. So I assume you had your editor as its own project and simply duplicated whatever you needed from the game project folder?
Exactly, took some time. I spent around 6-10 hours total of development time on my map editor.

User avatar
Positive07
Party member
Posts: 1006
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Advice on making a level editor

Post by Positive07 » Tue May 12, 2015 8:00 pm

What I usually do is structure my folder like this:

Code: Select all

editor {
    game {
        libs {
            --All your libs here
        }
        main.lua --Your game main.lua file
    }
    main.lua --Your level-editor main.lua file
}
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

User avatar
Lugen
Prole
Posts: 24
Joined: Mon Nov 10, 2014 8:36 am
Location: Sweden

Re: Advice on making a level editor

Post by Lugen » Wed May 13, 2015 9:33 pm

Germanunkol wrote: EDIT: Never mind. You can require from parent paths, which should work fine for your purposes:

Code: Select all

package.path = package.path .. ";../?.lua"    -- add the parent directory to the list of include dirs
package.path = package.path .. ";../scripts/?.lua"    -- add the scripts directory to the list of include dirs
require("common")  -- this could be in the parent directory or the scripts directory.

Code: Select all

- game
     - main.lua
- editor
     - main.lua
- scripts
     - common.lua
That sounds like exactly what I'm looking for.

Looked it up on the documentation for anyone interested.
http://www.lua.org/manual/5.1/manual.ht ... ckage.path

Could you explain the syntax of the paths in your example. Does "?" mean that any file ending with ".lua" in that folder can be loaded?
Is the ";" an indicator to add to the package list rather than overwriting it?

Thanks a bunch for your reply!

User avatar
Positive07
Party member
Posts: 1006
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Advice on making a level editor

Post by Positive07 » Wed May 13, 2015 9:49 pm

Lugen wrote: Could you explain the syntax of the paths in your example. Does "?" mean that any file ending with ".lua" in that folder can be loaded?
Is the ";" an indicator to add to the package list rather than overwriting it?

Thanks a bunch for your reply!
Yes and Yes, though I would never recommend this, since this only work with not packaged games.

Have you tried this solution:
Germanunkol wrote:Main file only chooses between running the game or the editor. You could even use a command-line switch for this (which would also work with .bat files, for example).
When, in the end, you want to distribute an .exe, you can simply change the main file to only load the game, then build your game.exe and then change it to only load the editor and build the editor.exe from it.

Code: Select all

--This will be your main.lua file
local released = false --Set to true when you release your game
local editor = false --Set to true if you wanna force the editor mode
love.load = function (args)
    for _, arg in ipairs(args) do
        if arg == "-editor" and not released then
            editor = true
        end
    end
    if editor then
        require "editor.lua" --Your editor "main.lua"
    else
        require "game.lua" --Your game "main.lua"
    end
    love.load(args)
end
Run from the console like:

Code: Select all

love path/to/the/game/folder -editor
Or put that in a .bat file and run it
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(Github.com/Positive07)

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests