예제 #1
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Species.Clear();
                var species = await DataStore.GetItemsAsync(true);

                foreach (var species2 in species)
                {
                    Species.Add(species2);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #2
0
        private async Task InitAsync(Film film)
        {
            IsLoading = true;
            if (film != null)
            {
                Film = film;

                Species.Clear();
                foreach (var specy in film.species)
                {
                    var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ??
                                       await _dataService.GetSingleByUrl <Specie>(specy);

                    Species.Add(currentSpecy);
                }
                Species = Species.OrderBy(item => item.name).ToObservableCollection();

                Starships.Clear();
                foreach (var starship in film.starships)
                {
                    var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                          await _dataService.GetSingleByUrl <Starship>(starship);

                    Starships.Add(currentStarship);
                }
                Starships = Starships.OrderBy(item => item.name).ToObservableCollection();

                Vehicles.Clear();
                foreach (var vehicle in film.vehicles)
                {
                    var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                         await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                    Vehicles.Add(currentVehicle);
                }
                Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();

                People.Clear();
                foreach (var character in film.characters)
                {
                    var currentPeople = await _peopleRepository.GetPeopleAsync(character) ??
                                        await _dataService.GetSingleByUrl <People>(character);

                    People.Add(currentPeople);
                }
                People = People.OrderBy(item => item.name).ToObservableCollection();

                Planets.Clear();
                foreach (var planet in film.planets)
                {
                    var currentPlanet = await _planetRepository.GetPlanetAsync(planet) ??
                                        await _dataService.GetSingleByUrl <Planet>(planet);

                    Planets.Add(currentPlanet);
                }
                Planets = Planets.OrderBy(item => item.name).ToObservableCollection();
            }
            IsLoading = false;
        }
예제 #3
0
파일: Population.cs 프로젝트: smart111/warp
        public void Load(string path)
        {
            DoAutosave = false;

            Path = path;

            using (Stream SettingsStream = File.OpenRead(path))
            {
                XPathDocument  Doc    = new XPathDocument(SettingsStream);
                XPathNavigator Reader = Doc.CreateNavigator();
                Reader.MoveToRoot();
                Reader.MoveToChild("Population", "");

                ReadFromXML(Reader);

                List <Species> AllSpecies = new List <Species>();
                foreach (XPathNavigator nav in Reader.Select("Species/Species"))
                {
                    Guid   SpeciesGUID = Guid.Parse(nav.GetAttribute("GUID", ""));
                    string SpeciesPath = nav.GetAttribute("Path", "");

                    Species LoadedSpecies = Sociology.Species.FromFile(SpeciesPath);
                    if (LoadedSpecies.GUID != SpeciesGUID)
                    {
                        throw new Exception("Stored GUID does not match that of the species.");
                    }

                    AllSpecies.Add(LoadedSpecies);
                }
                foreach (var species in AllSpecies)
                {
                    species.ResolveChildren(AllSpecies);
                }

                Species.Clear();
                foreach (var toplevel in AllSpecies.Where(s => s.Parent == null))
                {
                    Species.Add(toplevel);
                }

                foreach (XPathNavigator nav in Reader.Select("Sources/Source"))
                {
                    string Path       = nav.GetAttribute("Path", "");
                    Guid   SourceGUID = Guid.Parse(nav.GetAttribute("GUID", ""));

                    DataSource LoadedSource = DataSource.FromFile(Path);
                    if (SourceGUID != LoadedSource.GUID)
                    {
                        throw new Exception("Stored GUID does not match that of the data source.");
                    }

                    Sources.Add(LoadedSource);
                }
            }

            DoAutosave = true;
        }
 private void Culture_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedCulture = Culture.CreateCulture(GenerationConfiguration.Culture, GenerationConfiguration.UseCitizens, GenerationConfiguration.UseMishaps);
     if (selectedCulture is Classic.Zhodani.Culture)
     {
         // Psionic training and the like are handled at the "Culture" level
         ((Classic.Zhodani.Culture)selectedCulture).SkillOffered += SkillOffered;
     }
     if (selectedCulture != null)
     {
         Species.Clear();
         var list = selectedCulture.Species(generationStyle).Keys.ToList();
         foreach (var s in list)
         {
             Species.Add(s);
         }
     }
 }
        /// <summary>
        /// Create an initial random population.
        /// </summary>
        public void Reset()
        {
            // create the genome factory
            if (IsHyperNEAT)
            {
                CODEC         = new HyperNEATCODEC();
                GenomeFactory = new FactorHyperNEATGenome();
            }
            else
            {
                CODEC         = new NEATCODEC();
                GenomeFactory = new FactorNEATGenome();
            }

            // create the new genomes
            Species.Clear();

            // reset counters
            GeneIdGenerate.CurrentID       = 1;
            InnovationIDGenerate.CurrentID = 1;

            EncogRandom rnd = RandomNumberFactory.Factor();

            // create one default species
            BasicSpecies defaultSpecies = new BasicSpecies();

            defaultSpecies.Population = this;

            // create the initial population
            for (int i = 0; i < PopulationSize; i++)
            {
                NEATGenome genome = GenomeFactory.Factor(rnd, this,
                                                         InputCount, OutputCount,
                                                         InitialConnectionDensity);
                defaultSpecies.Add(genome);
            }
            defaultSpecies.Leader = defaultSpecies.Members[0];
            Species.Add(defaultSpecies);

            // create initial innovations
            Innovations = new NEATInnovationList(this);
        }
예제 #6
0
        private async Task InitAsync(People person)
        {
            IsLoading = true;

            if (person != null)
            {
                Person = person;

                Species.Clear();
                if (person.species != null && person.species.Count() > 1)
                {
                    foreach (var specy in person.species)
                    {
                        var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ??
                                           await _dataService.GetSingleByUrl <Specie>(specy);

                        Species.Add(currentSpecy);
                    }
                    Species = Species.OrderBy(item => item.name).ToObservableCollection();
                }
                else
                {
                    var specy = person.species.FirstOrDefault();
                    if (specy != null)
                    {
                        CurrentSpecie = await _speciesRepository.GetSpecieAsync(specy) ??
                                        await _dataService.GetSingleByUrl <Specie>(specy);
                    }
                }

                Starships.Clear();
                foreach (var starship in person.starships)
                {
                    var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                          await _dataService.GetSingleByUrl <Starship>(starship);

                    Starships.Add(currentStarship);
                }
                Starships = Starships.OrderBy(item => item.name).ToObservableCollection();

                Vehicles.Clear();
                foreach (var vehicle in person.vehicles)
                {
                    var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                         await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                    Vehicles.Add(currentVehicle);
                }
                Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();

                var movies = new ObservableCollection <Film>();
                foreach (var film in person.films)
                {
                    var currentFilm = await _filmRepository.GetFilmAsync(film) ??
                                      await _dataService.GetSingleByUrl <Film>(film);

                    movies.Add(currentFilm);
                }
                Movies = movies.OrderBy(item => item.episode_id).ToObservableCollection();

                HomeWorld = await _planetRepository.GetPlanetAsync(Person?.homeworld) ??
                            await _dataService.GetSingleByUrl <Planet>(Person?.homeworld);
            }
            IsLoading = false;
        }