package net.alcuria.umbracraft.definitions.map;

import net.alcuria.umbracraft.Game;
import net.alcuria.umbracraft.definitions.Definition;

import com.badlogic.gdx.utils.Array;

/** Defines a user-created map
 * @author Andrew Keturi */
public class MapDefinition extends Definition {

	/** the height of the map */
	private int height;
	/** the name of the map */
	public String name;
	/** the map tiles */
	public Array<Array<MapTileDefinition>> tiles;
	/** the width of the map */
	private int width;

	/** Creates the tiles array */
	public void createTiles() {
		// save off an old copy of the tiles (if available) to retain over
		Array<Array<MapTileDefinition>> copy = null;
		if (tiles != null) {
			copy = new Array<Array<MapTileDefinition>>();
			for (int i = 0; i < tiles.size; i++) {
				copy.insert(i, new Array<MapTileDefinition>(tiles.get(i)));
			}
		}
		Game.log("new size " + width + " " + height);
		// create the new array
		tiles = new Array<Array<MapTileDefinition>>();
		for (int i = 0; i < width; i++) {
			tiles.insert(i, new Array<MapTileDefinition>());
			for (int j = 0; j < height; j++) {
				MapTileDefinition oldDefinition = null;
				if (copy != null && i < copy.size && j < copy.get(0).size) {
					oldDefinition = copy.get(i).get(j);
					Game.log(i + " " + j);
				}
				tiles.get(i).insert(j, copy != null ? oldDefinition : new MapTileDefinition());
			}
		}
	}

	/** @return the map's height */
	public int getHeight() {
		return height;
	}

	@Override
	public String getName() {
		return name != null ? name : "Map";
	}

	/** @return the map's width */
	public int getWidth() {
		return width;
	}

	/** Resizes the map
	 * @param width the new width
	 * @param height the new height */
	public void resize(int width, int height) {
		setWidth(width);
		setHeight(height);
		createTiles();
	}

	/** sets the map's height
	 * @param height the new height */
	public void setHeight(int height) {
		this.height = height;
	}

	/** sets the map's width
	 * @param width the new width */
	public void setWidth(int width) {
		this.width = width;
	}

}

@@ -46,44 +46,8 @@
 p;%0A%0A
-import net.alcuria.umbracraft.Game;%0A
 impo
@@ -96,16 +96,16 @@
 nition;%0A
+
 %0Aimport 
@@ -527,359 +527,8 @@
 ) %7B%0A
-%09%09// save off an old copy of the tiles (if available) to retain over%0A%09%09Array%3CArray%3CMapTileDefinition%3E%3E copy = null;%0A%09%09if (tiles != null) %7B%0A%09%09%09copy = new Array%3CArray%3CMapTileDefinition%3E%3E();%0A%09%09%09for (int i = 0; i %3C tiles.size; i++) %7B%0A%09%09%09%09copy.insert(i, new Array%3CMapTileDefinition%3E(tiles.get(i)));%0A%09%09%09%7D%0A%09%09%7D%0A%09%09Game.log(%22new size %22 + width + %22 %22 + height);%0A
 %09%09//
@@ -776,201 +776,30 @@
 %09%09%09%09
-if (copy != null && i %3C copy.size && j %3C copy.get(0).size) %7B%0A%09%09%09%09%09oldDefinition = copy.get(i).get(j);%0A%09%09%09%09%09Game.log(i + %22 %22 + j);%0A%09%09%09%09%7D%0A%09%09%09%09tiles.get(i).insert(j, copy != null ? oldDefinition :
+tiles.get(i).insert(j,
  new
@@ -1151,32 +1151,32 @@
 e new height */%0A
-
 %09public void res
@@ -1204,16 +1204,97 @@
 ight) %7B%0A
+%09%09int deltaWidth = width - this.width;%0A%09%09int deltaHeight = height - this.height;%0A
 %09%09setWid

Remove copy logic from map create