Exemple #1
0
    private static void UpdateConfigInitiator(List <string> sheetNames, GenerationParam param)
    {
        CodeBuilder builder = new CodeBuilder();

        if (!string.IsNullOrEmpty(param.Package))
        {
            builder.AppendLine($"namespace {param.Package}")
            .AppendLine("{").AddIndent();
        }
        {
            builder.AppendLine("public static class ConfigInitiator")
            .AppendLine("{").AddIndent();
            {
                builder.AppendLine("public static void InitAllConfig()")
                .AppendLine("{").AddIndent();
                {
                    for (int i = 0; i < sheetNames.Count; i++)
                    {
                        builder.AppendLine($"{sheetNames[i]}.Init();");
                    }
                }
                builder.SubtractIndent().AppendLine("}");
            }
            builder.SubtractIndent().AppendLine("}");
        }
        if (!string.IsNullOrEmpty(param.Package))
        {
            builder.SubtractIndent().AppendLine("}");
        }
        Utility.SaveToFile(builder.ToString(), $"{param.OutDir}/ConfigInitiator.cs");
    }
Exemple #2
0
 void OnEnable()
 {
     if (ms_GenerationParamOnEnable != null && Instance != null)
     {
         Generate(ms_GenerationParamOnEnable.renderPipeline, ms_GenerationParamOnEnable.renderingMode, ms_GenerationParamOnEnable.enabledFeatures);
         ms_GenerationParamOnEnable = null;
     }
 }
Exemple #3
0
        public static Shader Generate(RenderPipeline rp, RenderingMode rm, EnabledFeatures enabledFeatures)
        {
            // The instance might not be accessible yet, when called from Config.OnEnable for instance if the Config is enabled before the ShaderGenerator.
            // In this case we don't generate the shader right away, we store the parameters instead and we'll generate the shader in ShaderGenerator.OnEnable.
            if (Instance == null)
            {
                ms_GenerationParamOnEnable = new GenerationParam {
                    renderPipeline = rp, renderingMode = rm, enabledFeatures = enabledFeatures
                };
                return(null);
            }

            return(new GenShader(rp, rm, enabledFeatures).Generate());
        }
 public RequiredGenerationParam(GenerationParam param, int index)
 {
     this.param = param;
     this.Index = index;
 }
Exemple #5
0
        public void Generate(ExcelSheet excelSheet, List <BaseField> fields, GenerationParam param)
        {
            CodeBuilder builder = new CodeBuilder();

            //生成 custom 文件
            if (!File.Exists($"{param.OutDir}/{excelSheet.ClassName}Custom.cs"))
            {
                CodeBuilder customBuilder = new CodeBuilder();
                if (!string.IsNullOrEmpty(param.Package))
                {
                    customBuilder.AppendLine($"namespace {param.Package}").AppendLine("{").AddIndent();
                }
                customBuilder.AppendLine($"public partial class {excelSheet.ClassName}")
                .AppendLine("{").AddIndent();
                customBuilder.SubtractIndent().AppendLine("}");
                if (!string.IsNullOrEmpty(param.Package))
                {
                    customBuilder.SubtractIndent().AppendLine("}");
                }
                Utility.SaveToFile(customBuilder.ToString(), $"{param.OutDir}/{excelSheet.ClassName}Custom.cs");
            }

            if (!string.IsNullOrEmpty(param.Package))
            {
                builder.AppendLine($"namespace {param.Package}")
                .AppendLine("{").AddIndent();
            }
            {
                builder.AppendLine($"public partial class {excelSheet.ClassName}")
                .AppendLine("{").AddIndent();

                {
                    //Data
                    builder.AppendLine($"public static System.Collections.Generic.List<Row> s_rows {{  private set; get; }}");
                    //Deserialization
                    builder.AppendLine("public static void Init()")
                    .AppendLine("{").AddIndent();
                    {
                        builder.AppendLine($"string data = System.IO.File.ReadAllText(\"{param.DataDir}/{excelSheet.ClassName}{param.From}\");");
                        builder.AppendLine("s_rows = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<Row>>(data);");

                        if (excelSheet.PrimaryFieldsList.Count > 0)
                        {
                            builder.AppendLine("foreach (var row in s_rows)")
                            .AppendLine("{").AddIndent();

                            foreach (var primaryFields in excelSheet.PrimaryFieldsList)
                            {
                                if (primaryFields.Count == 0)
                                {
                                    continue;
                                }

                                builder.AppendLine("{").AddIndent();
                                {
                                    string mapFieldName = $"s_{Utility.ToCamelCase(primaryFields.ConvertAll((v) => v.Name).ToArray())}Map";
                                    for (int i = 0; i < primaryFields.Count - 1; i++)
                                    {
                                        BaseField keyField          = primaryFields[i];
                                        string    mapValueType      = FieldFullMapName(primaryFields, i + 1);
                                        string    mapValueFieldName = $"{Utility.ToCamelCase(primaryFields.ConvertAll((v) => v.Name).ToArray(), i + 1)}Map";
                                        builder.AppendLine($"{mapValueType} {mapValueFieldName};");
                                        builder.AppendLine($"if (!{mapFieldName}.TryGetValue(row.{keyField.Name}, out {mapValueFieldName}))")
                                        .AppendLine("{").AddIndent();
                                        builder.AppendLine($"{mapValueFieldName} = new {mapValueType}();");
                                        builder.AppendLine($"{mapFieldName}.Add(row.{keyField.Name}, {mapValueFieldName});");
                                        builder.SubtractIndent().AppendLine("}");
                                        mapFieldName = mapValueFieldName;
                                    }
                                    builder.AppendLine($"{mapFieldName}.Add(row.{primaryFields[primaryFields.Count - 1].Name}, row);");
                                }
                                builder.SubtractIndent().AppendLine("}");
                            }

                            builder.SubtractIndent().AppendLine("}");
                        }
                    }
                    builder.SubtractIndent().AppendLine("}").AppendLine();

                    //PrimaryKey
                    foreach (var primaryFields in excelSheet.PrimaryFieldsList)
                    {
                        if (primaryFields.Count == 0)
                        {
                            continue;
                        }

                        string mapTypeName  = FieldFullMapName(primaryFields);
                        string mapFieldName = $"s_{Utility.ToCamelCase(primaryFields.ConvertAll((v) => v.Name).ToArray())}Map";
                        builder.AppendLine($"private static {mapTypeName} {mapFieldName} = new {mapTypeName}();");
                        builder.Append($"public static Row FindBy{Utility.ToPascalCase(primaryFields.ConvertAll((v) => v.Name).ToArray())}(");
                        for (int i = 0; i < primaryFields.Count; i++)
                        {
                            if (i != 0)
                            {
                                builder.Append(", ", true);
                            }
                            builder.Append($"{FieldFullTypeName(primaryFields[i])} {primaryFields[i].Name.ToLower()}", true);
                        }
                        builder.AppendLine(")", true)
                        .AppendLine("{").AddIndent();
                        {
                            for (int i = 0; i < primaryFields.Count - 1; i++)
                            {
                                BaseField keyField          = primaryFields[i];
                                string    mapValueType      = FieldFullMapName(primaryFields, i + 1);
                                string    mapValueFieldName = $"{Utility.ToCamelCase(primaryFields.ConvertAll((v) => v.Name).ToArray(), i + 1)}Map";
                                builder.AppendLine($"{mapValueType} {mapValueFieldName};");
                                builder.AppendLine($"if (!{mapFieldName}.TryGetValue({primaryFields[i].Name.ToLower()}, out {mapValueFieldName}))")
                                .AppendLine("{").AddIndent();
                                builder.AppendLine($"throw new System.Exception($\"Config Not Found:`{{{keyField.Name.ToLower()}}}`\");");
                                builder.SubtractIndent().AppendLine("}");
                                mapFieldName = mapValueFieldName;
                            }
                            builder.AppendLine("Row retVal;");
                            builder.AppendLine($"if (!{mapFieldName}.TryGetValue({primaryFields[primaryFields.Count - 1].Name.ToLower()}, out retVal))")
                            .AppendLine("{").AddIndent();
                            builder.AppendLine($"throw new System.Exception($\"Config Not Found:`{{{primaryFields[primaryFields.Count - 1].Name.ToLower()}}}`\");");
                            builder.SubtractIndent().AppendLine("}");
                            builder.AppendLine("return retVal;");
                        }
                        builder.SubtractIndent().AppendLine("}");
                    }

                    //Row
                    builder.AppendLine("public class Row")
                    .AppendLine("{").AddIndent();
                    {
                        foreach (var field in fields)
                        {
                            builder.AppendLine("/// <summary>")
                            .AppendLine($"/// {field.Description}")
                            .AppendLine("/// </summary>");
                            builder.AppendLine($"public {FieldFullTypeName(field)} {field.Name} {{ get; set; }}");
                        }
                    }
                    builder.SubtractIndent().AppendLine("}").AppendLine();
                }
                builder.SubtractIndent().AppendLine("}");
            }
            if (!string.IsNullOrEmpty(param.Package))
            {
                builder.SubtractIndent().AppendLine("}");
            }

            Utility.SaveToFile(builder.ToString(), $"{param.OutDir}/{excelSheet.ClassName}.cs");
        }
Exemple #6
0
 public virtual void OnPostGenerate(List <ExcelSheet> sheets, GenerationParam param)
 {
 }
 // Возвращает все значения параметра генерации p из тех сборок,
 // для которых значения параметров генерации соответствуют данным значениям (values).
 // (из сборок выбранных по имени модели).
 public override List<string> GetParameterValues(Dictionary<GenerationParam, string> values,
     GenerationParam p)
 {
     List<string> result = new List<string>();
     foreach (string resultName in this.assembliesID)
     {
         ResultAssembly r = this.resultStorage.Load(this.assemblies.
             Find(i => i.Name == resultName).ID);
         Dictionary<GenerationParam, string>.KeyCollection keys = values.Keys;
         bool b = true;
         foreach (GenerationParam key in keys)
         {
             if (r.GenerationParams.Count != 0)
                 b = b && (r.GenerationParams[key].ToString() == values[key]);
             else
             {
                 b = false;
                 break;
             }
         }
         if (b)
         {
             result.Add(r.GenerationParams[p].ToString());
         }
     }
     result.Sort();
     result = result.Distinct().ToList();
     return result;
 }
 // Возвращает все значения данного параметра генерации из всех сборок .
 // (выбранных по имени модели).
 public override List<string> GetParameterValues(GenerationParam p)
 {
     List<string> result = new List<string>();
     foreach (string resultName in this.assembliesID)
     {
         ResultAssembly r = this.resultStorage.Load(this.assemblies.
             Find(i => i.Name == resultName).ID);
         if (r.GenerationParams.Count != 0)
             result.Add(r.GenerationParams[p].ToString());
         else
             continue;
     }
     result.Sort();
     result = result.Distinct().ToList();
     return result;
 }
 // Возвращает значение данного параметра генерации для данного job-а.
 public override string GetParameterValue(string jobName, GenerationParam p)
 {
     try
     {
         ResultAssembly result = this.resultStorage.Load(this.assemblies.
             Find(i => i.Name == jobName).ID);
         return result.GenerationParams[p].ToString();
     }
     // Такая ситуация возникает при наличии XML-а с результатом статической генерации.
     catch (KeyNotFoundException)
     {
         return "Generation Parameter Error!";
     }
 }
 // Возвращает все значения параметра генерации p из тех сборок,
 // для которых значения параметров генерации соответствуют данным значениям (values).
 // (из сборок выбранных по имени модели).
 public abstract List<string> GetParameterValues(Dictionary<GenerationParam, string> values,
     GenerationParam p);
 // Возвращает все значения данного параметра генерации из всех сборок .
 // (выбранных по имени модели).
 public abstract List<string> GetParameterValues(GenerationParam p);
 // Возвращает значение данного параметра генерации для данного job-а.
 public abstract string GetParameterValue(string jobName, GenerationParam p);
 // Возвращает все значения данного параметра генерации из всех сборок .
 // (выбранных по имени модели).
 public override List<string> GetParameterValues(GenerationParam p)
 {
     return this.storage.GetParameterValuesByID(AvailableModels.models[this.modelName], (int)p);
 }
 // Возвращает значение данного параметра генерации для данного job-а.
 public override string GetParameterValue(string jobName, GenerationParam p)
 {
     return this.storage.GetParameterValueByID(jobName, (int)p);
 }
 // Возвращает все значения параметра генерации p из тех сборок,
 // для которых значения параметров генерации соответствуют данным значениям (values).
 // (из сборок выбранных по имени модели).
 public override List<string> GetParameterValues(Dictionary<GenerationParam, string> values, 
     GenerationParam p)
 {
     Dictionary<int, string> idValues = new Dictionary<int, string>();
     foreach(GenerationParam param in values.Keys)
     {
         idValues.Add((int)param, values[param]);
     }
     return this.storage.GetParameterValuesByID(AvailableModels.models[this.modelName],
         idValues, (int)p);
 }