Exemplo n.º 1
0
    public static void MergeInto(this CreatureSpawnerConfigurationFile source, CreatureSpawnerConfigurationFile target)
    {
        if (source.Subsections is null)
        {
            return;
        }

        foreach (var sourceLocation in source.Subsections)
        {
            if (target.Subsections.ContainsKey(sourceLocation.Key))
            {
                var targetSpawner = target.Subsections[sourceLocation.Key];

                foreach (var sourceSpawner in sourceLocation.Value.Subsections)
                {
                    if (!sourceSpawner.Value.TemplateEnabled.Value)
                    {
#if DEBUG
                        Log.LogDebug($"Local spawner '{sourceSpawner.Value.SectionKey}' template is disabled. Skipping merge.");
#endif
                        continue;
                    }

                    if (targetSpawner.Subsections.TryGetValue(sourceSpawner.Key, out var targetConfig))
                    {
                        if (targetConfig.TemplateEnabled.Value)
                        {
                            Log.LogWarning($"Overlapping local spawner configs for {sourceSpawner.Value.SectionKey}, overriding existing.");
                        }

#if DEBUG
                        Log.LogWarning("\t Override");
                        Log.LogWarning("\t" + sourceSpawner.Value.PrefabName);
                        Log.LogWarning("\t" + sourceSpawner.Value.Enabled);
                        Log.LogWarning("\t" + sourceSpawner.Value.TemplateEnabled);

                        Log.LogWarning("\t Existing");
                        Log.LogWarning("\t" + targetConfig.PrefabName);
                        Log.LogWarning("\t" + targetConfig.Enabled);
                        Log.LogWarning("\t" + targetConfig.TemplateEnabled);
#endif
                    }

                    targetSpawner.Subsections[sourceSpawner.Key] = sourceSpawner.Value;
                }
            }
            else
            {
                target.Subsections[sourceLocation.Key] = sourceLocation.Value;
            }
        }
    }
    public static void LoadAllConfigurations()
    {
        Stopwatch stopwatch = Stopwatch.StartNew();

        CreatureSpawnerConfig = LoadCreatureSpawnerConfiguration();

        stopwatch.Stop();

        Log.LogInfo("Config loading took: " + stopwatch.Elapsed);
        if (stopwatch.Elapsed > TimeSpan.FromSeconds(5) &&
            !ConfigurationManager.GeneralConfig.StopTouchingMyConfigs.Value)
        {
            Log.LogInfo("Long loading time detected. Consider setting \"StopTouchingMyConfigs=true\" in spawn_that.cfg to improve loading speed.");
        }
    }