コード例 #1
0
ファイル: Functions.cs プロジェクト: Nicolas-Reyland/Aquila
        /// <summary>
        /// Default function
        /// </summary>
        /// <para>
        /// Swaps the elements at index a and b in a list
        /// </para>
        /// <param name="list_expr"> the target <see cref="DynamicList"/> (as an <see cref="Expression"/>)</param>
        /// <param name="a_expr"> index of the first element</param>
        /// <param name="b_expr"> index of the second element</param>
        /// <returns> <see cref="NullVar"/> (equivalent of null/void)</returns>
        private static NullVar swapFunction(Expression list_expr, Expression a_expr, Expression b_expr)
        {
            // evaluate every expression
            DynamicList list = list_expr.evaluate() as DynamicList;
            Integer     a    = a_expr.evaluate() as Integer;
            Integer     b    = b_expr.evaluate() as Integer;

            // check indexes
            list.validateIndex(a);
            list.validateIndex(b);
            // extract both values
            Variable var_a = list.atIndex(a);
            Variable var_b = list.atIndex(b);

            // freeze the context
            Context.freeze();
            // change a
            list.removeValue(a);
            list.insertValue(var_b, a);
            // change b
            list.removeValue(b);
            list.insertValue(var_a, b);
            // unfreeze the context
            Context.unfreeze();
            // update manually (void)
            if (list.isTraced())
            {
                list.tracer.update(new Event(
                                       new Alteration("swap", list, list.getRawValue(), new dynamic[] { a.getRawValue(), b.getRawValue() })));
            }

            return(new NullVar());
        }
コード例 #2
0
    public void insert(Parser.Integer index, Parser.Variable value)
    {
        list.insertValue(value, index);
        float time_animation = 2f;

        GameObject[] obj_list = new GameObject[list.length().getValue() - index.getValue() - 1];
        for (int i = index.getValue() + 1, u = 0; i < list.length().getValue(); i++, u++)
        {
            obj_list[u] = list_dict[list.atIndex(new Parser.Integer(i)).getName()];
        }

        StartCoroutine(Animation.insertAnimation(obj_list, value.getName(), new Vector3(1, 0, 0), time_animation, 1, this));
    }
コード例 #3
0
ファイル: Functions.cs プロジェクト: Nicolas-Reyland/Aquila
        /// <summary>
        /// Insert the given value in the list at the given index
        /// </summary>
        /// <param name="list_expr"> The list</param>
        /// <param name="index_expr"> The index</param>
        /// <param name="value_expr"> The value</param>
        /// <returns> <see cref="NullVar"/> (equivalent of null/void)</returns>
        private static NullVar insertValueAt(Expression list_expr, Expression index_expr, Expression value_expr)
        {
            // extract list
            Variable list_var = list_expr.evaluate();

            Debugging.assert(list_var is DynamicList); // TypeError
            DynamicList list = list_var as DynamicList;
            // extract index
            Variable index_var = index_expr.evaluate();

            Debugging.assert(index_var is Integer);
            Integer index = index_var as Integer;
            // extract var
            Variable var_ = value_expr.evaluate();

            // insert
            list.insertValue(var_, index);
            return(new NullVar());
        }