Esempio n. 1
0
        private static void Load(FileHandle handle)
        {
            if (!handle.Exists())
            {
                Log.Error($"Achievement data {handle.FullPath} does not exist!");
                return;
            }

            var root = JsonValue.Parse(handle.ReadAll());

            foreach (var item in root.AsJsonObject)
            {
                var a = new Achievement(item.Key);
                a.Load(item.Value);
                Defined[item.Key] = a;
            }
        }
Esempio n. 2
0
        public static void Load(FileHandle handle)
        {
            if (!handle.Exists())
            {
                Log.Error($"Item data {handle.FullPath} does not exist!");
                return;
            }

            if (handle.IsDirectory())
            {
                foreach (var file in handle.ListFileHandles())
                {
                    Load(file);
                }

                foreach (var file in handle.ListDirectoryHandles())
                {
                    Load(file);
                }

                return;
            }

            if (handle.Extension != ".json")
            {
                return;
            }

            var d   = handle.ReadAll();
            var num = JsonCounter.Calculate(d);

            Log.Debug($"Item data number is {num}");

            if (num != Assets.ItemData)
            {
                Assets.DataModified = true;
            }

            var root = JsonValue.Parse(d);

            foreach (var item in root.AsJsonObject)
            {
                ParseItem(item.Key, item.Value);
            }
        }
Esempio n. 3
0
        private static void LoadSfx(FileHandle file, string path, bool root = false)
        {
            if (file.Exists())
            {
                path = $"{path}{file.Name}{(root ? "" : "/")}";

                foreach (var sfx in file.ListFileHandles())
                {
                    if (sfx.Extension == ".xnb")
                    {
                        LoadSfx(sfx.NameWithoutExtension, path);
                    }
                }

                foreach (var dir in file.ListDirectoryHandles())
                {
                    LoadSfx(dir, path);
                }
            }
        }
Esempio n. 4
0
        private void RenderGui()
        {
            if (!ImGui.Begin("Save files"))
            {
                ImGui.End();
                return;
            }

            ImGui.Text($"Save directory: \"{SaveManager.SaveDir}\"");

            ImGui.Text($"Exists: {saveDir.Exists()}");
            ImGui.SameLine();

            if (ImGui.Button("Refresh"))
            {
                RefreshSaveDir();
            }

            nodes.Render();
            ImGui.End();
        }
Esempio n. 5
0
        private static void Load(FileHandle handle)
        {
            if (!handle.Exists())
            {
                Log.Error($"Loot table {handle.FullPath} does not exist!");
                return;
            }

            if (handle.IsDirectory())
            {
                foreach (var file in handle.ListFileHandles())
                {
                    Load(file);
                }

                foreach (var file in handle.ListDirectoryHandles())
                {
                    Load(file);
                }

                return;
            }

            if (handle.Extension != ".json")
            {
                return;
            }

            var root = JsonValue.Parse(handle.ReadAll());

            foreach (var table in root.AsJsonObject)
            {
                try {
                    ParseTable(table.Key, table.Value);
                } catch (Exception e) {
                    Log.Error(e);
                }
            }
        }
Esempio n. 6
0
        public static void Init()
        {
            Log.Info($"Save directory is '{new FileHandle(SaveDir).FullPath}'");

            Savers = new Saver[6];
            Savers[(int)SaveType.Global]     = new GlobalSave();
            Savers[(int)SaveType.Game]       = new GameSave();
            Savers[(int)SaveType.Level]      = new LevelSave();
            Savers[(int)SaveType.Player]     = new PlayerSave();
            Savers[(int)SaveType.Secret]     = new SecretSave();
            Savers[(int)SaveType.Statistics] = new StatisticsSaver();

            var saveDirectory = new FileHandle(SaveDir);

            if (!saveDirectory.Exists())
            {
                saveDirectory.MakeDirectory();
                Log.Info("Creating the save directory");

                SecretSave.HadSaveBefore = false;
            }
        }
Esempio n. 7
0
    /// <summary>
    /// Reads a text file
    /// </summary>
    /// <returns>The text file.</returns>
    /// <param name="sFileName">S file name.</param>
    public static string ReadTextFile(string sFileName)
    {
        //Check to see if the specified filename exists, if not try adding '.txt', otherwise fail
        string sFileNameFound = "";

        if (FileHandle.Exists(sFileName))
        {
            sFileNameFound = sFileName; //file found
        }
        else if (FileHandle.Exists(sFileName + ".txt"))
        {
            sFileNameFound = sFileName + ".txt";
        }
        else
        {
            Debug.Log("Could not find file '" + sFileName + "'.");
            return(null);
        }

        string fileContents = FileHandle.ReadAllText(sFileNameFound);

        return(fileContents);
    }
Esempio n. 8
0
        private static void Load(FileHandle handle)
        {
            if (!handle.Exists())
            {
                return;
            }

            if (handle.IsDirectory())
            {
                foreach (var file in handle.ListFileHandles())
                {
                    Load(file);
                }

                foreach (var file in handle.ListDirectoryHandles())
                {
                    Load(file);
                }

                return;
            }

            if (handle.Extension != ".lvl")
            {
                return;
            }

            Log.Info($"Loading prefab {handle.FullPath}");

            try {
                var prefab = new Prefab();
                var stream = new FileReader(handle.FullPath);

                if (stream.ReadInt32() != SaveManager.MagicNumber)
                {
                    Log.Error("Invalid magic number!");

                    return;
                }

                var version = stream.ReadInt16();

                if (version > SaveManager.Version)
                {
                    Log.Error($"Unknown version {version}");
                }
                else if (version < SaveManager.Version)
                {
                    // do something on it
                }

                if (stream.ReadByte() != (byte)SaveType.Level)
                {
                    return;
                }

                saver.Load(new Area {
                    NoInit = true
                }, stream, false);

                prefab.Level = Run.Level;
                prefab.Datas = ArrayUtils.Clone(saver.Datas);
                saver.Datas.Clear();

                loaded[handle.NameWithoutExtension] = prefab;
                Run.Level = null;
            } catch (Exception e) {
                Log.Error($"Failed to load prefab {handle.NameWithoutExtension}");
                Log.Error(e);
            }
        }