rosshadden/MMORPGKTHX — Issue #27: Map Editor
Author: rosshadden
Created: 2011-11-26 16:52:23+00:00
State: open
Labels: Map Editor

A map editor should be created for easy creation/changing of maps. The map format may well change over time, so the map editor should be able to adapt to these arbitrary changes.

This is a commented example of a building with a door (JSON does not allow for comments, or I would comment one of the map files):

```javascript
{
"type":	"building",	//	Type of object. Currently 'building', 'structure', and 'item'.
"src":	"img/pokemon.png",	//	Source of the sprite sheet file.
"where": {	//	Location (in grid coordinates) where the object should be in the map.
"x":	6,
"y":	4
},
"x":	0,	//	Location of the object IN THE SPRITE SHEET.
"y":	0,
"w":	82,	//	Dimensions of the object IN THE SPRITE SHEET.
"h":	70,
"dw":	75,	//	Dimensions of the object in-game.
"dh":	70,
"door": {	//	Object containing info about the door.
"map": {	//	Which map the door points to.
"x":	1,
"y":	1
},
"instance": {	//	Which instance the door points to inside the given map (typically the same as the location of the door).
"x":	7,
"y":	6
},
"at": {	//	Location of the door.
"x":	7,
"y":	6
},
"to": {	//	Which grid tile the door takes players to, inside the given map and instance.
"x":	3,
"y":	7
}
}
}
```

This is a commented example of an item:

```javascript
{
"type":	"item",	//	Type of object. Currently 'building', 'structure', and 'item'.
"src":	"img/zelda.png",	//	Source of the sprite sheet file.
"where": {	//	Location (in grid coordinates) where the object should be in the map.
"x":	14,
"y":	14
},
"x":	102,	//	Location of the object IN THE SPRITE SHEET.
"y":	659,
"w":	16,	//	Dimensions of the object IN THE SPRITE SHEET.
"h":	16,
"dw":	25,	//	Dimensions of the object in-game.
"dh":	25,
"data":	{	//	Meta-data for the object.
"contents":	[{	//	Contents of the item (chest, in this case), in array form so that chests may contain multiple items.
"id":	4,	//	Chest contains item with an id of 4.
"amount":	2	//	Chest contains two of these items.
}]
}
}
```

Aaaaand this is an example of a structure (a wall):

```javascript
{
"type":	"structure",	//	Type of object. Currently 'building', 'structure', and 'item'.
"src":	"img/wall.jpg",	//	Source of the sprite sheet file.
"where": {	//	Location (in grid coordinates) where the object should be in the map.
"x":	23,
"y":	1
},
"x":	0,	//	Location of the object IN THE SPRITE SHEET.
"y":	0,
"w":	154,	//	Dimensions of the object IN THE SPRITE SHEET.
"h":	154,
"dw":	25,	//	Dimensions of the object in-game.
"dh":	25,
"repeatY":	13,	//	Object repeats vertically in this case, for 13 tiles.
"except": [{	//	Although it repeats for 13 tiles, it has two exceptions in the repeat, which create two gaps in the wall that players can walk through.
"x":	23,
"y":	2
},{
"x":	23,
"y":	3
}]
}
```

Some things to keep in mind:

* If a building does not have a door, it simply omits the `door` object.
* If a structure does not repeat or has no exceptions, it simply omits `repeatX`, `repeatY`, and `except`.
* Order shouldn't matter, but the maps might as well have everything in the same order for consistency.
* Although the engine currently uses the format outlined above, that does not mean it is the format that has to be used. The adaptation is a two-way street.
* The important thing to note is that since I was able to programmatically split buildings into individual tiles, we do not need to list every tile that is used--only the top-left tile in most cases.