Exemplo 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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public NBTag SerializeNBT()
        {
            NBTCompound tag = new NBTCompound("Shape");

            tag.Append("Color", Color);
            NBTList points = new NBTList("Points", NBTType.PointF, Points.Length);

            for (int p = 0; p < Points.Length; p++)
            {
                points[p] = new NBTag(NBTType.PointF, null, Points[p], points);
            }
            tag.Append(points);
            return(tag);
        }
Exemplo n.º 4
0
        public NBTag SerializeNBT()
        {
            NBTCompound tag = new NBTCompound("ProjectOptions");

            tag.Append("Matte", Matte);
            tag.Append("BackColor", BackColor);
            tag.Append("MaxOverlap", MaxOverlap);
            tag.Append("MinAlpha", MinAlpha);
            tag.Append("RefreshRate", RefreshRate.Ticks);
            tag.Append("WireframeColor", WireframeColor);
            tag.Append("LastChangeColor1", LastChangeColor1);
            tag.Append("LastChangeColor2", LastChangeColor2);
            tag.Append("RiskMargin", RiskMargin);
            tag.Append("RiskRate", RiskRate);
            return(tag);
        }
        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);
        }
        public static NBTag WriteModuleProperties(IModule module)
        {
            IModuleFactory factory = GetFactoryByType(module.GetType());
            NBTag          root    = new NBTCompound("Properties");

            foreach (PropertyInfo p in factory.ModuleType.GetProperties())
            {
                object val = p.GetValue(module, null);
                if (p.PropertyType == typeof(byte))
                {
                    root.Append(p.Name, (byte)val);
                }
                else if (p.PropertyType == typeof(short))
                {
                    root.Append(p.Name, (short)val);
                }
                else if (p.PropertyType == typeof(int))
                {
                    root.Append(p.Name, (int)val);
                }
                else if (p.PropertyType == typeof(long))
                {
                    root.Append(p.Name, (long)val);
                }
                else if (p.PropertyType == typeof(float))
                {
                    root.Append(p.Name, (float)val);
                }
                else if (p.PropertyType == typeof(double))
                {
                    root.Append(p.Name, (double)val);
                }
                else if (p.PropertyType == typeof(byte[]))
                {
                    root.Append(p.Name, (byte[])val);
                }
                else if (p.PropertyType == typeof(string))
                {
                    root.Append(p.Name, (string)val);
                }
                else if (p.PropertyType == typeof(bool))
                {
                    root.Append(p.Name, (bool)val);
                }
                else if (p.PropertyType == typeof(Color))
                {
                    root.Append(p.Name, (Color)val);
                }
                else if (p.PropertyType == typeof(Point))
                {
                    root.Append(p.Name, (Point)val);
                }
                else if (p.PropertyType == typeof(PointF))
                {
                    root.Append(p.Name, (PointF)val);
                }
                else
                {
                    throw new NotSupportedException("Unknown property type.");
                }
            }
            return(root);
        }
Exemplo n.º 7
0
        void SaveProject()
        {
            if (State.ProjectFileName != null)
            {
                NBTag presentationTag = new NBTCompound("Presentation");
                presentationTag.Append("OriginalVisible", picOriginal.Visible);
                presentationTag.Append("OriginalZoom", OriginalZoom);
                presentationTag.Append("BestMatchVisible", picBestMatch.Visible);
                presentationTag.Append("BestMatchZoom", picBestMatch.Zoom);
                presentationTag.Append("BestMatchWireframe", picBestMatch.Wireframe);
                presentationTag.Append("BestMatchShowLastChange", picBestMatch.ShowLastChange);
                presentationTag.Append("DiffVisible", picDiff.Visible);
                presentationTag.Append("DiffInvert", picDiff.Invert);
                presentationTag.Append("DiffExaggerate", picDiff.Exaggerate);
                presentationTag.Append("DiffShowColor", picDiff.ShowColor);
                presentationTag.Append("DiffZoom", picDiff.Zoom);
                presentationTag.Append("DiffShowLastChange", picDiff.ShowLastChange);
                presentationTag.Append("SyncZoom", cmOriginalZoomSync.Checked);

                NBTag tag = State.SerializeNBT();
                tag.Append(presentationTag);
                tag.WriteTag(State.ProjectFileName);
                Text = Path.GetFileName(State.ProjectFileName) + " | SuperImageEvolver | saved " + DateTime.Now;
            }
            else
            {
                SaveProjectAs();
            }
        }