private void BtnRemoveIO_Click(object sender, RoutedEventArgs e)
        {
            MenuFlyoutItem btnsender = sender as MenuFlyoutItem;

            Model.InteractableObject ioremoving = btnsender.DataContext as Model.InteractableObject;
            ioVM.RemoveInteractableObject(ioremoving);
        }
Пример #2
0
 public void RemoveInteractableObject(Model.InteractableObject removingIO)
 {
     if (removingIO != null)
     {
         this.interactableObjects.Remove(removingIO);
     }
 }
Пример #3
0
        private async Task <Model.MapStory> JSONtoModels(Windows.Storage.StorageFile file)
        {
            Model.Story storyModel = new Model.Story();
            Model.Map   mapModel   = new Model.Map();

            var dialog = new MessageDialog("");

            if (file != null)
            {
                string data = await Windows.Storage.FileIO.ReadTextAsync(file);

                JsonObject jsonObj = new JsonObject();
                jsonObj = JsonObject.Parse(data);

                MapStory.Story.Title       = jsonObj.GetNamedString("title");
                MapStory.Story.Description = jsonObj.GetNamedString("description");
                MapStory.Story.Author      = jsonObj.GetNamedString("author");

                //JsonObject, to access Json Api for Interactable Object.
                JsonObject interactableObjects = new JsonObject();

                interactableObjects = jsonObj.GetNamedObject("interactableobjects");
                //Multiple Interactable Objects usually. Has to dismantle and save them all into objects of the major Model: MapStory Model.
                foreach (var obj in interactableObjects)
                {
                    Model.InteractableObject interactableObjectModel = new Model.InteractableObject();

                    //Interactable Object (characters, enemies, bosses, friends, talking chair, etc)
                    interactableObjectModel.Name = obj.Key;
                    JsonObject jsonInteracatbleObject = new JsonObject();
                    jsonInteracatbleObject = JsonObject.Parse(obj.Value.ToString());
                    // Each interactable Objects has multiple branches, options, states, feelings etc...
                    foreach (var branch in jsonInteracatbleObject)
                    {
                        //Branch has a name.
                        Model.Branch branchModel = new Model.Branch();
                        branchModel.Messages = new List <Model.Message>();
                        branchModel.Name     = branch.Key;
                        JsonObject jsonObjBranch = new JsonObject();
                        jsonObjBranch = JsonObject.Parse(branch.Value.ToString());



                        //BranchModel added into the InteractableObjectModel. This process will repeatedly for the other branches.
                        interactableObjectModel.Branches.Add(branchModel);
                        //var dialogJson is not really a true JsonObject, it has only 2 properties (Key and Value).
                        //Those values have to be converted to Strings from a so called: "KeyValuePair".
                        foreach (var dialogJson in jsonObjBranch)
                        {
                            JsonObject dialogJsonObject = JsonObject.Parse(dialogJson.Value.ToString());

                            if (dialogJsonObject.ContainsKey("question"))
                            {
                                Model.Question questionModel = new Model.Question();
                                questionModel.Choices = new List <Model.Choice>();
                                questionModel.Name    = dialogJsonObject.GetNamedValue("name").ToString();
                                questionModel.Text    = dialogJsonObject.GetNamedValue("question").ToString();
                                if (dialogJsonObject.ContainsKey("emote"))
                                {
                                    questionModel.Emote = dialogJsonObject.GetNamedValue("emote").ToString();
                                }
                                JsonObject jsonObjChoices = new JsonObject();

                                if (JsonObject.TryParse(dialogJsonObject.GetNamedValue("choices").ToString(), out jsonObjChoices))
                                {
                                    foreach (var choiceJson in jsonObjChoices)
                                    {
                                        JsonObject   jsonObjectChoice = JsonObject.Parse(choiceJson.Value.ToString());
                                        Model.Choice choiceModel      = new Model.Choice();
                                        choiceModel.Name = jsonObjectChoice.GetNamedValue("name").ToString();

                                        //Recommend to have this... if it's empty, make a notification in the GUI.
                                        if (jsonObjChoices.ContainsKey("description"))
                                        {
                                            choiceModel.Description = jsonObjectChoice.GetNamedValue("description").ToString();
                                        }
                                        //Target is optional.
                                        if (jsonObjectChoice.ContainsKey("target"))
                                        {
                                            choiceModel.Function = jsonObjectChoice.GetNamedValue("target").ToString();
                                        }
                                        //Branch is optional... what's the real difference tho?
                                        if (jsonObjectChoice.ContainsKey("branch"))
                                        {
                                            choiceModel.Branch = jsonObjectChoice.GetNamedValue("branch").ToString();
                                        }
                                        questionModel.Choices.Add(choiceModel);
                                    }
                                    branchModel.Messages.Add(questionModel);
                                }
                                else
                                {
                                    MessageDialog msgbox = new MessageDialog("Error! There should be Choices jsonObject in the question JsonObject.");
                                    await msgbox.ShowAsync();
                                }
                            }

                            else
                            {
                                Model.Message message = new Model.Message();
                                if (dialogJsonObject.ContainsKey("name"))
                                {
                                    message.Name = dialogJsonObject.GetNamedValue("name").ToString();
                                }
                                else
                                {
                                    message.Name = "No name found?!";
                                }

                                if (dialogJsonObject.ContainsKey("message"))
                                {
                                    message.Text = dialogJsonObject.GetNamedValue("message").ToString();
                                }
                                else
                                {
                                    message.Text = "";
                                }
                                if (dialogJsonObject.ContainsKey("emote"))
                                {
                                    message.Emote = dialogJsonObject.GetNamedValue("emote").ToString();
                                }
                                branchModel.Messages.Add(message);
                            }

                            if (int.TryParse(dialogJson.Key, out int dialognumber))
                            {
                            }

                            else
                            {
                            }
                        }
                        //has chain of messages that the player has to go through.
                        //continue here ->
                        //extra info: go through another foreach. This time for the real dialogs.
                    }

                    //Interactable Object is filled... now it gets added into the MapStory.
                    this.MapStory.Story.InteractableObjects.Add(interactableObjectModel);
                }
            }



            else
            {
                dialog = new MessageDialog("Error, file is null!");
                await dialog.ShowAsync();
            }



            if (MapStory != null)
            {
                return(this.MapStory);
            }
            else
            {
                dialog = new MessageDialog("Error, MapStory is null!");
                await dialog.ShowAsync();

                MapStory = new Model.MapStory();
                return(MapStory);
            }
        }
Пример #4
0
 public void AddInteractableObject()
 {
     Model.InteractableObject newIO = new Model.InteractableObject();
     newIO.Name = NewIOName;
     InteractableObjects.Add(newIO);
 }