Skip to content

Commit

Permalink
Merge pull request #9 from konsumer/feature-7
Browse files Browse the repository at this point in the history
allow relative or blank projectRoot, for #7
  • Loading branch information
MikeMnD authored Apr 15, 2020
2 parents fc10605 + 19ac422 commit 631680b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ If you prefer watching check the video in YouTube:

[How to export from Tiled To Godot 3.2](https://youtu.be/4jSFAXIa_Lo)

After you open a Tilemap or Tileset you need to add this custom property:
`"projectRoot" : string` , then set the value to the root project folder of your Godot project.
For example: `D:/work/GodotProjects/game_one/`
### setting `res://`

The exporter needs to know where `res://` is. By default, it's in the same directory where the Tiled files are being saved. You can override it with a tile/map custom property `projectRoot : string` that is either relative to the file you are exporting (starting with a `.`), or absolute (not recommended.)

**_!!! Pay attention to the "/" instead of standard windows "\\".
Single Backslash "\\" is used for escaping special symbols._**
Expand Down
6 changes: 1 addition & 5 deletions export_to_godot_tilemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ class GodotTilemapExporter {
this.map = map;
this.fileName = fileName;
// noinspection JSUnresolvedFunction
this.projectRoot = this.map.property("projectRoot");
if (!this.projectRoot) {
throw new Error("Missing mandatory custom property: projectRoot!");
}
this.projectRoot = this.projectRoot.replace('\\', '/');
this.projectRoot = getResPath(this.map.property("projectRoot"), fileName);
this.tileOffset = 65536;
this.tileMapsString = "";
this.tilesetsString = "";
Expand Down
6 changes: 1 addition & 5 deletions export_to_godot_tileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ class GodotTilesetExporter {
this.tileset = tileset;
this.fileName = fileName;
// noinspection JSUnresolvedFunction
this.projectRoot = this.tileset.property("projectRoot");
if (!this.projectRoot) {
throw new Error("Missing mandatory custom property: projectRoot!");
}
this.projectRoot = this.projectRoot.replace('\\', '/');
this.projectRoot = getResPath(this.tileset.property("projectRoot"), fileName);
this.spriteImagePath = this.tileset.image.replace(this.projectRoot, "");
this.shapesResources = "";
this.shapes = "";
Expand Down
23 changes: 22 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,25 @@ function logf(data){
}
function logk(data){
console.log(Object.keys(data));
}
}

function getResPath (projectRoot, outputPath) {
const p = outputPath.split('/').slice(0, -1)
// check for projectRoot
// If projectRoot is not set, set it to current file's location
if (!projectRoot) {
projectRoot = p.join('/')
}
projectRoot = projectRoot.replace(/\\/g, '/')
// Use it as absolute, if it doesn't start with ".", relative if it does
if (projectRoot[0] === '.') {
const out = p
projectRoot.split('/').forEach((segment, i) => {
if (segment === '..') {
out.pop()
}
})
projectRoot = out.join('/')
}
return projectRoot
}

0 comments on commit 631680b

Please sign in to comment.