SuperImageEvolver.ModuleManager.WriteModule C# (CSharp) Méthode

WriteModule() public static méthode

public static WriteModule ( string tagName, IModule module ) : NBTag
tagName string
module IModule
Résultat NBTag
        public static NBTag WriteModule( string tagName, IModule module )
        {
            NBTCompound root = new NBTCompound( tagName );
            IModuleFactory factory = GetFactoryByType( module.GetType() );
            root.Append( "ID", factory.ID );

            bool auto =
                !factory.ModuleType.GetCustomAttributes( typeof( DisableAutoSerializationAttribute ), true ).Any();
            if( auto ) {
                root.Append( WriteModuleProperties( module ) );
            }
            NBTag customSettings = new NBTCompound( "Settings" );
            module.WriteSettings( customSettings );
            root.Append( customSettings );
            return root;
        }

Usage Example

Exemple #1
0
        public NBTCompound SerializeNBT()
        {
            HasChangedSinceSave = false;
            NBTCompound tag = new NBTCompound("SuperImageEvolver");

            tag.Append("FormatVersion", FormatVersion);
            tag.Append("Shapes", Shapes);
            tag.Append("Vertices", Vertices);
            tag.Append("ImprovementCounter", ImprovementCounter);
            tag.Append("MutationCounter", MutationCounter);
            tag.Append("RiskyMoveCounter", RiskyMoveCounter);
            tag.Append("ElapsedTime", DateTime.UtcNow.Subtract(TaskStart).Ticks);

            tag.Append(ProjectOptions.SerializeNBT());

            tag.Append(BestMatch.SerializeNBT("BestMatch"));

            NBTag initializerTag = ModuleManager.WriteModule("Initializer", Initializer);

            tag.Append(initializerTag);

            NBTag mutatorTag = ModuleManager.WriteModule("Mutator", Mutator);

            tag.Append(mutatorTag);

            NBTag evaluatorTag = ModuleManager.WriteModule("Evaluator", Evaluator);

            tag.Append(evaluatorTag);

            byte[] imageData;
            using (MemoryStream ms = new MemoryStream()) {
                lock ( OriginalImage ) {
                    OriginalImage.Save(ms, ImageFormat.Png);
                }
                ms.Flush();
                imageData = new byte[ms.Length];
                Buffer.BlockCopy(ms.GetBuffer(), 0, imageData, 0, imageData.Length);
            }

            tag.Append("ImageData", imageData);

            List <NBTCompound> statTags = new List <NBTCompound>();

            foreach (MutationType mtype in Enum.GetValues(typeof(MutationType)))
            {
                NBTCompound stat = new NBTCompound("MutationTypeStat");
                stat.Append("Type", mtype.ToString());
                stat.Append("Count", MutationCounts[mtype]);
                stat.Append("Sum", MutationImprovements[mtype]);
                statTags.Add(stat);
            }
            var stats = new NBTList("MutationStats", NBTType.Compound, statTags.ToArray());

            tag.Append(stats);

            return(tag);
        }