Beispiel #1
0
 public BdatMember(string name, BdatMemberType type, BdatValueType valType)
 {
     Name    = name;
     Type    = type;
     ValType = valType;
 }
Beispiel #2
0
        private static void GenerateType(BdatType type, Indenter sb)
        {
            var added = new HashSet <string>();

            sb.AppendLine("[BdatType]");
            sb.AppendLine("[Serializable]");
            sb.AppendLine($"public class {type.Name} : BdatItem");
            sb.AppendLineAndIncrease("{");

            foreach (BdatMember member in type.Members)
            {
                if (added.Contains(member.Name))
                {
                    continue;
                }
                added.Add(member.Name);

                BdatMemberType memberType = member.Type;
                string         name       = GetIdentifier(member.Name);
                switch (memberType)
                {
                case BdatMemberType.Flag:
                    sb.AppendLine($"public bool {name};");
                    break;

                case BdatMemberType.Scalar:
                    sb.AppendLine($"public {GetType(member.ValType)} {name};");
                    break;

                case BdatMemberType.Array:
                    int    length  = member.ArrayCount;
                    string valType = GetType(member.ValType);
                    sb.AppendLine($"public readonly {valType}[] {name} = new {valType}[{length}];");
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            foreach (BdatFieldInfo bdatRef in type.TableRefs)
            {
                bdatRef.Member = type.Members.First(x => x.Name == bdatRef.Field);
                string itemType = "";
                string itemName = bdatRef.Field;

                switch (bdatRef.Type)
                {
                case BdatFieldType.Reference:
                case BdatFieldType.Message:
                    itemType = bdatRef.ChildType;
                    break;

                case BdatFieldType.Item:
                case BdatFieldType.Task:
                case BdatFieldType.Condition:
                    itemType = "object";
                    break;

                case BdatFieldType.Enum:
                    itemType = bdatRef.EnumType.Name;
                    break;

                default:
                    if (bdatRef.EnumType != null)
                    {
                        itemType = bdatRef.EnumType.Name;
                    }
                    break;
                }

                switch (bdatRef.Member.Type)
                {
                case BdatMemberType.Scalar:
                    sb.AppendLine($"public {itemType} _{itemName};");
                    break;

                case BdatMemberType.Array:
                    sb.AppendLine($"public {itemType}[] _{itemName} = new {itemType}[{bdatRef.Member.ArrayCount}];");
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            foreach (BdatArrayInfo array in type.Arrays)
            {
                sb.AppendLine($"public {array.Type}[] _{array.Name};");
            }

            sb.DecreaseAndAppendLine("}");
        }