예제 #1
0
        /// <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 remove(Parser.Integer index)
    {
        string name           = list.atIndex(index).getName();
        float  time_animation = 3f;

        Destroy(list_dict[name], time_animation / 2f);
        list.removeValue(index);

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

        StartCoroutine(Animation.removeAnimation(obj_list, name, new Vector3(-1, 0, 0), time_animation, 0, this));
    }
예제 #3
0
        /// <summary>
        /// Delete the nth value of a list
        /// </summary>
        /// <param name="list_expr"> expression resulting in a <see cref="DynamicList"/> variable</param>
        /// <param name="index_expr"> expression resulting in a <see cref="Integer"/> variable</param>
        /// <returns> <see cref="NullVar"/> (equivalent of null/void)</returns>
        private static NullVar deleteValueAt(Expression list_expr, Expression index_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); // TypeError
            Integer index = index_var as Integer;

            // delete
            list.removeValue(index);
            return(new NullVar());
        }