public static Guid CreateEntityFromFile(string xmlFilePath, ref ECSContainer ecsContainer) { XmlSerializer serializer = new XmlSerializer(typeof(BaseEntity)); using (FileStream fileStream = new FileStream(xmlFilePath, FileMode.Open)) { BaseEntity entity = (BaseEntity)serializer.Deserialize(fileStream); return(ecsContainer.AddEntity(entity)); } }
public static void GenerateRandomInventoryItemsForEntity(ECSContainer ecsContainer, Guid ownerId) { List <Guid> itemIds = new List <Guid>(); int numberOfItems = Constants.Random.Next(1, 15); for (int i = 0; i <= numberOfItems; i++) { BaseEntity item = new BaseEntity(ComponentFlags.LABEL, ComponentFlags.DISPLAY); item.Label = new Label() { Color = Color.Black, Displacement = new Vector2(0, -4), WhenToShow = WhenToShowLabel.NEVER, Origin = Vector2.Zero, Rotation = 0f, Scale = 1f, DistanceRenderBuffer = 200, SpriteEffect = SpriteEffects.None, Text = "item" }; item.Display = new Display() { Color = Color.White, Layer = DisplayLayer.FOREGROUND, Opacity = 1f, Origin = new Vector2(Constants.Sprites.ItemGrid / 2, Constants.Sprites.ItemGrid / 2), Rotation = 0f, Scale = 2f, SpriteEffect = SpriteEffects.None, SpriteSheetSize = Constants.Sprites.ItemGrid, SpriteSheetKey = Constants.Sprites.ItemSheetKey, SpriteSheetCol = Constants.Random.Next(1, 22), SpriteSheetRow = Constants.Random.Next(1, 14) }; Guid id = ecsContainer.AddEntity(item); itemIds.Add(id); } BaseEntity ownerAddition = new BaseEntity(ComponentFlags.INVENTORY); ownerAddition.Inventory = new Inventory() { EntitiesOwned = itemIds }; ecsContainer.AppendEntity(ownerAddition, ownerId); }