Inheritance: Mistilteinn.ViewModels.ViewModelBase
コード例 #1
0
        public static async void ReadScript(Text text)
        {
            Voice = null;
            var bgm = text?.Music?.Path;
            var voice = text?.Voice?.Path;

            await Task.Run(() =>
            {
                if (Project.Current.IsMusicEnable && !String.IsNullOrEmpty(bgm))
                {
                    TStreamStatus status = new TStreamStatus();
                    BgmPlayer.GetStatus(ref status);

                    if (Bgm != bgm || !status.fPlay)
                    {
                        Bgm = bgm;
                        var bgmFile = FileHelper.FindFile(Project.Current.MusicPath, bgm);

                        if (!String.IsNullOrEmpty(bgmFile))
                        {
                            if (!Project.Current.IsMute && !Project.Current.IsMusicMute)
                            {
                                _notStop = true;
                                BgmPlayer.StopPlayback();
                                BgmPlayer.OpenFile(bgmFile, TStreamFormat.sfUnknown);
                                BgmPlayer.StartPlayback();
                            }
                        }
                    }
                }

                if (Project.Current.IsVoiceEnable  && !String.IsNullOrEmpty(voice))
                {
                    var voiceFile = FileHelper.FindFile(Project.Current.VoicePath, voice);
                    Voice = voiceFile;

                    if (!String.IsNullOrEmpty(voiceFile))
                    {
                        Voice = voiceFile;
                        if (!Project.Current.IsMute && !Project.Current.IsVoiceMute)
                        {
                            if (DateTime.Now - _createTime > TimeSpan.FromMilliseconds(500))
                            {
                                VoicePlayer.StopPlayback();
                                VoicePlayer.OpenFile(voiceFile, TStreamFormat.sfUnknown);
                                VoicePlayer.StartPlayback();
                            }
                            _createTime = DateTime.Now;
                        }
                    }
                }
            });
        }
コード例 #2
0
        public static async Task<ImageSource> ReadScript(Text text)
        {
            if (!Project.Current.IsPreviewEnable)
            {
                return null;
            }

            return await Task.Run(() =>
            {
                String bg = null;
                List<String> charas = null;

                if (text != null)
                {
                    bg = text.Background?.Path;
                    charas = text.Characters?.Select(c => c.Path).ToList();

                    DrawingVisual drawingVisual = new DrawingVisual();

                    using (var context = drawingVisual.RenderOpen())
                    {
                        if (!String.IsNullOrEmpty(bg))
                        {

                            var bgfile = FileHelper.FindFile(Project.Current.BackgroundPath, bg);

                            if (bgfile != null)
                            {
                                var bgImage = new BitmapImage(new Uri(bgfile));
                                context.DrawImage(bgImage, new Rect(0, 0, bgImage.PixelWidth, bgImage.PixelHeight));
                            }
                        }

                        charas = charas?.Distinct().ToList();

                        if ((charas?.Count ?? 0) > 0)
                        {
                            var charaImage = charas.Select(c =>
                            {
                                if (!String.IsNullOrEmpty(c))
                                {
                                    var charafile = FileHelper.FindFile(Project.Current.CharacterPath, c);

                                    if (charafile != null)
                                    {
                                        return new BitmapImage(new Uri(charafile));
                                    }
                                }

                                return null;
                            }).ToList();
                            charaImage.RemoveAll(b => b == null);

                            for (int index = 0; index < charaImage.Count; index++)
                            {
                                var image = charaImage[index];
                                switch (charaImage.Count)
                                {
                                    case 1:
                                        context.DrawImage(image, new Rect(0, 0, image.Width, image.Height));
                                        break;
                                    case 2:
                                        context.DrawImage(image, new Rect(-240 + (index * 440), 0, image.Width, image.Height));
                                        break;
                                    case 3:
                                        context.DrawImage(image, new Rect(-440 + (index * 440), 0, image.Width, image.Height));
                                        break;
                                }
                            }
                        }

                        context.Close();
                        RenderTargetBitmap renderBitmap = new RenderTargetBitmap(1280, 720, 96, 96, PixelFormats.Pbgra32);
                        renderBitmap.Render(drawingVisual);
                        if (renderBitmap.CanFreeze)
                        {
                            renderBitmap.Freeze();
                        }
                        return renderBitmap;
                    }
                }
                return null;
            });

        }
コード例 #3
0
ファイル: TextFile.cs プロジェクト: RuriJudgement/Mistilteinn
        public static TextFile FromFile(String path)
        {
            var result = new TextFile();

            var lines = File.ReadAllLines(path);
            var currentText = new Text(result);

            for (int index = 0; index < lines.Length; index++)
            {
                var line = lines[index];
                if (line.Length > 0)
                {
                    switch (line[0])
                    {
                        case '*':
                            var infomation = new TextFileInfomation(line.Substring(2, line.Length - 3).Split(','));
                            result.Infomations.Add(infomation);
                            break;
                        case '[':
                            var values = line.Trim('[', ']').Split(',');
                            if (values.Length > 0)
                            {
                                try
                                {
                                    currentText.InputTag = int.Parse(values[0]);
                                }
                                catch (Exception ex)
                                {
                                    throw new FormatException($"遇到不可读的导入标志,在{path},行{index},{line}", ex);
                                }
                                for (int i = 1; i < values.Length; i++)
                                {
                                    var value = values[i];
                                    switch (value[0])
                                    {
                                        case '$':
                                            currentText.NameBoard = value.Substring(1);
                                            break;
                                        case '%':
                                            currentText.Voice = new Voice(value.Substring(1));
                                            break;
                                        case '^':
                                            currentText.Background = new Background(value.Substring(1));
                                            break;
                                        case '@':
                                            currentText.Music = new Music(value.Substring(1));
                                            break;
                                        case '&':
                                            currentText.Characters.Add(new Character(value.Substring(1)));
                                            break;
                                        case '#':
                                            currentText.Face = new Face(value.Substring(1));
                                            break;
                                    }
                                }
                            }
                            break;
                        case '>':
                            if (String.IsNullOrEmpty(currentText.OriginalText))
                            {
                                currentText.OriginalText = line.Substring(1);
                            }
                            else
                            {
                                currentText.OriginalText += $"\r\n{line.Substring(1)}";
                            }
                            break;
                        case '<':
                            if (String.IsNullOrEmpty(currentText.TranslatedText))
                            {
                                currentText.TranslatedText = line.Substring(1);
                            }
                            else
                            {
                                currentText.TranslatedText += $"\r\n{line.Substring(1)}";
                            }
                            break;
                        case '#':
                            if (String.IsNullOrEmpty(currentText.Comment))
                            {
                                currentText.Comment = line.Substring(1);
                            }
                            else
                            {
                                currentText.Comment += $"\r\n{line.Substring(1)}";
                            }
                            break;
                        default:
                            Debug.WriteLine($"遇到未知标识符,在{path},行{index},{line}");
                            break;
                    }
                }
                else
                {
                    if (!currentText.IsEmpty)
                    {
                        currentText.Index = result.Texts.Count + 1;
                        result.Texts.Add(currentText);
                        currentText.CreateOver();
                        TextChecker.Check(currentText);
                        currentText = new Text(result);
                    }
                }
            }

            if (!currentText.IsEmpty && !result.Texts.Contains(currentText))
            {
                currentText.Index = result.Texts.Count + 1;
                result.Texts.Add(currentText);
                currentText.CreateOver();
                TextChecker.Check(currentText);
            }

            return result;
        }
コード例 #4
0
        public static TextCheckResult Check(Text text)
        {
            TextCheckResult result = new TextCheckResult()
            {
                Text = new WeakReference<Text>(text),
            };

            if (text.CheckResult != null)
            {
                if (text.CheckResult.IsChecking)
                {
                    return null;
                }
            }
            else
            {
                text.CheckResult = result;
            }

            text.CheckResult.IsChecking = true;

            if (String.IsNullOrEmpty(text.TranslatedText))
            {
                result.Result |= TextCheckResultType.NotTranslated;
                result.Importance |= ErrorImportance.Error;
            }

            if (text.TranslatedText.Any(c => c < 0xFF))
            {
                result.Result |= TextCheckResultType.HalfWidthCharacter;
                result.Importance |= ErrorImportance.Infomation;
            }

            var phoneticMarker = Regex.Match(text.TranslatedText, @"\[rb,[\s\S]*,[\s\S]*\]");
            if (phoneticMarker.Success)
            {
                result.Result |= TextCheckResultType.PhoneticMarker;
                result.Importance |= ErrorImportance.Infomation;
            }

            if (text.OriginalText.Split("\r\n".ToCharArray(), StringSplitOptions.None).Length !=
                text.TranslatedText.Split("\r\n".ToCharArray(), StringSplitOptions.None).Length)
            {
                result.Result |= TextCheckResultType.LineNotMatch;
                result.Importance |= ErrorImportance.Warnning;
            }

            var oStartChars = text.OriginalText.Substring(0,
                text.OriginalText.Length - text.OriginalText.TrimStart(" 。?!…「」『』".ToCharArray()).Length);
            var tStartChars = text.TranslatedText.Substring(0,
                text.TranslatedText.Length - text.TranslatedText.TrimStart(" 。?!…「」『』".ToCharArray()).Length);
            if (oStartChars != tStartChars)
            {
                result.Result |= TextCheckResultType.FormatNotMatch;
                result.Importance |= ErrorImportance.Warnning;
            }
            else
            {
                var oEndChars =
                    text.OriginalText.Substring(text.OriginalText.TrimEnd(" 。?!…「」『』".ToCharArray()).Length,
                        text.OriginalText.Length - text.OriginalText.TrimEnd(" 。?!…「」『』".ToCharArray()).Length);
                var tEndChars =
                    text.TranslatedText.Substring(text.TranslatedText.TrimEnd(" 。?!…「」『』".ToCharArray()).Length,
                        text.TranslatedText.Length - text.TranslatedText.TrimEnd(" 。?!…「」『』".ToCharArray()).Length);
                if (oEndChars != tEndChars)
                {
                    result.Result |= TextCheckResultType.FormatNotMatch;
                    result.Importance |= ErrorImportance.Warnning;
                }
            }

            if (NameTableUnit.NameTable.Where(n => text.OriginalText.ToLower().Contains(n.Key.ToLower())).Any(n => text.TranslatedText.ToLower().Contains(n.Key.ToLower()) && n.Key != n.Value.TranslatedText && !String.IsNullOrEmpty(n.Value.TranslatedText.Trim(" 。?!…「」『』,、".ToCharArray()))))
            {
                result.Result |= TextCheckResultType.NounNotReplaced;
                result.Importance |= ErrorImportance.Infomation;
            }

            var japanese = Regex.Match(text.TranslatedText, @"[\u3040-\u30FF\u31F0-\u31FF]+");
            if (japanese.Success)
            {
                result.Result |= TextCheckResultType.Japanese;
                result.Importance |= ErrorImportance.Infomation;
            }

            if (Microsoft.VisualBasic.Strings.StrConv(text.TranslatedText, VbStrConv.SimplifiedChinese) !=
                text.TranslatedText)
            {
                result.Result |= TextCheckResultType.TraditionalChinese;
                result.Importance |= ErrorImportance.Warnning;

            }
            else
            {
                var matches = Regex.Matches(text.TranslatedText, @"[\u4e00-\u9fa5]+");
                foreach (Match chinese in matches)
                {
                    if (chinese.Success)
                    {
                        Encoding gb = Encoding.GetEncoding("gb2312");
                        foreach (var ch in chinese.Value)
                        {
                            var bytes = gb.GetBytes(ch.ToString());

                            if (bytes.Length == 2)
                            {
                                if (bytes[0] >= 0xB0
                                    && bytes[0] <= 0xF7
                                    && bytes[1] >= 0xA1
                                    && bytes[1] <= 0xFE)
                                {

                                }
                                else
                                {
                                    result.Result |= TextCheckResultType.TraditionalChinese;
                                    result.Importance |= ErrorImportance.Warnning;
                                    goto TraditionalChinese;
                                }
                            }
                        }
                    }
                }
            }

            TraditionalChinese:;

            int okLenght = Math.Max(5, (int)Math.Round(text.OriginalText.Length * 0.45));

            if (text.OriginalText.Length - text.TranslatedText.Length > okLenght)
            {
                result.Result |= TextCheckResultType.TooShort;
                result.Importance |= ErrorImportance.Infomation;
            }

            if (text.OriginalText.Count(c => " 。?!…「」『』".Contains(c)) != text.TranslatedText.Count(c => " 。?!…「」『』".Contains(c)))
            {
                result.Result |= TextCheckResultType.PunctuationsNotMatch;
                result.Importance |= ErrorImportance.Infomation;
            }

            text.CheckResult.IsChecking = false;
            if (text.CheckResult != result)
            {
                text.CheckResult.Importance = result.Importance;
                text.CheckResult.Result = result.Result;
            }
            return text.CheckResult;
        }