Beispiel #1
0
        public Nugget SaveObject(Object SaveableObject)
        {
            if (SaveableObject == null)
            {
                return(null);
            }

            if (CreatedNuggets.ContainsKey(SaveableObject))
            {
                return(CreatedNuggets[SaveableObject]);
            }

            var    asSaveable = SaveableObject as ISaveableObject;
            Nugget result     = null;

            if (asSaveable != null)
            {
                result = asSaveable.SaveToNugget(this);
                result.AssociatedType = SaveableObject.GetType();
                result.Version        = Nugget.FindSaveableObjectVersion(asSaveable);
            }
            else
            {
                var generic = new GenericNugget();
                result                = generic;
                generic.Data          = SaveableObject;
                result.AssociatedType = SaveableObject.GetType();
                result.Version        = -1;

                GenericSaveableTypes.Add(SaveableObject.GetType().FullName);
            }

            CreatedNuggets.Add(SaveableObject, result);
            return(result);
        }
Beispiel #2
0
            void Saving.ISaveableObject.LoadFromNugget(Saving.Loader SaveSystem, Saving.Nugget From)
            {
                var n = From as ComponentSaveNugget;

                SaveableComponents = n.SaveableComponents.Select(o => SaveSystem.LoadObject(o) as GameComponent).ToList();
                RootComponent      = n.RootComponent;
            }
Beispiel #3
0
        void Saving.ISaveableObject.LoadFromNugget(Saving.Loader SaveSystem, Saving.Nugget From)
        {
            var n = From as SaveNugget;

            Factions = new Dictionary <string, Faction>();
            foreach (var savedFaction in n.Factions)
            {
                Factions.Add(savedFaction.Key, SaveSystem.LoadObject(savedFaction.Value) as Faction);
            }
        }
Beispiel #4
0
        public Object LoadObject(Nugget From)
        {
            if (From == null)
            {
                return(null);
            }
            if (From.LoadedObject != null)
            {
                return(From.LoadedObject);
            }

            if (From is GenericNugget)
            {
                var generic = From as GenericNugget;
                generic.LoadedObject = generic.Data;
                return(generic.Data);
            }

            var result = Activator.CreateInstance(From.AssociatedType) as ISaveableObject;

            if (result == null)
            {
                throw new InvalidOperationException("Attempted to load object that is not saveable.");
            }

            var resultVersion = Nugget.FindSaveableObjectVersion(result);
            var currentNugget = From;

            while (resultVersion > currentNugget.Version)
            {
                DiscoverUpgraders();
                var upgrader = Upgraders.FirstOrDefault(u =>
                                                        u.AssociatedType == currentNugget.AssociatedType &&
                                                        u.SourceVersion == currentNugget.Version);
                if (upgrader == null)
                {
                    throw new InvalidOperationException("Failed to upgrade nugget.");
                }

                currentNugget = upgrader.Method.Invoke(null, new Object[] { currentNugget }) as Nugget;
                currentNugget.AssociatedType = upgrader.AssociatedType;
                currentNugget.Version        = upgrader.DestinationVersion;
            }

            result.LoadFromNugget(this, currentNugget);
            From.LoadedObject = result;
            return(result);
        }
Beispiel #5
0
        public Nugget UpgradeNugget(Nugget From, int To)
        {
            var currentNugget = From;

            while (To > currentNugget.Version)
            {
                DiscoverUpgraders();
                var upgrader = Upgraders.FirstOrDefault(u =>
                                                        u.AssociatedType == currentNugget.AssociatedType &&
                                                        u.SourceVersion == currentNugget.Version);
                if (upgrader == null)
                {
                    throw new InvalidOperationException("Failed to upgrade nugget.");
                }

                currentNugget = upgrader.Method.Invoke(null, new Object[] { currentNugget }) as Nugget;
                currentNugget.AssociatedType = upgrader.AssociatedType;
                currentNugget.Version        = upgrader.DestinationVersion;
            }

            return(currentNugget);
        }
Beispiel #6
0
 public void LoadFromNugget(Loader SaveSystem, Nugget From)
 {
     Data = (From as SampleNugget2).Data;
 }
Beispiel #7
0
 Nugget __upgrade(Nugget From)
 {
     return(new SampleNugget2 {
         Data = (From as SampleNugget).Data
     });
 }