Example #1
0
        public override void LoadCommand(Whee.WordBuilder.ProjectV2.IProjectSerializer serializer)
        {
            ProjectV2.WeightedCommandBlockNode wcbn = new ProjectV2.WeightedCommandBlockNode(serializer);

            Children.Add(wcbn);

            foreach (ProjectV2.WeightedCommandNode wcn in wcbn.Children)
            {
                WeightedCommand wc = new WeightedCommand();
                wc.Weight = wcn.Weight;
                wc.Command = wcn.Command;
                Commands.Add(wc);
            }
        }
Example #2
0
        public override void LoadCommand(Whee.WordBuilder.ProjectV2.IProjectSerializer serializer)
        {
            ProjectV2.WeightedCommandBlockNode wcbn = new ProjectV2.WeightedCommandBlockNode(serializer);

            Children.Add(wcbn);

            foreach (ProjectV2.WeightedCommandNode wcn in wcbn.Children)
            {
                WeightedCommand wc = new WeightedCommand();
                wc.Weight  = wcn.Weight;
                wc.Command = wcn.Command;
                Commands.Add(wc);
            }
        }
Example #3
0
    public static bool ParseWeightedCommands(object context, TextReader reader, string line, ref int lineNumber)
    {
        if (string.IsNullOrEmpty(line))
        {
            return(true);
        }

        if (line.StartsWith("}"))
        {
            return(false);
        }

        object[] args               = context as object[];
        Project  project            = args[0] as Project;
        List <WeightedCommand> cmds = args[1] as List <WeightedCommand>;

        int    start     = 0;
        string weightStr = ReadToken(line, ref start);

        int cmdStart = start;

        double weight = 0;

        if (!double.TryParse(weightStr, out weight))
        {
            project.Warnings.Add(string.Format("Line {0}: Expected a weighted command.", lineNumber));
        }
        else
        {
            string command = ReadToken(line, ref start);

            List <Type> commandCandidates = new List <Type>();
            foreach (Type cmd in Commands)
            {
                if (cmd.Name.ToLower().StartsWith(command.ToLower()))
                {
                    commandCandidates.Add(cmd);
                }
            }

            if (commandCandidates.Count > 1)
            {
                project.Warnings.Add(string.Format("Line {1}: The command '{0}' is ambiguous.", command, lineNumber));
            }
            else
            {
                Type tp = commandCandidates.Count > 0 ? commandCandidates[0] : null;

                if (tp != null)
                {
                    CommandBase c = Activator.CreateInstance(tp) as CommandBase;

                    if (c != null)
                    {
                        c.LoadCommand(project, reader, line.Substring(cmdStart), ref lineNumber);
                    }
                    else
                    {
                        project.Warnings.Add(string.Format("Line {1}: The command '{0}' is not valid.", command, lineNumber));
                    }

                    WeightedCommand wc = new WeightedCommand();
                    wc.Command = c;
                    wc.Weight  = weight;
                    cmds.Add(wc);
                }
                else
                {
                    project.Warnings.Add(string.Format("Line {1}: The command '{0}' is not valid.", command, lineNumber));
                }
            }
        }

        return(true);
    }
Example #4
0
    public static bool ParseWeightedCommands(object context, TextReader reader, string line, ref int lineNumber)
    {
        if (string.IsNullOrEmpty(line)) {
            return true;
        }

        if (line.StartsWith("}")) {
            return false;
        }

        object[] args = context as object[];
        Project project = args[0] as Project;
        List<WeightedCommand> cmds = args[1] as List<WeightedCommand>;

        int start = 0;
        string weightStr = ReadToken(line, ref start);

        int cmdStart = start;

        double weight = 0;
        if (!double.TryParse(weightStr, out weight)) {
            project.Warnings.Add(string.Format("Line {0}: Expected a weighted command.", lineNumber));
        }
        else {
            string command = ReadToken(line, ref start);

            List<Type> commandCandidates = new List<Type>();
            foreach (Type cmd in Commands) {
                if (cmd.Name.ToLower().StartsWith(command.ToLower())) {
                    commandCandidates.Add(cmd);
                }
            }

            if (commandCandidates.Count > 1) {
                project.Warnings.Add(string.Format("Line {1}: The command '{0}' is ambiguous.", command, lineNumber));
            }
            else {
                Type tp = commandCandidates.Count > 0 ? commandCandidates[0] : null;

                if (tp != null) {
                    CommandBase c = Activator.CreateInstance(tp) as CommandBase;

                    if (c != null) {
                        c.LoadCommand(project, reader, line.Substring(cmdStart), ref lineNumber);
                    }
                    else {
                        project.Warnings.Add(string.Format("Line {1}: The command '{0}' is not valid.", command, lineNumber));
                    }

                    WeightedCommand wc = new WeightedCommand();
                    wc.Command = c;
                    wc.Weight = weight;
                    cmds.Add(wc);
                }
                else {
                    project.Warnings.Add(string.Format("Line {1}: The command '{0}' is not valid.", command, lineNumber));
                }
            }
        }

        return true;
    }