public void CanAddItemToUnitList() { IUnit testingunit1 = new StubIUnit { IsCollidableGet = () => true }; testsubject.AddItem(testingunit1); Assert.IsTrue(testsubject.UnitList.Contains(testingunit1)); }
/// <summary> /// Forcefully adds parsed content elements to this container. /// </summary> /// <param name="tile">The tile to add content to.</param> /// <param name="contentElements">The content elements to add.</param> private void AddContent(ITile tile, IEnumerable <IParsedElement> contentElements) { contentElements.ThrowIfNull(nameof(contentElements)); // load and add tile flags and contents. foreach (var e in contentElements) { foreach (var attribute in e.Attributes) { if (attribute.Name.Equals("Content")) { if (attribute.Value is IEnumerable <IParsedElement> elements) { var stack = new Stack <IItem>(); foreach (var element in elements) { IItem item = this.itemFactory.CreateItem(ItemCreationArguments.WithTypeId((ushort)element.Id)); if (item == null) { this.logger.LogWarning($"Item with id {element.Id} not found in the catalog, skipping."); continue; } this.SetItemAttributes(item, element.Attributes); stack.Push(item); } // Add them in reversed order. while (stack.Count > 0) { var item = stack.Pop(); tile.AddItem(this.itemFactory, item); item.ParentContainer = tile; } } } else { // it's a flag if (Enum.TryParse(attribute.Name, out TileFlag flagMatch)) { // TODO: implement // tile.SetFlag(flagMatch); } else { this.logger.LogWarning($"Unknown flag [{attribute.Name}] found on tile at location {tile.Location}."); } } } } }