Пример #1
0
        public bool ExportExcursionGameXML(string appName)
        {
            ExcursionGameElement egElement = null;
            ExcursionGameWrapper egWrapper = new ExcursionGameWrapper();
            List<MissionElementXml> missions = new List<MissionElementXml>();
            PrologueElement pElement = null;
            MissionListElement mlElement;
            try
            {
                egElement = elements.OfType<ExcursionGameElement>().First();
                egWrapper.GameTitle = egElement.Caption;
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show("No Excursion-Game building block found", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

            try
            {
                pElement = gridCanvas.GetElementsConnectedTo(egElement).OfType<PrologueElement>().First();
                egWrapper.PrologueTitle = pElement.Caption;
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("No Prologue building block found connected to the root.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

            try
            {
                mlElement = gridCanvas.GetElementsConnectedTo(pElement).OfType<MissionListElement>().First();
                foreach (KeyValuePair<int, MissionElement> pair in mlElement.MissionList)
                {
                    GoalElement goal = null;
                    OracleElement oracleHint = null;
                    try
                    {
                        goal = gridCanvas.GetElementsConnectedTo(pair.Value).OfType<GoalElement>().First();
                    }
                    catch (InvalidOperationException)
                    {
                        MessageBox.Show("No Goal building block found connected to Mission block '" + pair.Value.Caption + "'.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return false;
                    }

                    try
                    {
                        oracleHint = gridCanvas.GetElementsConnectedTo(pair.Value).OfType<OracleElement>().First();
                    }
                    catch (InvalidOperationException)
                    {
                        MessageBox.Show("No OracleHint building block found connected to Mission block '" + pair.Value.Caption + "'.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return false;
                    }

                    ResourceElementXml rxGoal = EncodeResourceElement(goal);
                    ResourceElementXml rxHint = EncodeResourceElement(oracleHint);
                    missions.Add(new MissionElementXml()
                    {
                        ID = pair.Value.Caption,
                        Index = pair.Key,
                        OracleHint = rxHint,
                        Goal = rxGoal,
                        PlaceId = pair.Value.PlaceId
                    });
                }
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("No Missions or MissionList building blocks found connected to the Prologue.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

            egWrapper.Missions = missions.ToArray();

            List<ContextualSoundXml> cxSounds = new List<ContextualSoundXml>();
            try
            {
                var csData = gridCanvas.GetElementsConnectedTo(egElement).OfType<ContextSoundElement>();
                foreach (ContextSoundElement csElement in csData)
                {
                    ResourceElementXml cxElement = EncodeResourceElement(csElement);

                    cxSounds.Add(new ContextualSoundXml() { ID = cxElement.ID, ResourceIDs = cxElement.ResourceIDs });
                }
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("No Contextual Sounds building blocks found connected to the root.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }

            egWrapper.ContextualSounds = cxSounds.ToArray();

            ResourceContainer rc = new ResourceContainer()
            {
                AudioResources = audios.ToArray(),
                ImageResources = images.ToArray(),
                TextResources = texts.ToArray()
            };

            DataManager.Serialize(rc, appName.Insert(appName.Length - 4, "_resources"));
            DataManager.Serialize(egWrapper, appName.Insert(appName.Length - 4, "_excursiongame"));

            return true;
        }
Пример #2
0
        public void ExportMuseumGuideXML(string appName)
        {
            foreach (ThemeElement themeElement in elements.OfType<ThemeElement>())
            {
                List<ResourceElementXml> items = new List<ResourceElementXml>();

                foreach (ResourceElement resourceElement in gridCanvas.GetElementsConnectedTo(themeElement).OfType<ResourceElement>())
                {
                    List<string> resourceIDs = new List<string>();

                    foreach (AbstractResource resource in resourceElement.ResourceBox.Items)
                    {

                        AddResource(resource);

                        resourceIDs.Add(resource.Id);
                    }
                    items.Add(new ResourceElementXml()
                    {
                        ID = resourceElement.Caption,
                        ResourceIDs = resourceIDs.ToArray()
                    });
                }
                themes.Add(new Theme() { Id = themeElement.Caption, Items = items.ToArray() });
            }

            ResourceContainer rc = new ResourceContainer()
            {
                AudioResources = audios.ToArray(),
                ImageResources = images.ToArray(),
                TextResources = texts.ToArray()
            };

            MuseumGuideElement mge = elements.OfType<MuseumGuideElement>().First();
            List<string> mgeResourceIds = new List<string>();
            foreach (AbstractResource resource in mge.ResourceBox.Items)
            {
                AddResource(resource);
                mgeResourceIds.Add(resource.Id);
            }
            MuseumGuide mg = new MuseumGuide()
            {
                Id = mge.Caption,
                ResourceIDs = mgeResourceIds.ToArray(),
                Themes = themes.ToArray()
            };

            DataManager.Serialize(rc, appName.Insert(appName.Length - 4, "_resources"));
            DataManager.Serialize(mg, appName.Insert(appName.Length - 4, "_museumguide"));
        }