Пример #1
0
            static void Prefix(SleepText __instance)
            {
                if (!modEnabled.Value)
                {
                    return;
                }

                if (lastFontName != fontName.Value) // call when config changes
                {
                    lastFontName = fontName.Value;
                    Dbgl($"new font {fontName.Value}");
                    Font font = GetFont(fontName.Value, 20);
                    if (font == null)
                    {
                        Dbgl($"new font not found");
                    }
                    else
                    {
                        currentFont = font;
                    }
                }
                if (currentFont != null)
                {
                    __instance.m_dreamField.font = currentFont;
                }

                __instance.m_dreamField.fontSize = fontSize.Value;
                __instance.m_dreamField.color    = textColor.Value;
            }
Пример #2
0
        private static void LoadDreams()
        {
            if (!Hud.instance)
            {
                return;
            }

            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CustomDreamTexts");

            if (!Directory.Exists(path))
            {
                Dbgl($"Directory {path} does not exist! Creating.");
                Directory.CreateDirectory(path);
            }
            string defaultFolder = Path.Combine(path, "Default");

            SleepText  sleepText  = Hud.instance.m_sleepingProgress.GetComponent <SleepText>();
            DreamTexts dreamTexts = sleepText.m_dreamTexts;

            if (!Directory.Exists(defaultFolder))
            {
                Dbgl($"Directory {defaultFolder} does not exist! Creating.");
                Directory.CreateDirectory(defaultFolder);

                List <string> localizedDreams = new List <string>();
                for (int i = 0; i < dreamTexts.m_texts.Count; i++)
                {
                    DreamTexts.DreamText dt = dreamTexts.m_texts[i];
                    localizedDreams.Add(dt.m_text + ": " + Localization.instance.Localize(dt.m_text));
                    string json = JsonUtility.ToJson(dt);
                    File.WriteAllText(Path.Combine(defaultFolder, (i + 1) + ".json"), json);
                }
                File.WriteAllLines(Path.Combine(defaultFolder, "localized.txt"), localizedDreams);
            }

            var files = Directory.GetFiles(path, "*.txt");

            foreach (string file in files)
            {
                string name   = Path.GetFileNameWithoutExtension(file);
                string folder = Path.Combine(path, name);
                if (Directory.Exists(folder))
                {
                    continue;
                }
                Directory.CreateDirectory(folder);
                string[] lines = File.ReadAllLines(file);
                for (int i = 0; i < lines.Length; i++)
                {
                    string[] parts = lines[i].Split('|');
                    string   text;
                    if (parts[0].Contains("^"))
                    {
                        string[] quoteAuthor = parts[0].Split('^');
                        text = quoteAuthor[0] + quoteAuthorSeparator.Value + quoteAuthor[1];
                    }
                    else
                    {
                        text = parts[0];
                    }

                    float chance = parts.Length > 1 && parts[1].Length > 0 ? float.Parse(parts[1]) : defaultChance.Value;

                    DreamTexts.DreamText dt = new DreamTexts.DreamText()
                    {
                        m_chanceToDream = chance,
                        m_text          = text
                    };
                    string json = JsonUtility.ToJson(dt);
                    File.WriteAllText(Path.Combine(folder, (i + 1) + ".json"), json);
                }
            }

            if (currentDreamFolder.Value != "Default")
            {
                string dreamFolder = Path.Combine(path, currentDreamFolder.Value);
                if (!Directory.Exists(dreamFolder))
                {
                    Dbgl("Dream folder does not exist!");
                    return;
                }
                sleepText.m_dreamTexts.m_texts.Clear();
                int    count     = 1;
                string thisDream = Path.Combine(dreamFolder, (count++) + ".json");
                while (File.Exists(thisDream))
                {
                    string dream = File.ReadAllText(thisDream);
                    sleepText.m_dreamTexts.m_texts.Add(JsonUtility.FromJson <DreamTexts.DreamText>(dream));
                    thisDream = Path.Combine(dreamFolder, (count++) + ".json");
                }
                Dbgl($"Loaded {sleepText.m_dreamTexts.m_texts.Count} dreams");
            }
        }