public TaskState( NBTag tag ) { if( FormatVersion != tag["FormatVersion"].GetInt() ) throw new FormatException( "Incompatible format." ); Shapes = tag["Shapes"].GetInt(); Vertices = tag["Vertices"].GetInt(); ImprovementCounter = tag["ImprovementCounter"].GetInt(); MutationCounter = tag["MutationCounter"].GetInt(); TaskStart = DateTime.UtcNow.Subtract( TimeSpan.FromTicks( tag["ElapsedTime"].GetLong() ) ); ProjectOptions = new ProjectOptions( tag["ProjectOptions"] ); BestMatch = new DNA( tag["BestMatch"] ); CurrentMatch = BestMatch; Initializer = (IInitializer)ModuleManager.ReadModule( tag["Initializer"] ); Mutator = (IMutator)ModuleManager.ReadModule( tag["Mutator"] ); Evaluator = (IEvaluator)ModuleManager.ReadModule( tag["Evaluator"] ); byte[] imageBytes = tag["ImageData"].GetBytes(); using( MemoryStream ms = new MemoryStream( imageBytes ) ) { OriginalImage = new Bitmap( ms ); } var statsTag = (NBTList)tag["MutationStats"]; foreach( NBTag stat in statsTag ) { MutationType mutationType = (MutationType)Enum.Parse( typeof( MutationType ), stat["Type"].GetString() ); MutationCounts[mutationType] = stat["Count"].GetInt(); MutationImprovements[mutationType] = stat["Sum"].GetDouble(); } }
public DNA(NBTag tag) { Divergence = tag["Divergence"].GetDouble(); var shapesTag = (NBTList)tag["Shapes"]; Shapes = new Shape[shapesTag.Tags.Length]; for (int i = 0; i < Shapes.Length; i++) { Shapes[i] = new Shape(shapesTag[i]); } }
public Shape( NBTag tag ) { Color = tag["Color"].GetColor(); var pointsTag = (NBTList)tag["Points"]; Points = new PointF[pointsTag.Tags.Length]; for( int i = 0; i < Points.Length; i++ ) { Points[i] = pointsTag[i].GetPointF(); } }
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; }
public ProjectOptions( NBTag tag ) : this() { Matte = tag["Matte"].GetColor(); BackColor = tag["BackColor"].GetColor(); MaxOverlap = tag["MaxOverlap"].GetInt(); MinAlpha = tag["MinAlpha"].GetByte(); RefreshRate = new TimeSpan( tag.GetLong( "RefreshRate", RefreshRate.Ticks ) ); WireframeColor = tag.GetColor( "WireframeColor", WireframeColor ); LastChangeColor1 = tag.GetColor( "LastChangeColor1", LastChangeColor1 ); LastChangeColor2 = tag.GetColor( "LastChangeColor2", LastChangeColor2 ); RiskRate = tag.GetDouble( "RiskRate", RiskRate ); RiskMargin = tag.GetDouble( "RiskMargin", RiskMargin ); }
void IModule.WriteSettings( NBTag tag ) { }
void IModule.ReadSettings( NBTag tag ) { }
public static IModule ReadModule( NBTag tag ) { string moduleID = tag["ID"].GetString(); if( !FactoriesById.ContainsKey( moduleID ) ) { return null; } IModuleFactory factory = GetFactoryByID( moduleID ); IModule module = factory.GetInstance(); if( tag.Contains( "Properties" ) ) {} module.ReadSettings( tag["Settings"] ); return module; }
public static void ReadModuleProperties( IModule module, NBTag tag ) { IModuleFactory factory = GetFactoryByType( module.GetType() ); foreach( PropertyInfo p in factory.ModuleType.GetProperties() ) { if( !tag.Contains( p.Name ) ) continue; if( p.PropertyType == typeof( byte ) ) { p.SetValue( module, tag.GetByte(), null ); } else if( p.PropertyType == typeof( short ) ) { p.SetValue( module, tag.GetShort(), null ); } else if( p.PropertyType == typeof( int ) ) { p.SetValue( module, tag.GetInt(), null ); } else if( p.PropertyType == typeof( long ) ) { p.SetValue( module, tag.GetLong(), null ); } else if( p.PropertyType == typeof( float ) ) { p.SetValue( module, tag.GetFloat(), null ); } else if( p.PropertyType == typeof( double ) ) { p.SetValue( module, tag.GetDouble(), null ); } else if( p.PropertyType == typeof( byte[] ) ) { p.SetValue( module, tag.GetBytes(), null ); } else if( p.PropertyType == typeof( string ) ) { p.SetValue( module, tag.GetString(), null ); } else if( p.PropertyType == typeof( bool ) ) { p.SetValue( module, tag.GetBool(), null ); } else if( p.PropertyType == typeof( Color ) ) { p.SetValue( module, tag.GetColor(), null ); } else if( p.PropertyType == typeof( Point ) ) { p.SetValue( module, tag.GetBool(), null ); } else if( p.PropertyType == typeof( PointF ) ) { p.SetValue( module, tag.GetPointF(), null ); } else { throw new NotSupportedException( "Unknown property type." ); } } }