示例#1
0
        public void SetTemporaryVariable(string name, Object value, bool declareNew, int contextIndex = -1)
        {
            if (contextIndex == -1)
            {
                contextIndex = currentElementIndex + 1;
            }

            var contextElement = callStack[contextIndex - 1];

            if (!declareNew && !contextElement.temporaryVariables.ContainsKey(name))
            {
                throw new StoryException("Could not find temporary variable to set: " + name);
            }

            Object oldValue;

            if (contextElement.temporaryVariables.TryGetValue(name, out oldValue))
            {
                ListValue.RetainListOriginsForAssignment(oldValue, value);
            }

            contextElement.temporaryVariables[name] = value;
        }
示例#2
0
        static Dictionary <string, object> InkListToJObject(ListValue listVal)
        {
            var rawList = listVal.value;

            var dict = new Dictionary <string, object> ();

            var content = new Dictionary <string, object> ();

            foreach (var itemAndValue in rawList)
            {
                var item = itemAndValue.Key;
                int val  = itemAndValue.Value;
                content [item.ToString()] = val;
            }

            dict ["list"] = content;

            if (rawList.Count == 0 && rawList.originNames != null && rawList.originNames.Count > 0)
            {
                dict ["origins"] = rawList.originNames.Cast <object> ().ToList();
            }

            return(dict);
        }
示例#3
0
        List <Value> CoerceValuesToSingleType(List <Runtime.Object> parametersIn)
        {
            ValueType valType = ValueType.Int;

            ListValue specialCaseList = null;

            // Find out what the output type is
            // "higher level" types infect both so that binary operations
            // use the same type on both sides. e.g. binary operation of
            // int and float causes the int to be casted to a float.
            foreach (var obj in parametersIn)
            {
                var val = (Value)obj;
                if (val.valueType > valType)
                {
                    valType = val.valueType;
                }

                if (val.valueType == ValueType.List)
                {
                    specialCaseList = val as ListValue;
                }
            }

            // Coerce to this chosen type
            var parametersOut = new List <Value> ();

            // Special case: Coercing to Ints to Lists
            // We have to do it early when we have both parameters
            // to hand - so that we can make use of the List's origin
            if (valType == ValueType.List)
            {
                foreach (Value val in parametersIn)
                {
                    if (val.valueType == ValueType.List)
                    {
                        parametersOut.Add(val);
                    }
                    else if (val.valueType == ValueType.Int)
                    {
                        int intVal = (int)val.valueObject;
                        var list   = specialCaseList.value.originOfMaxItem;

                        InkListItem item;
                        if (list.TryGetItemWithValue(intVal, out item))
                        {
                            var castedValue = new ListValue(item, intVal);
                            parametersOut.Add(castedValue);
                        }
                        else
                        {
                            throw new StoryException("Could not find List item with the value " + intVal + " in " + list.name);
                        }
                    }
                    else
                    {
                        throw new StoryException("Cannot mix Lists and " + val.valueType + " values in this operation");
                    }
                }
            }

            // Normal Coercing (with standard casting)
            else
            {
                foreach (Value val in parametersIn)
                {
                    var castedValue = val.Cast(valType);
                    parametersOut.Add(castedValue);
                }
            }

            return(parametersOut);
        }