private void AssignDecisionButtons(CharacterType char_type, ChineseEntry picked = null)
    {
        List <ChineseEntry> curr_entries = new List <ChineseEntry>();

        if (picked != null)
        {
            curr_entries.Add(picked);
        }

        List <ChineseEntry> shuffled_entries = my_characters.RequestEntries(nbr_choices, studied_only: false);
        int i = 0;

        while (curr_entries.Count < nbr_choices)
        {
            ChineseEntry choice_entry = shuffled_entries[i];
            curr_entries.Add(choice_entry);
            i++;
        }

        curr_entries = MyUtils.Shuffle(curr_entries);
        for (var j = 0; j < nbr_choices; j++)
        {
            ChineseEntry entry       = curr_entries[j];
            string       button_text = GetEntryText(entry, char_type);
            decision_buttons[j].SetText(button_text);
        }
    }
    private string GetEntryText(ChineseEntry entry, CharacterType char_type)
    {
        string entry_text;

        switch (char_type)
        {
        case CharacterType.English:
            entry_text = entry.english;
            break;

        case CharacterType.Pinying:
            entry_text = entry.pinying;
            break;

        default:
            throw new System.Exception("Unknown char_type: " + char_type);
        }
        return(entry_text);
    }
Ejemplo n.º 3
0
    // public static TextSource text_source = TextSource.HalfThreePigs;

    public List <ChineseEntry> ParseChineseEntries(string text_source)
    {
        word_entries    = new List <String[]>();
        chinese_entries = new List <ChineseEntry>();

        if (use_anki_format)
        {
            word_entries = ParseStoryEntities(text_source);

            foreach (String[] word_entry in word_entries)
            {
                String raw_chinese_char = word_entry[1];
                String raw_pinying      = word_entry[2];
                String raw_english      = word_entry[3];

                String       parsed_chinese_char = Regex.Replace(raw_chinese_char, "<.*?>", "");
                String       parsed_english      = Regex.Replace(Regex.Replace(raw_english, "•.*", ""), "<CC>", "");
                ChineseEntry entry = new ChineseEntry(parsed_chinese_char, raw_pinying, parsed_english);
                chinese_entries.Add(entry);
            }
        }
        else
        {
            word_entries = MyUtils.ParseTextToSplitList(text_source, "\t", expected_length: 4, enforce_expected_length: true);
            foreach (String[] word_entry in word_entries)
            {
                String raw_chinese_char = word_entry[0];
                String raw_pinying      = word_entry[1];
                String raw_english      = word_entry[2];
                String radical          = word_entry[3];
                // print(raw_chinese_char + " " + raw_pinying + " " + raw_english);

                ChineseEntry entry = new ChineseEntry(raw_chinese_char, raw_pinying, raw_english, radical);
                chinese_entries.Add(entry);
            }
        }
        return(chinese_entries);
    }