コード例 #1
0
        public void ReadConfigEcf(string contentPath, string activeScenario, string blockMappingFile, IModApi modApi)
        {
            ContentPath         = contentPath;
            ScenarioContentPath = string.IsNullOrEmpty(activeScenario) ? null : Path.Combine(contentPath, "Scenarios", activeScenario, "Content");

            Log($"EmpyrionScripting ReadConfigEcf: ContentPath:{contentPath} Scenario:{activeScenario} -> {ScenarioContentPath}", LogLevel.Message);

            var timer = Stopwatch.StartNew();

            ReadBlockMappingFile(blockMappingFile, modApi);
            ReadEcfFiles();
            MergeEcfFiles();
            BuildIdAndNameAccess();
            FlatEcfConfigData();
            CalcBlockRessources();
            timer.Stop();

            if (EmpyrionScripting.Configuration?.Current?.LogLevel == LogLevel.Debug)
            {
                BlockIdMapping.ForEach(B => Log($"ReadBlockMappingFile: '{B.Key}' -> {B.Value}]", LogLevel.Debug));
                Templates_Ecf.Blocks.ForEach(B => Log($"Templates_Ecf.Blocks: '{B.Name}[{B.Values?.FirstOrDefault(A => A.Key == "Id").Value}] '{B.Values?.FirstOrDefault(A => A.Key == "Name").Value}'", LogLevel.Debug));
                BlocksConfig_Ecf.Blocks.ForEach(B => Log($"BlocksConfig_Ecf.Blocks: '{B.Name}[{B.Values?.FirstOrDefault(A => A.Key == "Id").Value}] '{B.Values?.FirstOrDefault(A => A.Key == "Name").Value}'", LogLevel.Debug));
                ItemsConfig_Ecf.Blocks.ForEach(B => Log($"ItemsConfig_Ecf.Blocks: '{B.Name}[{B.Values?.FirstOrDefault(A => A.Key == "Id").Value}] '{B.Values?.FirstOrDefault(A => A.Key == "Name").Value}'", LogLevel.Debug));
                Configuration_Ecf.Blocks.ForEach(B => Log($"Configuration_Ecf.Blocks: '{B.Name}[{B.Values?.FirstOrDefault(A => A.Key == "Id").Value}] '{B.Values?.FirstOrDefault(A => A.Key == "Name").Value}'", LogLevel.Debug));
                Flat_Config_Ecf.Blocks.ForEach(B => Log($"Flat_Config_Ecf.Blocks: '{B.Name}[{B.Values?.FirstOrDefault(A => A.Key == "Id").Value}] '{B.Values?.FirstOrDefault(A => A.Key == "Name").Value}'", LogLevel.Debug));
                FlatConfigBlockById.ForEach(B => Log($"FlatConfigBlockById: '{B.Key}' -> {B.Value?.Values?.FirstOrDefault(A => A.Key == "Name").Value}]", LogLevel.Debug));
                FlatConfigBlockByName.ForEach(B => Log($"FlatConfigBlockByName: '{B.Key}' -> {B.Value?.Values?.FirstOrDefault(A => A.Key == "Name").Value}]", LogLevel.Debug));
                ResourcesForBlockById.ForEach(B => Log($"ResourcesForBlockById: [{B.Key}] {(EmpyrionScripting.ConfigEcfAccess.FlatConfigBlockById.TryGetValue(B.Key, out var data) ? data.Values["Name"] : "")} -> {B.Value.Aggregate("", (r, i) => $"{r}\n{i.Value}: [{i.Key}] {(EmpyrionScripting.ConfigEcfAccess.FlatConfigBlockById.TryGetValue(i.Key, out var data) ? data.Values["Name"] : "")}")}", LogLevel.Message));
                ParentBlockName.ForEach(B => Log($"ParentBlockName: {B.Key} -> {B.Value}", LogLevel.Debug));
            }

            Log($"EmpyrionScripting Configuration_Ecf: #{Configuration_Ecf?.Blocks?.Count} BlockById: #{ConfigBlockById?.Count} BlockByName: #{ConfigBlockByName?.Count} ParentBlockNames: #{ParentBlockName.Count} BlockIdMapping:[{BlockIdMapping?.Count}] {blockMappingFile} takes:{timer.Elapsed}", LogLevel.Message);
        }
コード例 #2
0
        private void GenerateParentBlockList()
        {
            FlatConfigBlockByName
            .Where(B => B.Value?.Values?.ContainsKey("ChildBlocks") == true)
            .ForEach(B => B.Value.Values["ChildBlocks"].ToString()
                     .Split(',').Select(N => N.Trim())
                     .ForEach(N => { if (!ParentBlockName.ContainsKey(N))
                                     {
                                         ParentBlockName.Add(N, B.Key);
                                     }
                              })
                     );

            FlatConfigBlockByName
            .Where(B => B.Value?.Values?.ContainsKey("ParentBlocks") == true)
            .ForEach(B => B.Value.Values["ParentBlocks"].ToString()
                     .Split(',').Select(N => N.Trim())
                     .ForEach(N => {
                if (!B.Value.Values.TryGetValue("Name", out var name) ||
                    !FlatConfigBlockByName.TryGetValue(N, out var parentBlock) ||
                    !parentBlock.Values.TryGetValue("AllowPlacingAt", out var placeableAt))
                {
                    return;
                }

                placeableAt.ToString().Split(',').Select(N => N.Trim())
                .ForEach(P => { if (!ParentBlockName.ContainsKey(P + name.ToString()))
                                {
                                    ParentBlockName.Add(P + name.ToString(), N);
                                }
                         });
            })
                     );
        }