Ejemplo n.º 1
0
    public static List <BasePart> GetAllTierParts(BasePart.PartTier tier, PartFlags flags = CustomizationManager.PartFlags.None)
    {
        List <BasePart> list = new List <BasePart>();

        if (tier == BasePart.PartTier.Regular)
        {
            for (int i = 0; i < WPFMonoBehaviour.gameData.m_parts.Count; i++)
            {
                if (flags == CustomizationManager.PartFlags.None)
                {
                    list.Add(WPFMonoBehaviour.gameData.m_parts[i].GetComponent <BasePart>());
                }
            }
        }
        else
        {
            List <CustomPartInfo> customParts = WPFMonoBehaviour.gameData.m_customParts;
            for (int j = 0; j < customParts.Count; j++)
            {
                if (customParts[j] != null && customParts[j].PartList != null && customParts[j].PartList.Count != 0)
                {
                    for (int k = 0; k < customParts[j].PartList.Count; k++)
                    {
                        if (customParts[j].PartList[k].m_partTier == tier && CustomizationManager.HasPartFlags(customParts[j].PartList[k], flags))
                        {
                            list.Add(customParts[j].PartList[k]);
                        }
                    }
                }
            }
        }
        return(list);
    }
Ejemplo n.º 2
0
        public DeferredPartBuilder(Type type, PartFlags partFlags)
        {
            _type  = type;
            _flags = partFlags;

            _writeMethod     = new LazyInitializer <MethodInfo>(() => _genericWriteMethod.MakeGenericMethod(type));
            _readMethod      = new LazyInitializer <MethodInfo>(() => _genericReadMethod.MakeGenericMethod(type));
            _readMethodByRef = new LazyInitializer <MethodInfo>(() => _genericReadMethodByRef.MakeGenericMethod(type));
            _fillMethod      = new LazyInitializer <MethodInfo>(() => _genericFillMethod.MakeGenericMethod(type));
            _fillMethodByRef = new LazyInitializer <MethodInfo>(() => _genericFillMethodByRef.MakeGenericMethod(type));
        }
Ejemplo n.º 3
0
 public static void FillRandom <T>(ref T instance, FillArgs args, PartFlags flags, string partName)
 {
     if (flags.IsSet(PartFlags.Dynamic))
     {
         args.RaiseSkippedWarning(partName, "dynamic or polymorphic fields can't be filled");
         instance = default(T);
         return;
     }
     if (args.BeginDeferredFill <T>())
     {
         var tester = BarfSerializers.GetTester <T>(flags);
         tester.Fill(ref instance, args);
         args.EndDeferredFill <T>();
     }
 }
Ejemplo n.º 4
0
            public static FormattedParts Create(string offset, string addr, string bytes,
                                                string flags, string attr, string label, string opcode, string operand,
                                                string comment, PartFlags pflags)
            {
                FormattedParts parts = new FormattedParts();

                parts.Offset        = offset;
                parts.Addr          = addr;
                parts.Bytes         = bytes;
                parts.Flags         = flags;
                parts.Attr          = attr;
                parts.Label         = label;
                parts.Opcode        = opcode;
                parts.Operand       = operand;
                parts.Comment       = comment;
                parts.IsLongComment = false;
                parts.mPartFlags    = pflags;

                return(parts);
            }
Ejemplo n.º 5
0
        public static void AssertAreEqual <T>(T expected, T actual, PartFlags flags, AssertArgs args, string partName)
        {
            if (flags.IsSet(PartFlags.Dynamic))
            {
                if (expected == null)
                {
                    Assert.AreEqual(null, actual);
                    return;
                }
                Assert.AreEqual(expected.GetType(), actual.GetType(), partName);

                var tester = BarfSerializers.GetTester(expected.GetType(), flags & ~PartFlags.Dynamic);
                tester.AssertAreEqual(expected, actual, args);
            }
            else
            {
                var tester = BarfSerializers.GetTester <T>(flags);
                tester.AssertAreEqual(expected, actual, args);
            }
        }
Ejemplo n.º 6
0
    public static int CustomizationCount(BasePart.PartTier tier, PartFlags flags = CustomizationManager.PartFlags.None)
    {
        int num = 0;
        List <CustomPartInfo> customParts = WPFMonoBehaviour.gameData.m_customParts;

        for (int i = 0; i < customParts.Count; i++)
        {
            if (customParts[i] != null && customParts[i].PartList != null && customParts[i].PartList.Count != 0)
            {
                for (int j = 0; j < customParts[i].PartList.Count; j++)
                {
                    if (customParts[i].PartList[j].m_partTier == tier && CustomizationManager.HasPartFlags(customParts[i].PartList[j], flags))
                    {
                        num++;
                    }
                }
            }
        }
        return(num);
    }
Ejemplo n.º 7
0
 public static void WritePart <T>(T part, BarfSerializationArgs args, PartFlags flags)
 {
     if (flags.IsSet(PartFlags.Dynamic))
     {
         if (!typeof(T).IsValueType && part == null)
         {
             args.Writer.WriteVarInt32(-1);
         }
         else
         {
             var type = part.GetType();
             args.Writer.WriteVarInt32(args.TypeTable.Include(type));
             var serializer = BarfSerializers.Get(type, flags & ~PartFlags.Dynamic);
             serializer.SerializeObject(part, args);
         }
     }
     else
     {
         BarfSerializers.Get <T>(flags).Serialize(part, args);
     }
 }
Ejemplo n.º 8
0
    private static bool HasPartFlags(BasePart part, PartFlags flags)
    {
        if (part == null)
        {
            return(false);
        }
        PartFlags partFlags = CustomizationManager.PartFlags.None;

        if (!CustomizationManager.IsPartUnlocked(part))
        {
            partFlags |= CustomizationManager.PartFlags.Locked;
        }
        if (part.craftable)
        {
            partFlags |= CustomizationManager.PartFlags.Craftable;
        }
        if (part.lootCrateReward)
        {
            partFlags |= CustomizationManager.PartFlags.Rewardable;
        }
        return((partFlags & flags) == flags);
    }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets an instance of the proper <see cref="IBarfTester{T}"/> implementation given the specified <paramref name="flags"/>.
 /// </summary>
 /// <typeparam name="T">The type that the <see cref="IBarfTester{T}"/> implementation will test.</typeparam>
 /// <param name="flags">Flags that affect the serialization.</param>
 /// <returns>An instance of the proper <see cref="IBarfTester{T}"/> implementation given the specified <paramref name="flags"/>.</returns>
 public static IBarfTester <T> GetTester <T>(PartFlags flags)
 {
     return((IBarfTester <T>)_testers(new BarfTypeKey(typeof(T), BarfFormatter.MaxFrameworkVersion)));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Gets an instance of the proper <see cref="IBarfTester"/> implementation given the specified <paramref name="flags"/>.
 /// </summary>
 /// <param name="type">The type that the <see cref="IBarfTester"/> implementation will test.</param>
 /// <param name="flags">Flags that affect the serialization.</param>
 /// <returns>An instance of the proper <see cref="IBarfTester"/> implementation given the specified <paramref name="flags"/>.</returns>
 public static IBarfTester GetTester(Type type, PartFlags flags)
 {
     return(_testers(new BarfTypeKey(type, BarfFormatter.MaxFrameworkVersion)));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets an instance of the proper <see cref="IBarfSerializer"/> implementation given the specified <paramref name="flags"/>.
 /// </summary>
 /// <param name="type">The type that the <see cref="IBarfSerializer"/> implementation will serialize.</param>
 /// <param name="flags">Flags that affect the serialization.</param>
 /// <returns>An instance of the proper <see cref="IBarfSerializer"/> implementation given the specified <paramref name="flags"/>.</returns>
 public static IBarfSerializer Get(Type type, PartFlags flags)
 {
     return(_serializers(new BarfTypeKey(type, BarfFormatter.MaxFrameworkVersion)));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets an instance of the proper <see cref="BarfSerializer{T}"/> implementation given the specified <paramref name="flags"/>.
 /// </summary>
 /// <typeparam name="T">The type that the <see cref="BarfSerializer{T}"/> implementation will serialize.</typeparam>
 /// <param name="flags">Flags that affect the serialization.</param>
 /// <returns>An instance of the proper <see cref="BarfSerializer{T}"/> implementation given the specified <paramref name="flags"/>.</returns>
 public static BarfSerializer <T> Get <T>(PartFlags flags)
 {
     return((BarfSerializer <T>)_serializers(new BarfTypeKey(typeof(T), BarfFormatter.MaxFrameworkVersion)));
 }
Ejemplo n.º 13
0
 public static void FillRandom <T>(T instance, FillArgs args, PartFlags flags, string partName)
     where T : class
 {
     FillRandom <T>(ref instance, args, flags, partName);
 }
Ejemplo n.º 14
0
 public static void ReadPart <T>(ref T instance, BarfDeserializationArgs args, PartFlags flags)
 {
     if (flags.IsSet(PartFlags.Dynamic))
     {
         var index = args.Reader.ReadVarInt32();
         if (index < 0)
         {
             instance = default(T);
         }
         else
         {
             var    type       = args.TypeTable.GetType(index);
             var    serializer = BarfSerializers.Get(type, flags & ~PartFlags.Dynamic);
             object obj        = instance;
             serializer.InnerDeserializeObject(ref obj, args);
             instance = (T)obj;
         }
     }
     else
     {
         BarfSerializers.Get <T>(flags).InnerDeserialize(ref instance, args);
     }
 }
Ejemplo n.º 15
0
 public static void ReadPart <T>(T instance, BarfDeserializationArgs args, PartFlags flags)
     where T : class
 {
     ReadPart <T>(ref instance, args, flags);
 }
Ejemplo n.º 16
0
 public static bool IsSet(this PartFlags flags, PartFlags value)
 {
     return((flags & value) == value);
 }