public static void WriteNMLUserParams(CargoScheme scheme, CargoDefinition cargoDef) { var outputDir = $"{Config.NMLOutputDirectory}\\{scheme.SchemeName}"; var templateDir = $"{Config.NMLTemplateDirectory}"; var schemeTemplateDir = $"{templateDir}\\{scheme.SchemeName}"; var templateFile = $"{templateDir}\\perishableCargoUserParams.nml"; var outputPath = $"{outputDir}\\cargomod_{scheme.SchemeName}.nml"; var registers = perishableRegisters; if (cargoDef.GetType() == typeof(BulkCargoDefinition)) { registers = bulkRegisters; templateFile = $"{templateDir}\\bulkCargoUserParams.nml"; } var contents = File.ReadAllText(templateFile); foreach (var register in registers) { var prop = cargoDef.GetType().GetProperty(register); if (prop == null) { continue; } var value = prop.GetValue(cargoDef).ToString(); contents = contents.Replace($"{{{{{register}}}}}", value); } contents = contents.Replace("{{TypeName}}", cargoDef.TypeName.Replace(" ", "_")); File.AppendAllText(outputPath, contents); }
private void CreateControls() { var propsWithAttrib = definition.GetType().GetProperties().Where(prop => prop.IsDefined(typeof(DynamicBindingAttribute), false)); propsWithAttrib = propsWithAttrib .OrderBy( x => (x.GetCustomAttribute(typeof(DynamicBindingAttribute)) as DynamicBindingAttribute)?.GroupSortOrder ?? 0 ).ThenBy( x => (x.GetCustomAttribute(typeof(DynamicBindingAttribute)) as DynamicBindingAttribute)?.ItemSortOrder ?? 0 ); var lastGroup = int.MinValue; foreach (var prop in propsWithAttrib) { var attrib = prop.GetCustomAttribute(typeof(DynamicBindingAttribute)) as DynamicBindingAttribute; if (attrib == null) { throw new NullReferenceException("This should technically be impossible but... Property with attribute DynamicBindingAttribute did not have the attribute."); } if (attrib.GroupSortOrder != lastGroup) { CreateGroupHeader(attrib.Group); lastGroup = attrib.GroupSortOrder; } CreateBinding(attrib.DisplayName, prop.Name, prop.PropertyType, attrib); } }
public static void WriteNMLCalculation(CargoScheme scheme, CargoDefinition cargoDef) { var outputDir = $"{Config.NMLOutputDirectory}\\{scheme.SchemeName}"; var templateDir = $"{Config.NMLTemplateDirectory}"; var schemeTemplateDir = $"{templateDir}\\{scheme.SchemeName}"; var templateFile = $"{templateDir}\\perishableCargoCalculations.nml"; var outputPath = $"{outputDir}\\cargomod_{scheme.SchemeName}.nml"; var registers = perishableRegisters; if (cargoDef.GetType() == typeof(BulkCargoDefinition)) { registers = bulkRegisters; templateFile = $"{templateDir}\\bulkCargoCalculations.nml"; } var contents = File.ReadAllText(templateFile); for (var i = 0; i < registers.Length; i++) { var register = registers[i]; contents = contents.Replace($"{{{{{register}}}}}", $"LOAD_TEMP({i})"); } File.AppendAllText(outputPath, contents); }