Ejemplo n.º 1
0
        private static void LoadTextures(FileHandle handle)
        {
            foreach (var h in handle.ListFileHandles())
            {
                LoadTexture(h);
            }

            foreach (var h in handle.ListDirectoryHandles())
            {
                LoadTextures(h);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
                }
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
0
        private void AddNodes(FileHandle dir, SaveGroup group)
        {
            foreach (var d in dir.ListDirectoryHandles())
            {
                var node = new SaveGroup {
                    FullPath = d.FullPath,
                    Name     = d.Name
                };

                group.Dirs.Add(node);
                AddNodes(d, node);
            }

            foreach (var f in dir.ListFileHandles())
            {
                var node = new SaveData {
                    FullPath = f.FullPath,
                    Name     = f.Name
                };

                group.Files.Add(node);
                node.Load();
            }
        }
Ejemplo n.º 6
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);
            }
        }