summaryrefslogtreecommitdiffstats
path: root/src/libjtmx/Map.java
blob: 70ff9b06e25230057ca0f8ae92e315816b25fdcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package libjtmx;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import java.io.InputStream;

import java.awt.Color;

import java.util.List;


@XmlRootElement(name = "map")
public class Map {
	public enum Orientation {
		ORTHOGONAL,
		ISOMETRIC,
		STAGGERED,
		HEXAGONAL
	}

	public enum RenderOrder {
		RIGHT_DOWN,
		RIGHT_UP,
		LEFT_DOWN,
		LEFT_UP
	}

	/* attributes */
	String version;
	String tiledVersion;

	Orientation orientation;
	RenderOrder renderOrder;

	int width;
	int height;

	int tileWidth;
	int tileHeight;

	// hex is not supported yet
	/*
	int hexSideLenght;
	Axis staggerAxis;
	String staggerIndex;
	*/

	Color backgroundColor;

	/* elements */
	List<TileSet> tileSets;

	private Map() {}

	public static Map load(InputStream is) {
		Map map = null;

		try {
			JAXBContext context = JAXBContext.newInstance(Map.class);
			Unmarshaller unmarshaller = context.createUnmarshaller();

			map = (Map) unmarshaller.unmarshal(is);
		} catch (JAXBException ex) {
			ex.printStackTrace();
		}

		return map;
	}
}