Example #1
0
 void LogInfo(string message, bool sameLine)
 {
     if (debug)
     {
         Log.Info(message, sameLine);
     }
 }
Example #2
0
        public void Initialize(IManager manager, string ipcIdentifier)
        {
            POVs = new Dictionary <string, Texture2D>();

            FileSystem = new FileSystem();
            Settings   = new Settings("povstatus");
            Logger     = new Logger("pov")
            {
                WriteToConsole = true
            };

            var currentPov = Settings.GetOrCreate("CurrentPOV", string.Empty);

            foreach (var pngFile in FileSystem.GetFiles("."))
            {
                if (!pngFile.EndsWith(".png"))
                {
                    continue;
                }

                var tex = new Texture2D(256, 256);

                using (var fs = FileSystem.OpenFile(pngFile))
                {
                    byte[] b = new byte[0];

                    using (BinaryReader br = new BinaryReader(fs))
                        b = br.ReadBytes((int)fs.Length);

                    tex.LoadImage(b);
                }
                POVs.Add(Path.GetFileNameWithoutExtension(pngFile), tex);
                Logger.Info($"Loaded POV decal '{pngFile}'");
            }

            if (POVs.Count == 0)
            {
                Logger.Warning("No POVs found. Stopping.");
                return;
            }

            if (string.IsNullOrEmpty(currentPov) || !POVs.ContainsKey(currentPov))
            {
                currentPov = POVs.First(x => true).Key;

                Settings["CurrentPOV"] = currentPov;
                Settings.Save();
            }

            var menuTree = new MenuTree("it.32-b.vdd.CustomPOVImageMenu", "Customizable wheel POV")
            {
                new ListBox <Texture2D>(MenuDisplayMode.Both, "it.32-b.vdd.CustomPOVImageMenu.POVs", "Available POVs")
                .WithEntries(POVs)
                .WithGetter(() => POVs[Settings.GetItem <string>("CurrentPOV")])
                .WithSetter((tex) =>
                {
                    foreach (var kvp in POVs)
                    {
                        if (tex == kvp.Value)
                        {
                            Settings["CurrentPOV"] = kvp.Key;
                            break;
                        }
                    }

                    POVChangeTriggered = true;
                })
                .WithDescription("Select one of available wheel POVs.")
            };

            manager.Menus.AddMenu(MenuDisplayMode.Both, menuTree, "Change how your wheels bling.");

            HarmonyInstance = HarmonyInstance.Create("it.32-b.vdd.CustomPOVImage");
            HarmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
        }