Esempio n. 1
0
        protected static void ParseWorld(WorldCollection worlds, Dictionary <string, string> dict, string line, int lineNumber, ErrorLogger errors)
        {
            try
            {
                FieldChecker checker = new FieldChecker(dict, errors, lineNumber, line);
                World        world   = new World();
                world.Hex        = checker.Check("Hex", HEX_REGEX);
                world.Name       = checker.Check("Name");
                world.UWP        = checker.Check("UWP", UWP_REGEX);
                world.Remarks    = checker.Check(new string[] { "Remarks", "Trade Codes", "Comments" });
                world.Importance = checker.Check(new string[] { "{Ix}", "{ Ix }", "Ix" }, options: CheckOptions.Optional);
                world.Economic   = checker.Check(new string[] { "(Ex)", "( Ex )", "Ex" }, options: CheckOptions.Optional);
                world.Cultural   = checker.Check(new string[] { "[Cx]", "[ Cx ]", "Cx" }, options: CheckOptions.Optional);
                world.Nobility   = checker.Check(new string[] { "N", "Nobility" }, NOBILITY_REGEX, CheckOptions.EmptyIfDash | CheckOptions.Optional);
                world.Bases      = checker.Check(new string[] { "B", "Bases" }, BASES_REGEX, CheckOptions.EmptyIfDash);
                world.Zone       = checker.Check(new string[] { "Z", "Zone" }, ZONE_REGEX, CheckOptions.EmptyIfDash);
                world.PBG        = checker.Check("PBG", PBG_REGEX);
                world.Allegiance = checker.Check(new string[] { "A", "Al", "Allegiance" },
                                                 // TODO: Allow unofficial sectors to have locally declared allegiances.
                                                 a => a.Length != 4 || SecondSurvey.IsKnownT5Allegiance(a));
                world.Stellar = checker.Check(new string[] { "Stellar", "Stars", "Stellar Data" }, STARS_REGEX, CheckOptions.Warning);

                byte w;
                if (byte.TryParse(checker.Check(new string[] { "W", "Worlds" }, options: CheckOptions.Optional), NumberStyles.Integer, CultureInfo.InvariantCulture, out w))
                {
                    world.Worlds = w;
                }

                int ru;
                if (int.TryParse(checker.Check("RU", options: CheckOptions.Optional), NumberStyles.Integer | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out ru))
                {
                    world.ResourceUnits = ru;
                }

                // Cleanup known placeholders
                if (world.Name == world.Name.ToUpperInvariant() && world.IsHi)
                {
                    world.Name = Util.FixCapitalization(world.Name);
                }

                if (worlds[world.X, world.Y] != null && errors != null)
                {
                    errors.Warning("Duplicate World", lineNumber, line);
                }

                if (!checker.HadError)
                {
                    worlds[world.X, world.Y] = world;
                }
            }
            catch (Exception e)
            {
                if (errors != null)
                {
                    errors.Error("Parse Error: " + e.Message, lineNumber, line);
                }
                else
                {
                    throw;
                }
                //throw new Exception(string.Format("UWP Parse Error in line {0}:\n{1}\n{2}", lineNumber, e.Message, line));
            }
        }
Esempio n. 2
0
        protected static void ParseWorld(WorldCollection worlds, Dictionary <string, string> dict, string line, int lineNumber, ErrorLogger?errors)
        {
            try
            {
                FieldChecker checker = new FieldChecker(dict, errors, lineNumber, line);
                World        world   = new World()
                {
                    Hex        = checker.Check("Hex", HEX_REGEX) ?? "",
                    Name       = checker.Check("Name") ?? "",
                    UWP        = checker.Check("UWP", UWP_REGEX) ?? "",
                    Remarks    = checker.Check(new string[] { "Remarks", "Trade Codes", "Comments" }, options: CheckOptions.EmptyIfDash) ?? "",
                    Importance = checker.Check(new string[] { "{Ix}", "{ Ix }", "Ix" }, options: CheckOptions.Optional),
                    Economic   = checker.Check(new string[] { "(Ex)", "( Ex )", "Ex" }, options: CheckOptions.Optional),
                    Cultural   = checker.Check(new string[] { "[Cx]", "[ Cx ]", "Cx" }, options: CheckOptions.Optional),
                    Nobility   = checker.Check(new string[] { "N", "Nobility" }, NOBILITY_REGEX, CheckOptions.EmptyIfDash | CheckOptions.Optional),
                    Bases      = checker.Check(new string[] { "B", "Bases" }, BASES_REGEX, CheckOptions.EmptyIfDash) ?? "",
                    Zone       = checker.Check(new string[] { "Z", "Zone" }, ZONE_REGEX, CheckOptions.EmptyIfDash) ?? "",
                    PBG        = checker.Check("PBG", PBG_REGEX) ?? "",
                    Allegiance = checker.Check(new string[] { "A", "Al", "Allegiance" },
                                               a => a.Length != 4 || SecondSurvey.IsKnownT5Allegiance(a),
                                               worlds.IsUserData ? CheckOptions.Warning : CheckOptions.Default,
                                               " - 4-character codes are allowed in custom data but not submitted data") ?? "",
                    Stellar = checker.Check(new string[] { "Stellar", "Stars", "Stellar Data" }, STARS_REGEX, CheckOptions.Warning) ?? ""
                };
                if (byte.TryParse(checker.Check(new string[] { "W", "Worlds" }, options: CheckOptions.Optional), NumberStyles.Integer, CultureInfo.InvariantCulture, out byte w))
                {
                    world.Worlds = w;
                }

                if (int.TryParse(checker.Check("RU", options: CheckOptions.Optional), NumberStyles.Integer | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out int ru))
                {
                    world.ResourceUnits = ru;
                }

                // Cleanup known placeholders
                if (world.Name == world.Name.ToUpperInvariant() && world.IsHi)
                {
                    world.Name = world.Name.FixCapitalization();
                }

                if (worlds[world.X, world.Y] != null)
                {
                    errors?.Warning("Duplicate World", lineNumber, line);
                }

                if (!checker.HadError)
                {
                    worlds[world.X, world.Y] = world;
                }

                if (errors != null)
                {
                    world.Validate(errors, lineNumber, line);

                    if (!T5StellarData.IsValid(world.Stellar))
                    {
                        errors.Warning("Invalid stellar data: " + world.Stellar, lineNumber, line);
                    }
                }
            }
            catch (Exception e) when(errors != null)
            {
                errors.Error("Parse Error: " + e.Message, lineNumber, line);
                //throw new Exception($"UWP Parse Error in line {lineNumber}:\n{e.Message}\n{line}");
            }
        }
Esempio n. 3
0
        protected static void ParseWorld(WorldCollection worlds, StringDictionary dict, string line, int lineNumber, ErrorLogger errors)
        {
            try
            {
                FieldChecker checker = new FieldChecker(dict, errors, lineNumber, line);
                World world = new World();
                world.Hex = checker.Check("Hex", HEX_REGEX);
                world.Name = dict["Name"];
                world.UWP = checker.Check("UWP", UWP_REGEX);
                world.Remarks = checker.Check(new string[] { "Remarks", "Trade Codes", "Comments" });
                world.Importance = checker.Check(new string[] { "{Ix}", "{ Ix }", "Ix" });
                world.Economic = checker.Check(new string[] { "(Ex)", "( Ex )", "Ex" });
                world.Cultural = checker.Check(new string[] { "[Cx]", "[ Cx ]", "Cx" });
                world.Nobility = checker.Check(new string[] { "N", "Nobility" }, NOBILITY_REGEX, CheckOptions.EmptyIfDash);
                world.Bases = checker.Check(new string[] { "B", "Bases" }, BASES_REGEX, CheckOptions.EmptyIfDash);
                world.Zone = checker.Check(new string[] { "Z", "Zone" }, ZONE_REGEX, CheckOptions.EmptyIfDash);
                world.PBG = checker.Check("PBG", PBG_REGEX);
                world.Allegiance = checker.Check(new string[] { "A", "Al", "Allegiance" },
                    // TODO: Allow unofficial sectors to have locally declared allegiances.
                    a => a.Length != 4 || SecondSurvey.IsKnownT5Allegiance(a));
                world.Stellar = checker.Check(new string[] { "Stellar", "Stars", "Stellar Data" }, STARS_REGEX, CheckOptions.Warning);

                int w;
                if (Int32.TryParse(checker.Check(new string[] { "W", "Worlds" }), NumberStyles.Integer, CultureInfo.InvariantCulture, out w))
                    world.Worlds = w;

                int ru;
                if (Int32.TryParse(dict["RU"], NumberStyles.Integer | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out ru))
                    world.ResourceUnits = ru;

                // Cleanup known placeholders
                if (world.Name == world.Name.ToUpperInvariant() && world.IsHi)
                    world.Name = Util.FixCapitalization(world.Name);

                if (worlds[world.X, world.Y] != null && errors != null)
                    errors.Warning("Duplicate World", lineNumber, line);

                if (!checker.HadError)
                {
                    worlds[world.X, world.Y] = world;
                }
            }
            catch (Exception e)
            {
                errors.Error("Parse Error: " + e.Message, lineNumber, line);
                //throw new Exception(String.Format("UWP Parse Error in line {0}:\n{1}\n{2}", lineNumber, e.Message, line));
            }
        }