/// <inheritdoc/>
 public void LoadSaveable(ISaveable saveable)
 {
     if (GameState.TryGetValue(saveable.Id, out var value))
     {
         saveable.Load((JObject)value);
     }
 }
Example #2
0
        private void LoadSaveable(ISaveable saveable)
        {
            string fileName = GetSaveableFilePath(saveable);

            if (System.IO.File.Exists(fileName))
            {
                using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open))) {
                    string saveString = reader.ReadString();
                    if (!string.IsNullOrEmpty(saveString))
                    {
                        saveable.Load(saveString);
                        saveable.OnLoaded();
                        RavenhillEvents.OnSaveableLoaded(saveable);
                    }
                    else
                    {
                        saveable.InitSave();
                        saveable.OnLoaded();
                        RavenhillEvents.OnSaveableLoaded(saveable);
                    }
                }
            }
            else
            {
                saveable.InitSave();
                saveable.OnLoaded();
                RavenhillEvents.OnSaveableLoaded(saveable);
            }
        }
Example #3
0
        private IEnumerator LoadSequence(List <SaveData> saveData)
        {
            Processing = true;
            yield return(new WaitForSecondsRealtime(0.5f));

            yield return(new WaitForSecondsRealtime(loadDelay));

            for (int i = 0; i < saveData.Count; i++)
            {
                SaveData  data     = saveData[i];
                ISaveable saveable = saveables.SingleOrDefault(x => x.Id == data.id);
                if (saveable != null && saveable.ToString() != "null")
                {
                    saveable.Load(data);
                }
            }

            Processing = false;

            ClearTrash();
            List <ISaveable> redundant = saveables.Where(x => !saveData.Any(y => y.id == x.Id)).ToList();

            for (int i = redundant.Count - 1; i >= 0; i--)
            {
                Destroy(redundant[i].GO);
            }

            DevTools.Instance().DisableAll();
            yield return(new WaitForEndOfFrame());

            onLoad?.Invoke();
        }
Example #4
0
        public static LoadResponse Load(BinaryReader reader, SaveType saveType)
        {
            /* 0 - Depersist object table. */
            uint rootId    = 0;
            bool rootFound = false;
            Dictionary <uint, ISaveable> objectTable = new Dictionary <uint, ISaveable>();

            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                uint   objectId = reader.ReadUInt32();
                String assemblyQualifiedTypeName = reader.ReadString();
                bool   isRoot = reader.ReadBoolean();
                if (isRoot && rootFound)
                {
                    throw new NotSupportedException("More than one root object defined in the save file!");
                }
                else if (isRoot)
                {
                    rootFound = true;
                    rootId    = objectId;
                }

                ISaveable loadedObject = constructType(assemblyQualifiedTypeName, objectId);
                loadedObject.Load(reader, saveType);

                objectTable.Add(loadedObject.GetId(), loadedObject);
            }

            if (rootFound == false)
            {
                throw new NotSupportedException("No root object defined in the save file!");
            }

            /* 1 - Inflate all objects */
            inflateObjects(objectTable, saveType);

            /* 2 - Construct the result object */
            List <ISaveable> values = new List <ISaveable>();

            foreach (ISaveable saveable in objectTable.Values)
            {
                values.Add(saveable);
            }

            LoadResponse response = new LoadResponse();

            response.root    = objectTable[rootId];
            response.objects = values;

            /* 3 - Return the response object */
            return(response);
        }