Exemplo n.º 1
0
        protected bool AreIngredientsAvailable(IndustryProcess process)
        {
            foreach (var ingred in process.Inputs)
            {
                if (!IsResourceAvailable(ingred.Key, ingred.Amount))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private static bool TryConvertProcess(JSONIndustryProcess jsonProcess, out IndustryProcess process)
        {
            process = new IndustryProcess()
            {
                ProcessingTime = jsonProcess.Time
            };

            process.Inputs = new IndustryResource[jsonProcess.Inputs.Count];
            int i = 0;

            foreach (var kvp in jsonProcess.Inputs)
            {
                if (TryConvertResource(kvp.Key, kvp.Value, out IndustryResource resource))
                {
                    process.Inputs[i] = resource;
                }
                else
                {
                    DVIndustry.ModEntry.Logger.Critical("Invalid process input");
                    return(false);
                }

                i++;
            }

            process.Outputs = new IndustryResource[jsonProcess.Outputs.Count];
            i = 0;
            foreach (var kvp in jsonProcess.Outputs)
            {
                if (TryConvertResource(kvp.Key, kvp.Value, out IndustryResource resource))
                {
                    process.Outputs[i] = resource;
                }
                else
                {
                    DVIndustry.ModEntry.Logger.Critical("Invalid process output");
                    return(false);
                }

                i++;
            }

            return(true);
        }
Exemplo n.º 3
0
        public static bool LoadConfig(string configPath)
        {
            JSONIndustryConfigList config;

            try
            {
                string json = File.ReadAllText(configPath);
                config = JsonConvert.DeserializeObject <JSONIndustryConfigList>(json);
            }
            catch (Exception ex)
            {
                DVIndustry.ModEntry.Logger.Critical($"Failed to open industry config file at \"{configPath}\":");
                DVIndustry.ModEntry.Logger.Error(ex.Message);
                return(false);
            }

            if (config == null)
            {
                DVIndustry.ModEntry.Logger.Critical($"Failed to parse industry config file at \"{configPath}\":");
                return(false);
            }

            foreach (JSONIndustryConfig jsonIndustry in config.Industries)
            {
                var processList = new IndustryProcess[jsonIndustry.Processes.Length];
                for (int i = 0; i < jsonIndustry.Processes.Length; i++)
                {
                    if (TryConvertProcess(jsonIndustry.Processes[i], out IndustryProcess process))
                    {
                        processList[i] = process;
                    }
                    else
                    {
                        DVIndustry.ModEntry.Logger.Critical($"Error loading processes for industry at {jsonIndustry.StationId}");
                        return(false);
                    }
                }

                IndustryConfigs.Add(jsonIndustry.StationId, processList);
            }

            return(true);
        }