Пример #1
0
        public static void SaveDefaultFile(Business[] businesses, Cooldown[] cooldowns)
        {
            if (SaveFileExists(true))
            {
                return;
            }

            BusinessmateSave defaultSave = new BusinessmateSave {
                BusinessSaves = new BusinessSave[businesses.Length], CooldownSaves = new CooldownSave[cooldowns.Length]
            };

            for (int i = 0; i < businesses.Length; ++i)
            {
                businesses[i].Save = new BusinessSave {
                    BusinessID = businesses[i].BusinessID
                };
                businesses[i].SaveBusiness();
                defaultSave.BusinessSaves[i] = businesses[i].Save;
            }

            for (int i = 0; i < cooldowns.Length; ++i)
            {
                cooldowns[i].Save = new CooldownSave {
                    CooldownID = cooldowns[i].CooldownID
                };
                cooldowns[i].SaveCooldown();
                defaultSave.CooldownSaves[i] = cooldowns[i].Save;
            }

            defaultSave.SaveToFile();
        }
Пример #2
0
        public static BusinessmateSave LoadFromFile()
        {
            BusinessmateSave save = Directory.Exists(Businessmate.SaveDirectory) && File.Exists(SaveFile) ? JsonUtility.FromJson <BusinessmateSave>(File.ReadAllText(SaveFile)) : null;

            if (save == null)
            {
                return(save);
            }

            save.BusinessDictionary = new Dictionary <string, BusinessSave>();

            if (save.BusinessSaves != null)
            {
                foreach (BusinessSave businessSave in save.BusinessSaves)
                {
                    save.BusinessDictionary.Add(businessSave.BusinessID, businessSave);
                }
            }

            save.CooldownDictionary = new Dictionary <string, CooldownSave>();

            if (save.CooldownSaves != null)
            {
                foreach (CooldownSave cooldownSave in save.CooldownSaves)
                {
                    save.CooldownDictionary.Add(cooldownSave.CooldownID, cooldownSave);
                }
            }

            return(save);
        }
Пример #3
0
        public void LoadData()
        {
            Configuration = BusinessmateConfiguration.LoadFromFile() ?? new BusinessmateConfiguration();

            BusinessmateSave.SaveDefaultFile(businesses, cooldowns);
            Save = BusinessmateSave.LoadFromFile() ?? new BusinessmateSave();

            foreach (Business business in businesses)
            {
                if (business != null && Configuration != null && Save != null)
                {
                    business.LoadBusiness(Configuration.GetBusiness(business.BusinessID), Save.GetBusiness(business.BusinessID));
                }
            }

            foreach (Cooldown cooldown in cooldowns)
            {
                if (cooldown != null && Configuration != null && Save != null)
                {
                    cooldown.LoadCooldown(Configuration.GetCooldown(cooldown.CooldownID), Save.GetCooldown(cooldown.CooldownID));
                }
            }

            Array.Sort(businesses, (i1, i2) => - i1.Configuration.Priority.CompareTo(i2.Configuration.Priority));
            Array.Sort(cooldowns, (i1, i2) => - i1.Configuration.Priority.CompareTo(i2.Configuration.Priority));
        }