예제 #1
0
        private void loadScript()
        {
            //код для загрузки script.rpy
            FileStream fs = new FileStream(projectFolder + "script.rpy", FileMode.Open);

            StreamReader readerlabels = new StreamReader(fs);

            while (!readerlabels.EndOfStream)
            {
                string label = readerlabels.ReadLine().TrimStart(' ');
                if (label.StartsWith("label"))
                {
                    ListView newLabel = createLabel(label.Substring(6, label.Length - 7));
                }
            }
            readerlabels.Dispose(); fs.Dispose();

            fs = new FileStream(projectFolder + "script.rpy", FileMode.Open);
            StreamReader reader = new StreamReader(fs);
            //контент ОЧЕНЬ неоднозначен, потому для его правильного распознания нужен код и в init, и в метках
            string singleLine;

            while (!reader.EndOfStream)
            {
                singleLine = reader.ReadLine().TrimStart(' ');

                if (singleLine.StartsWith("define"))
                {
                    if (singleLine.Contains("Character"))
                    {
                        XCharacter character = loadCharacter(singleLine);
                        characterList.Add(character);
                    }
                    else if (singleLine.Contains("audio."))
                    {
                        XAudio audio = new XAudio();
                        audio.loadAudio(singleLine, projectFolder + game);
                        audioMouseActions(audio);
                        musicListView.Items.Add(audio);
                    }
                }
                else if (singleLine.StartsWith("image"))
                {
                    if (!singleLine.Contains("Movie"))
                    {
                        XImage image = new XImage();
                        image.loadImage(singleLine, projectFolder + "images\\");
                        imageMouseActions(image);
                        if (!singleLine.StartsWith("image side"))
                        {
                            backImageListView.Items.Add(image);
                        }
                        else
                        {
                            image.Checkbox.Visibility = Visibility.Hidden;
                            sideListView.Items.Add(image);
                        }
                    }
                    else
                    {
                        XMovie movie = new XMovie();
                        movie.loadMovie(singleLine, projectFolder + "movies\\");
                        movieMouseActions(movie);
                        movieListView.Items.Add(movie);
                    }
                }
                else if (singleLine.StartsWith("label"))
                {
                    XLabel selectedLabel = tabControlStruct.Items.OfType <XLabel>().First(label => label.Text == singleLine.Substring(6, singleLine.Length - 7));
                    selectedLabel.IsSelected = true;
                    XFrame frame;
                    bool   buildmenu  = false;
                    bool   firstframe = true;

                    singleLine = reader.ReadLine().Trim(' ');

                    while (singleLine != "return" && !reader.EndOfStream)
                    {
                        frame        = createFrame();
                        currentFrame = frame;
                        (selectedLabel.Content as ListView).Items.Add(frame);
                        if (firstframe)
                        {
                            setPreviousFrames(); firstframe = false;
                        }
                        else
                        {
                            previousFrames.Add(frame);
                        }

                        List <string> framebody = new List <string> {
                        };

                        while (singleLine != "return" && !reader.EndOfStream)
                        {
                            if (singleLine.StartsWith("menu"))
                            {
                                buildmenu         = true;
                                frame.MenuOptions = new ObservableCollection <XMenuOption> {
                                };
                            }
                            else if (Regex.IsMatch(singleLine, @"[\S\s]*""[\S\s]*"":$"))
                            {
                                XMenuOption newmenuoption = createMenuOption(frame.MenuOptions.Count == 0);
                                newmenuoption.Choice = value(singleLine);

                                singleLine = reader.ReadLine().Trim(' ');
                                if (singleLine.StartsWith("jump"))
                                {
                                    newmenuoption.MenuAction.SelectedItem   = jumpAction;
                                    newmenuoption.ActionLabel.SelectedIndex = menuLabelList.IndexOf(menuLabelList.First(label => label.Content.ToString() == singleLine.Substring(singleLine.IndexOf(' ') + 1)));
                                    (tabControlStruct.Items[newmenuoption.ActionLabel.SelectedIndex] as XLabel).MenuChoice = frame;
                                }
                                else if (singleLine.StartsWith("call"))
                                {
                                    newmenuoption.MenuAction.SelectedItem   = callAction;
                                    newmenuoption.ActionLabel.SelectedIndex = menuLabelList.IndexOf(menuLabelList.First(label => label.Content.ToString() == singleLine.Substring(singleLine.IndexOf(' ') + 1)));
                                    (tabControlStruct.Items[newmenuoption.ActionLabel.SelectedIndex] as XLabel).MenuChoice = frame;
                                }
                                else
                                {
                                    newmenuoption.MenuAction.SelectedItem = passAction;
                                }
                                frame.MenuOptions.Add(newmenuoption);
                            }
                            else if (Regex.IsMatch(singleLine, @"[\S\s]*""[\S\s]*""$"))
                            {
                                if (buildmenu && frame.MenuOptions.Count != 0)
                                {
                                    break;
                                }
                                loadText(frame, singleLine);
                                if (!buildmenu)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (!buildmenu)
                                {
                                    framebody.Add(singleLine);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            singleLine = reader.ReadLine().Trim(' ');
                        }

                        for (int line = 0; line < framebody.Count; line++)
                        {
                            if (framebody[line].StartsWith("scene"))
                            {
                                string[]            all           = framebody[line].Split(' ');
                                XImage              selectedImage = backImageListView.Items.OfType <XImage>().First(item => item.Alias == all[1]);
                                ImageBackProperties BackProp      = new ImageBackProperties()
                                {
                                    Frame = frame, Image = selectedImage
                                };
                                if (all.Length > 2)
                                {
                                    if (all[2] == "with")
                                    {
                                        BackProp.AnimationInType = (byte)animationInTypeComboBox.Items.IndexOf(animationInTypeComboBox.Items.OfType <string>().First(item => item == all[3]));
                                    }
                                }
                                //секция поиска
                                if (BackInFrameProps.Any(prop => previousFrames.Contains(prop.Frame) && !previousFrames.Contains(prop.StopFrame)))
                                {
                                    ImageBackProperties previous = BackInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && !previousFrames.Contains(prop.StopFrame));
                                    //а вдруг меню, а мы неподготовлены? надо расставить все нужные метки
                                    if (previous.Frame.MenuOptions == null)
                                    {
                                        previous.StopFrame = frame;
                                    }
                                    else
                                    {
                                        if (previous.StopFrames == null)
                                        {
                                            previous.StopFrames = new List <XFrame> {
                                            }
                                        }
                                        ;
                                        previous.StopFrames.Add(frame);
                                    };
                                }                                //усьо
                                BackInFrameProps.Add(BackProp);
                            }
                            else if (framebody[line].StartsWith("show"))
                            {
                                string[] all = framebody[line].Split(' ');
                                XImage   selectedImage;
                                if (backImageListView.Items.OfType <XImage>().Any(item => item.Alias == all[1]))
                                {
                                    selectedImage = backImageListView.Items.OfType <XImage>().First(item => item.Alias == all[1]);
                                    backImageListView.Items.Remove(selectedImage);
                                    imageListView.Items.Add(selectedImage);
                                }
                                else
                                {
                                    selectedImage = imageListView.Items.OfType <XImage>().First(item => item.Alias == all[1]);
                                }

                                ImageCharProperties props = new ImageCharProperties()
                                {
                                    Frame = frame, Image = selectedImage, Displayable = newDisplayable()
                                };
                                props.Displayable.Source = imageShow(selectedImage.Path);

                                for (int i = 2; i < all.Length; i++)
                                {
                                    if (all[i] == "with")
                                    {
                                        props.AnimationInType = (byte)animationInTypeComboBox.Items.IndexOf(animationInTypeComboBox.Items.OfType <string>().First(item => item == all[i + 1]));
                                    }
                                    else if (all[i] == "at")
                                    {
                                        props.Align = (byte)alignComboBox.Items.IndexOf(alignComboBox.Items.OfType <string>().First(item => item == all[i + 1]));
                                    }
                                }
                                ImageInFrameProps.Add(props);
                            }
                            else if (framebody[line].StartsWith("hide"))
                            {
                                string[] all = framebody[line].Split(' ');
                                if (backImageListView.Items.OfType <XImage>().Any(prop => prop.Alias == all[1]))
                                {
                                    ImageBackProperties previous = BackInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && prop.Image.Alias == all[1]);
                                    if (all.Length > 2)
                                    {
                                        if (all[2] == "with")
                                        {
                                            previous.AnimationOutType = (byte)animationOutTypeComboBox.Items.IndexOf(animationOutTypeComboBox.Items.OfType <string>().First(item => item == all[3]));
                                        }
                                    }
                                    if (previous.Frame.MenuOptions == null)
                                    {
                                        previous.StopFrame = frame;
                                    }
                                    else
                                    {
                                        if (previous.StopFrames == null)
                                        {
                                            previous.StopFrames = new List <XFrame> {
                                            }
                                        }
                                        ;
                                        previous.StopFrames.Add(frame);
                                    };
                                }
                                else
                                {
                                    ImageCharProperties previous = ImageInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && prop.Image.Alias == all[1]);
                                    if (all.Length > 2)
                                    {
                                        if (all[2] == "with")
                                        {
                                            previous.AnimationOutType = (byte)animationOutTypeComboBox.Items.IndexOf(animationOutTypeComboBox.Items.OfType <string>().First(item => item == all[3]));
                                        }
                                    }
                                    if (previous.Frame.MenuOptions == null)
                                    {
                                        previous.StopFrame = frame;
                                    }
                                    else
                                    {
                                        if (previous.StopFrames == null)
                                        {
                                            previous.StopFrames = new List <XFrame> {
                                            }
                                        }
                                        ;
                                        previous.StopFrames.Add(frame);
                                    };
                                }
                            }
                            else if (framebody[line].StartsWith("stop"))
                            {
                                string          type     = framebody[line].Substring(5) + " ";
                                AudioProperties previous = AudioInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && prop.Audio.Type == type);
                                if (previous.Frame.MenuOptions == null)
                                {
                                    previous.StopFrame = frame;
                                }
                                else
                                {
                                    if (previous.StopFrames == null)
                                    {
                                        previous.StopFrames = new List <XFrame> {
                                        }
                                    }
                                    ;
                                    previous.StopFrames.Add(frame);
                                };
                            }
                            else if (framebody[line].StartsWith("play"))
                            {
                                string[] all   = framebody[line].Split(' ');
                                XAudio   audio = musicListView.Items.OfType <XAudio>().First(item => item.Alias == all[2]);
                                if (all[1] != "music")
                                {
                                    musicListView.Items.Remove(audio);
                                    if (all[1] == "sound")
                                    {
                                        soundListView.Items.Add(audio);
                                    }
                                    else
                                    {
                                        voiceListView.Items.Add(audio);
                                    }
                                }
                                AudioProperties props = new AudioProperties()
                                {
                                    Frame = frame, Audio = audio
                                };
                                for (int i = 2; i < all.Length; i++)
                                {
                                    if (all[i] == "fadein")
                                    {
                                        props.FadeIn = float.Parse(all[i + 1]);
                                    }
                                    else if (all[i] == "fadeout")
                                    {
                                        props.FadeOut = float.Parse(all[i + 1]);
                                    }
                                    else if (all[i] == "noloop")
                                    {
                                        props.Loop = false;
                                    }
                                }
                                AudioInFrameProps.Add(props);
                            }
                        }

                        if (singleLine != "return")
                        {
                            if (buildmenu)
                            {
                                buildmenu = false;
                            }
                            else
                            {
                                frame.IsSelected = true; singleLine = reader.ReadLine().TrimStart(' ');
                            }
                        }
                    }
                }
            }
            previousFrames.Clear();
            fs.Close();
        }