Пример #1
0
        public RybStarPopulator()
        {
            TaggableQueue <object, IkadnBaseObject> data;

            using (var parser = new IkonParser(new StreamReader(MapsFolder + ParametersFile)))
                data = parser.ParseAll();

            var starTypes = new List <StarType>();

            while (data.CountOf(StarTypeKey) > 0)
            {
                var starTypeData = data.Dequeue(StarTypeKey).To <IkonComposite>();
                starTypes.Add(new StarType(
                                  extractColor(starTypeData[StarColorKey].To <IkonArray>()),
                                  starTypeData[StarMinRadiationKey].To <double>(),
                                  starTypeData[StarMaxRadiationKey].To <double>()
                                  ));
            }
            this.starTypes = starTypes.ToArray();

            this.climateParameter = new SelectorParameter(LanguageContext, "climate", new Dictionary <int, string>()
            {
                { 0, "hostileClimate" },
                { 1, "normalClimate" },
                { 2, "paradiseClimate" },
            }, 1);
        }
Пример #2
0
        public static void StartConditionsLoader(IEnumerable <TracableStream> dataSources)
        {
            var conditionList = new List <StartingConditions>();

            foreach (var source in dataSources)
            {
                var parser = new IkonParser(source.Stream);
                try
                {
                    foreach (var item in parser.ParseAll())
                    {
                        conditionList.Add(new StartingConditions(item.Value.To <IkonComposite>()));
                    }
                }
                catch (IOException e)
                {
                    throw new IOException(source.SourceInfo, e);
                }
                catch (FormatException e)
                {
                    throw new FormatException(source.SourceInfo, e);
                }
            }

            Starts = conditionList.ToArray();
        }
Пример #3
0
        public static void OrganizationsLoader(IEnumerable <TracableStream> dataSources)
        {
            var list = new List <Organization>();

            foreach (var source in dataSources)
            {
                var parser = new IkonParser(source.Stream);
                try
                {
                    foreach (var item in parser.ParseAll())
                    {
                        var data = item.Value.To <IkonComposite>();
                        list.Add(new Organization(
                                     data[OrganizationNameKey].To <string>(),
                                     data[OrganizationDescriptionKey].To <string>()
                                     ));
                    }
                }
                catch (IOException e)
                {
                    throw new IOException(source.SourceInfo, e);
                }
                catch (FormatException e)
                {
                    throw new FormatException(source.SourceInfo, e);
                }
            }

            list.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));
            Organizations = list.ToArray();
        }
        public void Initialize(string dataPath)
        {
            TaggableQueue <object, IkadnBaseObject> data;

            using (var parser = new IkonParser(new StreamReader(dataPath + ParametersFile)))
                data = parser.ParseAll();

            degreesParameter = loadDegrees(data);
        }
Пример #5
0
        public void Load(SavedGameInfo savedGameData, IEnumerable <TracableStream> staticDataSources)
        {
            IkonComposite saveRawData;

            using (var parser = new IkonParser(savedGameData.FileInfo.OpenText()))
                saveRawData = parser.ParseAll().Dequeue(MainGame.SaveGameTag).To <IkonComposite>();

            this.gameController.LoadGame(GameBuilder.LoadGame(saveRawData, staticDataSources, GameController.GetStateManager()));
        }
        public ProximityLanesBuilder()
        {
            TaggableQueue <object, IkadnBaseObject> data;

            using (var parser = new IkonParser(new StreamReader(MapsFolder + ParametersFile)))
                data = parser.ParseAll();

            degreesParameter = loadDegrees(data);
        }
Пример #7
0
        public void Load(SavedGameInfo savedGameData, IEnumerable <NamedStream> staticDataSources)
        {
            if (savedGameData == null)
            {
                throw new ArgumentNullException(nameof(savedGameData));
            }

            IkonComposite saveRawData;

            using (var parser = new IkonParser(savedGameData.FileInfo.OpenText()))
                saveRawData = parser.ParseAll().Dequeue(MainGame.SaveGameTag).To <IkonComposite>();

            this.gameController.LoadGame(GameBuilder.LoadGame(saveRawData, staticDataSources, GameController.GetStateManager()));
        }
        protected override TaggableQueue <object, IkadnBaseObject> loadData()
        {
            TaggableQueue <object, IkadnBaseObject> data;

            if (File.Exists(SettingsFilePath))
            {
                using (var parser = new IkonParser(new StreamReader(SettingsFilePath)))
                    data = parser.ParseAll();
            }
            else
            {
                data = null;
            }

            return(data);
        }
Пример #9
0
        public void Initialize(string dataPath)
        {
            LabeledQueue <object, IkadnBaseObject> data;

            using (var parser = new IkonParser(new StreamReader(dataPath + ParametersFile)))
                data = parser.ParseAll();

            var constants = data.Dequeue(ConstantsKey).To <IkonComposite>();

            this.starDistance        = constants[StarDistanceKey].To <double>();
            this.homeSystemDistance  = constants[HomeSystemDistance].To <double>();
            this.emptyPositionsRatio = constants[EmptyPositionsRatio].To <double>();

            this.sizeParameter         = loadSizes(data);
            this.displacementParameter = new ContinuousRangeParameter(LanguageContext, "displacement", 0, 0.5, constants[DefaultDisplacementKey].To <double>(), displacementPercentage);
        }
Пример #10
0
        public static void StartConditionsLoader(IEnumerable <NamedStream> dataSources)
        {
            var conditionList = new List <StartingConditions>();

            using (var parser = new IkonParser(dataSources))
                foreach (var item in parser.ParseAll())
                {
                    var start = StartingConditions.Load(item.Value.To <IkonComposite>());
                    if (start != null)
                    {
                        conditionList.Add(start);
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }

            Starts = Array.AsReadOnly(conditionList.ToArray());
        }
Пример #11
0
        public void Initialize(string dataPath)
        {
            LabeledQueue <object, IkadnBaseObject> queue;
            IkadnBaseObject homeStarData;

            using (var parser = new IkonParser(new StreamReader(dataPath + ParametersFile)))
            {
                queue        = parser.ParseAll();
                homeStarData = parser.GetNamedObject("HomeStar");
            }

            var generalData = queue.Dequeue("General").To <IkonComposite>();
            var ranges      = generalData["ranges"].To <double[][]>();

            this.MinScore            = generalData["minScore"].To <double>();
            this.MaxScore            = generalData["maxScore"].To <double>();
            this.planetTraitIdGroups = generalData["traitGroups"].To <string[][]>();
            this.homeworldSize       = generalData["homeworldSize"].To <double>();
            this.homeworldPosition   = generalData["homeworldPosition"].To <int>();
            this.homeworldTraits     = generalData["homeworldTraits"].To <string[]>();

            this.traitConditions = new Dictionary <string, Formula>();
            var conditions = generalData["traitConditions"].To <IkonComposite>();

            foreach (var traitId in conditions.Keys)
            {
                var parser = new ExpressionParser(conditions[traitId].To <string>());
                parser.Parse();
                if (parser.errors.count > 0)
                {
                    throw new FormatException(parser.errors.errorMessages.ToString());
                }
                this.traitConditions[traitId] = parser.ParsedFormula;
            }

            var climates = new List <ClimateLevel>();

            while (queue.CountOf(ClimateLevelKey) > 0)
            {
                var data = queue.Dequeue(ClimateLevelKey).To <IkonComposite>();
                climates.Add(new ClimateLevel(
                                 data["langCode"].To <string>(),
                                 data["rangeWeights"].To <double[]>().Select((x, i) => new WeightedRange(ranges[i][0], ranges[i][1], x)).ToArray(),
                                 data["homeSystemStart"].To <double>()
                                 ));
            }
            climateLevels = climates.ToArray();

            var potentials = new List <PotentialLevel>();

            while (queue.CountOf(PotentialLevelKey) > 0)
            {
                var data = queue.Dequeue(PotentialLevelKey).To <IkonComposite>();
                potentials.Add(new PotentialLevel(
                                   data["langCode"].To <string>(),
                                   data["rangeWeights"].To <double[]>().Select((x, i) => new WeightedRange(ranges[i][0], ranges[i][1], x)).ToArray(),
                                   data["homeSystemPotential"].To <double>()
                                   ));
            }
            potentialLevels = potentials.ToArray();

            var starTypes = new List <StarType>();

            while (queue.CountOf(StarTypeKey) > 0)
            {
                var data = queue.Dequeue(StarTypeKey).To <IkonComposite>();
                var type = new StarType(
                    extractColor(data["color"].To <IkonArray>()),
                    data["minSize"].To <double>(),
                    data["maxSize"].To <double>(),
                    data["traits"].To <string[]>()
                    );

                starTypes.Add(type);
                if (data == homeStarData)
                {
                    this.homeStarType = type;
                }
            }
            this.starTypes = starTypes.ToArray();

            //TODO(v0.8) why Dictionary<int, string>?
            this.climateParameter = new SelectorParameter(
                LanguageContext, "climate",
                climates.Select((x, i) => i).ToDictionary(i => i, i => climates[i].LanguageCode),
                generalData["defaultClimate"].To <int>()
                );
            this.potentialParameter = new SelectorParameter(
                LanguageContext, "potential",
                potentials.Select((x, i) => i).ToDictionary(i => i, i => potentials[i].LanguageCode),
                generalData["defaultPotential"].To <int>()
                );
        }