public void export(string filename) { foreach (Layer l in Layers) { foreach (Item i in l.Items) { if (i is TextureItem) { TextureItem ti = (TextureItem)i; ti.texture_filename = RelativePath(ContentRootFolder, ti.texture_fullpath); ti.asset_name = ti.texture_filename.Substring(0, ti.texture_filename.LastIndexOf('.')); } } } XmlTextWriter writer = new XmlTextWriter(filename, null); writer.Formatting = Formatting.Indented; writer.Indentation = 4; XmlSerializer serializer = new XmlSerializer(typeof(Level)); serializer.Serialize(writer, this); writer.Close(); }
public String exportToString() { //String s = ""; foreach (Layer l in Layers) { foreach (Item i in l.Items) { if (i is TextureItem) { TextureItem ti = (TextureItem)i; ti.texture_filename = RelativePath(ContentRootFolder, ti.texture_fullpath); ti.asset_name = ti.texture_filename.Substring(0, ti.texture_filename.LastIndexOf('.')); } } } StringWriter writer = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(Level)); serializer.Serialize(writer, this); writer.Close(); return(writer.ToString()); }
/* * public void setCollisionBoxesForStaticObjects * (string propertyName, List<TextureItem> textureItems, List<StaticObject> staticObjects) * { * foreach (TextureItem items in textureItems) * { * CollisionBox collisionBox = null; * * if (items.CustomProperties.ContainsKey(propertyName)) * { * if (items.CustomProperties[propertyName].type == typeof(Item)) * { * Console.WriteLine("StaticObject CollisionBox"); * RectangleItem rectangleItem = (RectangleItem)items.CustomProperties[propertyName].value; * collisionBox = new CollisionBox(rectangleItem.Position, rectangleItem.Width, rectangleItem.Height); * * } * } * staticObjects.Add(new StaticObject(items.texture, items.asset_name, items.Name, items.Visible, items.Position, new Vector2(8, 8), * items.Rotation, items.Scale, items.Origin, collisionBox)); * } * } */ public void copyFromItemList() { foreach (Layer layer in Layers) { foreach (Item item in layer.Items) { if (item is TextureItem) { TextureItem textureItem = (TextureItem)item; layer.textureItems.Add(textureItem); } else if (item is RectangleItem) { RectangleItem rectangleItem = (RectangleItem)item; layer.rectangleItems.Add(rectangleItem); } else if (item is PathItem) { PathItem pathItem = (PathItem)item; layer.pathItems.Add(pathItem); } else if (item is CircleItem) { CircleItem circleItem = (CircleItem)item; layer.circleItems.Add(circleItem); } } } }
public override Item clone() { TextureItem result = (TextureItem)this.MemberwiseClone(); result.CustomProperties = new SerializableDictionary(CustomProperties); result.polygon = (Vector2[])polygon.Clone(); result.hovering = false; return(result); }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { if (destType == typeof(string) && value is TextureItem) { TextureItem textureItem = (TextureItem)value; return(textureItem.texture_filename); } return(base.ConvertTo(context, culture, value, destType)); }
// Factory functions. public static TextureItem CreateEmpty(GameObjectItem go) { var texture = new TextureItem(); texture.gameObject = go; texture.layer = go.layer; texture.Position = go.Position; texture.TintColor = Microsoft.Xna.Framework.Color.White; texture.Scale = Microsoft.Xna.Framework.Vector2.One; return(texture); }
public int loadAnimationProperty(TextureItem item, string property) { string type = null; int tall = 0; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { Console.WriteLine(property + " Loaded"); type = (String)item.CustomProperties[property].value; tall = int.Parse(type); } } else { Console.WriteLine("Failed to load " + property); } return tall; }
public string loadType(TextureItem item, string property) { string type = null; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { Console.WriteLine(property + " Loaded"); type = (String)item.CustomProperties[property].value; } } else { Console.WriteLine("Failed to load " + property); } return type; }
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer) { if (dictionary == null) throw new ArgumentNullException("dictionary"); if (type == typeof(Level)) { // Create the instance to deserialize into. Level level = new Level(); level.CanvasColor = new Color( (byte)(int)(dictionary["CanvasColor"] as ArrayList)[1], (byte)(int)(dictionary["CanvasColor"] as ArrayList)[2], (byte)(int)(dictionary["CanvasColor"] as ArrayList)[3], (byte)(int)(dictionary["CanvasColor"] as ArrayList)[0]); Constants.Instance.ColorBackground = level.CanvasColor; level.Scale = (int)dictionary["Scale"]; ArrayList spawnList = dictionary["PlayerSpawn"] as ArrayList; float spawnX = 0.0f; if (spawnList[0] is decimal) spawnX = (float)(decimal)spawnList[0]; if (spawnList[0] is int) spawnX = (float)(int)spawnList[0]; float spawnY = 0.0f; if (spawnList[1] is decimal) spawnY = (float)(decimal)spawnList[1]; if (spawnList[1] is int) spawnY = (float)(int)spawnList[1]; level.PlayerSpawn = new Vector2(spawnX, spawnY); level.Music = dictionary["Music"] as String; level.ContentRootFolder = dictionary["ContentRootFolder"] as String; // Deserialize the ListItemCollection's items. Dictionary<int, object> layersDict = new Dictionary<int, object>(); ArrayList itemsList = (ArrayList)dictionary["Layers"]; foreach (Dictionary<string, object> layerDict in itemsList) { Layer layer = new Layer(layerDict["ID"] as String); float scale = 1.0f; if (layerDict["Scale"] is decimal) scale = (float)(decimal)layerDict["Scale"]; if (layerDict["Scale"] is int) scale = (float)(int)layerDict["Scale"]; layer.ScrollSpeed = new Microsoft.Xna.Framework.Vector2(1.0f/scale, 1.0f/scale); layer.ZPos = (int)layerDict["Layer"]; level.Layers.Add(layer); layersDict.Add((int)layerDict["Layer"], layer); // level.Add(serializer.ConvertToType<ListItem>(itemsList[i])); } ArrayList objList = (ArrayList)dictionary["Objects"]; foreach (Dictionary<string, object> groupDict in objList) { ArrayList childList = (ArrayList)groupDict["Children"]; foreach (Dictionary<string, object> childDict in childList) { Vector2 position = new Vector2( 0.0f, 0.0f); float rotation = 0.0f; if (childDict.ContainsKey("Transform")) { Dictionary<string, object> transDict = childDict["Transform"] as Dictionary<string, object>; ArrayList posList = transDict["Position"] as ArrayList; float posX = 0.0f; if (posList[0] is decimal) posX = (float)(decimal)posList[0]; if (posList[0] is int) posX = (float)(int)posList[0]; float posY = 0.0f; if (posList[1] is decimal) posY = (float)(decimal)posList[1]; if (posList[1] is int) posY = (float)(int)posList[1]; position = new Vector2(posX * level.Scale, posY * level.Scale); if (transDict["Rotation"] is decimal) rotation = (float)(decimal)transDict["Rotation"]; if (transDict["Rotation"] is int) rotation = (float)(int)transDict["Rotation"]; } if (childDict.ContainsKey("Renderable")) { Dictionary<string, object> rendDict = childDict["Renderable"] as Dictionary<string, object>; TextureItem item = new TextureItem(level.ContentRootFolder + '/' + rendDict["Image"] as String, position); item.texture_filename = rendDict["Image"] as String; item.Name = childDict["Name"] as String; item.Rotation = rotation * MathHelper.Pi/180.0f; item.TintColor = new Color( (float)(int)(rendDict["ColorMod"] as ArrayList)[3], (float)(int)(rendDict["ColorMod"] as ArrayList)[0], (float)(int)(rendDict["ColorMod"] as ArrayList)[1], (float)(int)(rendDict["ColorMod"] as ArrayList)[2]); float xscale = 1.0f; if (rendDict["xScale"] is decimal) xscale = (float)(decimal)rendDict["xScale"]; if (rendDict["xScale"] is int) xscale = (float)(int)rendDict["xScale"]; float yscale = 1.0f; if (rendDict["yScale"] is decimal) yscale = (float)(decimal)rendDict["yScale"]; if (rendDict["yScale"] is int) yscale = (float)(int)rendDict["yScale"]; item.setScale(new Vector2(xscale, yscale)); //Game Specific components if (childDict.ContainsKey("Planet")) { Dictionary<string, object> gravDict = childDict["Planet"] as Dictionary<string, object>; double gravity = 0.0f; if (gravDict["Gravity"] is decimal) gravity = (double)(decimal)gravDict["Gravity"]; if (gravDict["Gravity"] is int) gravity = (double)(int)gravDict["Gravity"]; item.CustomProperties.Add("Gravity", new CustomProperty("Gravity", gravity, typeof(double), "")); } (layersDict[(int)rendDict["Layer"]] as Layer).Items.Add( item ); } } } //Engine draws things in reverse foreach (Layer layer in level.Layers) { layer.Items.Reverse(); } return level; } return null; }
public void paintTextureBrush(bool continueAfterPaint) { if (SelectedLayer == null) { System.Windows.Forms.MessageBox.Show(Resources.No_Layer); destroyTextureBrush(); return; } Item i = new TextureItem(currentbrush.fullpath, new Vector2((int)mouseworldpos.X, (int)mouseworldpos.Y)); i.Name = i.getNamePrefix() + level.getNextItemNumber(); i.layer = SelectedLayer; beginCommand("Add Item \"" + i.Name + "\""); AdesExtensions.onAddTextureItem(i, currentbrush.fullpath); addItem(i); endCommand(); updatetreeview(); if (!continueAfterPaint) destroyTextureBrush(); }
public List<Polygon> loadPolygons(TextureItem item, string property) { List<Polygon> polygons = new List<Polygon>(); int numberToLoad = 1; int numberOfLoaded = 0; bool loadNext = true; while (loadNext) { string tempProperty = property + numberToLoad.ToString(); if (item.CustomProperties.ContainsKey(tempProperty)) { //Console.WriteLine(tempProperty); if (item.CustomProperties[tempProperty].type == typeof(Item)) { Console.WriteLine(tempProperty + " Loaded"); PathItem pathItem = (PathItem)item.CustomProperties[tempProperty].value; if (pathItem != null) { List<Vector2> liste = new List<Vector2>(pathItem.WorldPoints); Polygon polygon = new Polygon(); foreach (Vector2 point in liste) { polygon.getPoints().Add(point); } polygon.buildEdges(); polygons.Add(polygon); numberToLoad++; numberOfLoaded++; } else { loadNext = false; } } } else { loadNext = false; } } if (numberOfLoaded == 0) { polygons = null; //Console.WriteLine("Did not load Polygons"); } return polygons; }
public int[] loadAnimationProperty2(TextureItem item, string property) { string type = null; int[] fArray = null; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { Console.WriteLine(property + " Loaded"); type = (String)item.CustomProperties[property].value; string[] array = type.Split(new char[] { ' ' }); fArray = new int[array.Count()]; for (int i = 0; i < array.Count(); i++) { fArray[i] = int.Parse(array[i]); } } } else { Console.WriteLine("Failed to load " + property); } return fArray; }
public string loadName(TextureItem item, string property) { string name = null; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { name = (String)item.CustomProperties[property].value; } } else { //Console.WriteLine("Failed to load " + property); } return name; }
public bool loadIsAnimated(TextureItem item, string property) { bool isAnimated = false; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(bool)) { isAnimated = (bool)item.CustomProperties[property].value; } } else { //Console.WriteLine("Failed to load " + property); } return isAnimated; }
public float loadDepthPosition(TextureItem item, string property) { string depthPosition = null; float fDepthPosition = 0; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { depthPosition = (String)item.CustomProperties[property].value; if (depthPosition != "") { fDepthPosition = float.Parse(depthPosition); } } } else { //Console.WriteLine("Failed to load " + property); } return fDepthPosition; }
public List<AABB> loadAxisAlignedBoxes(TextureItem item, string property) { List<AABB> axisAlignedBoxes = new List<AABB>(); int numberToLoad = 1; int numberOfLoaded = 0; bool loadNext = true; while (loadNext) { string tempProperty = property + numberToLoad.ToString(); if (item.CustomProperties.ContainsKey(tempProperty)) { if (item.CustomProperties[tempProperty].type == typeof(Item)) { Console.WriteLine(tempProperty + " Loaded"); RectangleItem rectangleItem = (RectangleItem)item.CustomProperties[tempProperty].value; AABB axisAlignedBox = new AABB(rectangleItem.Position, rectangleItem.Width, rectangleItem.Height); axisAlignedBoxes.Add(axisAlignedBox); numberToLoad++; numberOfLoaded++; } } else { loadNext = false; } } if (numberOfLoaded == 0) { axisAlignedBoxes = null; //Console.WriteLine("Did not load AxisAlignedBoxes"); } return axisAlignedBoxes; }
public Texture2D[] loadAnimationSprite(TextureItem item, string property) { Texture2D [] animationSprites = null; if (item.CustomProperties.ContainsKey(property)) { if (item.CustomProperties[property].type == typeof(string)) { Console.WriteLine(property + " Loaded"); String animationPath = (String)item.CustomProperties[property].value; string[] array = animationPath.Split(new char[] { ' ' }); animationSprites = new Texture2D[array.Count()]; for (int i = 0; i < array.Count(); i++) { animationSprites[i] = content.Load<Texture2D>(array[i]); } } } else { Console.WriteLine("Failed to load " + property); } return animationSprites; }