public IEnumerable <Property> ToProperties() { // Add simple fields. var properties = new List <Property> { new Property(nameof(WorldSize), WorldSize.ToString(), comment: "The width and height of the game world."), new Property(nameof(MsPerFrame), MsPerFrame.ToString(), comment: "The number of milliseconds to spend per frame. FPS = 1000 / MsPerFrame."), new Property(nameof(FramesPerShot), FramesPerShot.ToString(), comment: "The number of frames to pause between each firing of a projectile."), new Property(nameof(RespawnRate), RespawnRate.ToString(), comment: "How many frames before a dead ship respawns."), new Property(nameof(ShipHitpoints), ShipHitpoints.ToString(), comment: "How many hitpoints ships should start with."), new Property(nameof(ProjectileSpeed), ProjectileSpeed.ToString(CultureInfo.InvariantCulture), comment: "How many units per frame that projectiles travel."), new Property(nameof(ShipEngineStrength), ShipEngineStrength.ToString(CultureInfo.InvariantCulture), comment: "How many units per frame that ships accellerate when thrusting."), new Property(nameof(ShipTurningRate), ShipTurningRate.ToString(CultureInfo.InvariantCulture), comment: "The degrees that a ship can rotate per frame."), new Property(nameof(ShipCollisionRadius), ShipCollisionRadius.ToString(CultureInfo.InvariantCulture), comment: "How close a projectile must get to collide with a ship."), new Property(nameof(StarCollisionRadius), StarCollisionRadius.ToString(CultureInfo.InvariantCulture), comment: "How close a projectile or ship must get to collide with a star."), new Property(nameof(ExplosiveGameMode), ExplosiveGameMode.ToString(), comment: "Set to true to enable the explosive game mode, where a large number of projectiles are spawned each time a sihp dies.") }; // Add all stars. foreach (var star in Stars) { properties.Add(new Property( nameof(Star), attributes: new Dictionary <string, string> { ["x"] = star.Location.GetX().ToString(CultureInfo.InvariantCulture), ["y"] = star.Location.GetY().ToString(CultureInfo.InvariantCulture), ["mass"] = star.Mass.ToString(CultureInfo.InvariantCulture) }, comment: "The location and mass of a star." )); } return(properties); }
public void LoadWorld() { WorldInfo Info = worldInfo; Task.Run(() => { lock (fsWorld) { try { fsWorld.Seek(0, SeekOrigin.Begin); uint magicNumber = WorldReader.ReadUInt32(); uint version = WorldReader.ReadUInt32(); long seed = WorldReader.ReadInt64(); char[] worldChars = WorldReader.ReadChars(128); string worldName = ""; for (int i = 0; i < 128; i++) { if (worldChars[i] == 0) { break; } worldName += worldChars[i]; } uint width = WorldReader.ReadUInt32(); WorldSize worldSize = (WorldSize)WorldReader.ReadByte(); DateTime creationTime = DateTime.FromBinary(WorldReader.ReadInt64()); ulong playTime = WorldReader.ReadUInt64(); Difficulty difficulty = (Difficulty)WorldReader.ReadByte(); Generator generator = (Generator)WorldReader.ReadByte(); uint timeOfDay = WorldReader.ReadUInt32(); uint lengthOfDay = WorldReader.ReadUInt32(); Console.WriteLine("magic number: {0}, {1}", magicNumber, magicNumber == 0x42171701 ? "Matches." : "No Match!"); Console.WriteLine("version: {0}", version.ToString("X")); Console.WriteLine("seed: {0}", seed.ToString("X")); Console.WriteLine("worldName: {0}", worldName); Console.WriteLine("width: {0}", width.ToString("X")); Console.WriteLine("worldSize: {0}", worldSize.ToString("X")); Console.WriteLine("creationTime: {0}", creationTime.ToString()); Console.WriteLine("playTime: {0}", playTime.ToString("X")); Console.WriteLine("difficulty: {0}", difficulty.ToString("X")); Console.WriteLine("generator: {0}", generator.ToString("X")); Console.WriteLine("timeOfDay: {0}", timeOfDay.ToString("X")); Console.WriteLine("lengthOfDay: {0}", lengthOfDay.ToString("X")); Info.seed = seed; Info.width = width; Info.timeOfDay = timeOfDay; Info.lengthOfDay = lengthOfDay; Info.Name = worldName; Info.difficulty = difficulty; Info.generator = generator; Info.Size = worldSize; Info.creationTime = creationTime; Info.playTime = playTime; } catch (Exception e) { throw new Exception("Error reading world", e); } } }); }