Exemple #1
0
 public virtual void SetUi(XVariable node)
 {
     VariableDef = node;
     GetMaskFromCapture(node.Capture, out Mask, out ShiftedMask);
     //Helper.TryParseHex(node.mask, out Mask);
     //ShiftedMask = Helper.ShiftMask(Mask);
     Helper.TryParseHex(node.@default, out Default);
 }
        public XVariableParser(XVariable var, Game game)
        {
            this.item   = var;
            this.game   = game;
            this.hidden = (var.UI.Item is UIHidden);

            foreach (var v in var.Value)
            {
                short key = short.Parse(v.Data, NumberStyles.HexNumber);
                if (valueDefinitions.ContainsKey(key))
                {
                    Console.WriteLine($"Duplicate key: {key}, {v.Description} {v.Comment}");
                }
                else
                {
                    valueDefinitions.Add(key, v);
                }
            }

            capture   = new CaptureExpression(var.Capture);
            condition = new ConditionExpression(var.Condition);
            switch (var.UI.Item)
            {
            case UITextId textId:
                PrintVariable = (x, get) =>
                {
                    ushort baseId = ushort.Parse(textId.Base, NumberStyles.HexNumber);
                    return($"{item.Description}: { get(capture)(x) + baseId:X4}");
                }; break;

            case UISwitchFlag sf:
                PrintVariable = (x, get) => { return($"{item.Description}: {get(capture)(x):X2}"); }; break;

            case UIBitFlag bf:
                PrintVariable = (x, get) => { return($"{item.Description}: {get(capture)(x) > 0}"); }; break;

            default:
                PrintVariable = (x, get) =>
                {
                    short value = (short)get(capture)(x);
                    if (valueDefinitions.TryGetValue(value, out XVariableValue valueDef))
                    {
                        if (item.Description == "Type")
                        {
                            return(valueDef.Description);
                        }
                        else
                        {
                            return($"{item.Description}: {valueDef.Description}");
                        }
                    }
                    else
                    {
                        return($"{item.Description}: {value:X4}");
                    }
                }; break;
            }
        }
Exemple #3
0
        private XVariable NoMaskSet(XActor currentActor)
        {
            XVariable r = new XVariable();

            currentActor.Variables.Add(r);

            //r.maskType =  MaskType.And;
            //r.mask = "FFFF";
            r.Description = "#N/A";
            return(r);
        }
Exemple #4
0
        public override void SetUi(XVariable node)
        {
            base.SetUi(node);

            descriptionLabel.Text = node.Description;
            if (!node.nullable)
            {
                nullCheckBox.Visible = false;
            }
            UpdateValue(Default);
        }
Exemple #5
0
        /// <summary>
        /// Prints the stats on a packed initialization variable
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="var"></param>
        private static void PrintVariable(StringBuilder sb, XVariable var, Game game)
        {
            sb.Append($";{var.Capture} = {var.Description}");

            PrintComments(sb, var.Comment, true);
            sb.AppendLine();

            CaptureExpression capture = new(var.Capture);

            foreach (XVariableValue value in var.Value)
            {
                PrintVariableValue(sb, value, capture);
            }
        }
Exemple #6
0
        /// <summary>
        /// Prints the stats on a packed initialization variable
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="var"></param>
        private static void PrintVariable(StringBuilder sb, XVariable var)
        {
            //sb.AppendFormat(" {0} {1} - {2} ",
            //    (var.maskType == MaskType.And) ? "&" : "|",
            //    var.mask,
            //    var.Description);
            sb.Append($" {var.Capture}: {var.Description}");
            //sb.Append($" {GetCaptureCatch(var.Capture)} - {var.Description} ");

            PrintComments(sb, var.Comment, true);
            sb.AppendLine();

            foreach (XVariableValue value in var.Value)
            {
                PrintVariableValue(sb, value, GetCaptureMask(var.Capture));
            }
        }
Exemple #7
0
            internal void AddVarInfo(List <Inline> list, XVariable var)
            {
                Run temp;

                temp            = new Run(var.Name + " ");
                temp.Foreground = txtBrush;
                list.Add(temp);
                temp            = new Run(_optionsPage.formatKeyword(var.ParamTypeDesc) + " ");
                temp.Foreground = this.kwBrush;
                list.Add(temp);
                temp            = new Run(var.TypeName);
                temp.Foreground = this.txtBrush;
                list.Add(temp);
                if (var.IsArray)
                {
                    temp            = new Run("[] ");
                    temp.Foreground = this.txtBrush;
                    list.Add(temp);
                }
            }
Exemple #8
0
        public override void SetUi(XVariable node)
        {
            base.SetUi(node);
            List <XVariableValueDisplay> display = new List <XVariableValueDisplay>();

            descriptionLabel.Text = VariableDef.Description;
            foreach (var item in node.Value)
            {
                if (!item.uihide)
                {
                    display.Add(new XVariableValueDisplay(item));
                }
            }
            comboBox.DataSource = display;

            if (!node.nullable)
            {
                nullCheckBox.Visible = false;
            }

            UpdateValue(Default);
        }
Exemple #9
0
        public XActors ParseLines(String[] lines)
        {
            XActors   root            = new XActors();
            String    currentComment  = string.Empty;
            XActor    currentActor    = null;
            XVariable currentVariable = null;
            Object    commentParent   = null;

            foreach (string line in lines)
            {
                string line_nocomment;
                String lineComment;//comment within the current line

                //remove comment
                line_nocomment = StripComment(line, out lineComment);

                //if line only contains a comment
                if (line_nocomment.Trim().Length == 0)
                {
                    //continue the current comment
                    currentComment += (String.IsNullOrEmpty(currentComment)) ? lineComment : Environment.NewLine + lineComment;
                    continue;
                }

                //Else match one of three patterns:
                //Actor/Object id line,
                //Mask Line
                //Value line

                //If Actor/Object id line
                if (IdLine.IsMatch(line_nocomment))
                {
                    //attach currentComment to proper node
                    AddCommentToNode(ref commentParent, ref currentComment, lineComment);

                    //Start a new XActor, attach it
                    currentActor = new XActor();
                    root.Actor.Add(currentActor);

                    //set new comment node
                    commentParent = currentActor;

                    //null current variable
                    currentVariable = null;

                    NewActorDefinition(IdLine.Matches(line_nocomment)[0].Groups, currentActor);
                }
                //mask value line
                else if (MaskLine.IsMatch(line_nocomment))
                {
                    //Push currentComment to proper node
                    AddCommentToNode(ref commentParent, ref currentComment, lineComment);

                    currentVariable = new XVariable();
                    currentActor.Variables.Add(currentVariable);

                    commentParent = currentVariable;
                    throw new NotImplementedException();
                    //NewVariableDefinition(MaskLine.Matches(line_nocomment)[0].Groups, currentVariable);
                }
                else if (ValueLine.IsMatch(line_nocomment))
                {
                    //Push currentComment to proper node
                    AddCommentToNode(ref commentParent, ref currentComment, lineComment);

                    if (currentVariable == null)
                    {
                        currentVariable = NoMaskSet(currentActor);
                    }

                    XVariableValue val = new XVariableValue();
                    currentVariable.Value.Add(val);

                    commentParent = val;

                    NewVariableValue(ValueLine.Matches(line_nocomment)[0].Groups, val);
                }
                else //unknown
                {
                    currentComment += String.Format("{1}#NOPARSE: {0}", line_nocomment,
                                                    (String.IsNullOrEmpty(currentComment)) ? string.Empty : Environment.NewLine);
                    continue;
                }
            }
            AddCommentToNode(ref commentParent, ref currentComment, string.Empty);
            return(root);
        }
Exemple #10
0
        public static XActors ParseLines(string[] lines)
        {
            XActors   root        = new XActors();
            XActor    curActor    = null;
            XVariable curVariable = null;

            //assume lines are trimmed
            foreach (var line_untrimmed in lines)
            {
                string line = line_untrimmed.Trim();
                if (line.StartsWith("==A") ||
                    line.StartsWith("Variables:"))
                //do nothing
                {
                    continue;
                }
                if (line.StartsWith("===0"))
                //new actor
                {
                    curActor = new XActor()
                    {
                        id = line.Substring(3, 4)
                    };
                    root.Actor.Add(curActor);
                }
                else if (line.StartsWith("Identity:"))
                //name
                {
                    curActor.Description = line.Substring(9).Trim();
                }
                else if (line.StartsWith("Objects:"))
                {
                    curActor.Objects = new XObjects();
                    curActor.Objects.Object.Add(line.Substring(8).Trim());
                }
                else if (line.StartsWith("Notes:"))
                {
                    var comment = line.Substring(6).Trim();
                    if (comment.Length > 0)
                    {
                        curActor.Comment = comment;
                    }
                }
                else if (line.ToLower().StartsWith("x rot:") ||
                         line.ToLower().StartsWith("y rot:") ||
                         line.ToLower().StartsWith("z rot:"))
                //capture
                {
                    string vType = line[0].ToString().ToLower();
                    string desc  = line.Substring(6).Trim();

                    curVariable = new XVariable()
                    {
                        Capture     = $"r{vType} &>> 0x1FF",
                        Description = desc,
                    };

                    curActor.Variables.Add(curVariable);
                }
                else if (line.StartsWith("&"))
                //new variable
                {
                    var extract = MaskLine.Match(line);

                    curVariable = new XVariable()
                    {
                        Capture     = $"v {extract.Groups[1].Value}>> 0x{extract.Groups[2].Value}",
                        Description = extract.Groups[3].ToString()
                    };
                    curActor.Variables.Add(curVariable);
                }
                else
                //variable value
                {
                    var extract = ValueLine.Match(line).Groups;
                    var value   = new XVariableValue()
                    {
                        Description = extract[4].ToString(),
                        Data        = extract[1].ToString()
                    };
                    if (extract[2].ToString() == "+")
                    {
                        value.repeat = "+";
                    }

                    curVariable.Value.Add(value);
                }
            }

            return(root);
        }