コード例 #1
0
        public override void Entry(params object[] objects)
        {
            PlayerEvents.InventoryChanged += OnInventoryChanged;
            PlayerEvents.LoadedGame       += OnGameLoaded;

            // save learned gift tastes at the end of the day, when the game saves
            TimeEvents.OnNewDay += (object sender, EventArgsNewDay e) =>
            {
                // only save once per day (newDay will be true the second time, and on new games)
                if (!Game1.newDay && null != GiftManager)
                {
                    GiftManager.UpdateGiftData();
                }
            };

            ModConfig = new GiftTrackerConfig().InitializeConfig(BaseConfigPath);

            Command.RegisterCommand("list_gifttastes", "List all learned gift tastes").CommandFired += list_gifttastes;

            if (!Directory.Exists(DirectoryName))
            {
                Directory.CreateDirectory(DirectoryName);
            }

            Log.Out("Gift Tracker entry");
        }
コード例 #2
0
        public GiftTasteManager(GiftTrackerConfig ModConfig, string GiftDataPath)
        {
            this.ModConfig   = ModConfig;
            GiftDataFilepath = GiftDataPath;

            // fill Data
            if (!File.Exists(GiftDataFilepath))
            {
                try
                {
                    File.Create(GiftDataFilepath);
                }
                catch (Exception ex)
                {
                    Log.Error("Gift tracker: could not create save file");
                    Log.Error(ex.Message);
                }
                GenerateGiftTasteDictionary();
            }
            else
            {
                try
                {
                    Data = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <GiftTaste, HashSet <string> > > >(File.ReadAllText(GiftDataFilepath));
                }
                catch (Exception ex)
                {
                    Log.Error("Gift Tracker: Error loading gift data");
                    Log.Error(ex.Message);
                }

                // could happen if the file was created for a save
                // but not written to at the end of the day
                if (Data == null || Data.Count == 0)
                {
                    GenerateGiftTasteDictionary();
                }
            }
        }