Exemple #1
0
        public void OnClickSave()
        {
            //Debug.Log("OnClickSave");

            //new save if saveName=null

            //otherwise save over old save

            if (!GameState.Instance.SaveLocked && !GameState.Instance.ManualSaveLocked)
            {
                string saveName = SaveNameField.text;
                string saveFileName;

                if (SelectedSaveName != null)
                {
                    //assume save name is already okay

                    saveName     = SelectedSaveName; //we know it already has a prefix
                    saveFileName = saveName + ".json";
                    string savePath = CoreParams.SavePath + Path.DirectorySeparatorChar + saveName + ".json";
                    if (File.Exists(savePath))
                    {
                        File.Delete(savePath); //this "works" but seems to be bugged- race condition?
                    }
                }
                else
                {
                    saveFileName = "m_" + SaveUtils.GetSafeName(saveName) + ".json";
                }

                if (!string.IsNullOrEmpty(saveName))
                {
                    try
                    {
                        SharedUtils.SaveGame(saveFileName, true, false);
                        Modal.PushMessageModal(Sub.Replace("SaveSuccessMessage", SubList), Sub.Replace("SaveSuccess", SubList), null, null);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError($"Save failed! ({e.GetType().Name})");
                        Debug.LogException(e);
                        Modal.PushMessageModal(e.Message, Sub.Replace("SaveFail", SubList), null, null);
                    }
                    SignalPaint();
                }
                else
                {
                    Modal.PushMessageModal(Sub.Replace("SaveBadFilenameMessage", SubList), Sub.Replace("SaveFail", SubList), null, null);
                }
            }
            else
            {
                //can't save!

                Modal.PushMessageModal(Sub.Replace("SaveNotAllowedMessage", SubList), Sub.Replace("SaveNotAllowed", SubList), null, null);
            }
        }