コード例 #1
0
        internal void OnEarlyInitialize()
        {
            // offload reading and parsing XML files to a worker thread
            var loadingTask = Task.Run(UpdateFeatureDefLoader.LoadUpdateFeatureDefNodes);

            // this should put us just before backstory loading in the DoPlayLoad cycle
            // we inject our defs early on to take advantage of the stock translation injection system
            LongEventHandler.ExecuteWhenFinished(ResolveAndInjectNewsDefs);

            void ResolveAndInjectNewsDefs()
            {
                // this must be done synchronously to avoid creating potential race conditions with other mods
                try {
                    if (!loadingTask.Wait(TimeSpan.FromSeconds(3)))
                    {
                        throw new InvalidOperationException("XML loading did not resolve in time");
                    }
                    var(nodes, errors) = loadingTask.Result;
                    UpdateFeatureDefLoader.HandleDefLoadingErrors(errors);
                    UpdateFeatureDefLoader.ResolveAndInjectUpdateFeatureDefs(nodes);
                } catch (Exception e) {
                    HugsLibController.Logger.Error("Failed to load UpdateFeatureDefs: " + e);
                }
            }
        }
コード例 #2
0
 IEnumerable <UpdateFeatureDef> IUpdateFeaturesDevActions.ReloadAllUpdateFeatureDefs()
 {
     UpdateFeatureDefLoader.ReloadAllUpdateFeatureDefs();
     return(DefDatabase <UpdateFeatureDef> .AllDefs);
 }