Пример #1
0
        public void Enum_FlagsSansAttributeTest()
        {
            try
            {
                FlagsEnumSansAttribute e = FlagsEnumSansAttribute.Flag0;
                // The below statement should throw a TypeInitializationException
                EnumFlags.Add(ref e, FlagsEnumSansAttribute.Flag2);

                Assert.Fail("EnumFlags didn't fail on an Enum without a Flags attribute!");
            } catch (System.Exception ex)
            {
                Assert.IsInstanceOfType(ex.InnerException, typeof(System.NotSupportedException));
            }
        }
Пример #2
0
        public void Enum_FlagsAddTest()
        {
            //////////////////////////////////////////////////////////////////////////
            // Test by-ref
            const FlagsEnum kExpectedResult1 = FlagsEnum.Flag0 | FlagsEnum.Flag2;
            FlagsEnum       e1 = FlagsEnum.Flag0;

            EnumFlags.Add(ref e1, FlagsEnum.Flag2);
            Assert.AreEqual(kExpectedResult1, e1);
            //////////////////////////////////////////////////////////////////////////
            // Test by-value
            const FlagsEnum kExpectedResult2 = kExpectedResult1 | FlagsEnum.Flag3;
            FlagsEnum       e2 = EnumFlags.Add(e1, FlagsEnum.Flag3);

            Assert.AreEqual(kExpectedResult2, e2);
        }
Пример #3
0
 void InterpretFlags(KSoft.Collections.BitVector32 flags)
 {
     if (flags.Test(GvarAssemblerFlags.ClearTitleUpdateData))
     {
         mClearTitleUpdateData = true;
     }
     if (flags.Test(GvarAssemblerFlags.ClearWeaponTuning))
     {
         mClearWeaponTuning = true;
     }
     if (flags.Test(GvarAssemblerFlags.AddAllTeams))
     {
         // #TODO_MGLO:
     }
     if (flags.Test(GvarAssemblerFlags.ReadOperationNamesOnly))
     {
         EnumFlags.Add(ref mModelStreamFlags,
                       MegaloModel.MegaloScriptModelTagElementStreamFlags.UseConditionTypeNames |
                       MegaloModel.MegaloScriptModelTagElementStreamFlags.UseActionTypeNames);
     }
 }
Пример #4
0
        public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            bool reading = s.IsReading;

            #region Value0
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value0) || reading) &&
                s.StreamElementOpt("Value0", ref mValue0))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value0);
            }
            #endregion
            #region Value1
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value1) || reading) &&
                s.StreamElementOpt("Value1", ref mValue1))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value1);
            }
            #endregion
            #region Value2
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value2) || reading) &&
                s.StreamElementOpt("Value2", ref mValue2))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value2);
            }
            #endregion
            #region Value3
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value3) || reading) &&
                s.StreamElementOpt("Value3", ref mValue3))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value3);
            }
            #endregion
            #region Value4
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value4) || reading) &&
                s.StreamElementOpt("Value4", ref mValue4))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value4);
            }
            #endregion
            #region Value5
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value5) || reading) &&
                s.StreamElementOpt("Value5", ref mValue5))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value5);
            }
            #endregion
            #region Value6
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value6) || reading) &&
                s.StreamElementOpt("Value6", ref mValue6))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value6);
            }
            #endregion
            #region Value7
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value7) || reading) &&
                s.StreamElementOpt("Value7", ref mValue7))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value7);
            }
            #endregion
            #region Value8
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value8) || reading) &&
                s.StreamElementOpt("Value8", ref mValue8))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value8);
            }
            #endregion
            #region Value9
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value9) || reading) &&
                s.StreamElementOpt("Value9", ref mValue9))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value9);
            }
            #endregion
            #region Value10
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value10) || reading) &&
                s.StreamElementOpt("Value10", ref mValue10))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value10);
            }
            #endregion
            #region Value11
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value11) || reading) &&
                s.StreamElementOpt("Value11", ref mValue11))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value11);
            }
            #endregion
            #region Value12
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value12) || reading) &&
                s.StreamElementOpt("Value12", ref mValue12))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value12);
            }
            #endregion
            #region Value13
            if ((EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value13) || reading) &&
                s.StreamElementOpt("Value13", ref mValue13))
            {
                EnumFlags.Add(ref Modifiers, WeaponTuningModifiers.Value13);
            }
            #endregion
        }
Пример #5
0
        void DecodeParseSwitches(string switches,
                                 out MegaloModel.MegaloScriptModelTagElementStreamFlags modelStreamFlags,
                                 ref bool ignoreWritePredicates)
        {
            modelStreamFlags =
                MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjects |
                MegaloModel.MegaloScriptModelTagElementStreamFlags.UseEnumNames |
                MegaloModel.MegaloScriptModelTagElementStreamFlags.UseIndexNames |
                MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteConditionTypeNames |
                MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteActionTypeNames |

                MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjectsWriteSansIds
            ;
            if (switches == null)
            {
                switches = "";
            }
            const string k_switches_ctxt = "GameVariant:Decode";

            bool using_op_names = false;

            if (SwitchIsOn(switches, 0, k_switches_ctxt + ":Megalo", "Use operation names (instead of DBIDs)"))
            {
                EnumFlags.Add(ref modelStreamFlags,
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.UseConditionTypeNames |
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.UseActionTypeNames);

                EnumFlags.Remove(ref modelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteConditionTypeNames |
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteActionTypeNames);

                using_op_names = true;
            }
            if (SwitchIsOn(switches, 1, k_switches_ctxt + ":Megalo", "Write operation parameter names"))
            {
                EnumFlags.Add(ref modelStreamFlags,
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteParamNames);
            }
            if (SwitchIsOn(switches, 2, k_switches_ctxt + ":Megalo", "Write operation parameter contexts"))
            {
                EnumFlags.Add(ref modelStreamFlags,
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteParamKinds);
            }
            if (mGameBuildAndTarget.Build.IsWithinSameBranch(KBlam.Engine.EngineRegistry.EngineBranchHaloReach) &&
                SwitchIsOn(switches, 3, k_switches_ctxt + ":Megalo", "Try to port Reach operations to H4"))
            {
                if (using_op_names)
                {
                    Console.WriteLine("\tIgnoring switch since you have me writing operation names");
                }
                else
                {
                    EnumFlags.Add(ref modelStreamFlags,
                                  MegaloModel.MegaloScriptModelTagElementStreamFlags.TryToPort);
                }
            }
            if (SwitchIsOn(switches, 4, k_switches_ctxt + ":Megalo", "Don't use enum/index names"))
            {
                EnumFlags.Remove(ref modelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.UseEnumNames |
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.UseIndexNames);
            }
            if (SwitchIsOn(switches, 5, k_switches_ctxt + ":Megalo", "Serialize with object IDs"))
            {
                EnumFlags.Remove(ref modelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjectsWriteSansIds);
            }
            if (SwitchIsOn(switches, 6, k_switches_ctxt + ":Megalo", "Don't embed objects"))
            {
                EnumFlags.Remove(ref modelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjects |
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjectsWriteSansIds);
            }
            if (SwitchIsOn(switches, 7, k_switches_ctxt + ":Megalo", "Always write 'default' data"))
            {
                ignoreWritePredicates = true;
            }
        }
Пример #6
0
        void InterpretFlags(KSoft.Collections.BitVector32 flags)
        {
            bool using_op_names = false;

            if (flags.Test(GvarDisassemblerFlags.WriteOperationNamesOnly))
            {
                EnumFlags.Add(ref mModelStreamFlags,
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.UseConditionTypeNames |
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.UseActionTypeNames);

                EnumFlags.Remove(ref mModelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteConditionTypeNames |
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteActionTypeNames);

                using_op_names = true;
            }
            if (flags.Test(GvarDisassemblerFlags.WriteOperationParameterNames))
            {
                EnumFlags.Add(ref mModelStreamFlags,
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteParamNames);
            }
            if (flags.Test(GvarDisassemblerFlags.WriteOperationParameterContexts))
            {
                EnumFlags.Add(ref mModelStreamFlags,
                              MegaloModel.MegaloScriptModelTagElementStreamFlags.WriteParamKinds);
            }
            if (flags.Test(GvarDisassemblerFlags.TryToPort) &&
                mGameBuildAndTarget.Build.IsWithinSameBranch(KBlam.Engine.EngineRegistry.EngineBranchHaloReach))
            {
                if (using_op_names)
                {
                    Debug.Trace.MgloGui.TraceInformation("Ignoring TryToPort since you have me writing operation names");
                }
                else
                {
                    EnumFlags.Add(ref mModelStreamFlags,
                                  MegaloModel.MegaloScriptModelTagElementStreamFlags.TryToPort);
                }
            }
            if (flags.Test(GvarDisassemblerFlags.DoNotWriteEnumOrIndexNames))
            {
                EnumFlags.Remove(ref mModelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.UseEnumNames |
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.UseIndexNames);
            }
            if (flags.Test(GvarDisassemblerFlags.WriteWithObjectIds))
            {
                EnumFlags.Remove(ref mModelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjectsWriteSansIds);
            }
            if (flags.Test(GvarDisassemblerFlags.DoNotEmbedObjects))
            {
                EnumFlags.Remove(ref mModelStreamFlags,
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjects |
                                 MegaloModel.MegaloScriptModelTagElementStreamFlags.EmbedObjectsWriteSansIds);
            }
            if (flags.Test(GvarDisassemblerFlags.AlwaysWriteDefaultData))
            {
                mIgnoreWritePredicates = true;
            }
        }