SuperImageEvolver.DNA.SerializeNBT C# (CSharp) Method

SerializeNBT() public method

public SerializeNBT ( string tagName ) : NBTag
tagName string
return NBTag
        public NBTag SerializeNBT(string tagName)
        {
            NBTCompound compound = new NBTCompound(tagName);
            compound.Append("Divergence", Divergence);
            NBTList tag = new NBTList("Shapes", NBTType.Compound, Shapes.Length);
            for (int i = 0; i < Shapes.Length; i++) {
                tag[i] = Shapes[i].SerializeNBT();
            }
            compound.Append(tag);
            return compound;
        }

Usage Example

Esempio n. 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);
        }