Beispiel #1
0
        private IEnumerable <Node> EmitNodes(NodeType type, string name = null, string value = null, bool fallback = false, bool imaginary = false)
        {
            if (scope.Imaginary)
            {
                scope.Imaginary = false;
                if (type == NodeType.Value)
                {
                    scope.Discarded = true;
                }
                else if (type == NodeType.Value || type.HasFlag(NodeType.End))
                {
                    scope.Discarded = true;
                    yield return(new Node(NodeType.Value, null));
                }
                else
                {
                    yield return(new Node(scope.Type | NodeType.Start, scope.Name));
                }
            }

            if (type.HasFlag(NodeType.Start))
            {
                scope = new Scope
                {
                    Parent    = scope,
                    Name      = name ?? reader.Name,
                    Type      = type & ~NodeType.Start,
                    Imaginary = imaginary,
                    Fallback  = fallback
                };
                if (!scope.Imaginary)
                {
                    yield return(new Node(scope.Type | NodeType.Start, scope.Name));
                }
            }
            else if (type.HasFlag(NodeType.End))
            {
                if (!scope.Discarded)
                {
                    yield return(new Node(type));
                }
                scope = scope.Parent;

                while (scope.Fallback)
                {
                    yield return(new Node(scope.Type | NodeType.End));

                    scope = scope.Parent;
                }
            }
            else
            {
                yield return(new Node(type, value?.Trim()));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sorts the game explorer row.
        /// </summary>
        /// <returns>The sorting priority of the row. This value can be -1, 0 or 1 if
        /// A sorts before B, A sorts with B or A sorts after B, respectively.</returns>
        /// <param name="model">Model.</param>
        /// <param name="a">Iter a.</param>
        /// <param name="b">Iter b.</param>
        private int SortGameTreeRow(ITreeModel model, TreeIter a, TreeIter b)
        {
            const int sortABeforeB = -1;
            const int sortAWithB   = 0;
            const int sortAAfterB  = 1;

            var nodeA = (FileNode)model.GetValue(a, 0);
            var nodeB = (FileNode)model.GetValue(b, 0);

            NodeType typeofA = nodeA.Type;
            NodeType typeofB = nodeB.Type;

            // Special case for meta nodes - if A is a meta node, but B is not
            if (typeofA.HasFlag(NodeType.Meta) && !typeofB.HasFlag(NodeType.Meta))
            {
                // Then it should always sort after B
                return(sortAAfterB);
            }

            if (typeofB.HasFlag(NodeType.Meta) && !typeofA.HasFlag(NodeType.Meta))
            {
                // Then it should always sort before B
                return(sortABeforeB);
            }

            if (typeofA < typeofB)
            {
                return(sortAAfterB);
            }
            if (typeofA > typeofB)
            {
                return(sortABeforeB);
            }

            string nodeAName = this.TreeModel.GetNodeName(nodeA);

            string nodeBName = this.TreeModel.GetNodeName(nodeB);

            int result = string.CompareOrdinal(nodeAName, nodeBName);

            if (result <= sortABeforeB)
            {
                return(sortAAfterB);
            }

            if (result >= sortAAfterB)
            {
                return(sortABeforeB);
            }

            return(sortAWithB);
        }
Beispiel #3
0
 public static NodeType[] GetCandidate(NodeType type, int level)
 {
     if (!type.HasFlag(NodeType.FlagAbstract))
     {
         return(new[] { type });
     }
     type -= NodeType.FlagAbstract;
     if (level > MaxLevel && !type.HasFlag(NodeType.FlagType))
     {
         return(new[] { NodeType.End });
     }
     return(candidateTypes.Where(x => (x & type) == type).ToArray());
 }
Beispiel #4
0
        static TreeBase CreateNode(NodeType type)
        {
            Debug.Assert(!type.HasFlag(NodeType.FlagAbstract));
            ModifierType mt;

            if (ModifierTable.TryGetValue(type, out mt))
            {
                return(new Modifier(mt));
            }
            switch (type)
            {
            case NodeType.NopA:
                return(new Nop(Nop.ConnectionType.A));

            case NodeType.NopB:
                return(new Nop(Nop.ConnectionType.B));

            case NodeType.NopW:
                return(new Nop(Nop.ConnectionType.W));

            case NodeType.End:
                return(new EndA());

            case NodeType.Add:
                return(new FunctionNode <Adder>());

            case NodeType.Mult:
                return(new FunctionNode <Multiplier>());

            case NodeType.Filter:
                return(new FunctionNode <Filter>());

            case NodeType.Delay:
                return(new FunctionNode <Delay>());

            case NodeType.Split:
                return(new FunctionNode <Splitter>());

            case NodeType.Oscil:
                return(new FunctionNode <ConstantOscillator>());

            case NodeType.Parabola:
                return(new FunctionNode <Parabola>());

            case NodeType.Wire:
                return(new FunctionNode <Wire>());

            case NodeType.Constant:
                return(new Constant(RandomProvider.GetThreadRandom().NextDouble() * 2.0 - 1.0));

            default:
                throw new ArgumentException();
            }
        }