예제 #1
0
        public static StaticsDB Load(IEnumerable <TracableStream> dataSources)
        {
            //TODO(v0.8) update IKON with HasNext with tag
            //TODO(v0.8) support nested subformulas
            var subformulas = new Dictionary <string, Formula>();

            foreach (var source in dataSources)
            {
                try
                {
                    var queue = new Parser(source.Stream).ParseAll();

                    while (queue.CountOf("Subformulas") > 0)
                    {
                        var data = queue.Dequeue("Subformulas").To <IkonComposite>();
                        foreach (var key in data.Keys)
                        {
                            subformulas[key] = data[key].To <Formula>();
                        }
                    }
                }
                catch (IOException e)
                {
                    throw new IOException(source.SourceInfo, e);
                }
                catch (FormatException e)
                {
                    throw new FormatException(source.SourceInfo, e);
                }
            }
            subformulas = ExpressionParser.ResloveSubformulaNesting(subformulas);

            var db = new StaticsDB();

            foreach (var source in dataSources)
            {
                var parser = new Parser(source.Stream, subformulas);
                try
                {
                    foreach (var data in parser.ParseAll().Select(x => x.Value.To <IkonComposite>()))
                    {
                        switch ((string)data.Tag)
                        {
                        case "Building":
                            db.Buildings.Add(data[GeneralCodeKey].To <string>(), loadBuilding(data));
                            break;

                        case "ColonyFormulas":
                            db.ColonyFormulas = loadColonyFormulas(data);
                            break;

                        case "Constructable":
                            db.Constructables.Add(loadConstructable(data));
                            break;

                        case "DevelopmentFocusOptions":
                            db.DevelopmentFocusOptions.AddRange(loadFocusOptions(data));
                            break;

                        case "DevelopmentTopic":
                            db.DevelopmentTopics.Add(loadDevelopmentTopic(data));
                            break;

                        case "Subformulas":
                            //TODO(v0.8) remove after IKON update
                            break;

                        case "Natives":
                            db.loadNatives(data.To <IkonComposite>());
                            break;

                        case "PlanetFormulas":
                            var formulaSet = loadPlanetFormulas(data);
                            db.PlanetForumlas[formulaSet.Key] = formulaSet.Value;
                            break;

                        case "PlayerFormulas":
                            db.PlayerFormulas = loadPlayerFormulas(data);
                            break;

                        case "SystemPolicy":
                            db.Policies.Add(loadPolicy(data));
                            break;

                        case "PredefinedDesign":
                            db.PredeginedDesigns.Add(loadDesignTemplate(data));
                            break;

                        case "ResearchTopic":
                            db.ResearchTopics.Add(loadResearchTopic(data));
                            break;

                        case "ShipFormulas":
                            db.ShipFormulas = loadShipFormulas(data);
                            break;

                        case "StarFormulas":
                            db.StellarisFormulas = loadStarFormulas(data);
                            break;

                        case "PlanetTrait":
                            db.PlanetTraits.Add(data[GeneralCodeKey].To <string>(), loadPlanetTrait(data));
                            break;

                        case "StarTrait":
                            db.StarTraits.Add(data[GeneralCodeKey].To <string>(), loadStarTrait(data));
                            break;

                        case ArmorTag:
                            db.Armors.Add(data[GeneralCodeKey].To <string>(), loadArmor(data));
                            break;

                        case HullTag:
                            db.Hulls.Add(data[GeneralCodeKey].To <string>(), loadHull(data));
                            break;

                        case IsDriveTag:
                            db.IsDrives.Add(data[GeneralCodeKey].To <string>(), loadIsDrive(data));
                            break;

                        case MissionEquipmentTag:
                            db.MissionEquipment.Add(data[GeneralCodeKey].To <string>(), loadMissionEquiptment(data));
                            break;

                        case ReactorTag:
                            db.Reactors.Add(data[GeneralCodeKey].To <string>(), loadReactor(data));
                            break;

                        case SensorTag:
                            db.Sensors.Add(data[GeneralCodeKey].To <string>(), loadSensor(data));
                            break;

                        case ShieldTag:
                            db.Shields.Add(data[GeneralCodeKey].To <string>(), loadShield(data));
                            break;

                        case SpecialEquipmentTag:
                            db.SpecialEquipment.Add(data[GeneralCodeKey].To <string>(), loadSpecialEquiptment(data));
                            break;

                        case ThrusterTag:
                            db.Thrusters.Add(data[GeneralCodeKey].To <string>(), loadThruster(data));
                            break;

                        default:
                            throw new FormatException("Invalid game data object with tag " + data.Tag);
                        }
                    }
                }
                catch (IOException e)
                {
                    throw new IOException(source.SourceInfo, e);
                }
                catch (FormatException e)
                {
                    throw new FormatException(source.SourceInfo, e);
                }
            }

            foreach (var research in db.ResearchTopics)
            {
                for (int level = 0; level <= research.MaxLevel; level++)
                {
                    foreach (var unlock in research.Unlocks[level])
                    {
                        db.DevelopmentRequirements[unlock] = new DevelopmentRequirement(research.IdCode, level);
                    }
                }
            }

            return(db);
        }
예제 #2
0
        public static StaticsDB Load(IEnumerable <TracableStream> dataSources)
        {
            var db = new StaticsDB();

            foreach (var source in dataSources)
            {
                var parser = new Parser(source.Stream);
                try
                {
                    foreach (var data in parser.ParseAll().Select(x => x.Value.To <IkonComposite>()))
                    {
                        switch ((string)data.Tag)
                        {
                        case BuildingTag:
                            db.Buildings.Add(data[GeneralCodeKey].To <string>(), loadBuilding(data));
                            break;

                        case ColonizersTag:
                            db.loadColonizers(data.To <IkonComposite>());
                            break;

                        case ColonyFormulasTag:
                            db.ColonyFormulas = loadColonyFormulas(data);
                            break;

                        case ConstructableTag:
                            db.Constructables.Add(loadConstructable(data));
                            break;

                        case DevelopmentFocusesTag:
                            db.DevelopmentFocusOptions.AddRange(loadFocusOptions(data));
                            break;

                        case DevelopmentTag:
                            db.DevelopmentTopics.Add(loadDevelopmentTopic(data));
                            break;

                        case NativesTag:
                            db.loadNatives(data.To <IkonComposite>());
                            break;

                        case PlayerFormulasTag:
                            db.PlayerFormulas = loadPlayerFormulas(data);
                            break;

                        case PredefinedDesignTag:
                            db.PredeginedDesigns.Add(loadPredefDesign(data));
                            break;

                        case ResearchTag:
                            db.ResearchTopics.Add(loadResearchTopic(data));
                            break;

                        case ShipFormulasTag:
                            db.ShipFormulas = loadShipFormulas(data);
                            break;

                        case TraitTag:
                            db.Traits.Add(data[GeneralCodeKey].To <string>(), loadTrait(data));
                            break;

                        case ArmorTag:
                            db.Armors.Add(data[GeneralCodeKey].To <string>(), loadArmor(data));
                            break;

                        case HullTag:
                            db.Hulls.Add(data[GeneralCodeKey].To <string>(), loadHull(data));
                            break;

                        case IsDriveTag:
                            db.IsDrives.Add(data[GeneralCodeKey].To <string>(), loadIsDrive(data));
                            break;

                        case MissionEquipmentTag:
                            db.MissionEquipment.Add(data[GeneralCodeKey].To <string>(), loadMissionEquiptment(data));
                            break;

                        case ReactorTag:
                            db.Reactors.Add(data[GeneralCodeKey].To <string>(), loadReactor(data));
                            break;

                        case SensorTag:
                            db.Sensors.Add(data[GeneralCodeKey].To <string>(), loadSensor(data));
                            break;

                        case ShieldTag:
                            db.Shields.Add(data[GeneralCodeKey].To <string>(), loadShield(data));
                            break;

                        case SpecialEquipmentTag:
                            db.SpecialEquipment.Add(data[GeneralCodeKey].To <string>(), loadSpecialEquiptment(data));
                            break;

                        case ThrusterTag:
                            db.Thrusters.Add(data[GeneralCodeKey].To <string>(), loadThruster(data));
                            break;

                        default:
                            throw new FormatException("Invalid game data object with tag " + data.Tag);
                        }
                    }
                }
                catch (IOException e)
                {
                    throw new IOException(source.SourceInfo, e);
                }
                catch (FormatException e)
                {
                    throw new FormatException(source.SourceInfo, e);
                }
            }

            foreach (var research in db.ResearchTopics)
            {
                for (int level = 0; level <= research.MaxLevel; level++)
                {
                    foreach (var unlock in research.Unlocks[level])
                    {
                        db.DevelopmentRequirements[unlock] = new DevelopmentRequirement(research.IdCode, level);
                    }
                }
            }

            return(db);
        }