public void Save() { List <XmlEntity> xmlentities = new List <XmlEntity>(); XmlLevel xmllevel = new XmlLevel(name, id, xmlentities); for (int i = 0; i < entities.Count; i++) { Entity entity = entities[i]; XmlEntity xmlentity = new XmlEntity(); xmlentity.position = entity.position; xmlentity.rotation = entity.rotation; xmlentity.size = entity.size; if (entity is StaticModelEntity) { StaticModelEntity modelentity = entity as StaticModelEntity; xmlentity.asset = Resources.GetName(modelentity.GetModel()); xmlentity.type = "static_model"; } if (entity is AnimatedModelEntity) { AnimatedModelEntity modelentity = entity as AnimatedModelEntity; xmlentity.asset = Resources.GetName(modelentity.GetModel()); xmlentity.type = "animated_model"; } if (entity is WallModelEntity) { WallModelEntity wallentity = entity as WallModelEntity; xmlentity.asset = Resources.GetName(wallentity.GetModel()); xmlentity.type = "wall_model"; } if (entity is Billboard) { Billboard billboard = entity as Billboard; xmlentity.asset = Resources.GetName(billboard.region.texture); xmlentity.type = "billboard"; xmlentity.color = billboard.color; } xmlentities.Add(xmlentity); } XmlHelper.Save(xmllevel); }
public void Load() { entities.Clear(); XmlLevel xmllevel = XmlHelper.Load(id); List <XmlEntity> xmlentities = xmllevel.entities; for (int i = 0; i < xmlentities.Count; i++) { XmlEntity xmlentity = xmlentities[i]; Entity entity = null; if (xmlentity.type == "static_model") { Model model = (Model)Resources.GetObject(xmlentity.asset); entity = new StaticModelEntity(model); } if (xmlentity.type == "animated_model") { Model model = (Model)Resources.GetObject(xmlentity.asset); entity = new AnimatedModelEntity(model); } if (xmlentity.type == "wall_model") { Model model = (Model)Resources.GetObject(xmlentity.asset); entity = new WallModelEntity(model); } if (xmlentity.type == "billboard") { Texture2D texture = (Texture2D)Resources.GetObject(xmlentity.asset); entity = new Billboard(texture); ((Billboard)entity).color = xmlentity.color; } if (entity == null) { continue; } entity.position = xmlentity.position; entity.rotation = xmlentity.rotation; entity.size = xmlentity.size; Add(entity); } }
private Level Parse(XmlLevel toParse) { Level parsed = new Level(); parsed.AmbientLight = new Vector4(toParse.ambientLightColor.red, toParse.ambientLightColor.blue, toParse.ambientLightColor.blue, toParse.ambientLightIntensity); parsed.Lights = new List<LightSource>(); foreach (XmlLightSource lightSource in toParse.lightSources) { LightSource parsedLightSource = new LightSource(); parsedLightSource.Light = new Vector4(lightSource.color.red, lightSource.color.green, lightSource.color.blue, lightSource.lightIntensity); parsedLightSource.PositionInWorld = new Vector4(lightSource.position.x, lightSource.position.y, lightSource.position.z, lightSource.position.w); parsed.Lights.Add(parsedLightSource); } parsed.gameObjects = new List<GameObject>(); foreach (XmlGameObject gameObject in toParse.gameObjects) { GameObject parsedObject = new GameObject(); // TODO error handling parsedObject.ObjectModelContentName = gameObject.model; parsedObject.PositionInWorld = new Vector3(gameObject.position.x, gameObject.position.y, gameObject.position.z); parsedObject.RotationAxis = new Vector3(gameObject.rotationAxis.x, gameObject.rotationAxis.y, gameObject.rotationAxis.z); parsedObject.ScalingInWorld = gameObject.scaling; parsedObject.World = Matrix.Identity; parsed.gameObjects.Add(parsedObject); } return parsed; }
private void restoreXmlLevel(Level level, XmlLevel xmlLevel) { var objects = new List <object>(); xmlLevel.Islands.ForEach(xmlI => { var i = level.CreateNewIsland(xmlI.Position); //var constructionMethod = level.GetType().GetMethod(xmlI.ConstructionConstructor); //i.Construction = (Construction)constructionMethod.Invoke(level, new[] { i }); xmlI.Island = i; i.Type = (Island.IslandType)Enum.Parse(typeof(Island.IslandType), xmlI.Type); objects.Add(i); }); xmlLevel.Islands.ForEach(xmlI => xmlI.ConnectedIslands.Select(i => objects[i]).Cast <Island>().ForEach(xmlN => xmlI.Island.AddBridgeTo(xmlN))); }
private XmlLevel buildXmlLevel(Level level) { int nextID = 1; var xmlLevel = new XmlLevel(); xmlLevel.Islands = level.Islands.Select(island => new XmlIsland() { Island = island, ID = nextID++, Position = island.Position, //ConstructionConstructor = island.Construction.LevelConstructorMethod, Type = island.Type.ToString() }).ToArray(); xmlLevel.Islands.ForEach(i => i.ConnectedIslands = i.Island.ConnectedIslands.Select( connectedI => xmlLevel.Islands.TakeWhile(j => j.Island != connectedI).Count()) .ToArray()); return(xmlLevel); }
public XmlTagAttribute(string tag, XmlLevel level) { Tag = tag; Level = level; }