Created
April 11, 2013 02:31
-
-
Save codeimpossible/5360190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Runtime.Serialization; | |
using System.Runtime.Serialization.Json; | |
using FragEngine.Entities; | |
using FragEngine.IO; | |
using Microsoft.Xna.Framework; | |
namespace ThunderDome | |
{ | |
public class Program | |
{ | |
[DataContract] | |
public class Level | |
{ | |
public Level() | |
{ | |
Entities = new Dictionary<int, List<EntityBase>>(); | |
} | |
[DataMember] | |
public Dictionary<int, List<EntityBase>> Entities { get; set; } | |
[DataMember] | |
public string Name { get; set; } | |
public void AddEntity(int layer, EntityBase entity) | |
{ | |
if (Entities.ContainsKey(layer)) | |
{ | |
Entities[layer].Add(entity); | |
} | |
else | |
{ | |
Entities.Add(layer, new List<EntityBase>() { entity }); | |
} | |
} | |
} | |
public class Car : EntityBase | |
{ | |
} | |
public class EnemyA : EntityBase | |
{ | |
} | |
public class EnemyB : EntityBase | |
{ | |
} | |
static void Main( string[] args ) | |
{ | |
var level = new Level { Name = "TheFirstLevel" }; | |
var car = new Car { Position = new Vector2( 100, 100 ) }; | |
car.Settings.Add( "name", "CutsceneIntroTurret" ); | |
car.Settings.Add( "targeting", true ); | |
car.Settings.Add( "speed", 100 ); | |
level.AddEntity( 1, car ); | |
var enemy = new EnemyA {Position = new Vector2(1000, 100)}; | |
enemy.Settings.Add("range", 100 ); | |
var enemy2 = new EnemyB { Position = new Vector2( 2000, 200 ) }; | |
enemy2.Settings.Add("range", 200 ); | |
level.AddEntity( 2, enemy ); | |
level.AddEntity( 3, enemy2 ); | |
// SerializeWithShittyXmlSerializer(car); | |
// SerializeWithLessShittyJsonSerializer(car); | |
SerializeWithServiceStack(level); | |
var readLevel = Persistant.Load<Level>(@"c:\Temp\level.json"); | |
// SerializeWithProtoBuf(car); | |
Console.WriteLine("Level persisted"); | |
Console.ReadLine(); | |
} | |
private static void SerializeWithServiceStack(Level level) | |
{ | |
Persistant.Persist(@"c:\Temp\level.json", level); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment