auto-tile-webpack-plugin
Advanced tools
Comparing version
{ | ||
"name": "auto-tile-webpack-plugin", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Generate autotiles for Tiled automatically", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -13,3 +13,3 @@ | ||
|---|---| | ||
||| | ||
||| | ||
@@ -49,3 +49,3 @@ # Usage | ||
- original_autotiles/ | ||
- town.png // Minimal autile image (Follow `examples/input.png`) | ||
- town.png // Minimal autile image (Follow `examples/input_*.png`) | ||
- tilesets/ | ||
@@ -63,2 +63,3 @@ - town.png // Generated image | ||
|output|Output directory. Extruded images will be here.| | ||
|pattern|Autotile pattern (`'pattern1'` | `'pattern2'`) (Not require)| | ||
@@ -75,3 +76,4 @@ ## Use it on Tiled | ||
The around of the autotiles need to be filled with something another tile. | ||
- The around of the autotiles need to be filled with something another tile. | ||
- Layer name need to be same as file name. (`town.png` -> `town`) | ||
@@ -78,0 +80,0 @@ # Requirements |
const sharp = require('sharp') | ||
const TILES = [ | ||
[13, 14, 17, 18], | ||
[2, 14, 17, 18], | ||
[13, 3, 17, 18], | ||
[2, 3, 17, 18], | ||
[13, 14, 17, 7], | ||
[2, 14, 17, 7], | ||
[13, 3, 17, 7], | ||
[2, 3, 17, 7], | ||
// --- | ||
[13, 14, 6, 18], | ||
[2, 14, 6, 18], | ||
[13, 3, 6, 18], | ||
[2, 3, 6, 18], | ||
[13, 14, 6, 7], | ||
[2, 14, 6, 7], | ||
[13, 3, 6, 7], | ||
[2, 3, 6, 7], | ||
// --- | ||
[12, 14, 16, 18], | ||
[12, 3, 16, 18], | ||
[12, 14, 16, 7], | ||
[12, 3, 16, 7], | ||
[9, 10, 17, 18], | ||
[9, 10, 17, 7], | ||
[9, 10, 6, 18], | ||
[9, 10, 6, 7], | ||
// --- | ||
[13, 15, 17, 19], | ||
[13, 15, 6, 19], | ||
[2, 15, 17, 19], | ||
[2, 15, 6, 19], | ||
[13, 14, 21, 22], | ||
[2, 14, 21, 22], | ||
[13, 3, 21, 22], | ||
[2, 3, 21, 22], | ||
// --- | ||
[12, 15, 16, 19], | ||
[9, 10, 21, 22], | ||
[8, 9, 12, 13], | ||
[8, 9, 12, 7], | ||
[10, 11, 14, 15], | ||
[10, 11, 6, 15], | ||
[18, 19, 22, 23], | ||
[2, 19, 22, 23], | ||
// --- | ||
[16, 17, 20, 21], | ||
[16, 3, 20, 21], | ||
[8, 11, 12, 15], | ||
[8, 9, 20, 21], | ||
[16, 19, 20, 23], | ||
[10, 11, 22, 23], | ||
[8, 11, 20, 23], | ||
[8, 11, 20, 23] | ||
] | ||
const pattern1 = require('./settings/pattern1') | ||
const pattern2 = require('./settings/pattern2') | ||
const getSetting = pattern => { | ||
switch (pattern) { | ||
case 'pattern1': return pattern1 | ||
case 'pattern2': return pattern2 | ||
default: throw new Error('Undefined pattern') | ||
} | ||
} | ||
const indexToPos = (index, numOfHorizontal, size) => { | ||
@@ -66,5 +20,5 @@ const left = (index % numOfHorizontal) * size | ||
} | ||
const convert = async (inputPath, size) => { | ||
const convert = async (inputPath, size, pattern = 'pattern1') => { | ||
const original = await sharp(inputPath) | ||
const bufferData = await Promise.all(TILES.map(async indexes => { | ||
const bufferData = await Promise.all(getSetting(pattern).map(async indexes => { | ||
const promises = indexes.map(index => original.extract(indexToExtractData(index, size / 2)).toBuffer()) | ||
@@ -71,0 +25,0 @@ return await Promise.all(promises) |
@@ -39,3 +39,3 @@ const path = require('path') | ||
const size = this.settings.size | ||
convert(path.join(this.inputDir, file), size).then(buffer => { | ||
convert(path.join(this.inputDir, file), size, this.settings.pattern).then(buffer => { | ||
return fs.writeFileSync(path.join(this.outputDir, file), buffer) | ||
@@ -42,0 +42,0 @@ }) |
913830
2.49%12
33.33%207
44.76%82
2.5%