Inheritance: SubrecordBase
Exemple #1
0
 private RecordStructure(RecordsRecord rec, SubrecordBase[] subrecordTree, SubrecordStructure[] subrecords)
 {
     this.name = rec.name;
     this.description = rec.desc;
     this.subrecordTree = subrecordTree;
     this.subrecords = subrecords;
 }
Exemple #2
0
        /// <summary>
        ///     Build the Subrecord array with groups expanded.
        /// </summary>
        /// <param name="list">
        ///     The list.
        /// </param>
        /// <returns>
        ///     The System.Collections.Generic.List`1[T -&gt; TESVSnip.SubrecordStructure].
        /// </returns>
        private static List <SubrecordStructure> BuildSubrecordStructure(IEnumerable <SubrecordBase> list)
        {
            var subrecords = new List <SubrecordStructure>();

            foreach (var sr in list)
            {
                if (sr is SubrecordStructure)
                {
                    subrecords.Add((SubrecordStructure)sr);
                }
                else if (sr is SubrecordGroup)
                {
                    var sg = sr as SubrecordGroup;
                    List <SubrecordStructure> sss = BuildSubrecordStructure(sg.elements);
                    if (sss.Count > 0)
                    {
                        if (sg.repeat > 0)
                        {
                            sss[0] = new SubrecordStructure(sss[0], sss.Count, sss.Count); // replace
                        }
                        else if (sg.optional > 0)
                        {
                            sss[0] = new SubrecordStructure(sss[0], sss.Count, 0); // optional
                        }
                    }

                    subrecords.AddRange(sss);
                }
            }

            return(subrecords);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="SubrecordStructure" /> class.
 ///     Clone structure with optional and repeat values overridden.
 /// </summary>
 /// <param name="src">
 /// </param>
 /// <param name="optional">
 /// </param>
 /// <param name="repeat">
 /// </param>
 public SubrecordStructure(SubrecordStructure src, int optional, int repeat)
     : base(src, optional, repeat)
 {
     this.elements             = src.elements;
     this.elementTree          = src.elementTree;
     this.notininfo            = src.notininfo;
     this.size                 = src.size;
     this.Condition            = src.Condition;
     this.CondID               = src.CondID;
     this.CondOperand          = src.CondOperand;
     this.ContainsConditionals = src.ContainsConditionals;
     this.UseHexEditor         = src.UseHexEditor;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="SubrecordStructure" /> class.
 ///     Clone structure with optional and repeat values overridden.
 /// </summary>
 /// <param name="src">
 /// </param>
 /// <param name="optional">
 /// </param>
 /// <param name="repeat">
 /// </param>
 public SubrecordStructure(SubrecordStructure src, int optional, int repeat)
     : base(src, optional, repeat)
 {
     this.elements = src.elements;
     this.elementTree = src.elementTree;
     this.notininfo = src.notininfo;
     this.size = src.size;
     this.Condition = src.Condition;
     this.CondID = src.CondID;
     this.CondOperand = src.CondOperand;
     this.ContainsConditionals = src.ContainsConditionals;
     this.UseHexEditor = src.UseHexEditor;
 }
Exemple #5
0
        /// <summary>
        ///     Build the Subrecord array with groups expanded.
        /// </summary>
        /// <param name="list">
        ///     The list.
        /// </param>
        /// <returns>
        ///     The System.Collections.Generic.List`1[T -&gt; TESVSnip.SubrecordStructure].
        /// </returns>
        private static List<SubrecordStructure> BuildSubrecordStructure(IEnumerable<SubrecordBase> list)
        {
            var subrecords = new List<SubrecordStructure>();
            foreach (var sr in list)
            {
                if (sr is SubrecordStructure)
                {
                    subrecords.Add((SubrecordStructure) sr);
                }
                else if (sr is SubrecordGroup)
                {
                    var sg = sr as SubrecordGroup;
                    List<SubrecordStructure> sss = BuildSubrecordStructure(sg.elements);
                    if (sss.Count > 0)
                    {
                        if (sg.repeat > 0)
                        {
                            sss[0] = new SubrecordStructure(sss[0], sss.Count, sss.Count); // replace
                        }
                        else if (sg.optional > 0)
                        {
                            sss[0] = new SubrecordStructure(sss[0], sss.Count, 0); // optional
                        }
                    }

                    subrecords.AddRange(sss);
                }
            }

            return subrecords;
        }
Exemple #6
0
        private static bool MatchRecordCheckCondition(Dictionary<int, Conditional> conditions, SubrecordStructure ss)
        {
            if (ss.Condition == CondType.Exists)
            {
                if (conditions.ContainsKey(ss.CondID))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else if (ss.Condition == CondType.Missing)
            {
                if (conditions.ContainsKey(ss.CondID))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

            Conditional cond;
            if (!conditions.TryGetValue(ss.CondID, out cond))
            {
                return false;
            }

            switch (cond.type)
            {
                case ElementValueType.SByte:
                case ElementValueType.Byte:
                case ElementValueType.UShort:
                case ElementValueType.Short:
                case ElementValueType.Int:
                case ElementValueType.UInt:
                case ElementValueType.FormID:
                    {
                        int i = Convert.ToInt32(cond.value), i2;
                        if (!int.TryParse(ss.CondOperand, out i2))
                        {
                            return false;
                        }

                        switch (ss.Condition)
                        {
                            case CondType.Equal:
                                return i == i2;
                            case CondType.Not:
                                return i != i2;
                            case CondType.Less:
                                return i < i2;
                            case CondType.Greater:
                                return i > i2;
                            case CondType.GreaterEqual:
                                return i >= i2;
                            case CondType.LessEqual:
                                return i <= i2;
                            default:
                                return false;
                        }
                    }

                case ElementValueType.Float:
                    {
                        float i = (float)cond.value, i2;
                        if (!float.TryParse(ss.CondOperand, out i2))
                        {
                            return false;
                        }

                        switch (ss.Condition)
                        {
                            case CondType.Equal:
                                return i == i2;
                            case CondType.Not:
                                return i != i2;
                            case CondType.Less:
                                return i < i2;
                            case CondType.Greater:
                                return i > i2;
                            case CondType.GreaterEqual:
                                return i >= i2;
                            case CondType.LessEqual:
                                return i <= i2;
                            default:
                                return false;
                        }
                    }

                case ElementValueType.Str4:
                case ElementValueType.BString:
                case ElementValueType.IString:
                case ElementValueType.String:
                    {
                        var s = (string)cond.value;
                        switch (ss.Condition)
                        {
                            case CondType.Equal:
                                return s == ss.CondOperand;
                            case CondType.Not:
                                return s != ss.CondOperand;
                            case CondType.StartsWith:
                                return s.StartsWith(ss.CondOperand);
                            case CondType.EndsWith:
                                return s.EndsWith(ss.CondOperand);
                            case CondType.Contains:
                                return s.Contains(ss.CondOperand);
                            default:
                                return false;
                        }
                    }

                case ElementValueType.LString:
                    {
                        int i = (int)cond.value, i2;
                        if (!int.TryParse(ss.CondOperand, out i2))
                        {
                            return false;
                        }

                        switch (ss.Condition)
                        {
                            case CondType.Equal:
                                return i == i2;
                            case CondType.Not:
                                return i != i2;
                            case CondType.Less:
                                return i < i2;
                            case CondType.Greater:
                                return i > i2;
                            case CondType.GreaterEqual:
                                return i >= i2;
                            case CondType.LessEqual:
                                return i <= i2;
                            default:
                                return false;
                        }
                    }

                default:
                    return false;
            }
        }