internal void PushEvaluationStack(Runtime.Object obj)
        {
            // Include metadata about the origin List for list values when
            // they're used, so that lower level functions can make use
            // of the origin list to get related items, or make comparisons
            // with the integer values etc.
            var listValue = obj as ListValue;

            if (listValue)
            {
                // Update origin when list is has something to indicate the list origin
                var rawList = listValue.value;
                var names   = rawList.originNames;
                if (names != null)
                {
                    var origins = new List <ListDefinition> ();
                    foreach (var n in names)
                    {
                        ListDefinition def = null;
                        story.listDefinitions.TryGetDefinition(n, out def);
                        if (!origins.Contains(def))
                        {
                            origins.Add(def);
                        }
                    }

                    rawList.origins = origins;
                }
            }

            evaluationStack.Add(obj);
        }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
    private Godot.Object MakeGDListDefinition(Ink.Runtime.ListDefinition listDefinition)
    {
        var items = new Godot.Collections.Dictionary <Godot.Object, int>();

        foreach (KeyValuePair <Ink.Runtime.InkListItem, int> kv in listDefinition.items)
        {
            var inkListItem = MakeGDInkListItem(kv.Key);
            items.Add(inkListItem, kv.Value);
        }

        var definitionParams  = new object[] { listDefinition.name, items };
        var inkListDefinition = (Godot.Object)InkListDefinition.New(definitionParams);

        return(inkListDefinition);
    }
Exemplo n.º 4
0
        Value CallListIncrementOperation(List <Object> listIntParams)
        {
            var listVal = (ListValue)listIntParams[0];
            var intVal  = (IntValue)listIntParams[1];


            var resultRawList = new InkList();

            foreach (var listItemWithValue in listVal.value)
            {
                var listItem      = listItemWithValue.Key;
                var listItemValue = listItemWithValue.Value;

                // Find + or - operation
                var intOp = (BinaryOp <int>)_operationFuncs[ValueType.Int];

                // Return value unknown until it's evaluated
                int targetInt = (int)intOp(listItemValue, intVal.value);

                // Find this item's origin (linear search should be ok, should be short haha)
                ListDefinition itemOrigin = null;
                foreach (var origin in listVal.value.origins)
                {
                    if (origin.name == listItem.originName)
                    {
                        itemOrigin = origin;
                        break;
                    }
                }

                if (itemOrigin != null)
                {
                    InkListItem incrementedItem;
                    if (itemOrigin.TryGetItemWithValue(targetInt, out incrementedItem))
                    {
                        resultRawList.Add(incrementedItem, targetInt);
                    }
                }
            }

            return(new ListValue(resultRawList));
        }
Exemplo n.º 5
0
        /// <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;
            }
        }
Exemplo n.º 6
0
        public static ListDefinitionsOrigin JTokenToListDefinitions(object obj)
        {
            var defsObj = (Dictionary <string, object>)obj;

            var allDefs = new List <ListDefinition> ();

            foreach (var kv in defsObj)
            {
                var name        = (string)kv.Key;
                var listDefJson = (Dictionary <string, object>)kv.Value;

                // Cast (string, object) to (string, int) for items
                var items = new Dictionary <string, int> ();
                foreach (var nameValue in listDefJson)
                {
                    items.Add(nameValue.Key, (int)nameValue.Value);
                }

                var def = new ListDefinition(name, items);
                allDefs.Add(def);
            }

            return(new ListDefinitionsOrigin(allDefs));
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 public bool TryGetDefinition(string name, out ListDefinition def)
 {
     return(_lists.TryGetValue(name, out def));
 }