Esempio n. 1
0
        public static Contract TryParseContract(ConfigBlock block)
        {
            if (block.content == null || block.content.Count == 0)
            {
                return(null);
            }

            var c = new Contract();

            if (!c.FetchContract(block))
            {
                return(null);
            }
            Console.WriteLine($"Parsed contract {c.Name}");
            return(c);
        }
Esempio n. 2
0
        private bool FetchContract(ConfigBlock block)
        {
            List <string[]> cfg = block.content;

            for (int i = 0; i < cfg.Count; i++)
            {
                string[] line = cfg[i];
                if (line.Length == 2)
                {
                    string field = line[0];
                    string value = line[1];

                    field = field.RemoveOperator();

                    switch (field)
                    {
                    case "title":
                        if (!genericTitle)
                        {
                            Title = value;
                        }
                        break;

                    case "genericTitle":
                        Title        = value;
                        genericTitle = true;
                        break;

                    case "name":
                        Name = value;
                        break;
                    }
                }
            }

            foreach (ConfigBlock innerBlock in block.childrenBlocks)
            {
                GetDataFromBlock(innerBlock);
                if (innerBlock.type == BlockType.DataExpand)
                {
                    return(false);   // cannot parse expanded contracts yet
                }
            }

            return(!string.IsNullOrWhiteSpace(Name));
        }
Esempio n. 3
0
 private void GetDataFromBlock(ConfigBlock block)
 {
     if (block.type == BlockType.DataExpand && block.content[0][0] == "type" && block.content[0][1] == "CelestialBody")
     {
         string paramName = block.content[1][0];
         string bodiesKey = block.content[1][1];
         // TODO: try to properly expand scansat contracts:
         //  1) fetch the body names from Groups.cfg using bodiesKey
         //  2) return a separate Contract for every body
         //  3) in every Contract, replace all occurrences of paramName with body name
         //  4) append $".{body name}" to the name of every Contract
     }
     else if (block.type == BlockType.DataExpand && block.content[0][0] == "type" && block.content[0][1] == "string")
     {
         // probably expanding based on scansat experiment type?
     }
 }
Esempio n. 4
0
        private void FetchContract(List <string[]> cfg)
        {
            for (int i = 0; i < cfg.Count; i++)
            {
                string[] line = cfg[i];
                if (line.Length == 2)
                {
                    string field = line[0];
                    string value = line[1];

                    field = field.RemoveOperator();

                    switch (field)
                    {
                    case "title":
                        if (!genericTitle)
                        {
                            Title = value;
                        }
                        break;

                    case "genericTitle":
                        Title        = value;
                        genericTitle = true;
                        break;

                    case "name":
                        Name = value;
                        break;
                    }
                }
                else if (line[0].Contains("{"))
                {
                    var block = ConfigBlock.ExtractBlock(cfg, cfg[i - 1][0], ref i, true);

                    GetDataFromBlock(block);
                }
            }
        }
Esempio n. 5
0
 private void GetDataFromBlock(ConfigBlock block)
 {
 }