コード例 #1
0
ファイル: Process.cs プロジェクト: JonnyOThan/Kerbalism
        public Process(ConfigNode node)
        {
            name      = Lib.ConfigValue(node, "name", string.Empty);
            modifiers = Lib.Tokenize(Lib.ConfigValue(node, "modifier", string.Empty), ',');

            // check that name is specified
            if (name.Length == 0)
            {
                throw new Exception("skipping unnamed process");
            }

            inputs = new Dictionary <string, double>();
            foreach (string input in node.GetValues("input"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(input, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed input on process " + name);
                }
                string input_res  = tok[0];
                double input_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (input_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (Lib.GetDefinition(input_res) == null)
                {
                    throw new Exception("resource " + input_res + " doesn't exist for process " + name);
                }

                // record input
                inputs[input_res] = input_rate;
            }

            outputs = new Dictionary <string, double>();
            foreach (string output in node.GetValues("output"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed output on process " + name);
                }
                string output_res  = tok[0];
                double output_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (output_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (Lib.GetDefinition(output_res) == null)
                {
                    throw new Exception("resource " + output_res + " doesn't exist for process " + name);
                }

                // record output
                outputs[output_res] = output_rate;
            }

            cures = new Dictionary <string, double>();
            foreach (string output in node.GetValues("cures"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed cure on process " + name);
                }
                string cure      = tok[0];
                double cure_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (cure.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // record cure
                cures[cure] = cure_rate;
            }

            // parse dump specs
            dump = new DumpSpecs(Lib.ConfigValue(node, "dump", "false"), Lib.ConfigValue(node, "dump_valve", "false"));
        }
コード例 #2
0
ファイル: Process.cs プロジェクト: judicator/Kerbalism
        public Process(ConfigNode node)
        {
            name      = Lib.ConfigValue(node, "name", string.Empty);
            title     = Lib.ConfigValue(node, "title", name);
            broker    = ResourceBroker.GetOrCreate(name, ResourceBroker.BrokerCategory.Converter, title);
            modifiers = Lib.Tokenize(Lib.ConfigValue(node, "modifier", string.Empty), ',');

            // check that name is specified
            if (name.Length == 0)
            {
                throw new Exception("skipping unnamed process");
            }

            // fix for https://github.com/JadeOfMaar/RationalResources/issues/25
            bool skip_resources_validity_check = Lib.ConfigValue(node, "skip_resources_validity_check", false);

            inputs = new Dictionary <string, double>();
            foreach (string input in node.GetValues("input"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(input, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed input on process " + name);
                }
                string input_res  = tok[0];
                double input_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (input_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (skip_resources_validity_check || Lib.GetDefinition(input_res) == null)
                {
                    throw new Exception("resource " + input_res + " doesn't exist for process " + name);
                }

                // record input
                inputs[input_res] = input_rate;
            }

            outputs = new Dictionary <string, double>();
            foreach (string output in node.GetValues("output"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed output on process " + name);
                }
                string output_res  = tok[0];
                double output_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (output_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (skip_resources_validity_check || Lib.GetDefinition(output_res) == null)
                {
                    throw new Exception("resource " + output_res + " doesn't exist for process " + name);
                }

                // record output
                outputs[output_res] = output_rate;
            }

            cures = new Dictionary <string, double>();
            foreach (string output in node.GetValues("cures"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed cure on process " + name);
                }
                string cure      = tok[0];
                double cure_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (cure.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // record cure
                cures[cure] = cure_rate;
            }

            // parse dump specs
            dump = new DumpSpecs(Lib.ConfigValue(node, "dump", "false"), Lib.ConfigValue(node, "dump_valve", "false"));
        }