-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
I made useful tool using OTBM2JSON.
Replaces item IDs on map. For people who want to convert map from one .otb to another.
const otbm2json = require("./otbm2json");
// FROM_ID: TO_ID
var replaceArray = {
5091: 5090,
12659: 11703,
}
const mapData = otbm2json.read("before.otbm");
let notReplaced = {};
function replaceItem(itemid) {
if (!replaceArray[itemid]) {
notReplaced[itemid] = itemid;
}
return replaceArray[itemid] ? replaceArray[itemid] : itemid;
}
function replaceItemRecursive(item) {
if (item.type === otbm2json.HEADERS.OTBM_ITEM) {
item.id = replaceItem(item.id);
if (item.content && item.content.length) {
item.content.forEach(function (containerItem) {
replaceItemRecursive(containerItem)
});
}
}
}
// Go over all nodes
mapData.data.nodes.forEach(function (n) {
n.features.forEach(function (e) {
if (e.type !== otbm2json.HEADERS.OTBM_TILE_AREA) {
return;
}
e.tiles.forEach(function (tile) {
if (tile.type !== otbm2json.HEADERS.OTBM_TILE && tile.type !== otbm2json.HEADERS.OTBM_HOUSETILE) {
return;
}
tile.tileid = replaceItem(tile.tileid);
if (tile.items && tile.items.length) {
tile.items.forEach(function (item) {
replaceItemRecursive(item)
});
}
});
});
});
// Write the output to OTBM using the library
otbm2json.write("after.otbm", mapData);
console.log(notReplaced);slawkens and natanbeckman
Metadata
Metadata
Assignees
Labels
No labels