/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
        public SpectrumWriterV2([NotNull] string directory, [NotNull] string prefix, SaveType saveType)
        {
            _writerV2Implementation = new SerialWriterV2 <TracedSpectrum>();
            var dateTime  = DateTime.Now;
            var timeStamp = dateTime.ToString("HHmmssfff");
            var timeStr   = timeStamp.Enclose("TS");
            var path      = Path.Combine(directory, timeStr + prefix);

            if (saveType == SaveType.UnwrappedPhase)
            {
                _writerV2Implementation.ElementDequeued += spectrum => {
                    var phase = new double[spectrum.Length()];
                    for (var i = 0; i < spectrum.Length(); i++)
                    {
                        phase[i] = spectrum.Array[i].Phase;
                    }
                    var unwrap = Functions.Unwrap(phase);
                    Toolbox.WriteStringArray(path + saveType.ToString().Enclose() + spectrum.Tag.Enclose("No") +
                                             spectrum.PulseCount.Enclose("Cnt") + Suffix,
                                             unwrap.Select(p => p.ToString()).ToArray());
                };
            }
            else
            {
                var toStringFunc = GetToStringFunc(saveType);
                _writerV2Implementation.ElementDequeued += spectrum => {
                    Toolbox.WriteStringArray(
                        path + saveType.ToString().Enclose() + spectrum.Tag.Enclose() +
                        spectrum.PulseCount.Enclose("Cnt") + Suffix,
                        spectrum.ToStringArray(toStringFunc));
                };
            }
        }
Example #2
0
    /// <summary> 클라이언트에 저장된 데이터 불러오기 </summary>
    /// <param name="type"> 저장시킨 타입 </param>
    /// <param name="data"> object형태로 콜백됨 저장시켰던 형태로 변환하여 사용하시오</param>
    /// <returns></returns>
    public static IEnumerator Load(SaveType type, Action <object> data)
    {
        var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        if (!File.Exists(Application.persistentDataPath + "/" + type.ToString() + ".dat"))
        {
            yield break;
        }

        using (Stream fileStream = File.Open(Application.persistentDataPath + "/" + type.ToString() + ".dat", FileMode.Open))
        {
            data(formatter.Deserialize(fileStream));
            yield break;
        }
    }
Example #3
0
    /// <summary> 클라이언트에 저장된 데이터 지우기 </summary>
    public static IEnumerator Clear(SaveType type)
    {
        string fileName = Application.persistentDataPath + "/" + type.ToString() + ".dat";

        File.Delete(fileName);
        yield break;
    }
Example #4
0
        public virtual void SavePresets(SaveType saveType)
        {
            if (presets == null || presets.Count <= 0)
            {
                Debug.LogError(
                    "presets cannot be null or empty: " + (presets == null ? "NULL" : "EMPTY"));
                return;
            }

            var jsonColor = new JsonColor();

            jsonColor.SetColors(presets.ToArray());


            string jsonData = JsonUtility.ToJson(jsonColor);

            switch (saveType)
            {
            case SaveType.None:
                Debug.LogWarning("Called SavePresets with SaveType = None...");
                break;

            case SaveType.PlayerPrefs:
                PlayerPrefs.SetString(playerPrefsKey, jsonData);
                break;

            case SaveType.JsonFile:
                System.IO.File.WriteAllText(JsonFilePath, jsonData);
                //Application.OpenURL(JsonFilePath);
                break;

            default:
                throw new System.NotImplementedException(saveType.ToString());
            }
        }
        /// <summary>
        /// Prompts the user if input path is invalid, and creates a new folder in the executing directory if no choice is made by the user. Finds/creates subfolders corresponding to saveType and date.
        /// </summary>
        /// <param name="path">A path to CiceroBackupSettings. Will be checked for validity.</param>
        /// <param name="saveType">What type of data will be saved in this folder.</param>
        /// <param name="date">The date this data will be saved in.</param>
        /// <returns>A valid path that can be used to store data, or null if it was unable to do so.</returns>
        private static string CorrectPath(string path, SaveType saveType, DateTime date)
        {
            if (!Path.IsPathRooted(path) || !path.EndsWith("CiceroBackupSettings"))
            {
                //If the path is incorrect for some reason, ask the user to supply a path
                path = MainClientForm.PromptUserForSavePath();

                //If this lowlife still won't supply a valid path, create a subfolder in the Cicero
                //directory, which is more than this nerf-herder deserves
                if (path == null || !Path.IsPathRooted(path) || !path.EndsWith("CiceroBackupSettings"))
                {
                    path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                    path = Path.Combine(path, "CiceroBackupSettings");
                }
            }

            //Now that we know the path correctly points to the CiceroBackupSettings folder, use saveType and date
            //to specify the correct folder for what we will be saving
            path = Path.Combine(path, date.Year.ToString());
            path = Path.Combine(path, MonthToName(date.Month));
            path = Path.Combine(path, date.Day.ToString());
            path = Path.Combine(path, saveType.ToString());

            try
            {
                Directory.CreateDirectory(path); //Automatically creates all subdirectories unless they already exist
            }
            catch (Exception e)
            {
                //MessageBox.Show("Attempted to create a directory in " + path + ", but the process failed: " + e.ToString());
                path = null;
            }

            return(path);
        }
Example #6
0
    /// <summary> 클라이언트에 저장하기 </summary>
    /// <param name="type"> 저장하고자 하는 타입 (중복불가,데이터가 덧붙여짐)</param>
    /// <param name="data"> 저장하고자 하는 데이터 List<T> or Data Class </param>
    /// <returns></returns>
    public static IEnumerator Save(SaveType type, object data)
    {
        var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        using (Stream fileStream = File.Open(Application.persistentDataPath + "/" + type.ToString() + ".dat", FileMode.Create))
        {
            formatter.Serialize(fileStream, data);
            yield break;
        }
    }
        public virtual void LoadPresets(SaveType saveType)
        {
            string jsonData = "";

            switch (saveType)
            {
            case SaveType.None:
                break;

            case SaveType.PlayerPrefs:
                if (PlayerPrefs.HasKey(playerPrefsKey))
                {
                    jsonData = PlayerPrefs.GetString(playerPrefsKey);
                }

                break;

            case SaveType.JsonFile:
                if (System.IO.File.Exists(JsonFilePath))
                {
                    jsonData = System.IO.File.ReadAllText(JsonFilePath);
                }

                break;

            default:
                throw new System.NotImplementedException(saveType.ToString());
            }

            if (!string.IsNullOrEmpty(jsonData))
            {
                try {
                    var jsonColors = JsonUtility.FromJson <JsonColor>(jsonData);
                    var colors     = jsonColors.GetColors();
                    for (var i = 0; i < colors.Length; i++)
                    {
                        presets.Add(new Tuple <int, Color>(i, colors[i]));
                    }
                } catch (System.Exception e) {
                    Debug.LogException(e);
                }
            }

            foreach (var item in presets)
            {
                CreatePreset(item.Item2, true);
            }
        }
Example #8
0
        static public void MapSaverXMLFile(HexGridData MapToSave, string path, SaveType saveType)
        {
            CInfo.NumberFormat.NumberDecimalSeparator = ".";

            XDocument XmlDoc = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement("MapDatas"));

            XElement MapData = new XElement("MapData", new XAttribute("name", MapToSave.name));

            XmlDoc.Root.Add(MapData);

            MapData.Add(new XElement("width", MapToSave.width));
            MapData.Add(new XElement("height", MapToSave.height));

            MapData.Add(new XElement("cellSize", MapToSave.cellSize));
            MapData.Add(new XElement("cellPadding", MapToSave.cellPadding));

            MapData.Add(new XElement("accuracyOfApproximation", MapToSave.AccurcyOfApproximation));

            MapData.Add(new XElement("materialPath", MapToSave.materialPath));

            XElement HeightMap = new XElement("HeightMap", new XAttribute("type", saveType.ToString()));


            XElement ColorMap = new XElement("ColorMap", new XAttribute("type", SaveType.overrideSave));

            switch (saveType)
            {
            case SaveType.defaultSave:
                MapSaverXMLFile_DefaultSave(ref HeightMap, ref ColorMap, MapToSave);
                break;

            case SaveType.overrideSave:
                MapSaverXMLFile_OverrideSave(ref HeightMap, ref ColorMap, MapToSave);
                break;
            }
            MapData.Add(HeightMap);
            MapData.Add(ColorMap);

            XmlDoc.Save(Application.dataPath + "/" + "Resources/" + path + ".xml");
            // AssetDatabase.SaveAssets();
            // AssetDatabase.Refresh();
        }
Example #9
0
    public static void Save(SaveType type, string id, object data)
    {
        string fileName = Application.persistentDataPath + "/" + type.ToString() + "_" + id + ".dat";

        //데이타 비어 있으면 해당 세이브 파일 삭제
        if (data == null)
        {
            File.Delete(fileName);
            return;
        }

        var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        using (Stream fileStream = File.Open(fileName, FileMode.Create))
        {
            formatter.Serialize(fileStream, data);
        }

        //Debug.Log("Save data. type: " + type + ", id: " + id);
    }
Example #10
0
    public static object Load(SaveType type, string id)
    {
        string fileName = Application.persistentDataPath + "/" + type.ToString() + "_" + id + ".dat";

        if (!File.Exists(fileName))
        {
            return(null);
        }

        var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        using (Stream fileStream = File.Open(fileName, FileMode.Open))
        {
            //안전장치. 문제 생기면 제거. 불러올 때 너무 사이즈가 작은 세이브 파일은 뭔가 이상한거?
            if (fileStream.Length < 20)
            {
                return(null);
            }

            return(formatter.Deserialize(fileStream));
        }
    }
Example #11
0
        /// <summary>
        /// Saves selected data
        /// </summary>
        private void SaveData()
        {
            // If the required objects are missing, return
            if (_mainForm == null || _mainForm.RomData == null || cbSave.SelectedItem == null || cbSaveAs.SelectedItem == null)
            {
                return;
            }

            // Set up objects
            ObjectID   objectID   = null;
            Bitmap     bmp        = null;
            SaveType   saveType   = (SaveType)(cbSave.SelectedItem as ObjectID).ID;
            SaveAsType saveAsType = (SaveAsType)(cbSaveAs.SelectedItem as ObjectID).ID;
            string     save       = EnumMethods.GetDescription(typeof(SaveType), saveType);
            string     saveAs     = EnumMethods.GetDescription(typeof(SaveAsType), saveAsType);

            switch (saveType)
            {
            case SaveType.PaletteGroup: objectID = GetSelectedPaletteGroup(); bmp = objectID != null?GetSelectedPaletteGroup().GetPaletteGroupImage() : null; break;

            case SaveType.Sprite: objectID = GetSelectedSprite(); bmp = pnlSprite.Image; break;

            case SaveType.SpriteTileset: objectID = GetSelectedTileset(cbSpriteTilesets); bmp = pnlSpriteTilesets.Image; break;

            case SaveType.SpriteTileMap: objectID = GetSelectedTileMap(cbSpriteTileMaps); bmp = pnlSpriteTileMaps.Image; break;

            case SaveType.Tileset: objectID = GetSelectedTileset(cbTilesets); bmp = pnlTilesets.Image; break;

            case SaveType.TileMap: objectID = GetSelectedTileMap(cbTileMaps); bmp = pnlTileMaps.Image; break;
            }

            // If no object was selected, return
            if (objectID == null)
            {
                ShowMessage("Please select a " + EnumMethods.GetDescription(typeof(SaveType), saveType).ToLower() + " to save.");
                return;
            }

            // Create open file dialog
            using (SaveFileDialog dialog = new SaveFileDialog())
            {
                // Set up the open file dialog
                dialog.Filter   = saveAsType == SaveAsType.Binary ? "Uncompressed Binary|*.bin" : saveAsType == SaveAsType.CompressedBinary ? "Compressed Binary|*.bin" : "Image|*.png";
                dialog.Title    = "Save " + save + " " + saveAs + " File";
                dialog.FileName = objectID.Name + saveType.ToString() + saveAsType.ToString();

                // Show dialog, if the user clicks OK
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // Write data to disk, based on save as type
                    switch (saveAsType)
                    {
                    case SaveAsType.Binary: using (BinaryWriter bw = new BinaryWriter(File.Create(dialog.FileName))) { bw.Write(MainForm.RomData.Decompress(objectID.Compression, objectID.DataStart, objectID.Length)); break; }

                    case SaveAsType.CompressedBinary: using (BinaryWriter bw = new BinaryWriter(File.Create(dialog.FileName))) { bw.Write(MainForm.RomData.GetBytes(objectID.DataStart, objectID.Length)); } break;

                    case SaveAsType.Image: if (bmp != null)
                        {
                            bmp.Save(dialog.FileName, ImageFormat.Png);
                        }
                        break;
                    }
                }
            }
        }
Example #12
0
    public static void Clear(SaveType type, string id)
    {
        string fileName = Application.persistentDataPath + "/" + type.ToString() + "_" + id + ".dat";

        File.Delete(fileName);
    }
Example #13
0
 private static string GetSavePath(string name, SaveType type)
 {
     return(Path.Combine(Application.persistentDataPath, name + "." + type.ToString()));
 }
Example #14
0
 public static byte[] GetBytes(string String, int maxSize = 0)
 {
     if (Save_Type == SaveType.Animal_Crossing)
     {
         byte[] returnedString   = new byte[maxSize > 0 ? maxSize : String.Length];
         TextElementEnumerator t = StringInfo.GetTextElementEnumerator(String);
         int i = 0;
         while (t.MoveNext() && i < returnedString.Length)
         {
             if (Char_Dictionary.ContainsValue((string)t.Current))
             {
                 returnedString[i] = Char_Dictionary.FirstOrDefault(o => o.Value == (string)t.Current).Key;
             }
             else
             {
                 returnedString[i] = Encoding.UTF8.GetBytes(new char[1] {
                     String[t.ElementIndex]
                 })[0];
             }
             i++;
         }
         for (int x = 0; x < returnedString.Length; x++)
         {
             if (returnedString[x] == 0)
             {
                 returnedString[x] = 0x20;
             }
         }
         return(returnedString);
     }
     else if (Save_Type == SaveType.Wild_World)
     {
         byte[] String_Buffer = StringUtil.To_Wild_World_String(Encoding.UTF8.GetBytes(String));
         if (maxSize > 0)
         {
             Array.Resize(ref String_Buffer, maxSize);
         }
         return(String_Buffer);
     }
     else if (Save_Type == SaveType.City_Folk)
     {
         byte[] String_Buffer = new byte[maxSize > 0 ? maxSize : String.Length * 2]; //Characters are now unicode
         byte[] String_Bytes  = Encoding.Unicode.GetBytes(String);
         for (int i = 0; i < String_Bytes.Length; i += 2)
         {
             Buffer.BlockCopy(String_Bytes.Skip(i).Take(2).Reverse().ToArray(), 0, String_Buffer, i, 2);
         }
         return(String_Buffer);
     }
     else if (Save_Type == SaveType.New_Leaf || Save_Type == SaveType.Welcome_Amiibo)
     {
         byte[] String_Buffer = Encoding.Unicode.GetBytes(String);
         if (maxSize > 0)
         {
             Array.Resize(ref String_Buffer, maxSize);
         }
         return(String_Buffer);
     }
     else
     {
         NewMainForm.Debug_Manager.WriteLine(string.Format("StringUtil was passed an unknown SaveType enum. Received Type: {0}", Save_Type.ToString()), DebugLevel.Error);
         return(null);
     }
 }
Example #15
0
        public static byte[] GetBytes(string String, int maxSize = 0)
        {
            var i = 0;

            switch (_saveType)
            {
            case SaveType.AnimalCrossing:
                var returnedString = new byte[maxSize > 0 ? maxSize : String.Length];
                var t = StringInfo.GetTextElementEnumerator(String);
                while (t.MoveNext() && i < returnedString.Length)
                {
                    if (_charDictionary.ContainsValue((string)t.Current))
                    {
                        returnedString[i] = _charDictionary.FirstOrDefault(o => o.Value == (string)t.Current).Key;
                    }
                    else
                    {
                        returnedString[i] = Encoding.UTF8.GetBytes(new[] { String[t.ElementIndex] })[0];
                    }
                    i++;
                }
                for (var x = 0; x < returnedString.Length; x++)
                {
                    if (returnedString[x] == 0)
                    {
                        returnedString[x] = 0x20;
                    }
                }
                return(returnedString);

            case SaveType.DoubutsuNoMori:
            case SaveType.DoubutsuNoMoriPlus:
            case SaveType.DoubutsuNoMoriEPlus:
            case SaveType.AnimalForestEPlus:
            {
                var stringBytes = new byte[maxSize > 0 ? maxSize : String.Length];
                for (i = 0; i < String.Length; i++)
                {
                    if (i >= stringBytes.Length)
                    {
                        break;
                    }
                    if (StringUtility.DoubutsuNoMoriEPlusCharMap.ContainsValue(String[i].ToString()))
                    {
                        stringBytes[i] = StringUtility.DoubutsuNoMoriEPlusCharMap.First(o => o.Value == String[i].ToString()).Key;
                    }
                    else
                    {
                        stringBytes[i] = Encoding.ASCII.GetBytes(new[] { String[i] })[0];
                    }
                }

                if (maxSize <= 0 || String.Length >= maxSize)
                {
                    return(stringBytes);
                }
                for (i = String.Length; i < maxSize; i++)
                {
                    stringBytes[i] = 0x20;
                }
                return(stringBytes);
            }

            case SaveType.WildWorld:
            {
                var stringBuffer = new byte[maxSize > 0 ? maxSize : String.Length];
                for (i = 0; i < String.Length; i++)
                {
                    var character = String[i].ToString();
                    if (StringUtility.WwCharacterDictionary.ContainsValue(character))
                    {
                        stringBuffer[i] = StringUtility.WwCharacterDictionary.FirstOrDefault(o => o.Value.Equals(character)).Key;
                    }
                }

                return(stringBuffer);
            }

            case SaveType.CityFolk:
            {
                var stringBuffer = new byte[maxSize > 0 ? maxSize : String.Length * 2];     //Characters are now unicode
                var stringBytes  = Encoding.Unicode.GetBytes(String);
                for (i = 0; i < stringBytes.Length; i += 2)
                {
                    Buffer.BlockCopy(stringBytes.Skip(i).Take(2).Reverse().ToArray(), 0, stringBuffer, i, 2);
                }
                return(stringBuffer);
            }

            case SaveType.NewLeaf:
            case SaveType.WelcomeAmiibo:
            {
                var stringBuffer = Encoding.Unicode.GetBytes(String);
                if (maxSize > 0)
                {
                    Array.Resize(ref stringBuffer, maxSize);
                }
                return(stringBuffer);
            }

            case SaveType.AnimalForest:     // Animal Forest iQue support will be added soon
                return(null);

            case SaveType.Unknown:
                MainForm.DebugManager.WriteLine(
                    $"StringUtil was passed an unknown SaveType enum. Received Type: {_saveType.ToString()}", DebugLevel.Error);
                return(null);

            default:
                return(null);
            }
        }
Example #16
0
        public static byte[] GetBytes(string String, int maxSize = 0)
        {
            var i = 0;

            switch (_saveType)
            {
            case SaveType.AnimalCrossing:
                var returnedString = new byte[maxSize > 0 ? maxSize : String.Length];
                var t = StringInfo.GetTextElementEnumerator(String);
                while (t.MoveNext() && i < returnedString.Length)
                {
                    var idx = Array.IndexOf(_charDictionary, (string)t.Current);
                    if (idx > -1)
                    {
                        returnedString[i] = (byte)idx;
                    }
                    else
                    {
                        returnedString[i] = Encoding.UTF8.GetBytes(new[] { String[t.ElementIndex] })[0];
                    }
                    i++;
                }
                for (var x = 0; x < returnedString.Length; x++)
                {
                    if (returnedString[x] == 0)
                    {
                        returnedString[x] = 0x20;
                    }
                }
                return(returnedString);

            case SaveType.DoubutsuNoMori:
            case SaveType.DoubutsuNoMoriPlus:
            case SaveType.DoubutsuNoMoriEPlus:
            case SaveType.AnimalForestEPlus:
            {
                var stringBytes = new byte[maxSize > 0 ? maxSize : String.Length];
                for (i = 0; i < String.Length; i++)
                {
                    if (i >= stringBytes.Length)
                    {
                        break;
                    }

                    var idx = Array.IndexOf(CharacterSets.DoubutsuNoMoriEPlusCharMap, String[i].ToString());
                    if (idx > -1)
                    {
                        stringBytes[i] = (byte)idx;
                    }
                    else
                    {
                        stringBytes[i] = Encoding.ASCII.GetBytes(new[] { String[i] })[0];
                    }
                }

                if (maxSize <= 0 || String.Length >= maxSize)
                {
                    return(stringBytes);
                }
                for (i = String.Length; i < maxSize; i++)
                {
                    stringBytes[i] = 0x20;
                }
                return(stringBytes);
            }

            case SaveType.WildWorld:
            {
                var stringBuffer = new byte[maxSize > 0 ? maxSize : String.Length];
                for (i = 0; i < String.Length; i++)
                {
                    var idx = Array.IndexOf(CharacterSets.WwCharacterDictionary, String[i].ToString());
                    if (idx > -1)
                    {
                        stringBuffer[i] = (byte)idx;
                    }
                    else
                    {
                        stringBuffer[i] = 0x85;     // Space
                    }
                }

                return(stringBuffer);
            }

            case SaveType.DongwuSenlin:
            {
                var stringBuffer = new byte[maxSize > 0 ? maxSize : String.Length];

                for (i = 0; i < String.Length; i++)
                {
                    var idx = Array.IndexOf(CharacterSets.DongwuSenlinCharacterSet, String[i].ToString());
                    if (idx > -1)
                    {
                        var(multiByte, charIdx, bank) = EncodeCharacterFromIndex(idx);
                        if (multiByte)
                        {
                            if (i + 1 < stringBuffer.Length)
                            {
                                stringBuffer[i++] = charIdx;
                                stringBuffer[i]   = bank;
                            }
                            else
                            {
                                stringBuffer[i] = 0x20;     // Space
                            }
                        }
                        else
                        {
                            stringBuffer[i] = charIdx;
                        }
                    }
                    else
                    {
                        stringBuffer[i] = 0x20;     // Space
                    }
                }

                return(stringBuffer);
            }

            case SaveType.CityFolk:
            {
                var stringBuffer = new byte[maxSize > 0 ? maxSize : String.Length * 2];     //Characters are now unicode
                var stringBytes  = Encoding.Unicode.GetBytes(String);
                for (i = 0; i < stringBytes.Length; i += 2)
                {
                    Buffer.BlockCopy(stringBytes.Skip(i).Take(2).Reverse().ToArray(), 0, stringBuffer, i, 2);
                }
                return(stringBuffer);
            }

            case SaveType.NewLeaf:
            case SaveType.WelcomeAmiibo:
            {
                var stringBuffer = Encoding.Unicode.GetBytes(String);
                if (maxSize > 0)
                {
                    Array.Resize(ref stringBuffer, maxSize);
                }
                return(stringBuffer);
            }

            case SaveType.Unknown:
                MainForm.DebugManager.WriteLine(
                    $"StringUtil was passed an unknown SaveType enum. Received Type: {_saveType.ToString()}", DebugLevel.Error);
                return(null);

            default:
                return(null);
            }
        }
Example #17
0
    public IEnumerator Save()
    {
        //TODO Update Save UI - Saving terrain;
        Popup.Message("Saving..", "Saving Terrain");
        yield return(new WaitForEndOfFrame());

        m_tiles          = new string[WorldManager.worldWidth * Chunk.WIDTH, WorldManager.worldHeight *Chunk.HEIGHT];
        ChunkTile[,] map = ManagerInstance.Get <WorldManager>().completeMap;
        for (int x = 0; x < WorldManager.worldWidth * Chunk.WIDTH; x++)
        {
            for (int y = 0; y < WorldManager.worldHeight * Chunk.HEIGHT; y++)
            {
                m_tiles[x, y] = map[x, y].identity;
            }
        }

        //TODO Update Save UI - Saving entities;
        Popup.Message("Saving..", "Saving Entities");
        yield return(new WaitForEndOfFrame());

        m_entities = ManagerInstance.Get <EntityManager>().activeEntities;

        for (int i = 0; i < m_entities.Count; i++)
        {
            m_entities[i].SetProperty("x", m_entities[i].x);
            m_entities[i].SetProperty("y", m_entities[i].y);

            Debug.Log(m_entities[i].x);
            Debug.Log(m_entities[i].y);
        }

        //TODO Update Save UI - Saving Fog of War;
        Popup.Message("Saving..", "Saving Fog of War");
        yield return(new WaitForEndOfFrame());

        m_FOW = new float[WorldManager.worldWidth * Chunk.WIDTH, WorldManager.worldHeight *Chunk.HEIGHT];
        ChunkFOWTile[,] FOWTiles = ManagerInstance.Get <FogOfWarManager>().completeMap;
        for (int x = 0; x < WorldManager.worldWidth * Chunk.WIDTH; x++)
        {
            for (int y = 0; y < WorldManager.worldHeight * Chunk.HEIGHT; y++)
            {
                m_FOW[x, y] = FOWTiles[x, y].strength;
            }
        }

        //TODO Update Save UI - Saving dependencies - entities;
        Popup.Message("Saving..", "Saving Dependencies - Entities");
        yield return(new WaitForEndOfFrame());

        m_entityDependencies = ManagerInstance.Get <EntityManager>().loadedEntities;

        //TODO Update Save UI - Saving dependencies - tiles;
        Popup.Message("Saving..", "Saving Dependencies - Tiles");
        yield return(new WaitForEndOfFrame());

        m_tileDependencies = ManagerInstance.Get <DatabaseManager>().dataBase.loadedData;

        //TODO Update Save UI - Writing to disk
        Popup.Message("Saving..", "Writing To Disk");
        yield return(new WaitForEndOfFrame());

        if (m_saveName == null)
        {
            m_saveName = System.DateTime.Now.ToString();
        }

        char[] chars       = { '/', ':', ' ' };
        string trimmedName = m_saveName.Trim(chars);

        //TODO Update Save UI - Writing to disk
        yield return(new WaitForEndOfFrame());

        bool succes = true;

        try
        {
            BinaryFormatter bf       = new BinaryFormatter();
            string          dataPath = Application.dataPath + "/../data/saves/" + m_saveType.ToString().ToLower() + "/" + trimmedName;
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }

            FileStream file = File.Create(dataPath + "/" + trimmedName + ".save");
            bf.Serialize(file, this);
            file.Close();
        }catch (FileNotFoundException error)
        {
            Debug.LogError(error);
            succes = false;
        }

        Popup.Message("Saved", "Game Saved.");
        loaded = true;
        yield break;
    }
Example #18
0
        /// <summary>
        /// 数据采集,传入数据,频率,是否循环采集
        /// </summary>
        /// <param name="data"></param>
        /// <param name="loop"></param>
        /// <param name="frequency"></param>
        public void DataCollect(IData data, bool loop = true, int frequency = 200)
        {
            if (!_isClientInit)
            {
                Debug.LogError("LabData未初始化");
                return;
            }


            //StartUpload();
            var basePathStr = Application.dataPath + "/Output";

            LabTools.CreatFolder(basePathStr);
            var userStr = _userId.PadLeft(2, '0');

            basePathStr = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr);
            basePathStr = LabTools.CreatFolder(basePathStr);

            if (_saveType == SaveType.Csv)
            {
                string dataPath = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr, data.SaveData.DataCodeName, data.SaveData.LabDataBase.Invoke() + "." + _saveType.ToString());
                LabTools.CreatData(dataPath);
                DataWriter dw = new DataWriter(dataPath, data.SaveData.LabDataBase.Invoke, _saveType);
                dw.WriteCsvTitle();
                dw.Dispose();
            }
            if (loop)
            {
                string dataPath = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr, data.SaveData.DataCodeName, data.SaveData.LabDataBase.Invoke() + "." + _saveType.ToString());
                LabTools.CreatData(dataPath);
                DataWriter dw = new DataWriter(dataPath, () => data.SaveData.LabDataBase.Invoke(), _saveType);
                dw.WriteDataAsyncFrequency();
                _dataWriters.Add(dw);
            }
            else
            {
                string dataPath = string.Join("_", basePathStr + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr, data.SaveData.DataCodeName, data.SaveData.LabDataBase.Invoke() + "." + _saveType.ToString());
                LabTools.CreatData(dataPath);
                DataWriter dw = new DataWriter(dataPath, () =>
                {
                    if (_sendToServer)
                    {
                        Scope.Send(data.SaveData.LabDataBase.Invoke());
                    }
                    return(data.SaveData.LabDataBase.Invoke());
                }, _saveType);
                dw.WriteOnce();
                dw.Dispose();
            }
        }
Example #19
0
        /// <summary>
        /// SaveFileDialog를 호출하는 Method
        /// </summary>
        /// <param name="saveType"></param>
        /// <param name="structureType"></param>
        /// <returns></returns>
        private bool SaveMacroFile(SaveType saveType, SavedContainerType structureType)
        {
            string saveFilePath = "";

            if (saveType == SaveType.저장 && !WorkFlowName.Equals(""))
            {
                saveFilePath = WorkFlowPath;
            }
            else
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = string.Format("{0} {1}|{2}", PROGRAM_KEY_WORD, structureType.ToString(), GstStructureExtension[structureType]);
                saveFileDialog.Title  = string.Format("{0} {1}", structureType.ToString(), saveType.ToString());
                if (saveFileDialog.ShowDialog() != DialogResult.OK || saveFileDialog.FileName.Equals(""))
                {
                    return(false); // Cancle
                }
                saveFilePath = saveFileDialog.FileName;
            }
            BinaryFormatter serializer = new BinaryFormatter();
            Stream          stream     = File.Open(saveFilePath, FileMode.Create);

            switch (structureType)
            {
            case SavedContainerType.워크플로우:
                serializer.Serialize(stream, Nodes);
                WorkFlowPath = saveFilePath;
                break;

            case SavedContainerType.이벤트집합:
                SerializePrefabs.PrefabsDupCheckSet = PrefabsDupCheckSet;
                serializer.Serialize(stream, SerializePrefabs);
                break;
            }
            stream.Close();
            isModified = false;
            return(true);
        }