예제 #1
0
        string IStorySerializer.Serialize(Story story)
        {
            Model.Story serializationModel = new Model.Story();
            serializationModel.Serialize(story, story);

            return JsonConvert.SerializeObject(serializationModel);
        }
예제 #2
0
        private void liststory_SelectedValueChanged(object sender, EventArgs e)
        {
            contentchap.Text = "";
            Model.Story story = (Model.Story)liststory.SelectedItem;
            idt = story.idt;
            lbStoryName.Text = story.name;
            List <Model.Chapter> list = story.getChapters();

            listchap.DataSource = list;
        }
예제 #3
0
        /// <summary>The get story by name.</summary>
        /// <param name="storyName">The story name.</param>
        /// <returns>The <see cref="Story"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when an argument is null.</exception>
        public Story GetStoryByName(string storyName)
        {
            if (string.IsNullOrWhiteSpace(storyName))
            {
                throw new ArgumentNullException("storyName");
            }

            Model.Story storyModel = this.databaseContext.Stories.FirstOrDefault(st => st.Name == storyName);
            var         story      = Mapper.Map <Story>(storyModel);

            return(story);
        }
예제 #4
0
        public StoryResponse(Model.Story story, ApiController apiController)
        {
            if (story == null)
            {
                return;
            }

            this.Title      = story.Title?.Value;
            this.Content    = story.Content?.Text;
            this.Popularity = story.Rating?.Popularity;
            var mainImage = story.VisualRepresentation?.GetMainImage();

            if (mainImage != null)
            {
                this.MainImage = apiController.GetImageRoute(mainImage.Id);
            }
        }
예제 #5
0
 public ResultSearch(Form home, HomePage homepage, string input, Model.Story story)
 {
     this.home     = home;
     this.homepage = homepage;
     this.input    = input;
     if (story != null)
     {
         stories = new Model.Stories();
         stories.addStory(story);
     }
     else
     {
         stories = Model.MyDatabase.stories;
     }
     InitializeComponent();
     TimKiem();
 }
예제 #6
0
        public void Show(int iStory)
        {
            this.iStory = iStory;
            switch (iStory)
            {
            case 0:
                pictureBox1.BackgroundImage = Properties.Resources.logo_01;
                break;

            case 1:
                pictureBox1.BackgroundImage = Properties.Resources.logo_02;
                break;

            case 2:
                pictureBox1.BackgroundImage = Properties.Resources.logo_03;
                break;

            case 3:
                pictureBox1.BackgroundImage = Properties.Resources.logo_04;
                break;

            case 4:
                pictureBox1.BackgroundImage = Properties.Resources.logo_05;
                break;

            case 5:
                pictureBox1.BackgroundImage = Properties.Resources.logo_06;
                break;
            }
            contentchap.Text    = "";
            listchap.DataSource = null;
            Show();

            string[] files = Directory.GetFiles(Application.StartupPath);
            foreach (string file in files)
            {
                string[] token = file.Split('\\');
                if (token[token.Length - 1].StartsWith(iStory + "_"))
                {
                    filesave = token[token.Length - 1];
                    break;
                }
            }

            if (chapautoscroll == -1)
            {
                string[] datasave = filesave.Split('_');
                chapautoscroll = int.Parse(datasave[1]);
                posautoscroll  = int.Parse(datasave[2]);
            }

            story = Model.MyDatabase.stories.getStories()[iStory];
            if (story != null)
            {
                List <Model.Chapter> list = story.getChapters();
                if (list != null && list.Count > 0)
                {
                    listchap.DataSource    = list;
                    listchap.SelectedIndex = chapautoscroll;
                }
            }
        }
예제 #7
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);
            }
        }