예제 #1
0
        public static string WriteNML(CargoScheme scheme)
        {
            var outputDir     = $"{Config.NMLOutputDirectory}\\{scheme.SchemeName}";
            var outputPath    = $"{outputDir}\\cargomod_{scheme.SchemeName}.nml";
            var outputFileNml = $"cargomod_{scheme.SchemeName}.nml";
            var outputFileGrf = $"cargomod_{scheme.SchemeName.Replace(" ", "_")}.grf";

            PrepareNMLFile(scheme);
            WriteNMLCalculation(scheme, new PerishableCargoDefinition());
            WriteNMLCalculation(scheme, new BulkCargoDefinition());
            foreach (var cargoDef in scheme.CargoDefinitions)
            {
                WriteNMLUserParams(scheme, cargoDef);
            }
            foreach (var cargoDef in scheme.CargoDefinitions)
            {
                WriteNMLCargoItem(scheme, cargoDef);
            }

            var res = StartProcess(outputDir, "NMLC", $"-c --verbosity=3 --grf \"{outputFileGrf}\" \"{outputFileNml}\"");

            var ottdDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\OpenTTD\\newgrf";

            File.Copy($"{outputDir}\\{outputFileGrf}", $"{ottdDocs}\\{outputFileGrf}", true);

            return(res);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public static void PrepareNMLFile(CargoScheme scheme)
        {
            var outputDir         = $"{Config.NMLOutputDirectory}\\{scheme.SchemeName}";
            var templateDir       = $"{Config.NMLTemplateDirectory}";
            var schemeTemplateDir = $"{templateDir}\\{scheme.SchemeName}";
            var templateFile      = $"{templateDir}\\cargomod_{scheme.SchemeName}.nml";
            var outputPath        = $"{outputDir}\\cargomod_{scheme.SchemeName}.nml";

            Directory.CreateDirectory($"{Config.NMLOutputDirectory}");
            Directory.CreateDirectory(outputDir);

            if (Directory.Exists(schemeTemplateDir))
            {
                foreach (var directory in Directory.GetDirectories(schemeTemplateDir))
                {
                    Directory.CreateDirectory(directory.Replace(schemeTemplateDir, outputDir));
                }
                foreach (var file in Directory.GetFiles(schemeTemplateDir, "*.*", SearchOption.AllDirectories))
                {
                    File.Copy(file, file.Replace(schemeTemplateDir, outputDir), true);
                }
            }
            var content = "";

            if (File.Exists(templateFile))
            {
                content = File.ReadAllText(templateFile);
            }
            File.WriteAllText(outputPath, content);
        }
 private void CargoScheme_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count == 0)
     {
         return;
     }
     CurrentScheme = e.AddedItems[0] as CargoScheme;
     GraphCargoes();
 }
        public RenameCargoScheme(CargoScheme scheme, string message = "")
        {
            InitializeComponent();

            Title = $"{Title}{(!string.IsNullOrWhiteSpace(message) ? $" - {message}" : "")}";

            SchemeName.SetBinding(TextBox.TextProperty, new Binding("SchemeName")
            {
                Source = scheme, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
            });
        }
예제 #7
0
        public static void WriteNMLCargoItem(CargoScheme scheme, CargoDefinition cargoDef)
        {
            var outputDir         = $"{Config.NMLOutputDirectory}\\{scheme.SchemeName}";
            var templateDir       = $"{Config.NMLTemplateDirectory}";
            var schemeTemplateDir = $"{templateDir}\\{scheme.SchemeName}";
            var templateFile      = $"{templateDir}\\cargoItem.nml";
            var outputPath        = $"{outputDir}\\cargomod_{scheme.SchemeName}.nml";

            var contents = File.ReadAllText(templateFile);

            contents = contents
                       .Replace("{{TypeName}}", cargoDef.TypeName.Replace(" ", "_"))
                       .Replace("{{ItemID}}", cargoDef.ItemID.ToString())
                       .Replace("{{PriceFactor}}", cargoDef.PriceFactor.ToString())
                       .Replace("{{CargoSprite}}", cargoDef.CargoSprite)
                       .Replace("{{CargoIcon}}", cargoDef.CargoSprite == "NEW_CARGO_SPRITE" ? $"{cargoDef.CargoIcon}; " : "");

            File.AppendAllText(outputPath, contents);
        }
        private void AddCargoSchemesToDropdown(CargoScheme trySelectScheme = null)
        {
            CargoSchemeDropdown.Items.Clear();
            foreach (var def in DefaultDefinitions.Defaults)
            {
                CargoSchemeDropdown.Items.Add(def);
            }

            var files = Directory.GetFiles(Config.CargoSchemesDirectory, "*.xml");

            foreach (var file in files)
            {
                try {
                    var def = CargoScheme.Load(file);
                    CargoSchemeDropdown.Items.Add(def);
                } catch (Exception ex) {
                    var fileName = new FileInfo(file).Name;
                    var wnd      = new ExceptionWindow(ex)
                    {
                        Title = $"Something went wrong loading Cargo Scheme file '{fileName}'"
                    };
                    wnd.ShowDialog();
                }
            }
            if (trySelectScheme != null)
            {
                foreach (var item in CargoSchemeDropdown.Items)
                {
                    var scheme = item as CargoScheme;
                    if (scheme == null || scheme.SchemeName != trySelectScheme.SchemeName)
                    {
                        continue;
                    }

                    CargoSchemeDropdown.SelectedItem = item;
                    return;
                }
            }
            CargoSchemeDropdown.SelectedIndex = 0;
        }