Example #1
0
        /// <summary>
        /// Save the beastie file.
        /// </summary>
        /// <param name="beastieFile">serialisable object to save</param>
        public void Save(Beastie beastieFile)
        {
            if (string.IsNullOrWhiteSpace(beastieFile.Name))
            {
                this.logger.WriteLine(
                    $"Error saving beastie file, filename is null or empty");
                return;
            }

            string path = $"{DataPath.BeastieDataPath}";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                XmlFileIo.WriteXml(
                    beastieFile,
                    $"{path}\\{beastieFile.Name}.xml");
            }
            catch (Exception ex)
            {
                this.logger.WriteLine(
                    $"Error saving {beastieFile.Name}: {ex}");
            }
        }
        /// <summary>
        /// Save the beastie back to the file.
        /// </summary>
        private void Save()
        {
            if (!this.IsValid())
            {
                return;
            }

            Beastie currentBeastie =
                this.dataManager.Beasties.Find(b => string.Compare(b.Name, this.Beasties[this.BeastieIndex]) == 0);

            if (currentBeastie == null)
            {
                return;
            }

            currentBeastie.DisplayName    = this.DisplayName;
            currentBeastie.LatinName      = this.NameLatin;
            currentBeastie.Genus          = this.Genus;
            currentBeastie.SubFamily      = this.SubFamily;
            currentBeastie.Family         = this.Family;
            currentBeastie.Order          = this.Order;
            currentBeastie.Classification = this.Class;
            currentBeastie.GenusLatin     = this.GenusLatin;
            currentBeastie.SubFamilyLatin = this.SubFamilyLatin;
            currentBeastie.FamilyLatin    = this.FamilyLatin;
            currentBeastie.OrderLatin     = this.OrderLatin;
            currentBeastie.ClassLatin     = this.ClassLatin;
            currentBeastie.Size           = this.Size;
            currentBeastie.Wingspan       = this.Wingspan;
            currentBeastie.Image          = this.BeastieImageList[this.BeastieImageListIndex];
            currentBeastie.Presence       = this.PresenceList[this.PresenceListIndex];

            this.fileFactory.Save(currentBeastie);
        }
Example #3
0
        /// <summary>
        /// Create a beastie file for <paramref name="name"/> and set it up with a set of default
        /// values.
        /// </summary>
        /// <param name="name">The name of the new beastie</param>
        private void CreateEmptyBeastieFile(string name)
        {
            Beastie newFile =
                new Beastie()
            {
                Name           = name,
                DisplayName    = name,
                LatinName      = string.Empty,
                Image          = string.Empty,
                ThumbnailImage = string.Empty,
                Size           = 0,
                Wingspan       = 0,
                Classification = string.Empty,
                ClassLatin     = string.Empty,
                Order          = string.Empty,
                OrderLatin     = string.Empty,
                Family         = string.Empty,
                FamilyLatin    = string.Empty,
                SubFamily      = "N/A",
                SubFamilyLatin = "N/A",
                Genus          = string.Empty,
                GenusLatin     = string.Empty
            };

            this.Save(newFile);
            this.dataManager.AddBeastie(newFile);
        }
Example #4
0
        /// <summary>
        /// Find and return a specific beastie
        /// </summary>
        /// <param name="name">name to search for</param>
        /// <returns>found beastie</returns>
        public Beastie Find(string name)
        {
            Beastie foundBeastie =
                this.dataManager.Beasties.Find(
                    b => string.Compare(b.Name, name) == 0);

            return(foundBeastie);
        }
Example #5
0
 // reference: https://answers.unity.com/questions/8003/how-can-i-know-if-a-gameobject-is-seen-by-a-partic.html
 private bool beastieVisible(Beastie beast)
 {
     Plane[] planes = GeometryUtility.CalculateFrustumPlanes(ARCamera);
     if (GeometryUtility.TestPlanesAABB(planes, beast.GetComponent <Collider>().bounds))
     {
         return(true);
     }
     return(false);
 }
Example #6
0
    private void InstantiateNewBeasties()
    {
        int beastiesToSpawn = gameManager.DefaultBeastiesSpawnCount;

        for (int i = 0; i < beastiesToSpawn; i++)
        {
            Beastie beastie = BeastieFactory.Instance.GenerateBeastie();
            float   x       = player.transform.position.x + GenerateRange();
            float   y       = player.transform.position.y;
            float   z       = player.transform.position.z + GenerateRange();
            gameManager.AddBeastie(Instantiate(beastie, new Vector3(x, y, z), Quaternion.Euler(0.0f, UnityEngine.Random.Range(0.0f, 360.0f), 0.0f)));
        }
    }
Example #7
0
    private void PlaceBeastieOnPlane(ARPlanesChangedEventArgs obj)
    {
        if (captureViewBeastie == null && obj.added.Count > 0 && obj.added[0] != null)
        {
            ARPlane plane           = obj.added[0];
            Beastie selectedBeastie = gameManager.GetSelectedBeastie();

            captureViewBeastie = Instantiate(selectedBeastie, plane.transform.position, Quaternion.identity);
            Debug.Log(selectedBeastie.Equals(captureViewBeastie));

            captureViewBeastie.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
            captureViewBeastie.transform.position   = plane.transform.position;
            captureViewBeastie.gameObject.SetActive(true);
        }
    }
        /// <summary>
        /// Load a beastie from a file.
        /// </summary>
        private void Load()
        {
            if (!this.IsValid())
            {
                return;
            }

            Beastie currentBeastie =
                this.dataManager.Beasties.Find(b => string.Compare(b.Name, this.Beasties[this.BeastieIndex]) == 0);

            if (currentBeastie == null)
            {
                return;
            }

            this.DisplayName    = currentBeastie.DisplayName;
            this.NameLatin      = currentBeastie.LatinName;
            this.Genus          = currentBeastie.Genus;
            this.SubFamily      = currentBeastie.SubFamily;
            this.Family         = currentBeastie.Family;
            this.Order          = currentBeastie.Order;
            this.Class          = currentBeastie.Classification;
            this.GenusLatin     = currentBeastie.GenusLatin;
            this.SubFamilyLatin = currentBeastie.SubFamilyLatin;
            this.FamilyLatin    = currentBeastie.FamilyLatin;
            this.OrderLatin     = currentBeastie.OrderLatin;
            this.ClassLatin     = currentBeastie.ClassLatin;
            this.Size           = currentBeastie.Size;
            this.Wingspan       = currentBeastie.Wingspan;

            for (int index = 0; index < this.BeastieImageList.Count; ++index)
            {
                if (string.Compare(this.BeastieImageList[index], currentBeastie.Image) == 0)
                {
                    this.BeastieImageListIndex = index;
                    break;
                }
            }

            for (int index = 0; index < this.PresenceList.Count; ++index)
            {
                if (this.PresenceList[index] == currentBeastie.Presence)
                {
                    this.PresenceListIndex = index;
                    break;
                }
            }
        }
Example #9
0
        /// <summary>
        /// Load a file and store it in the Data Manager
        /// </summary>
        /// <param name="path">path of the file to load</param>
        private void LoadFile(string path)
        {
            try
            {
                Beastie beastie =
                    XmlFileIo.ReadXml <Beastie>(
                        path);

                this.dataManager.AddBeastie(beastie);
            }
            catch (Exception ex)
            {
                AppStatusMessage message =
                    new AppStatusMessage(
                        $"Error loading {path}");
                Messenger.Default.Send(message);

                this.logger.WriteLine(
                    $"Error loading {path}: {ex}");
            }
        }
Example #10
0
        /// <summary>
        /// Select a new page for the view.
        /// </summary>
        /// <param name="newPageName">
        /// Name of the page to display.
        /// </param>
        private void NewPage(string newPageName)
        {
            if (StringCompare.SimpleCompare(newPageName, EventDetails))
            {
                this.CurrentWorkspace = this.detailsViewModel;
            }
            else
            {
                this.beastieEntryViewModel.Clear();

                List <string> beasties =
                    this.dataEntryModel.GetBeastiesOnAPage(
                        newPageName);

                foreach (string beastie in beasties)
                {
                    bool isIncluded =
                        this.observations.GetIncluded(
                            beastie,
                            this.detailsViewModel.IsSeen);

                    Beastie modelBeastie = this.getBeastie(beastie);

                    this.beastieEntryViewModel.Add(
                        beastie,
                        modelBeastie?.LatinName ?? string.Empty,
                        modelBeastie?.Image ?? string.Empty,
                        modelBeastie?.Presence ?? (Presence)(-1),
                        isIncluded);
                }

                this.CurrentWorkspace = this.beastieEntryViewModel;
                this.beastieEntryViewModel.Refresh();
            }

            this.ResetSelectedPage(newPageName);

            this.RaisePropertyChangedEvent(nameof(this.CurrentWorkspace));
        }
Example #11
0
        /// <summary>
        /// Open the event specified by the path.
        /// </summary>
        /// <param name="path">
        /// The path to the raw data for the event to be opened.
        /// </param>
        public void OpenEvent(string path)
        {
            RawObservations observations =
                XmlFileIo.ReadXml <RawObservations>(
                    path);

            if (observations == null)
            {
                return;
            }

            this.Location  = observations.Location;
            this.Date      = observations.Date;
            this.Notes     = observations.Notes;
            this.Length    = observations.Length.ToString();
            this.Intensity = observations.Intensity;
            this.TimeOfDay = observations.TimeOfDay.ToString();
            this.Weather   = observations.Weather.ToString();

            this.Habitats.Clear();

            foreach (ObservationHabitat habitat in observations.Habitats.Habitats)
            {
                this.Habitats.Add(habitat.ToString());
            }

            this.Beasties.Clear();

            foreach (string beastie in observations.Species.Kind)
            {
                Beastie modelBeastie = this.getBeastie(beastie);

                IBeastieReportIconViewModel beastieIcon =
                    new BeastieReportIconViewModel(
                        modelBeastie.DisplayName,
                        modelBeastie?.LatinName ?? string.Empty,
                        modelBeastie?.Image ?? string.Empty,
                        modelBeastie?.Presence ?? (Presence)(-1));

                this.Beasties.Add(beastieIcon);
            }

            foreach (string beastie in observations.Heard.Kind)
            {
                Beastie modelBeastie = this.getBeastie(beastie);

                IBeastieReportIconViewModel beastieIcon =
                    new BeastieReportIconViewModel(
                        modelBeastie.DisplayName,
                        modelBeastie?.LatinName ?? string.Empty,
                        modelBeastie?.Image ?? string.Empty,
                        modelBeastie?.Presence ?? (Presence)(-1));

                this.Beasties.Add(beastieIcon);
            }

            this.RaisePropertyChangedEvent(nameof(this.Location));
            this.RaisePropertyChangedEvent(nameof(this.Date));
            this.RaisePropertyChangedEvent(nameof(this.Notes));
            this.RaisePropertyChangedEvent(nameof(this.Length));
            this.RaisePropertyChangedEvent(nameof(this.Intensity));
            this.RaisePropertyChangedEvent(nameof(this.TimeOfDay));
            this.RaisePropertyChangedEvent(nameof(this.Weather));
            this.RaisePropertyChangedEvent(nameof(this.Habitats));
            this.RaisePropertyChangedEvent(nameof(this.Beasties));
        }