private static void SaveDialogs()
        {
            if (files.Length == 0)
            {
                return;
            }

            Locale.Save();
            Log.Info($"Saving {files[current]}");

            var nodes = ImNodes.Nodes;
            var root  = new JsonArray();

            foreach (var p in nodes)
            {
                var node = p.Value;

                var obj = new JsonObject();

                node.Save(obj);
                root.Add(obj);
            }

            var file   = File.CreateText(FileHandle.FromRoot($"Dialogs/{files[current]}.json").FullPath);
            var writer = new JsonWriter(file);

            writer.Write(root);
            file.Close();
        }
Exemple #2
0
		public static void Delete() {
			try {
				FileHandle.FromRoot($"Locales/{Current}.json").Delete();
				Current = "en";
			} catch (Exception e) {
				Log.Error(e);
			}
		}
Exemple #3
0
        internal static void Load()
        {
            var textureDir = FileHandle.FromRoot("Textures/");

            if (textureDir.Exists())
            {
                LoadTextures(textureDir);
            }
        }
        public static void Load()
        {
            if (true)
            {
                return;
            }

            Load(FileHandle.FromRoot("Loot/"));
        }
        private void Delete()
        {
            var file = FileHandle.FromRoot($"Prefabs/{levels[currentLevel]}.lvl");

            try {
                file.Delete();
            } catch (Exception e) {
                Log.Error(e);
            }
        }
        private void Save()
        {
            if (levels.Length == 0)
            {
                Log.Error("Nothing to save");
                return;
            }

            SaveManager.Save(Editor.Area, SaveType.Level, true, FileHandle.FromRoot($"Prefabs/{levels[currentLevel]}.lvl").FullPath);
        }
Exemple #7
0
		private static void LoadRaw(string name, string path, bool backup = false) {
			if (Loaded.TryGetValue(name, out var cached)) {
				Map = cached;
				return;
			}

			if (name == "qu") {
				cached = new Dictionary<string, string>();
				Loaded[name] = cached;

				var i = 0;

				foreach (var entry in Fallback) {
					cached[entry.Key] = Regex.Replace(entry.Value, @"\w+(?<!^\[)\b", (m) => {
						i++;
						return char.IsUpper(m.Value[0]) ? "Quack" : quacks[(m.Value[0] + i * 5) % quacks.Length];
					});
				}
				
				return;
			}
			
			var file = FileHandle.FromRoot(path);

			if (!file.Exists()) {
				Log.Error($"Locale {path} was not found!");
				return;
			}

			try {
				var root = JsonValue.Parse(file.ReadAll());
				
				cached = new Dictionary<string, string>();
				Loaded[name] = cached;

				foreach (var entry in root.AsJsonObject) {
					cached[entry.Key] = entry.Value.AsString;
				}

				if (backup) {
					Fallback = cached;
				} else {
					Loaded[name] = cached;
					Map = cached;
				}
			} catch (Exception e) {
				Log.Error(e);
			}
		}
Exemple #8
0
        public static void Load()
        {
            var shaderDir = FileHandle.FromRoot("bin/Shaders/");

            if (shaderDir.Exists())
            {
                foreach (var h in shaderDir.ListFileHandles())
                {
                    if (h.Extension == ".xnb")
                    {
                        LoadEffect(h);
                    }
                }
            }
        }
        public static void LoadCurrent()
        {
            if (files.Length == 0)
            {
                return;
            }

            try {
                ImGuiHelper.ClearNodes();
                var name = files[current];
                LoadFromRoot(name, JsonValue.Parse(FileHandle.FromRoot($"Dialogs/{name}.json").ReadAll()));
            } catch (Exception e) {
                Log.Error(e);
            }
        }
Exemple #10
0
        public static void Save()
        {
            Log.Info("Saving loot tables");

            var root = new JsonObject();

            foreach (var d in Data)
            {
                root[d.Key] = d.Value;
            }

            var file   = File.CreateText(FileHandle.FromRoot("Loot/loot.json").FullPath);
            var writer = new JsonWriter(file);

            writer.Write(root);
            file.Close();
        }
Exemple #11
0
        public static void Load()
        {
            if (!Assets.LoadMods)
            {
                return;
            }

            var dir = FileHandle.FromRoot("Mods/");

            if (!dir.Exists())
            {
                Log.Error("Mod directory was not found, creating and exiting.");
                dir.MakeDirectory();
                return;
            }

            Log.Info("Found mod directory");

            foreach (var handle in dir.ListFileHandles())
            {
                if (handle.Extension != ".dll")
                {
                    continue;
                }

                var mod = Mod.Load(handle);

                if (mod == null)
                {
                    Log.Error($"Failed to load mod {handle.Name}");
                    continue;
                }

                var prefix = mod.Prefix;

                if (Loaded.ContainsKey(prefix))
                {
                    Log.Error($"Conflicting mods with the same prefix {prefix}");
                    continue;
                }

                Log.Info($"Loaded mod {prefix}");
                Loaded[prefix] = mod;
                mod.Init();
            }
        }
Exemple #12
0
        public static void Save()
        {
            var root = new JsonObject();

            foreach (var a in Defined.Values)
            {
                var data = new JsonObject();
                a.Save(data);
                root[a.Id] = data;
            }

            var file   = File.CreateText(FileHandle.FromRoot("achievements.json").FullPath);
            var writer = new JsonWriter(file);

            writer.Write(root);
            file.Close();

            Locale.Save();
        }
Exemple #13
0
        internal static void Load()
        {
            var animationDir = FileHandle.FromRoot("Animations/");

            if (animationDir.Exists())
            {
                foreach (var animation in animationDir.ListFileHandles())
                {
                    if (animation.Extension == ".ase")
                    {
                        try {
                            LoadAnimation(animation.NameWithoutExtension, animation.FullPath);
                        } catch (Exception e) {
                            Log.Error(e);
                        }
                    }
                }
            }
        }
        public EditorWindow(Editor e)
        {
            Editor = e;

            EntityEditor.Editor = e;
            TileEditor.Window   = this;
            TileEditor.Editor   = e;

            Commands = new CommandQueue {
                Editor = e
            };

            if (!Engine.EditingLevel)
            {
                TileEditor.ReloadBiome();
                return;
            }

            var locales = FileHandle.FromRoot("Prefabs/");

            if (!locales.Exists())
            {
                levels = new[] {
                    "test"
                };

                return;
            }

            var names = new List <string>();

            foreach (var f in locales.ListFileHandles())
            {
                if (f.Extension == ".lvl")
                {
                    names.Add(f.NameWithoutExtension);
                }
            }

            levels = names.ToArray();
            Load();
        }
Exemple #15
0
        public static void Load()
        {
            var dir = FileHandle.FromRoot("Dialogs");

            foreach (var f in dir.ListFileHandles())
            {
                if (f.Extension == ".json")
                {
                    try {
                        var name = f.NameWithoutExtension;
                        var root = JsonValue.Parse(f.ReadAll());

                        // Create nodes
                        foreach (var vl in root.AsJsonArray)
                        {
                            try {
                                ImNode.Create(name, vl);
                            } catch (Exception e) {
                            }
                        }

                        // Connect em
                        foreach (var node in ImNodes.Nodes)
                        {
                            node.Value.ReadOutputs();
                        }

                        // Parse
                        foreach (var node in ImNodes.Nodes)
                        {
                            ParseNode(node.Value);
                        }

                        ImNodes.Nodes.Clear();
                        ImNode.LastId = 0;
                    } catch (Exception e) {
                        Log.Error(e);
                    }
                }
            }
        }
        static LocaleEditor()
        {
            var locales = FileHandle.FromRoot("Locales/");

            if (!locales.Exists())
            {
                aviableLocales = new[] { "en" };
                return;
            }

            var names = new List <string>();

            foreach (var f in locales.ListFileHandles())
            {
                if (f.Extension == ".json")
                {
                    names.Add(f.NameWithoutExtension);
                }
            }

            aviableLocales = names.ToArray();
            locale         = names.IndexOf(Locale.Current);
        }
        public static void Load()
        {
            var folder = FileHandle.FromRoot("Dialogs");

            if (!folder.Exists())
            {
                Log.Error("Dialog folder is not found!");
                files = new string[0];
                return;
            }

            var fs = new List <string>();

            foreach (var f in folder.ListFileHandles())
            {
                if (f.Extension == ".json")
                {
                    fs.Add(f.NameWithoutExtension);
                }
            }

            files = fs.ToArray();
        }
Exemple #18
0
		public static void Save() {
			Log.Info($"Saving locale {Current}");
			
			try {
				var file = File.CreateText(FileHandle.FromRoot($"Locales/{Current}.json").FullPath);
				var writer = new JsonWriter(file, 
					#if DEBUG
						true
					#else
						false
					#endif
					);
				var root = new JsonObject();

				foreach (var t in Map) {
					root[t.Key] = t.Value;
				}

				writer.Write(root);
				file.Close();
			} catch (Exception e) {
				Log.Error(e);
			}
		}
Exemple #19
0
 public static void Load()
 {
     Load(FileHandle.FromRoot("Prefabs/"));
     Run.Level = null;
 }
Exemple #20
0
 public static void Load()
 {
     Load(FileHandle.FromRoot("items.json"));
 }
Exemple #21
0
        public static void Save()
        {
            var root = new JsonObject();

            foreach (var item in Datas.Values)
            {
                var data = new JsonObject();

                data["id"] = item.Id;

                if (item.Animation != null)
                {
                    data["animation"] = item.Animation;
                }

                if (Math.Abs(item.UseTime) > 0.01f)
                {
                    data["time"] = item.UseTime;
                }

                if (item.Type != ItemType.Artifact)
                {
                    data["type"] = (int)item.Type;
                }

                if (Math.Abs(item.Chance.Any - 1f) > 0.01f)
                {
                    data["chance"] = item.Chance.ToJson();
                }

                if (item.Single)
                {
                    data["single"] = item.Single;
                }

                if (item.Scourged)
                {
                    data["scourged"] = true;
                }

                if (item.Quality != ItemQuality.Wooden)
                {
                    data["quality"] = (int)item.Quality;
                }

                if (item.AutoPickup)
                {
                    data["auto_pickup"] = item.AutoPickup;
                }

                if (item.Automatic)
                {
                    data["auto"] = item.Automatic;
                }

                if (item.SingleUse)
                {
                    data["single_use"] = item.SingleUse;
                }

                data["pool"] = item.Pools;
                data["uses"] = item.Uses;

                if (item.Renderer.IsJsonObject)
                {
                    data["renderer"] = item.Renderer;
                }

                if (item.Lockable)
                {
                    data["lock"]   = item.Lockable;
                    data["uprice"] = item.UnlockPrice;
                }

                if (item.Type == ItemType.Weapon)
                {
                    data["weapon"] = (int)item.WeaponType;
                }

                root[item.Id] = data;
            }

            var file   = File.CreateText(FileHandle.FromRoot("items.json").FullPath);
            var writer = new JsonWriter(file);

            writer.Write(root);
            file.Close();

            Locale.Save();
        }
Exemple #22
0
        public override void Run(Console console, string[] args)
        {
            if (args.Length == 0 || args.Length > 3)
            {
                console.Print("save [save path] (save type)");
                return;
            }

            var path     = args[0];
            var saveType = args.Length == 1 ? "all" : args[1];
            var area     = Engine.Instance.State.Area;

            var thread = new Thread(() => {
                switch (saveType)
                {
                case "all": {
                    SaveManager.Save(area, SaveType.Level, false, path);
                    SaveManager.Save(area, SaveType.Player, false, path);
                    SaveManager.Save(area, SaveType.Game, false, path);
                    SaveManager.Save(area, SaveType.Global, false, path);
                    break;
                }

                case "level": {
                    SaveManager.Save(area, SaveType.Level, false, path);
                    break;
                }

                case "player": {
                    SaveManager.Save(area, SaveType.Player, false, path);
                    break;
                }

                case "game": {
                    SaveManager.Save(area, SaveType.Game, false, path);
                    break;
                }

                case "global": {
                    SaveManager.Save(area, SaveType.Global, false, path);
                    break;
                }

                case "run": {
                    SaveManager.Save(area, SaveType.Level, false, path);
                    SaveManager.Save(area, SaveType.Player, false, path);
                    SaveManager.Save(area, SaveType.Game, false, path);
                    break;
                }

                case "prefab": {
                    SaveManager.Save(area, SaveType.Level, false, $"{FileHandle.FromRoot("Prefabs/").FullPath}/{path}.lvl");
                    break;
                }

                default: {
                    console.Print($"Unknown save type {saveType}. Should be one of all, level, player, game, global, run, prefab");
                    break;
                }
                }

                console.Print($"Done saving {saveType}");
            });

            thread.Start();
        }
Exemple #23
0
 public static void Load()
 {
     Load(FileHandle.FromRoot("achievements.json"));
     LoadState();
 }
        public static void Render()
        {
            if (ImGuiHelper.BeforeRender())
            {
                ImGui.PushItemWidth(-1);

                var old = current;

                if (ImGui.Combo("##file", ref current, files, files.Length))
                {
                    var o = current;
                    current = old;
                    SaveDialogs();
                    current = o;
                    LoadCurrent();
                }

                ImGui.PopItemWidth();

                if (ImGui.Button("Save"))
                {
                    SaveDialogs();
                }

                ImGui.SameLine();

                if (ImGui.Button("Delete"))
                {
                    ImGui.OpenPopup("Delete?");
                }

                if (ImGui.BeginPopupModal("Delete?"))
                {
                    ImGui.Text("This operation can't be undone!");
                    ImGui.Text("Are you sure?");

                    if (ImGui.Button("Yes"))
                    {
                        ImGui.CloseCurrentPopup();
                        var list = files.ToList();
                        var s    = files[current];

                        try {
                            var file = FileHandle.FromRoot($"Dialogs/{s}.json");
                            file.Delete();
                        } catch (Exception e) {
                            Log.Error(e);
                        }

                        list.RemoveAt(current);
                        files   = list.ToArray();
                        current = 0;
                        LoadCurrent();
                    }

                    ImGui.SameLine();
                    ImGui.SetItemDefaultFocus();

                    if (ImGui.Button("No"))
                    {
                        ImGui.CloseCurrentPopup();
                    }

                    ImGui.EndPopup();
                }

                ImGui.SameLine();

                if (ImGui.Button("New"))
                {
                    ImGui.OpenPopup("New tree");
                }

                if (ImGui.BeginPopupModal("New tree"))
                {
                    ImGui.SetItemDefaultFocus();
                    var input  = ImGui.InputText("Name", ref newName, 64, ImGuiInputTextFlags.EnterReturnsTrue);
                    var button = ImGui.Button("Create");

                    ImGui.SameLine();

                    if (ImGui.Button("Cancel"))
                    {
                        ImGui.CloseCurrentPopup();
                        newName = "";
                    }
                    else
                    {
                        if (input || button)
                        {
                            var list = files.ToList();
                            list.Add(newName);
                            files   = list.ToArray();
                            current = list.Count - 1;

                            newName = "";
                            SaveDialogs();
                            LoadCurrent();
                            ImGuiHelper.ClearNodes();
                            ImGui.CloseCurrentPopup();
                        }
                    }

                    ImGui.EndPopup();
                }

                ImGui.Separator();
                ImGuiHelper.RenderNodes();
            }
        }