void PlaySound(string name)
    {
        Bilingual playUnit = null;
        //获取卡牌类型
        //不是字母的话播放双语
        string pare = null;

        //先去小库(500个单词)里找解释
        if (ContentHelper.Instance.units.ContainsKey(name))
        {
            WordUnit unit = ContentHelper.Instance.units[name];
            pare = unit.Parephrase;
        }
        else//去词典里找解释
        {
            pare = ContentHelper.Instance.GetPare(name);
        }
        if (name.Contains("-"))
        {
            name = name.Replace("-", " ");
        }
        playUnit = new Bilingual(name, pare);
        //AudioManager.Instance.PlayBilingual(playUnit);
        playUnit.Play();
        //AudioManager.Instance.SetUnits(playUnit);
    }
예제 #2
0
    /// <summary>播放单个语音</summary>
    private void PlaySound(IListenerTracker listener)
    {
        string name = null;

        name = listener.OnGetCurrentTransform().name.ToLower();
        PlayUnit playUnit = null;

        //获取卡牌类型
        //不是字母的话播放双语
        if (listener.Type != TrackerType.LETTER)
        {
            string pare = null;
            //先去小库(500个单词)里找解释
            if (ContentHelper.Instance.units.ContainsKey(name))
            {
                WordUnit unit = ContentHelper.Instance.units[name];
                pare = unit.Parephrase;
            }
            else//去词典里找解释
            {
                pare = ContentHelper.Instance.GetPare(name);
            }
            playUnit = new Bilingual(name, pare);
        }
        else//只播放声音(非双语)
        {
            playUnit = new SingleTone(name);
        }
        AudioManager.Instance.SetUnits(playUnit);
    }
예제 #3
0
        private void AppendLine(List <WordUnit> words, int level)
        {
            WordUnit word;

            if (words.Count == 0)
            {
                words.Add(word = new WordUnit());
            }
            else
            {
                word = new WordUnit('\r')
                {
                    UnitType = TemplateUnitType.Code
                };
                word.Append(-1, '\n');
                if (words[words.Count - 1].ItemFamily != CodeItemFamily.Space)
                {
                    words.Add(word);
                }
                else
                {
                    words[words.Count - 1] = word;
                }
            }
            for (int i = 0; i < level * 4; i++)
            {
                word.Append(-1, ' ');
            }
        }
        private TreeItem CreateLuaTreeItem(object arg)
        {
            var block = arg as AnalyzeBlock;

            if (block != null)
            {
                return(new TreeItem <AnalyzeUnitBase>(block)
                {
                    IsExpanded = block.ItemRace > CodeItemRace.Value,
                    Header = $"{block.Name ?? block.Word ?? "$"}{(block.IsError ? "×" : "√")}{block.ValueType}",
                    CreateChildFunc = CreateLuaTreeItem,
                    FriendItems = block.Elements,
                    SoruceTypeIcon = Application.Current.Resources["tree_Folder"] as BitmapImage
                });
            }
            WordUnit unit = arg as WordUnit;

            if (unit != null)
            {
                return(new TreeItem <AnalyzeUnitBase>(unit)
                {
                    Header = unit.IsKeyWord
                        ? unit.Word
                        : $"{unit.Name ?? unit.Word ?? "_root_"}{(unit.IsError ? "×" : "√")}{unit.ValueType}",
                    SoruceTypeIcon = Application.Current.Resources["img_file"] as BitmapImage
                });
            }
            return(new TreeItem("???")
            {
                SoruceTypeIcon = Application.Current.Resources["img_file"] as BitmapImage
            });
        }
예제 #5
0
 /// <summary>
 ///     类型对等设置
 /// </summary>
 /// <param name="def"></param>
 /// <param name="value"></param>
 private void SetVarDataType(WordUnit def, AnalyzeUnitBase value)
 {
     if (def == null)
     {
         return;
     }
     if (def.Name == null)
     {
         def.Name = def.Word;
     }
     if (!_vers.ContainsKey(def.Name))
     {
         _vers.Add(def.Name, AnalyzeValueBlock(value));
     }
     else if (_vers[def.Name] == LuaDataTypeItem.Confirm)
     {
         _vers[def.Name] = AnalyzeValueBlock(value);
     }
 }
예제 #6
0
 private void CheckWord()
 {
     foreach (var tm in TemplateElements)
     {
         if (tm.IsContent)
         {
             continue;
         }
         WordUnit pre = null;
         foreach (var element in tm.Elements)
         {
             switch (element.ItemRace)
             {
             case CodeItemRace.Completion:
                 pre = null;
                 continue;
             }
             foreach (var word in element.Words)
             {
                 if (word.IsEmpty || word.ItemFamily == CodeItemFamily.Rem)
                 {
                     continue;
                 }
                 if (word.IsSpace || word.ItemType == CodeItemType.String)
                 {
                     pre = null;
                     continue;
                 }
                 if (word.IsPunctuate)
                 {
                     CheckPunctuate(word, ref pre);
                 }
                 else
                 {
                     CheckWord(word);
                 }
             }
         }
     }
 }
예제 #7
0
        private void CheckPunctuate(WordUnit word, ref WordUnit pre)
        {
            switch (word.Char)
            {
                #region 其它

            case '#':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 33;
                word.JoinLevel    = 2;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.Front;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Operator, CodeItemType.StringLen);
                pre = null;
                break;

            case ';':
                word.IsKeyWord = true;
                word.SetRace(CodeItemRace.Control, CodeItemFamily.Control, CodeItemType.Separator_Semicolon);
                pre = null;
                break;

            default:
                pre = null;
                break;

                #endregion

                #region 扩号区域

            case '{':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 2;
                word.ValueType    = LuaDataTypeItem.TableDefinition;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets41);
                pre = null;
                break;

            case '}':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 2;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets42);
                pre = null;
                break;

            case '(':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 3;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets21);
                pre = null;
                break;

            case ')':
                word.IsKeyWord = true;
                word.JoinLevel = 3;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets22);
                pre = null;
                break;

            case '[':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 1;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets31);
                pre = null;
                break;

            case ']':
                word.IsKeyWord = true;
                word.JoinLevel = 1;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets32);
                pre = null;
                break;

                #endregion

                #region 算术计算

            case '+':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 5;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Add);
                pre = null;
                break;

            case '-':
                word.IsKeyWord   = true;
                word.JoinLevel   = 5;
                word.ValueType   = LuaDataTypeItem.NumberValue;
                word.JoinFeature = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Sub);
                pre = null;
                break;

            case '*':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 4;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Mulit);
                pre = null;
                break;

            case '/':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 4;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Div);
                pre = null;
                break;

            case '%':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 4;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Mod);
                pre = null;
                break;

            case '^':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 3;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Exp);
                pre = null;
                break;

                #endregion

                #region 连接符

            case ',':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 3;
                word.JoinFeature  = JoinFeature.Connect;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_Comma);
                pre = null;
                break;

            case ':':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 1;
                word.JoinFeature  = JoinFeature.Connect;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_Colon);
                pre = null;
                break;

            case '.':
                if (pre == null || pre.FirstChar != '.')
                {
                    word.IsKeyWord    = true;
                    word.PrimaryLevel = 1;
                    word.JoinLevel    = 1;
                    word.JoinFeature  = JoinFeature.Connect;
                    word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_Dot);
                    pre = word;
                }
                else if (pre.Chars.Count == 1)
                {
                    pre.Append(word);
                    word.Clear();
                    pre.JoinLevel = 2;
                    pre.ValueType = LuaDataTypeItem.StringValue;
                    pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_StringJoin);
                }
                else
                {
                    pre.Append(word);
                    word.Clear();
                    word.IsKeyWord  = false;
                    pre.JoinLevel   = -1;
                    pre.ValueType   = LuaDataTypeItem.TableDefinition;
                    pre.JoinFeature = JoinFeature.None;
                    pre.SetRace(CodeItemRace.Variable, CodeItemFamily.Variable, CodeItemType.Variable_Arg);
                    pre = null;
                }
                break;
                #endregion

                #region 逻辑比较

            case '>':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.ValueType    = LuaDataTypeItem.BoolValue;
                word.JoinLevel    = 6;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_Greater);
                pre = word;
                break;

            case '<':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.ValueType    = LuaDataTypeItem.BoolValue;
                word.JoinLevel    = 6;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_Less);
                pre = word;
                break;

            case '~':
                pre = word;
                break;

            case '=':
                bool canLink = false;
                if (pre != null)
                {
                    switch (pre.Char)
                    {
                    case '>':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_GreaterEqual);
                        break;

                    case '<':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_LessEqual);
                        break;

                    case '~':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_NotEqual);
                        break;

                    case '=':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_Equal);
                        break;
                    }
                }
                if (canLink)
                {
                    pre.Append(word);
                    word.Clear();
                    pre.PrimaryLevel = 1;
                    pre.ValueType    = LuaDataTypeItem.BoolValue;
                    pre.JoinLevel    = 6;
                    pre.JoinFeature  = JoinFeature.TowWay;
                    pre = null;
                }
                else
                {
                    word.PrimaryLevel = 1;
                    word.IsKeyWord    = true;
                    word.JoinLevel    = 9;
                    word.JoinFeature  = JoinFeature.TowWay;
                    word.SetRace(CodeItemRace.Sentence, CodeItemFamily.SetValue, CodeItemType.Separator_Equal);
                    pre = word;
                }
                break;

                #endregion
            }
        }
예제 #8
0
        /// <summary>
        ///     括号块组合
        /// </summary>
        /// <returns></returns>
        public void MergeBracket(AnalyzeBlock root)
        {
            var cur = root;
            Stack <CodeItemType> stack = new Stack <CodeItemType>();

            foreach (var unit in root.ResetElements())
            {
                if (unit.IsEmpty)
                {
                    continue;
                }
                var word = unit as WordUnit;
                if (word == null)
                {
                    cur.Append(unit);
                    continue;
                }
                if (word.IsSpace)
                {
                    continue;
                }
                AnalyzeBlock block;
                switch (unit.ItemType)
                {
                case CodeItemType.Brackets31:
                    var vw = new WordUnit('.')
                    {
                        Start        = unit.Start,
                        End          = unit.End,
                        IsReplenish  = true,
                        IsKeyWord    = true,
                        PrimaryLevel = 1,
                        JoinLevel    = 1,
                        JoinFeature  = JoinFeature.Connect
                    };
                    vw.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_Dot);
                    cur.Append(vw);
                    stack.Push(unit.ItemType + 1);
                    block = new AnalyzeBlock
                    {
                        Parent  = cur,
                        Primary = word
                    };
                    cur.Append(block);
                    cur = block;
                    break;

                case CodeItemType.Brackets21:
                case CodeItemType.Brackets41:
                    stack.Push(unit.ItemType + 1);
                    block = new AnalyzeBlock
                    {
                        Parent  = cur,
                        Primary = word
                    };
                    cur.Append(block);
                    cur = block;
                    break;

                case CodeItemType.Brackets22:
                case CodeItemType.Brackets32:
                case CodeItemType.Brackets42:
                    if (stack.Count > 0 && stack.Peek() == unit.ItemType)
                    {
                        stack.Pop();
                        unit.IsError = true;
                        cur.Append(unit);
                        cur.Release();
                        if (cur.Parent == null)
                        {
                            cur.IsError = true;
                        }
                        else
                        {
                            cur = cur.Parent;
                        }
                        continue;
                    }
                    break;
                }
                cur.Append(word);
            }
            LinkBarket(root);
        }
예제 #9
0
        private void CheckWord(WordUnit word)
        {
            if (char.IsNumber(word.Chars[0]))
            {
                word.ValueType = LuaDataTypeItem.NumberValue;
                word.SetRace(CodeItemRace.Value, CodeItemFamily.Constant, CodeItemType.Number);
                return;
            }
            if (!_keyWords.Contains(word.Word))
            {
                word.Name = word.Word;
                word.SetRace(CodeItemRace.Variable, CodeItemFamily.Variable);
                return;
            }
            word.IsKeyWord = true;
            switch (word.Word)
            {
            default:
                word.SetRace(CodeItemRace.None, CodeItemFamily.KeyWord);
                break;

            case "nil":
                word.ValueType = LuaDataTypeItem.Nil;
                word.SetRace(CodeItemRace.Value, CodeItemFamily.Constant, CodeItemType.Value_Null);
                break;

            case "true":
                word.ValueType = LuaDataTypeItem.BoolValue;
                word.SetRace(CodeItemRace.Value, CodeItemFamily.Constant, CodeItemType.Value_True);
                break;

            case "false":
                word.ValueType = LuaDataTypeItem.BoolValue;
                word.SetRace(CodeItemRace.Value, CodeItemFamily.Constant, CodeItemType.Value_False);
                break;

            case "and":
                word.JoinLevel    = 7;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Logical, CodeItemType.Key_And);
                break;

            case "or":
                word.JoinLevel    = 8;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Logical, CodeItemType.Key_Or);
                break;

            case "not":
                word.JoinLevel    = 2;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.Front;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Key_Not);
                break;

            case "local":
                word.JoinLevel    = 2;
                word.JoinFeature  = JoinFeature.Front;
                word.PrimaryLevel = 33;
                word.SetRace(CodeItemRace.Control, CodeItemFamily.Scope, CodeItemType.Key_Local);
                break;

            case "break":
                word.SetRace(CodeItemRace.Control, CodeItemFamily.Control, CodeItemType.Key_Break);
                break;

            case "return":
                word.JoinLevel    = 2;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.Front;
                word.SetRace(CodeItemRace.Control, CodeItemFamily.Control, CodeItemType.Key_Return);
                break;

            case "for":
                word.JoinLevel    = 12;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.RangeOpen;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Iterator, CodeItemType.Key_For);
                break;

            case "in":
                word.JoinLevel   = 9;
                word.JoinFeature = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Control, CodeItemType.Key_In);
                break;

            case "if":
                word.JoinLevel    = 11;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.RangeOpen;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Condition, CodeItemType.Key_If);
                break;

            case "while":
                word.JoinLevel    = 11;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.RangeOpen;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Condition, CodeItemType.Key_While);
                break;

            case "else":
                word.PrimaryLevel = 3;
                word.JoinFeature  = JoinFeature.RangeShift;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Condition, CodeItemType.Key_Else);
                break;

            case "elseif":
                word.PrimaryLevel = 2;
                word.JoinFeature  = JoinFeature.RangeShift;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Condition, CodeItemType.Key_Elseif);
                break;

            case "then":
                word.JoinFeature = JoinFeature.RangeShift;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Control, CodeItemType.Key_Then);
                break;

            case "go":
                word.JoinFeature = JoinFeature.RangeShift;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Control, CodeItemType.Key_Go);
                break;

            case "repeat":
                word.JoinLevel   = 10;
                word.JoinFeature = JoinFeature.RangeOpen;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Condition, CodeItemType.Key_Repeat);
                break;

            case "until":
                word.JoinLevel    = 10;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.RangeClose;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Condition, CodeItemType.Key_Until);
                break;

            case "function":
                word.JoinLevel    = 11;
                word.PrimaryLevel = 1;
                word.JoinFeature  = JoinFeature.RangeOpen;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.FunctionRange, CodeItemType.Key_Function);
                break;

            case "do":
                word.JoinLevel    = 11;
                word.PrimaryLevel = 2;
                word.JoinFeature  = JoinFeature.RangeOpen;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Key_Do);
                break;

            case "end":
                word.JoinLevel   = 11;
                word.JoinFeature = JoinFeature.RangeClose;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Key_End);
                break;
            }
        }
예제 #10
0
 private void Append(List <WordUnit> words, WordUnit word)
 {
     words.Add(word);
 }
예제 #11
0
        private void LevelCode(List <AnalyzeElement> elements1)
        {
            int level = 4;

            foreach (var aelement in elements1)
            {
                if (aelement.Elements[0].ItemType != CodeItemType.Line)
                {
                    aelement.Insert(0, CreateLineElement());
                }
                WordUnit pre = null;
                foreach (var element in aelement.Elements)
                {
                    switch (element.ItemRace)
                    {
                    case CodeItemRace.Value:
                    case CodeItemRace.Variable:
                    case CodeItemRace.Assist:
                        pre = null;
                        continue;
                    }
                    foreach (var word in element.Words)
                    {
                        if (word.IsPunctuate)
                        {
                            if (!word.IsSpace)
                            {
                                pre = null;
                            }
                            else if (word.IsLine)
                            {
                                pre       = word;
                                pre.Level = level;
                            }
                            continue;
                        }
                        switch (word.Word)
                        {
                        case "end":
                        case "until":
                        case "elseif":
                            level -= 4;
                            if (pre != null)
                            {
                                pre.Level = level;
                            }
                            break;

                        case "else":
                            if (pre != null && level > 4)
                            {
                                pre.Level = level - 4;
                            }
                            break;

                        case "do":
                        case "go":
                        case "then":
                        case "repeat":
                            level += 4;
                            break;
                        }
                        pre = null;
                    }
                }
            }
        }