Ejemplo n.º 1
0
    /**
     * Continue a game
     */
    public void Continue()
    {
        PersistenceData data  = JsonPersistence.ReadPersistenceData();
        int             level = data.gameData != null & data.gameData.currentLevel > 0 ? data.gameData.currentLevel : 1;

        this.LoadLevel(level, false);
    }
Ejemplo n.º 2
0
    public void OnLoad(PersistenceData persistenceData)
    {
        PlayerData playerData = persistenceData.PlayerData;

        transform.localPosition = new Vector3(playerData.LastPosition[0], playerData.LastPosition[1], playerData.LastPosition[2]);
        transform.forward       = new Vector3(playerData.LastDirection[0], playerData.LastDirection[1], playerData.LastDirection[2]);
    }
Ejemplo n.º 3
0
    public void OnLoad(PersistenceData persistenceData)
    {
        CurrencyData currencyData = persistenceData.CurrencyData;

        currentSoftCurrency = currencyData.CurrentSoftCurrency;
        currentHardCurrency = currencyData.CurrentHardCurrency;
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks if the file name is a settings file. If so, the contained logfile name
        /// is returned. If not, the given file name is returned unchanged.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private string FindFilenameForSettings(string fileName)
        {
            if (fileName.EndsWith(".lxp"))
            {
                PersistenceData persistenceData = Persister.LoadOptionsOnly(fileName);
                if (persistenceData == null)
                {
                    return(fileName);
                }

                if (!string.IsNullOrEmpty(persistenceData.fileName))
                {
                    IFileSystemPlugin fs = PluginRegistry.GetInstance().FindFileSystemForUri(persistenceData.fileName);
                    if (fs != null && !fs.GetType().Equals(typeof(LocalFileSystem)))
                    {
                        return(persistenceData.fileName);
                    }

                    // On relative paths the URI check (and therefore the file system plugin check) will fail.
                    // So fs == null and fs == LocalFileSystem are handled here like normal files.
                    if (Path.IsPathRooted(persistenceData.fileName))
                    {
                        return(persistenceData.fileName);
                    }

                    // handle relative paths in .lxp files
                    string dir = Path.GetDirectoryName(fileName);
                    return(Path.Combine(dir, persistenceData.fileName));
                }
            }

            return(fileName);
        }
Ejemplo n.º 5
0
    private PersistenceData GeneratePersistenceData()
    {
        PersistenceData persistenceData = new PersistenceData();

        foreach (var item in persistenceList)
        {
            item.OnSave(persistenceData);
        }
        return(persistenceData);
    }
Ejemplo n.º 6
0
    public void OnSave(PersistenceData persistenceData)
    {
        Vector3 localPosition = transform.localPosition;

        float[] lastPosition = { localPosition.x, localPosition.y, localPosition.z };
        Vector3 forward      = transform.forward;

        float[] lastDirection = { forward.x, forward.y, forward.z };
        persistenceData.PlayerData = new PlayerData(lastPosition, lastDirection);
    }
Ejemplo n.º 7
0
    public void LoadData()
    {
        PersistenceData persistenceData = GetDeserializedPersistenceData();

        if (persistenceData == null)
        {
            return;
        }

        FinishLoadData(persistenceData);
    }
Ejemplo n.º 8
0
    /**
    * Create a PersistenceData with all game data
    */
    private PersistenceData CreatePersistenceData() {
        GameManager gm = GameManager.gm;
        List<Item> itens = new List<Item>();
        itens.AddRange(gm.invControl.itens);

        GameData gameData = new GameData(gm.currentLevel);
        PersistenceData data = new PersistenceData();
        data.itens = itens;
        data.gameData = gameData;

        return data;
    }
Ejemplo n.º 9
0
 void Awake()
 {
     if (control == null)
     {
         DontDestroyOnLoad(this);
         control = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Ejemplo n.º 10
0
    /**
     * Get the PersistenceData from the Json file
     */
    private static PersistenceData GetPersitenceData(JsonData jsonData)
    {
        PersistenceData data     = new PersistenceData();
        GameData        gameData = GetGameDataFromJsonData(jsonData);
        List <Item>     itens    = GetItemFromJsonData(jsonData);

        data.itens = new List <Item>();
        data.itens.AddRange(itens);
        data.gameData = gameData;

        return(data);
    }
Ejemplo n.º 11
0
    private PersistenceData GetDeserializedPersistenceData()
    {
        PersistenceData persistenceData = null;
        string          filePath        = Application.persistentDataPath + PERSISTENCE_FILE_NAME;

        if (File.Exists(filePath))
        {
            FileStream      fileStream      = new FileStream(filePath, FileMode.Open);
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            persistenceData = binaryFormatter.Deserialize(fileStream) as PersistenceData;
            fileStream.Close();
        }
        return(persistenceData);
    }
Ejemplo n.º 12
0
    private void FinishLoadData(PersistenceData persistenceData)
    {
        foreach (var item in persistenceList)
        {
            item.OnLoad(persistenceData);
        }

        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.Append("Loaded Data - ");
        stringBuilder.Append($"Player's last position: ({persistenceData.PlayerData.LastPosition[0]}, {persistenceData.PlayerData.LastPosition[1]}, {persistenceData.PlayerData.LastPosition[2]}) ")
        .Append($" | Currency SC / HC: {persistenceData.CurrencyData.CurrentSoftCurrency} / {persistenceData.CurrencyData.CurrentHardCurrency}");
        Debug.Log(stringBuilder);
    }
Ejemplo n.º 13
0
    /**
     * Create a PersistenceData with all game data
     */
    private PersistenceData CreatePersistenceData()
    {
        GameManager gm    = GameManager.gm;
        List <Item> itens = new List <Item>();

        itens.AddRange(gm.invControl.itens);

        GameData        gameData = new GameData(gm.currentLevel);
        PersistenceData data     = new PersistenceData();

        data.itens    = itens;
        data.gameData = gameData;

        return(data);
    }
Ejemplo n.º 14
0
        public virtual void Restore(PersistenceData data)
        {
            if (data == null)
            {
                Debug.LogWarning(string.Format("No data was saved for object {0}.", gameObject.name));
                return;
            }

            using (MemoryStream stream = new MemoryStream(data.Bytes))
            {
                BinaryFormatter formatter     = new BinaryFormatter();
                object          persistedData = formatter.Deserialize(stream);
                ApplySerializedData(persistedData);
            }
        }
Ejemplo n.º 15
0
    /**
     * Load the Player Data before the game starts:
     * - Load itens;
     * - Create inventory and itens.
     */
    public void LoadData(bool isNewGame)
    {
        PersistenceData       data   = JsonPersistence.ReadPersistenceData();
        List <ItemController> itensC = new List <ItemController>();

        if (data != null && !isNewGame)
        {
            foreach (Item i in data.itens)
            {
                ItemController ic = gameObject.AddComponent <ItemController>();
                ic.item = i;
                itensC.Add(ic);
            }
        }
        invControl.allItens = itensC;
        invControl.PrepareInventory();
    }
Ejemplo n.º 16
0
    private void FinishSaveData(PersistenceData persistenceData)
    {
        string          filePath        = Application.persistentDataPath + PERSISTENCE_FILE_NAME;
        FileStream      fileStream      = new FileStream(filePath, FileMode.Create);
        BinaryFormatter binaryFormatter = new BinaryFormatter();

        binaryFormatter.Serialize(fileStream, persistenceData);
        fileStream.Close();

        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.Append("Saved Data - ");
        stringBuilder.Append($"Player's last position: ({persistenceData.PlayerData.LastPosition[0]}, {persistenceData.PlayerData.LastPosition[1]}, {persistenceData.PlayerData.LastPosition[2]}) ")
        .Append($" | Currency SC / HC: {persistenceData.CurrencyData.CurrentSoftCurrency} / {persistenceData.CurrencyData.CurrentHardCurrency}");
        stringBuilder.Append($"\nFile : {filePath}");
        Debug.Log(stringBuilder);
    }
Ejemplo n.º 17
0
        public virtual PersistenceData Persist()
        {
            PersistenceData data = new PersistenceData()
            {
                GUID = _guid
            };

            //Serialize the data we want to save.
            using (MemoryStream stream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, BuildSerializationData());

                data.Bytes = stream.ToArray();
            }

            return(data);
        }
Ejemplo n.º 18
0
 /**
  * Read the PersistenceData from the Json file
  */
 public static PersistenceData ReadPersistenceData()
 {
     //string filePath = Application.persistentDataPath + "/playerInfo.json";
     if (File.Exists(filePath))
     {
         try {
             using (Stream stream = File.OpenRead(filePath)) {
                 String          jsonString = File.ReadAllText(filePath);
                 JsonData        jsonData   = JsonMapper.ToObject(jsonString);
                 PersistenceData data       = GetPersitenceData(jsonData);
                 return(data);
             }
         } catch (Exception e) {
             Debug.Log(e.Message);
         }
     }
     return(null);
 }
Ejemplo n.º 19
0
 private void LoadData()
 {
     Data = new PersistenceData();
     if (Config.BotUsePersistence)
     {
         if (!string.IsNullOrWhiteSpace(Config.BotUserSaveFolder))
         {
             JsonPath = Config.BotUserSaveFolder;
             if (!JsonPath.EndsWith(Path.DirectorySeparatorChar))
             {
                 JsonPath += Path.DirectorySeparatorChar;
             }
             if (!Directory.Exists(Config.BotUserSaveFolder))
             {
                 Log.LogDebug("Create session directory {0}", JsonPath);
                 try
                 {
                     Directory.CreateDirectory(JsonPath);
                 }
                 catch (Exception ex)
                 {
                     Log.LogError(default, ex, "Coundn't create {0} directory, using current.", JsonPath);
 public static unsafe void Write(global::Improbable.Worker.Internal.GcHandlePool _pool,
                                 PersistenceData _data, global::Improbable.Worker.Internal.Pbio.Object *_obj)
 {
 }
Ejemplo n.º 21
0
 public PersistenceLoader()
 {
     pd = new PersistenceData();
 }
Ejemplo n.º 22
0
 public void OnSave(PersistenceData persistenceData)
 {
     persistenceData.CurrencyData = new CurrencyData(currentSoftCurrency, currentHardCurrency);
 }
Ejemplo n.º 23
0
        private static async Task PersitFiles <TData, TOption>(UpdateMain update, string location, List <TData> collection, List <TOption> options) where TData : PersistenceData where TOption : Options.Option
        {
            var localFiles = Directory.GetFiles(location).Select((s, i) => Path.GetFileName(s)).ToArray();

            var trackedFiles   = new List <PersistenceData>();
            var untrackedFiles = new List <string>(localFiles);

            foreach (var item in collection)
            {
                item.exists = untrackedFiles.Contains(item.file);

                if (item.exists)
                {
                    untrackedFiles.Remove(item.file);
                    trackedFiles.Add(item);
                }
            }

            foreach (var item in options)
            {
                if (untrackedFiles.Count == 0)
                {
                    break;
                }
                if (untrackedFiles.Contains(item.File))
                {
                    bool contained = false;
                    foreach (var data in collection)
                    {
                        if (data.id == item.Id)
                        {
                            data.file = item.File;
                            contained = true;
                            untrackedFiles.Remove(item.File);
                            trackedFiles.Add(data);
                            break;
                        }
                    }

                    if (!contained)
                    {
                        var data = PersistenceData.CreateData(item);
                        untrackedFiles.Remove(item.File);
                        trackedFiles.Add(data);
                        collection.Add(data as TData);
                    }
                }
            }
            if (Globals.Settings.checkSimilaritiesOnUpdate && untrackedFiles.Count > 0)
            {
                List <int> removeAtIndexes = new List <int>();
                foreach (var option in options)
                {
                    int index = 0;
                    foreach (var file in untrackedFiles)
                    {
                        var calc = new LookalikeCalculator(option.File, file);
                        var diff = calc.SimilaritiesAndDifferences.Total;
                        if (diff <= Globals.Settings.similaritiesThresholdAdvanced)
                        {
                            Utils.Info("Lookalike detected: " + option.File + " as " + file);
                            var data = PersistenceData.CreateData(option);
                            removeAtIndexes.Add(index);
                            data.file = file;
                            trackedFiles.Add(data);
                        }
                        index++;
                    }
                }

                removeAtIndexes.Sort();

                try
                {
                    for (int i = removeAtIndexes.Count - 1; i >= 0; i--)
                    {
                        var removeAtIndex = removeAtIndexes[i];
                        untrackedFiles.RemoveAt(removeAtIndex);
                    }
                }
                catch (Exception e)
                {
                    Utils.Debug(e);
                }
            }

            update.UnmanagedFiles.AddRange(untrackedFiles);


            foreach (var item in trackedFiles)
            {
                string errorAt = string.Empty;
                try
                {
                    errorAt = "if (item.UpdateAvailable)";
                    if (item.UpdateAvailable)
                    {
                        Utils.Info("Updating " + item.file);
                        errorAt = "var fileLocation = Path.Combine(location, item.file);";
                        var fileLocation = Path.Combine(location, item.file);
                        errorAt = "File.Delete(fileLocation);";
                        File.Delete(fileLocation);
                        errorAt = "var option = item.Option;";
                        var option = item.Option;
                        errorAt = "var tempfileLocation = Utils.DownloadFileTempFolderLocation(option);";
                        var tempfileLocation = Utils.DownloadFileTempFolderLocation(option);
                        errorAt = "await Globals.DownloadFileByte(option.downloadUrl, tempfileLocation);";
                        await Globals.DownloadFileByte(option.DownloadUrl, tempfileLocation);

                        errorAt = "File.Move(tempfileLocation, Path.Combine(location, option.file));";
                        File.Move(tempfileLocation, Path.Combine(location, option.File));
                        errorAt   = "item.file = option.file;";
                        item.file = option.File;
                    }
                }
                catch (Exception e)
                {
                    Utils.Debug(e);
                    Utils.Debug("errorAt: " + errorAt);
                    Utils.Debug("item.file: " + item.file);
                    Utils.Log(e, "Error Updating File" + item.file, "errorAt: " + errorAt);
                    Utils.Error("Error Updating " + item.file);
                }
            }
        }