Exemple #1
0
        public static T LoadConfig <T>(string file = "config.yaml") where T : new()
        {
            var directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (directoryName != null)
            {
                var directoryInfo = new DirectoryInfo(directoryName);
                var config        = Path.Combine(directoryName, file);
                Debug.Log(config);

                var fileInfo = new FileInfo(config);

                if (!fileInfo.Exists)
                {
                    var cfg = new T();
                    YamlIO.Save(cfg, config);
                    return(cfg);
                }

                return(YamlIO.LoadFile <T>(config,
                                           delegate(YamlIO.Error error, bool warning) { Debug.Log($"ERROR - {error}"); }));
            }

            return(new T());
        }
Exemple #2
0
        private void UpdateWorldCache(string path, List <YamlIO.Error> errors)
        {
            ListPool <FileHandle, Worlds> .PooledList pooledList = ListPool <FileHandle, Worlds> .Allocate();

            FileSystem.GetFiles(FileSystem.Normalize(System.IO.Path.Combine(path, "worlds")), "*.yaml", pooledList);
            foreach (FileHandle item in pooledList)
            {
                FileHandle world_file = item;
                World      world      = YamlIO.LoadFile <World>(world_file.full_path, delegate(YamlIO.Error error, bool force_log_as_warning)
                {
                    error.file = world_file;
                    errors.Add(error);
                }, null);
                if (world == null)
                {
                    DebugUtil.LogWarningArgs("Failed to load world: ", world_file.full_path);
                }
                else if (!world.skip)
                {
                    world.filePath             = GetWorldName(world_file.full_path);
                    worldCache[world.filePath] = world;
                }
            }
            pooledList.Recycle();
        }
Exemple #3
0
    public static NoiseNodeCanvas CreateInstance()
    {
        NoiseNodeCanvas noiseNodeCanvas = ScriptableObject.CreateInstance <NoiseNodeCanvas>();

        noiseNodeCanvas.ntf = YamlIO.LoadFile <NoiseTreeFiles>(NoiseTreeFiles.GetPath(), null, null);
        return(noiseNodeCanvas);
    }
Exemple #4
0
        public static List <T> CollectFromYAML <T>(string path)
        {
            List <T> list  = new List <T>();
            var      files = ListPool <FileHandle, Yaml> .Allocate();

            FileSystem.GetFiles(FileSystem.Normalize(path), "*.yaml", files);
            FileSystem.GetFiles(FileSystem.Normalize(path), "*.yml", files);
            var errors = ListPool <YamlIO.Error, Yaml> .Allocate();

            Log.Info($"Loading {files.Count} files from {path}");

            foreach (FileHandle file in files)
            {
                Log.Info($"Loading {file.full_path} files");

                T obj = YamlIO.LoadFile <T>(file.full_path, delegate(YamlIO.Error error, bool force_log_as_warning)
                {
                    errors.Add(error);
                });
                if (obj != null)
                {
                    list.Add(obj);
                }
            }
            files.Recycle();
            if (Global.Instance != null && Global.Instance.modManager != null)
            {
                Global.Instance.modManager.HandleErrors(errors);
            }
            errors.Recycle();
            return(list);
        }
Exemple #5
0
    public static List <SubEntry> CollectSubEntries(string folder)
    {
        List <SubEntry> list = new List <SubEntry>();
        string          path = (!(folder == string.Empty)) ? Path.Combine(baseEntryPath, folder) : baseEntryPath;

        string[] array = new string[0];
        try
        {
            array = Directory.GetFiles(path, "*.yaml", SearchOption.AllDirectories);
        }
        catch (UnauthorizedAccessException obj)
        {
            Debug.LogWarning(obj);
        }
        string[] array2 = array;
        foreach (string text in array2)
        {
            try
            {
                SubEntry subEntry = YamlIO.LoadFile <SubEntry>(text, YamlParseErrorCB, widgetTagMappings);
                if (subEntry != null)
                {
                    list.Add(subEntry);
                }
            }
            catch (Exception ex)
            {
                DebugUtil.DevLogErrorFormat("CodexCache.CollectSubEntries failed to load [{0}]: {1}", text, ex.ToString());
            }
        }
        list.Sort((SubEntry x, SubEntry y) => x.title.CompareTo(y.title));
        return(list);
    }
    public static List <ElementEntry> CollectElementsFromYAML()
    {
        List <ElementEntry> list = new List <ElementEntry>();

        ListPool <FileHandle, ElementLoader> .PooledList pooledList = ListPool <FileHandle, ElementLoader> .Allocate();

        FileSystem.GetFiles(FileSystem.Normalize(path), "*.yaml", pooledList);
        ListPool <YamlIO.Error, ElementLoader> .PooledList errors = ListPool <YamlIO.Error, ElementLoader> .Allocate();

        foreach (FileHandle item in pooledList)
        {
            FileHandle             file = item;
            ElementEntryCollection elementEntryCollection = YamlIO.LoadFile <ElementEntryCollection>(file.full_path, delegate(YamlIO.Error error, bool force_log_as_warning)
            {
                error.file = file;
                errors.Add(error);
            }, null);
            if (elementEntryCollection != null)
            {
                list.AddRange(elementEntryCollection.elements);
            }
        }
        pooledList.Recycle();
        if ((UnityEngine.Object)Global.Instance != (UnityEngine.Object)null && Global.Instance.modManager != null)
        {
            Global.Instance.modManager.HandleErrors(errors);
        }
        errors.Recycle();
        return(list);
    }
        private static string LoadFeature(string longName, List <YamlIO.Error> errors)
        {
            string name = string.Empty;

            if (!GetPathAndName(GetPath(), longName, out name))
            {
                Debug.LogWarning("LoadFeature GetPathAndName: Attempting to load feature: " + name + " failed");
                return(longName);
            }
            if (!featuresettings.ContainsKey(name))
            {
                FeatureSettings featureSettings = YamlIO.LoadFile <FeatureSettings>(GetPath() + name + ".yaml", null, null);
                if (featureSettings != null)
                {
                    featuresettings.Add(name, featureSettings);
                    if (featureSettings.forceBiome != null)
                    {
                        LoadBiome(featureSettings.forceBiome, errors);
                        DebugUtil.Assert(biomes.BiomeBackgroundElementBandConfigurations.ContainsKey(featureSettings.forceBiome), longName, "(feature) referenced a missing biome named", featureSettings.forceBiome);
                    }
                }
                else
                {
                    Debug.LogWarning("WorldGen: Attempting to load feature: " + name + " failed");
                }
            }
            return(name);
        }
Exemple #8
0
        /// <summary>
        /// Loads codex entries from the specified directory.
        /// </summary>
        /// <param name="entries">The location where the data will be placed.</param>
        /// <param name="dir">The directory to load.</param>
        /// <param name="category">The category to assign to each entry thus loaded.</param>
        private static void LoadFromDirectory(ICollection <CodexEntry> entries, string dir,
                                              string category)
        {
            string[] codexFiles = new string[0];
            try {
                // List codex data files in the codex directory
                codexFiles = Directory.GetFiles(dir, CODEX_FILES);
            } catch (UnauthorizedAccessException ex) {
                PUtil.LogExcWarn(ex);
            } catch (IOException ex) {
                PUtil.LogExcWarn(ex);
            }
            var widgetTagMappings = WIDGET_TAG_MAPPINGS?.GetValue(null) as WidgetMappingList;

            if (widgetTagMappings == null)
            {
                PDatabaseUtils.LogDatabaseWarning("Unable to load codex files: no tag mappings found");
            }
            foreach (string str in codexFiles)
            {
                try {
                    string filename   = str;
                    var    codexEntry = YamlIO.LoadFile <CodexEntry>(filename, YamlParseErrorCB,
                                                                     widgetTagMappings);
                    if (codexEntry != null)
                    {
                        codexEntry.category = category;
                        entries.Add(codexEntry);
                    }
                } catch (IOException ex) {
                    PDatabaseUtils.LogDatabaseWarning("Unable to load codex files from {0}:".
                                                      F(dir));
                    PUtil.LogExcWarn(ex);
                }
            }
        public static bool LoadFiles(List <YamlIO.Error> errors)
        {
            if (worlds.worldCache.Count > 0)
            {
                return(false);
            }
            worlds.LoadFiles(GetPath(), errors);
            List <FileHandle> list = new List <FileHandle>();

            FileSystem.GetFiles(FileSystem.Normalize(System.IO.Path.Combine(path, "traits")), "*.yaml", list);
            foreach (FileHandle item in list)
            {
                FileHandle trait_file = item;
                WorldTrait worldTrait = YamlIO.LoadFile <WorldTrait>(trait_file.full_path, delegate(YamlIO.Error error, bool force_log_as_warning)
                {
                    error.file = trait_file;
                    errors.Add(error);
                }, null);
                int    num  = FirstUncommonCharacter(path, trait_file.full_path);
                string text = (num <= -1) ? trait_file.full_path : trait_file.full_path.Substring(num);
                text = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(text), System.IO.Path.GetFileNameWithoutExtension(text));
                if (worldTrait == null)
                {
                    DebugUtil.LogWarningArgs("Failed to load trait: ", text);
                }
                else
                {
                    traits[text] = worldTrait;
                }
            }
            foreach (KeyValuePair <string, World> item2 in worlds.worldCache)
            {
                LoadFeatures(item2.Value.globalFeatures, errors);
                LoadSubworlds(item2.Value.subworldFiles, errors);
            }
            foreach (KeyValuePair <string, WorldTrait> trait in traits)
            {
                LoadFeatures(trait.Value.globalFeatureMods, errors);
                LoadSubworlds(trait.Value.additionalSubworldFiles, errors);
            }
            layers = MergeLoad <LevelLayerSettings>(GetPath() + "layers.yaml", errors);
            layers.LevelLayers.ConvertBandSizeToMaxSize();
            rivers = MergeLoad <ComposableDictionary <string, River> >(GetPath() + "rivers.yaml", errors);
            rooms  = MergeLoad <ComposableDictionary <string, Room> >(path + "rooms.yaml", errors);
            foreach (KeyValuePair <string, Room> room in rooms)
            {
                room.Value.name = room.Key;
            }
            temperatures = MergeLoad <ComposableDictionary <Temperature.Range, Temperature> >(GetPath() + "temperatures.yaml", errors);
            borders      = MergeLoad <ComposableDictionary <string, List <WeightedSimHash> > >(GetPath() + "borders.yaml", errors);
            defaults     = YamlIO.LoadFile <DefaultSettings>(GetPath() + "defaults.yaml", null, null);
            mobs         = MergeLoad <MobSettings>(GetPath() + "mobs.yaml", errors);
            foreach (KeyValuePair <string, Mob> item3 in mobs.MobLookupTable)
            {
                item3.Value.name = item3.Key;
            }
            DebugUtil.LogArgs("World settings reload complete!");
            return(true);
        }
 public void LoadAllTrees()
 {
     for (int i = 0; i < tree_files.Count; i++)
     {
         Tree tree = YamlIO.LoadFile <Tree>(GetTreeFilePath(tree_files[i]), null, null);
         if (tree != null)
         {
             trees.Add(tree_files[i], tree);
         }
     }
 }
 public Tree GetTree(string name, string path)
 {
     if (!trees.ContainsKey(name))
     {
         Tree tree = YamlIO.LoadFile <Tree>(path + "/" + name + ".yaml", null, null);
         if (tree == null)
         {
             return(null);
         }
         trees.Add(name, tree);
     }
     return(trees[name]);
 }
Exemple #12
0
 public static void Get(out PublishedFileId_t item, out System.DateTime lastModified)
 {
     if (Exists())
     {
         InstalledLanguageData installedLanguageData = YamlIO.LoadFile <InstalledLanguageData>(FilePath(), null, null);
         if (installedLanguageData != null)
         {
             lastModified = System.DateTime.FromFileTimeUtc(installedLanguageData.LastModified);
             item         = new PublishedFileId_t(installedLanguageData.PublishedFileId);
             return;
         }
     }
     lastModified = System.DateTime.MinValue;
     item         = PublishedFileId_t.Invalid;
 }
 public Tree LoadTree(string name, string path)
 {
     if (name != null && name.Length > 0)
     {
         if (!trees.ContainsKey(name))
         {
             Tree tree = YamlIO.LoadFile <Tree>(path + name + ".yaml", null, null);
             if (tree != null)
             {
                 trees.Add(name, tree);
             }
         }
         return(trees[name]);
     }
     return(null);
 }
Exemple #14
0
    private NodeCanvas Load(string name, CompleteLoadCallback onComplete)
    {
        NodeCanvas nodeCanvas   = null;
        string     treeFilePath = NoiseTreeFiles.GetTreeFilePath(name);
        Tree       tree         = YamlIO.LoadFile <Tree>(treeFilePath, null, null);

        if (tree != null)
        {
            if (tree.settings.name == null || tree.settings.name == string.Empty)
            {
                tree.settings.name = name;
            }
            nodeCanvas = PopulateNoiseNodeEditor(tree);
        }
        onComplete(name, nodeCanvas);
        return(nodeCanvas);
    }
Exemple #15
0
 public static CodexEntry GetTemplate(string templatePath)
 {
     if (!entries.ContainsKey(templatePath))
     {
         entries.Add(templatePath, null);
     }
     if (entries[templatePath] == null)
     {
         string     text       = Path.Combine(baseEntryPath, templatePath);
         CodexEntry codexEntry = YamlIO.LoadFile <CodexEntry>(text + ".yaml", null, widgetTagMappings);
         if (codexEntry == null)
         {
             Debug.LogWarning("Missing template [" + text + ".yaml]");
         }
         entries[templatePath] = codexEntry;
     }
     return(entries[templatePath]);
 }
    private static void AddWorldMods(object user_data, List <SettingLevel> levels)
    {
        string path = FileSystem.Normalize(System.IO.Path.Combine(SettingsCache.GetPath(), "worlds"));

        ListPool <string, CustomGameSettings> .PooledList pooledList = ListPool <string, CustomGameSettings> .Allocate();

        FileSystem.GetFiles(path, "*.yaml", pooledList);
        foreach (string item in pooledList)
        {
            ProcGen.World world       = YamlIO.LoadFile <ProcGen.World>(item, null, null);
            string        worldName   = Worlds.GetWorldName(item);
            string        id          = worldName;
            string        name        = world.name;
            string        description = world.description;
            levels.Add(new SettingLevel(id, name, description, 0, user_data));
        }
        pooledList.Recycle();
    }
 public static void LoadSubworlds(List <WeightedName> subworlds, List <YamlIO.Error> errors)
 {
     foreach (WeightedName subworld in subworlds)
     {
         SubWorld subWorld = null;
         string   text     = subworld.name;
         if (subworld.overrideName != null && subworld.overrideName.Length > 0)
         {
             text = subworld.overrideName;
         }
         if (!SettingsCache.subworlds.ContainsKey(text))
         {
             SubWorld subWorld2 = YamlIO.LoadFile <SubWorld>(path + subworld.name + ".yaml", null, null);
             if (subWorld2 != null)
             {
                 subWorld      = subWorld2;
                 subWorld.name = text;
                 SettingsCache.subworlds[text] = subWorld;
                 noise.LoadTree(subWorld.biomeNoise, path);
                 noise.LoadTree(subWorld.densityNoise, path);
                 noise.LoadTree(subWorld.overrideNoise, path);
             }
             else
             {
                 Debug.LogWarning("WorldGen: Attempting to load subworld: " + subworld.name + " failed");
             }
             if (subWorld.centralFeature != null)
             {
                 subWorld.centralFeature.type = LoadFeature(subWorld.centralFeature.type, errors);
             }
             foreach (WeightedBiome biome in subWorld.biomes)
             {
                 LoadBiome(biome.name, errors);
                 DebugUtil.Assert(biomes.BiomeBackgroundElementBandConfigurations.ContainsKey(biome.name), subWorld.name, "(subworld) referenced a missing biome named", biome.name);
             }
             DebugUtil.Assert(subWorld.features != null, "Features list for subworld", subWorld.name, "was null! Either remove it from the .yaml or set it to the empty list []");
             foreach (Feature feature in subWorld.features)
             {
                 feature.type = LoadFeature(feature.type, errors);
             }
         }
     }
 }
Exemple #18
0
    public static List <CodexEntry> CollectEntries(string folder)
    {
        List <CodexEntry> list = new List <CodexEntry>();
        string            path = (!(folder == string.Empty)) ? Path.Combine(baseEntryPath, folder) : baseEntryPath;

        string[] array = new string[0];
        try
        {
            array = Directory.GetFiles(path, "*.yaml");
        }
        catch (UnauthorizedAccessException obj)
        {
            Debug.LogWarning(obj);
        }
        string category = folder.ToUpper();

        string[] array2 = array;
        foreach (string text in array2)
        {
            try
            {
                CodexEntry codexEntry = YamlIO.LoadFile <CodexEntry>(text, YamlParseErrorCB, widgetTagMappings);
                if (codexEntry != null)
                {
                    codexEntry.category = category;
                    list.Add(codexEntry);
                }
            }
            catch (Exception ex)
            {
                DebugUtil.DevLogErrorFormat("CodexCache.CollectEntries failed to load [{0}]: {1}", text, ex.ToString());
            }
        }
        foreach (CodexEntry item in list)
        {
            if (string.IsNullOrEmpty(item.sortString))
            {
                item.sortString = Strings.Get(item.title);
            }
        }
        list.Sort((CodexEntry x, CodexEntry y) => x.sortString.CompareTo(y.sortString));
        return(list);
    }
    public static AnimCommandFile GetParseCommands(string path)
    {
        string       fullName = Directory.GetParent(path).FullName;
        HashedString key      = new HashedString(fullName);

        if (Get().commandFiles.ContainsKey(key))
        {
            return(instance.commandFiles[key]);
        }
        string text = Path.Combine(fullName, ANIM_COMMAND_FILE);

        if (File.Exists(text))
        {
            AnimCommandFile animCommandFile = YamlIO.LoadFile <AnimCommandFile>(text, null, null);
            animCommandFile.directory  = "Assets/anim/" + Directory.GetParent(path).Name;
            instance.commandFiles[key] = animCommandFile;
            return(animCommandFile);
        }
        return(null);
    }
Exemple #20
0
 public override void AdditionalSaveMethods(string sceneCanvasName, CompleteLoadCallback onComplete)
 {
     GUILayout.BeginHorizontal();
     if (GUILayout.Button(new GUIContent("Load Yaml", "Loads the Canvas from a Yaml Save File")))
     {
         Load(sceneCanvasName, onComplete);
     }
     if (GUILayout.Button(new GUIContent("Save to Yaml", "Saves the Canvas to a Yaml file"), GUILayout.ExpandWidth(false)))
     {
         BeforeSavingCanvas();
         Tree tree = BuildTreeFromCanvas();
         if (tree != null)
         {
             tree.ClearEmptyLists();
             string treeFilePath = NoiseTreeFiles.GetTreeFilePath(sceneCanvasName);
             YamlIO.Save(tree, treeFilePath, null);
         }
     }
     GUILayout.EndHorizontal();
     if (ntf == null)
     {
         ntf = YamlIO.LoadFile <NoiseTreeFiles>(NoiseTreeFiles.GetPath(), null, null);
     }
     if (ntf != null && GUILayout.Button(new GUIContent("Load Tree", "Loads the Canvas from Trees list")))
     {
         GenericMenu genericMenu = new GenericMenu();
         foreach (string tree_file in ntf.tree_files)
         {
             genericMenu.AddItem(new GUIContent(tree_file), false, delegate(object fileName)
             {
                 Load((string)fileName, onComplete);
             }, tree_file);
         }
         genericMenu.Show(lastRectPos.position, 40f);
     }
     if (Event.current.type == EventType.Repaint)
     {
         Rect lastRect = GUILayoutUtility.GetLastRect();
         lastRectPos = new Rect(lastRect.x + 2f, lastRect.yMax + 2f, lastRect.width - 4f, 0f);
     }
 }
        public static EndpointState Load()
        {
            EndpointState result;

            try
            {
                result = YamlIO.LoadFile <EndpointState>(Filename());
            }
            catch (Exception ex)
            {
                Debug.LogWarning("Failed to load endpoint_state.yml: " + ex.ToString());
                result = new EndpointState();
            }
            if (result.times_rescued == null)
            {
                Debug.Log("Missing times_rescued");
                result.times_rescued = new Dictionary <string, int>();
            }
            Debug.Log("Loaded Endpoint state: " + result.ToString());
            return(result);
        }
Exemple #22
0
        /// <summary>
        /// Loads all codex entries for all mods registered.
        /// </summary>
        /// <param name="lockKey">Key for shared data lock.</param>
        /// <param name="tableKey">Key for shared data table.</param>
        /// <param name="category">The codex category under which these data entries should be loaded.</param>
        /// <returns>The list of entries that were loaded.</returns>
        private static IList <CodexEntry> LoadEntries(string lockKey, string tableKey,
                                                      string category)
        {
            var entries = new List <CodexEntry>(32);

            lock (PSharedData.GetLock(lockKey)) {
                var table = PSharedData.GetData <IList <string> >(tableKey);
                if (table != null)
                {
                    foreach (string dir in table)
                    {
#if DEBUG
                        PUtil.LogDebug("Loaded codex entries from directory: {0}".F(dir));
#endif
                        string[] codexFiles = new string[0];
                        try {
                            // List codex data files in the codex directory
                            codexFiles = Directory.GetFiles(dir, CODEX_FILES);
                        } catch (UnauthorizedAccessException ex) {
                            PUtil.LogExcWarn(ex);
                        } catch (IOException ex) {
                            PUtil.LogExcWarn(ex);
                        }
                        var widgetTagMappings = Traverse.Create(typeof(CodexCache)).
                                                GetField <List <Tuple <string, Type> > >("widgetTagMappings");
                        foreach (string str in codexFiles)
                        {
                            try {
                                string filename   = str;
                                var    codexEntry = YamlIO.LoadFile <CodexEntry>(filename, PUtil.
                                                                                 YamlParseErrorCB, widgetTagMappings);
                                if (codexEntry != null)
                                {
                                    codexEntry.category = category;
                                    entries.Add(codexEntry);
                                }
                            } catch (IOException ex) {
                                PUtil.LogException(ex);
                            }
                        }