/// <summary> /// Adds the given item to the ink list, attempting to find the origin list definition that it belongs to. /// The item must therefore come from a list definition that is already "known" to this list, so that the /// item's value can be looked up. By "known", we mean that it already has items in it from that source, or /// it did at one point - it can't be a completely fresh empty list, or a list that only contains items from /// a different list definition. /// </summary> public void AddItem(string itemName) { ListDefinition foundListDef = null; foreach (var origin in origins) { if (origin.ContainsItemWithName(itemName)) { if (foundListDef != null) { throw new System.Exception("Could not add the item " + itemName + " to this list because it could come from either " + origin.name + " or " + foundListDef.name); } else { foundListDef = origin; } } } if (foundListDef == null) { throw new System.Exception("Could not add the item " + itemName + " to this list because it isn't known to any list definitions previously associated with this list."); } var item = new InkListItem(foundListDef.name, itemName); var itemVal = foundListDef.ValueForItem(item); this [item] = itemVal; }
/// <summary> /// Adds the given item to the ink list, attempting to find the origin list definition that it belongs to. /// The item must therefore come from a list definition that is already "known" to this list, so that the /// item's value can be looked up. /// By "known", we mean that it already has items in it from that source, or /// it did at one point - it can't be a completely fresh empty list, or a list that only contains items from /// a different list definition. /// You can also provide the Story object, so in the case of an unknown element, it can be created fresh /// </summary> public void AddItem(string itemName, Story storyObject = null) { ListDefinition foundListDef = null; if (origins != null) { foreach (var origin in origins) { if (origin.ContainsItemWithName(itemName)) { if (foundListDef != null) { throw new System.Exception("Could not add the item " + itemName + " to this list because it could come from either " + origin.name + " or " + foundListDef.name); } else { foundListDef = origin; } } } } if (foundListDef == null) { if (storyObject == null) { throw new System.Exception("Could not add the item " + itemName + " to this list because it isn't known to any list definitions previously associated with this list, and no ink Story object was provided to create it from."); } else { var newItem = FromString(itemName, storyObject).orderedItems[0]; this[newItem.Key] = newItem.Value; } } else { var item = new InkListItem(foundListDef.name, itemName); var itemVal = foundListDef.ValueForItem(item); this[item] = itemVal; } }
public ListValue FindSingleItemListWithName(string name) { RawListItem item = RawListItem.Null; ListDefinition list = null; // Name could be in the form itemName or listName.itemName var nameParts = name.Split('.'); if (nameParts.Length == 2) { item = new RawListItem(nameParts [0], nameParts [1]); TryGetDefinition(item.originName, out list); } else { foreach (var namedList in _lists) { var listWithItem = namedList.Value; item = new RawListItem(namedList.Key, name); if (listWithItem.ContainsItem(item)) { list = listWithItem; break; } } } // Manager to get the list that contains the given item? if (list != null) { int itemValue = list.ValueForItem(item); return(new ListValue(item, itemValue)); } return(null); }