public GlueProjectSave ToGlueProjectSave(ArrowProjectSave arrowProject) { GlueProjectSave toReturn = new GlueProjectSave(); ArrowElementToGlueConverter elementToElementConverter = new ArrowElementToGlueConverter(); foreach (var element in arrowProject.Elements) { IElement glueElement = elementToElementConverter.ToGlueIElement(element); if (glueElement is ScreenSave) { toReturn.Screens.Add(glueElement as ScreenSave); } else { toReturn.Entities.Add(glueElement as EntitySave); } } return toReturn; }
public void TestConversion() { ArrowProjectSave project = new ArrowProjectSave(); SpriteSave spriteSave = new SpriteSave(); spriteSave.X = 3; spriteSave.Y = 4; spriteSave.Name = "SpriteInstance"; spriteSave.Texture = "Entities/FirstElement/redball.BMP"; ArrowElementSave element = new ArrowElementSave(); element.Name = "FirstElement"; element.Sprites.Add(spriteSave); project.Elements.Add(element); element = new ArrowElementSave(); element.Name = "ContainerOfFirstElement"; element.Sprites.Add(spriteSave); project.Elements.Add(element); ArrowElementInstance instance = new ArrowElementInstance(); instance.Name = "FirstElementInstance"; instance.Type = "FirstElement"; instance.SetVariable("X", 4); instance.SetVariable("Y", 5); element.ElementInstances.Add(instance); ArrowProjectToGlueProjectConverter converter = new ArrowProjectToGlueProjectConverter(); GlueProjectSave gps = converter.ToGlueProjectSave(project); EntitySave firstElementEntity = gps.Entities.FirstOrDefault(item => item.Name == "Entities/FirstElement"); EntitySave containerOfFirstElement = gps.Entities.FirstOrDefault(item => item.Name == "Entities/ContainerOfFirstElement"); if (firstElementEntity.Name.StartsWith("Entities/") == false) { throw new Exception("Entity names must start with \"Entities/\""); } if (firstElementEntity.ReferencedFiles.Count == 0) { throw new Exception("The Entity should automatically contain a ReferencedFile for the redball file"); } if (containerOfFirstElement.NamedObjects.FirstOrDefault(item => item.InstanceName == "FirstElementInstance") == null) { throw new Exception("The entity should contain a NOS for another element, but it doesn't"); } string gluxString; FileManager.XmlSerialize(gps, out gluxString); string aroxString; FileManager.XmlSerialize(project, out aroxString); }