Beispiel #1
0
        /// <summary>
        /// Called when the component is activated
        /// </summary>
        void Start()
        {
            // Get all types who extend a Tweaker Interface and add them to the storage
            AssemblyLoader.loadedAssemblies.TypeOperation(type =>
            {
                if (typeof(IPQSModTweaker).IsAssignableFrom(type) && !type.IsAbstract)
                {
                    IPQSModTweaker tweaker = (IPQSModTweaker)Activator.CreateInstance(type);
                    PQSModTweakers.Add(tweaker);

                    // Get the config
                    String configNodeName = tweaker.GetConfig();
                    if (!ConfigCache.ContainsKey(configNodeName))
                    {
                        ConfigNode config = GameDatabase.Instance.GetConfigs(configNodeName)[0].config;
                        ConfigCache.Add(configNodeName, config);
                    }
                }
                if (typeof(ICelestialBodyTweaker).IsAssignableFrom(type) && !type.IsAbstract)
                {
                    ICelestialBodyTweaker tweaker = (ICelestialBodyTweaker)Activator.CreateInstance(type);
                    CBTweakers.Add(tweaker);

                    // Get the config
                    String configNodeName = tweaker.GetConfig();
                    if (!ConfigCache.ContainsKey(configNodeName))
                    {
                        ConfigNode config = GameDatabase.Instance.GetConfigs(configNodeName)[0].config;
                        ConfigCache.Add(configNodeName, config);
                    }
                }
                if (typeof(IPQSTweaker).IsAssignableFrom(type) && !type.IsAbstract)
                {
                    IPQSTweaker tweaker = (IPQSTweaker)Activator.CreateInstance(type);
                    PQSTweakers.Add(tweaker);

                    // Get the config
                    String configNodeName = tweaker.GetConfig();
                    if (!ConfigCache.ContainsKey(configNodeName))
                    {
                        ConfigNode config = GameDatabase.Instance.GetConfigs(configNodeName)[0].config;
                        ConfigCache.Add(configNodeName, config);
                    }
                }
            });

            // Get the blacklist
            bodyBlacklist = GameDatabase.Instance.GetConfigs("PD_BODY_BLACKLIST")[0].config;

            // Register the callback for manipulating the system
            GameEvents.onGameSceneSwitchRequested.Add(OnGameSceneSwitchRequested);
            GameEvents.onLevelWasLoaded.Add(OnLevelWasLoaded);
        }
        /// <summary>
        /// Save the given config and perform if necessary a live update of the module with the config entries.
        /// </summary>
        /// <param name="configuration">The configuration which should be saved.</param>
        /// <param name="liveUpdate">Should a live update of the configuration be performed?</param>
        /// <param name="name">Name of the configuration</param>
        public void SaveConfiguration(IConfig configuration, bool liveUpdate, string name)
        {
            var configType = configuration.GetType();

            lock (ConfigCache)
            {
                if (liveUpdate && ConfigCache.ContainsKey(name) && typeof(IUpdatableConfig).IsAssignableFrom(configType))
                {
                    _liveUpdater.UpdateLive(configType, ConfigCache[name].Instance, configuration);
                }
                else
                {
                    ConfigCache[name] = new CacheEntry
                    {
                        Type     = configType,
                        Instance = configuration,
                    };
                }
            }

            SaveSharedConfigs(configuration, liveUpdate);
            WriteToFile(configuration, name);
        }