[go: nahoru, domu]

Skip to content

Commit

Permalink
🐾 Updated Tiled2PkUnity to v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwifruitDev committed Jul 25, 2017
1 parent 7cbaac7 commit 6575c29
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
11 changes: 11 additions & 0 deletions TOOLS/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# Pokemon Unity Tools
These tools are included to provide ease of use when using the framework.

## List of tools included:
* Animated Sprites Setup - Create animated sprites for use in battles and summary pages.
* Map Creation Tutorials - Learn how to create maps
* Poke Map Editor - Create maps using Blender quickly and easily
* Map Texture Tilesets - Have access to all tiles available to create your maps
* Terrain Models - Use these building blocks to keep your maps consistant
* Tiled2PkUnity - Compile collision maps made in Tiled to add boundaries
* DeKay's Collision Map Compiler - Compile collision maps made in Pokemon Essentials to add boundaries
* Viewport Height Chart - Measure player camera distances
2 changes: 1 addition & 1 deletion TOOLS/Tiled2PkUnity/Launch.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
node tiled2pkunity.js ./tileMAP.json ./tileSET.json collision.txt
node tiled2pkunity.js ./tileMAP.json ./tileSET.json collision.txt 1
pause
Empty file.
73 changes: 59 additions & 14 deletions TOOLS/Tiled2PkUnity/tiled2pkunity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,65 @@
//Tiled2PkUnity was developed in Node.js by Kisu-Amare/TeamPopplio.
//Please ask me for help/support with this app rather than contacting the Pokemon Unity team.

const fs = require('fs') //Filesystem Module
if(process.argv.slice(2)[0] != "merge") { //If you're not executing the merger

if(process.argv.slice(2)[0] != undefined && process.argv.slice(2)[0] != null && process.argv.slice(2)[1] != undefined && process.argv.slice(2)[1] != null && process.argv.slice(2)[2] != undefined && process.argv.slice(2)[2] != null) {

//Consistents\\
const fs = require('fs') //Filesystem Module
const json = require(process.argv.slice(2)[0]) //JSON file
const tilesetagain = require(process.argv.slice(2)[1]) //Tileset file
const filename = process.argv.slice(2)[2] //Filename

//Variables\\
var fd = fs.openSync(filename, 'w') //Create file
var tiles = json.layers[0].data //JSON Tilemap
var errors = 0 //Error count
var collision = [] //Blank array
var nocollision = [] //Blank array
var water = [] //Blank array
var environment2 = [] //Blank array
var layer = parseInt(process.argv.slice(2)[3]) - 1 //Layers
if(isNaN(layer)) {
layer = 0 //No layer? I'll do it at #1 instead
}
var realnum = layer + 1

//Tileset Terrain Tags\\
console.log(" ")
console.log("Creating tileset terrain tags...")
console.log(" ")
for(var z = 0; z< tilesetagain.tilecount; z++) {
var tile = tilesetagain.tileproperties[z.toString()]
var num = z + 1
if(tile.Collision == true && tile.Water == false && tile.Environment2 == false) {
collision.push(z + 1)
collision.push(num)
console.log("Tileset #" + z.toString() + " = Collidable")
} else if(tile.Collision == false && tile.Water == false && tile.Environment2 == false) {
nocollision.push(z + 1)
nocollision.push(num)
console.log("Tileset #" + z.toString() + " = Non-collidable")
} else if(tile.Collision == false && tile.Water == true && tile.Environment2 == false) {
water.push(z + 1)
water.push(num)
console.log("Tileset #" + z.toString() + " = Water")
} else if(tile.Collision == false && tile.Water == false && tile.Environment2 == true) {
nocollision.push(z + 1)
nocollision.push(num)
console.log("Tileset #" + z.toString() + " = Env2")
} else {
errors = errors+1
console.log("Error! Tileset #" + z.toString() + " = ??? Please make sure that water tiles have no collision and env2 tiles are not water/collidable, and make sure that all properties are present and are booleans.")
console.log("Tileset #" + z.toString() + " = ??? Please make sure that water tiles have no collision and env2 tiles are not water/collidable, and make sure that all properties are present and are booleans.")
process.exit()
}
}

//Collision Map\\
var tileset = []
var tileset = [] //Blank array
console.log(" ")
console.log("Creating collision map...")
console.log(" ")
for(var a = 0; a< tiles.length; a++) {
var ti = tiles[a]
for(var a = 0; a< json.layers[layer].data.length; a++) { //Excuse my horrible workaround lmao
var ti = json.layers[layer].data[a]
if(ti == 0) {
tileset.push(0)
console.log("Tile #" + a.toString() + " = Blank")
}
for(var b = 0; b< collision.length; b++) {
if(ti == collision[b]) {
tileset.push(1)
Expand All @@ -77,16 +88,50 @@ if(process.argv.slice(2)[0] != undefined && process.argv.slice(2)[0] != null &&
}
}
}

//Writing the file\\
fs.writeFile(filename,tileset.join(" "), (err) => {
if (err) throw err;
console.log(" ")
console.log("Finished conversion process with " + errors.toString() + " tileset collision error(s), printed collision map to " + filename)
console.log("Finished conversion process for layer #" + realnum + ", printed collision map to " + filename)
console.log(" ")
fs.closeSync(fd)
})
} else {
console.log("Missing arguments!") //Error output
}} else {

//Merging\\
if(process.argv.slice(2)[0] != undefined && process.argv.slice(2)[0] != null && process.argv.slice(2)[1] != undefined && process.argv.slice(2)[1] != null && process.argv.slice(2)[2] != undefined && process.argv.slice(2)[2] != null) {
const collision1 = process.argv.slice(2)[1] //First collision map layer
const collision2 = process.argv.slice(2)[2] //Second collision map layer
const filename = process.argv.slice(2)[3] //Filename
var fd = fs.openSync(filename, 'w') //Create file
console.log(" ")
console.log("Merging " + process.argv.slice(2)[1] + " with " + process.argv.slice(2)[2] + "...")
console.log(" ")
var array1 = [] //Blank array
var array2 = [] //Blank array
var text1 = fs.readFileSync(collision1, "utf-8")
var text2 = fs.readFileSync(collision2, "utf-8")
array1 = text1.split(" ")
array2 = text2.split(" ")
for(var a = 0; a< array2.length; a++) {
if(array2[a] != 0) {
console.log("#" + array1[a].toString() + " -> #" + array2[a])
array1.splice(a, 1, array2[a]) //Replace the value in the first array with the new one
}
}

//Writing the file\\
fs.writeFile(filename,array1.join(" "), (err) => {
if (err) throw err;
console.log(" ")
console.log("Finished merging " + process.argv.slice(2)[2] + " with " + process.argv.slice(2)[1] + ", printed collision map to " + filename)
console.log(" ")
fs.closeSync(fd)
})
} else {
console.log("Missing arguments!") //Error output
}
}
//Version 1.0
//Version 1.5

0 comments on commit 6575c29

Please sign in to comment.