Giter Club home page Giter Club logo

godot-ldtk-import's Introduction

Please note, I am no longer actively maintaining this plugin as of 04/09/2023. There are several forks of this project that are more up to date, as well as other similar plugins that are available on GitHub. I'll be leaving the project up for those that want to view the code and/or build from it, but do note that it most likely will be outdated.

Levi

godot-LDtk-import

  • Godot version: 3.4.4
  • LDtk version: 1.1.3

Basic GDscript for importing LDtk files into the Godot game engine.

Updates:

7/17/2022

  • New feature: Post Import Script (thanks to univeous)
  • Level metadata is now imported when "Import Metadata" option is enabled (thanks to univeous)
  • Fixed entities not saving CollisionShape2D's

7/4/2022

  • Updated to Godot version 3.4.4
  • Updated to LDtk version 1.1.3
  • Fixed collision layer import.
  • Rewrote some of the information below on how to use the importer.

5/29/2021

  • Added option to import entities layer as YSort.

3/15/2021

  • Added option to import custom entities.
  • Added option to import metadata.
  • Added option to import collisions.

1/4/2021:

  • Updated for new version of LDtk.
  • Changed import style: instead of making a new scene you can just open the ldtk file.

11/24/2020:

  • removed import files.

11/22/2020:

  • The Importer is now an addon/plugin.
  • Added basic import options for Entities.

11/13/2020:

  • Added basic functionality for autolayers and intgrid layers.

Can now create tilemaps from autolayers and intgrid layers with tilesets. Intgrid layers without tilesets are ignored currently.

11/12/2020:

  • Currently this script has very basic functionality. Only Tile Layers are currently working.

How to use:

  1. Copy the addons folder to your godot project folder.
  2. Enable LDtk Importer under Project Settings/Plugins.
  3. Add a .ldtk map file and any spritesheets you're using to your project folder.
  4. Select your .ldtk file and open the Import menu to toggle importing collisions, custom entities, metadata, and YSort.

Tips:

  • IntGrid, Tiles, and AutoLayers are imported as TileMap Nodes.
  • Currently Entities have very basic functionality, checkout the testmap.ldtk for examples.

Import Menu Options:

  • Import_Collisions: Import collisions from IntGrid layer (see import collisions below).
  • Import_Custom_Entities: Import your own Resources (see entities). Keep in mind that this will remove the other node options (they will still be imported, but only as Node2D).
  • Import_Metadata: Import any fields set on entities or levels. For entities, If they have an exported property with the same name, it will set the value of the property with the value on LDtk, if they don't (or the plugin can't find it), they will be imported as metadata (using 'set_meta()') and can be retrieved later using 'get_meta()' on the imported object. Level's fields will all be imported as metadata.
  • Import_YSort_Entities_Layer: Any Entities Layer whose name begins with "YSort" will be imported as a YSort node, and all the entities will be set as children of this YSort node.
  • Post_Import_Script: The selected script will have it's post_import(scene) method run. This enables you to change the generated scene automatically upon each reimport. The post_import method will receive the built scene and must return the changed scene.

Importing Collisions:

  • Create an IntGrid layer called "Collisions", tiles on this layer will be made into CollisionShape2D and added to a StaticBody2D node.

Entities:

You can set up how your entities are imported:

  1. Create a new Entity
  2. Add a String Field Type
  3. Set the Field Identifier to: NodeType
  4. Set the Default Value to the type of Node
  5. Any fields added to the entity on LDtk can set properties on the object or be added as metadata if the option is set when importing (retrieve using the function 'get_meta()' on the object after importing).

If your entity does not have a NodeType field, it will be imported as a Node2D node and all fields will be imported as metadata. You can set up post-import scripts to handle the imported entities yourself.

Current node options are:

  1. If not using Custom Entities:

    • Position2D
    • Area2D
    • KinematicBody2D
    • RigidBody2D
    • StaticBody2D
  2. If using Custom Entities:

    • Set the Default Value to the resource path (eg: 'res://Player.tscn').

Notes:

  • The example is using the tileset that comes with LDtk: Cavernas_by_Adam_Saltsman.png
  • The conversion functions: coordId_to_gridCoords(), tileId_to_gridCoords(), tileId_to_pxCoords() are from the LDtk documentation.

godot-ldtk-import's People

Contributors

davidmag avatar justuspan avatar levigilbert avatar lmerriam avatar m3dzik avatar stefanmielke avatar stingly avatar univeous 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

godot-ldtk-import's Issues

Collisions are not created correctly if we set a single tile at the right side of the level.

LDtk version: 1.1.3
Godot version 3.5.rc5 (also happens in 3.4.4 stable)
Hi, I have found some issue setting a level with a single tile width at the right of the level. This level for example:
imagen
If you import it, you will get these collisions:
imagen
I have added a few prints to try to understand what is happening and I have found that looks like initial_position is not being calculated correctly for the case where there's a single tile:
imagen
If I add one more tile the issue is gone:
imagen
The issue happens as well if there isn't any tile at the beginning of the row:
imagen

'Rectangle of tiles' doesn't import properly

Unsure if limitation or user error, but marking an area of tiles in either an Intgrid or Autotile layer fails to import appropriately into Godot.

image

It behaves appropriately in editor but doesn't seem to in the generated scene.

LDTK
image

Godot
image

Using Godot 3.5 Stable with LDtk 1.1.3-64bit

Minimal recreation: The 'AutoLayers 2 stamps' sample map in LDtk uses a 2x2 rectangle of tiles rule in its Intgrid layer.

Entity Import Discussion

Currently, entities without the NodeType field will be skipped for import.
I think this behavior needs some more discussion.
I would prefer to import it as a Node2d node and import all fields as metadata to be used by post-processing scripts.

Also currently, only custom fields are imported. I think it might be useful to import the non-custom fields (__tags etc.) together.

I will open a proposed PR later.

Relative paths error

Godot couldn't load the TileSet texture. The bug turned out to be that the plugin specified the wrong path to the image.

Here's my file structure:

res://
  maps/
    test.ldtk
    tilesets/
      dungeon.png

In the test.ldtk file the relative path to dungeon.png was specified as tilesets/dungeon.png.

On the line 123 in the LDtk.gd Godot returns an error file 'res://tilesets/dungeon.png' not found.

#create new tileset from tileset_data.
func new_tileset(tileset_data):
	var tileset = TileSet.new()
	var texture_filepath = 'res://' + tileset_data.relPath
	var texture = load(texture_filepath) 

I fixed this bug by changing the value of the texture_filepath to:

var texture_filepath = map_data.base_dir + '/' + tileset_data.relPath

map_data.base_dir appears in the function load_LDtk_file:

#get LDtk file as JSON.
func load_LDtk_file(filepath):
    var json_file = File.new()
    json_file.open(filepath, File.READ)
    var json = JSON.parse(json_file.get_as_text()).result
    json_file.close()

    json['base_dir'] = filepath.get_base_dir()

    return json

After that, everything worked.

P.S.
sorry for my broken english

Not able to import tilemap images

Error given is in Godot 3.5.stable:
res://addons/LDtk-Importer/LDtk.gd:189 - Invalid get index 'autoTilesetDefUid' (on base: 'Dictionary').

I have all the tilemaps set and the IntGrid map name is: Collisions
even in the test-example provided in the repo if I draw a new map in GridVania mode the example fails

Combining colliders of different types

I imported sample LDTK project and colliders located in the same row are combined.

image

I expected colliders of type "ladder" to be separate from "dirt" colliders - so I can apply some game logic to ladders right away.

I'm not entirely sure that it is importer combines the colliders - but I can't find an option to "uncheck" the combining in the LDTK editor.

Godot 4

How do you plan to handle the update to 4?
Not at all?
Maybe?
Soon?
Dont know yet?

Collisions preset not working.

The collisions preset does nothing. I have the preset enabled on the import tab, and in LDtk I've created a layer named "Collisions," but no colliders are generated when reimporting .ldtk file.

Showing no tiles on collision layer.

Hi, im using Godot 3.5 and Ldtk 1.2.5 and after the update of ldtk to the latest update (1.2.5) the collision layer is not showing any tiles. Any fix for that?
NoTiles

Collisions not imported

I created a layer named "Collisions", and put down tiles in it, but I do not see any collision shapes imported in the game
(Clicking "Show collisions" on the TileMap doesn't reveal anything)

Let's collaborate

Hi lgilbert,

I couldn't track down your contact info so this issue will have to do :)

Currently there are three Godot LDtk importers:

When I first checked out your importer, it was not as far along, and then I made the mistake of not checking back when embarking on reworking Josh's importer for my own holiday game making. I suggested to Josh that we all work together here:

JoshLee0915/GodotLDtkImporter#18

I believe our entity handling is more sophisticated (we can instance user scenes), but your importer has a bunch of better aspects like proper unit testing. If you want to chat realtime, I'm on the LDtk Discord, and my email is just my last name at gmail.

Cheers,
Keir

Requested file format unknown

I have added the addon, and it is working so far, however I get the following message when playing:
grafik

Is this something I can ignore? If so, is there a way to disable the window from showing?

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.