Exemple #1
0
        public static BusinessmateConfiguration LoadFromFile()
        {
            BusinessmateConfiguration configuration = Directory.Exists(Businessmate.ConfigurationDirectory) && File.Exists(ConfigurationFile) ? JsonUtility.FromJson <BusinessmateConfiguration>(File.ReadAllText(ConfigurationFile)) : null;

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

            configuration.BusinessDictionary = new Dictionary <string, BusinessConfiguration>();

            if (configuration.BusinessConfigurations != null)
            {
                foreach (BusinessConfiguration businessConfiguration in configuration.BusinessConfigurations)
                {
                    configuration.BusinessDictionary.Add(businessConfiguration.BusinessID, businessConfiguration);
                }
            }

            configuration.CooldownDictionary = new Dictionary <string, CooldownConfiguration>();

            if (configuration.CooldownConfigurations != null)
            {
                foreach (CooldownConfiguration cooldownConfiguration in configuration.CooldownConfigurations)
                {
                    configuration.CooldownDictionary.Add(cooldownConfiguration.CooldownID, cooldownConfiguration);
                }
            }

            return(configuration);
        }
        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));
        }