-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 99cf83d
Showing
21 changed files
with
878 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = tab | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[{README.md,package.json,.travis.yml}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Automatically normalize line endings for all text-based files | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Automap | ||
!Automap/.gitignore | ||
Automap-new | ||
data | ||
test/data | ||
test/maps-new | ||
|
||
# Installed npm modules | ||
node_modules | ||
|
||
# Folder view configuration files | ||
.DS_Store | ||
Desktop.ini | ||
|
||
# Thumbnail cache files | ||
._* | ||
Thumbs.db | ||
|
||
# Files that might appear on external disks | ||
.Spotlight-V100 | ||
.Trashes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright Mathias Bynens <https://mathiasbynens.be/> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# `tibia-maps` CLI | ||
|
||
`tibia-maps` is a command-line utility to convert between binary [Tibia](https://secure.tibia.com/) maps and human-readable forms of the map data. | ||
|
||
## Installation | ||
|
||
**Note:** [io.js](https://iojs.org/en/) is required. | ||
|
||
```sh | ||
npm install -g tibia-maps | ||
``` | ||
|
||
## Usage | ||
|
||
### `*.map` → `*.png` + `*.json` | ||
|
||
To generate PNGs for the maps + pathfinding visualization and JSON for the marker data based on the map files in the `Automap` directory, run: | ||
|
||
```sh | ||
tibia-maps --from-maps=./Automap --output-dir=./data | ||
``` | ||
|
||
The output is saved in the `data` directory. | ||
|
||
### `*.png` + `*.json` → `*.map` | ||
|
||
To generate Tibia-compatible `*.map` files based on the PNGs and JSON files in the `data` directory, run: | ||
|
||
```sh | ||
tibia-maps --from-data=./data --output-dir=./Automap-new | ||
``` | ||
|
||
The output is saved in the `Automap-new` directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
const argv = require('argh').argv; | ||
const mkdirp = require('mkdirp'); | ||
const rimraf = require('rimraf'); | ||
|
||
const convertFromMaps = require('../src/from-maps.js'); | ||
const convertToMaps = require('../src/to-maps.js'); | ||
const generateBounds = require('../src/generate-bounds.js'); | ||
|
||
const emptyDirectory = function(path) { | ||
return new Promise(function(resolve, reject) { | ||
rimraf(`${path}/*`, function() { | ||
mkdirp(path, function() { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
const main = function() { | ||
if (!argv['from-maps'] && !argv['from-data']) { | ||
console.log('Missing `--from-maps` or `--from-data` flag.'); | ||
return process.exit(1); | ||
} | ||
|
||
if (argv['from-maps'] && argv['from-data']) { | ||
console.log('Cannot use `--from-maps` and `--from-data` at the same time. Pick one.'); | ||
return process.exit(1); | ||
} | ||
|
||
if (argv['from-maps']) { | ||
if (argv['from-maps'] === true) { | ||
console.log('`--from-maps` path not specified. Using the default, i.e. `Automap`.'); | ||
argv['from-maps'] = 'Automap'; | ||
} | ||
const mapsDirectory = path.resolve(argv['from-maps']); | ||
if (!argv['output-dir'] || argv['output-dir'] === true) { | ||
console.log('`--output-dir` path not specified. Using the default, i.e. `data`.'); | ||
argv['output-dir'] = 'data'; | ||
} | ||
const dataDirectory = path.resolve(argv['output-dir']); | ||
emptyDirectory(dataDirectory).then(function() { | ||
return generateBounds(mapsDirectory, dataDirectory); | ||
}).then(function(bounds) { | ||
return convertFromMaps(bounds, mapsDirectory, dataDirectory); | ||
}); | ||
return; | ||
} | ||
|
||
if (argv['from-data']) { | ||
if (argv['from-data'] === true) { | ||
console.log('`--from-data` path not specified. Using the default, i.e. `data`.'); | ||
argv['from-data'] = 'data'; | ||
} | ||
const dataDirectory = path.resolve(argv['from-data']); | ||
if (!argv['output-dir'] || argv['output-dir'] === true) { | ||
console.log('`--output-dir` path not specified. Using the default, i.e. `Automap-new`.'); | ||
argv['output-dir'] = 'Automap-new'; | ||
} | ||
const outputDirectory = path.resolve(argv['output-dir']); | ||
emptyDirectory(outputDirectory).then(function() { | ||
convertToMaps(dataDirectory, outputDirectory); | ||
}); | ||
return; | ||
} | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "tibia-maps", | ||
"version": "0.0.0", | ||
"description": "A command-line utility to convert between binary Tibia maps and human-readable forms of the map data.", | ||
"homepage": "https://mths.be/tibiamaps", | ||
"main": "bin/cli.js", | ||
"bin": "bin/cli.js", | ||
"keywords": [ | ||
"data", | ||
"mmorpg", | ||
"tibia", | ||
"tibia-maps" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Mathias Bynens", | ||
"url": "https://mathiasbynens.be/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/tibiamaps/tibia-maps-script.git" | ||
}, | ||
"bugs": "https://github.com/tibiamaps/tibia-maps-script/issues", | ||
"files": [ | ||
"LICENSE-MIT.txt", | ||
"bin/", | ||
"src/" | ||
], | ||
"directories": { | ||
"bin": "bin", | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "./test/test.sh" | ||
}, | ||
"dependencies": { | ||
"argh": "^0.1.4", | ||
"canvas": "^1.2.3", | ||
"glob": "^5.0.12", | ||
"lodash.padleft": "^3.1.1", | ||
"lodash.range": "^3.0.1", | ||
"mkdirp": "^0.5.1", | ||
"rimraf": "^2.4.1", | ||
"sort-object": "^2.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const icons = require('./icons.js'); | ||
|
||
const arrayToMarkerBuffer = function(array) { | ||
let result = new Buffer(4); | ||
result.writeUIntLE(array.length, 0x0, 4); | ||
for (const marker of array) { | ||
const markerBuffer = new Buffer(14 + marker.description.length); | ||
markerBuffer.writeUInt8(marker.xPosition, 0x0); | ||
markerBuffer.writeUInt8(marker.xTile, 0x1); | ||
markerBuffer.write('\0\0', 0x2, 2, 'utf8'); | ||
markerBuffer.writeUInt8(marker.yPosition, 0x4); | ||
markerBuffer.writeUInt8(marker.yTile, 0x5); | ||
markerBuffer.write('\0\0', 0x6, 2, 'utf8'); | ||
const iconByte = icons.byName[marker.icon]; | ||
console.assert(iconByte != null); | ||
markerBuffer.writeUIntLE(iconByte, 0x8, 4); | ||
markerBuffer.writeUIntLE(marker.description.length, 0xC, 2); | ||
markerBuffer.write(marker.description, 0xE, marker.description.length, 'ascii'); | ||
result = Buffer.concat([result, markerBuffer]); | ||
} | ||
return result; | ||
}; | ||
|
||
module.exports = arrayToMarkerBuffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const byByte = { | ||
0x00: { r: 0, g: 0, b: 0 }, // black (empty) | ||
0x0C: { r: 0, g: 102, b: 0 }, // dark green (trees) | ||
0x18: { r: 0, g: 204, b: 0 }, // green (grass) | ||
0x1E: { r: 0, g: 255, b: 0 }, // light green (old swamp) | ||
0x28: { r: 51, g: 0, b: 204 }, // blue (old water) | ||
0x33: { r: 51, g: 102, b: 153 }, // light blue | ||
0x56: { r: 102, g: 102, b: 102 }, // dark gray (stone/mountains) | ||
0x72: { r: 153, g: 51, b: 0 }, // dark brown (earth/stalagmites) | ||
0x79: { r: 153, g: 102, b: 51 }, // brown (earth) | ||
0x81: { r: 153, g: 153, b: 153 }, // gray (floor) | ||
0x8C: { r: 153, g: 255, b: 102 }, // light green | ||
0xB3: { r: 204, g: 255, b: 255 }, // light blue (ice) | ||
0xBA: { r: 255, g: 51, b: 0 }, // red (city/walls) | ||
0xC0: { r: 255, g: 102, b: 0 }, // orange (lava) | ||
0xCF: { r: 255, g: 204, b: 153 }, // beige (sand) | ||
0xD2: { r: 255, g: 255, b: 0 }, // yellow (ladders/holes/…) | ||
0xD7: { r: 255, g: 255, b: 255 } // white (snow / target?) | ||
}; | ||
|
||
const byColor = {}; | ||
Object.keys(byByte).forEach(function(key) { | ||
const byteValue = Number(key); | ||
const color = byByte[byteValue]; | ||
const id = `${color.r},${color.g},${color.b}`; | ||
byColor[id] = byteValue; | ||
}); | ||
|
||
module.exports = { | ||
'byByte': byByte, | ||
'byColor': byColor | ||
}; |
Oops, something went wrong.