//public void ImportFile(string _filePath) public void ImportFile(int _numWords, string _lettersToUse) { // TODO: Poner aqui para coger los nuevos objetos // Poner un tope de palabras que queremos coger (para aligerar cargas) FreqWord[] freqWords = GameFunctions.GetWordsAndFreqsJson(_numWords, _lettersToUse); // De momento metemos a mano la cantidad de niveles //int levels = 30; wordsPerLevel = freqWords.Length / maxLevels; for (int i = 0; i < freqWords.Length; i++) { WordLine nextWord = new WordLine(freqWords[i].word); nextWord.charLetter = freqWords[i].keyLetter; nextWord.Value = SetWordDifficulty(difficultyCriterias, nextWord.Word, Int32.Parse(freqWords[i].frequency)); // Las de longitud 1 las prugamos aqui // Sería más correcto hacerlos en la función con la que las obtenemos // Pero me da pereza //if (nextWord.Word.Length > 1) lines.Add(i, nextWord); } //dictionaryFile.Close(); }
private void AddLine(int _currentLine, WordLine newLine) { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(GUILayout.MaxHeight(20)); //Dialogue line EditorGUILayout.LabelField(_currentLine.ToString(), GUILayout.MaxWidth(30)); //Dialogue Text string typeOfDialogue = "Word: "; EditorGUILayout.LabelField(typeOfDialogue, GUILayout.MaxWidth(50)); newLine.Word = EditorGUILayout.TextField("", newLine.Word, GUILayout.MaxWidth(300)); // NOTA: De querer mantenerlo podemos hacer que genere el ENUM al cargar las palabras //Letter to skip //EditorGUILayout.LabelField("Letter: ", GUILayout.MaxWidth(40)); //newLine.letter = (Letters)EditorGUILayout.EnumPopup(newLine.letter, options: GUILayout.MaxWidth(80)); //Points EditorGUILayout.LabelField("Value: ", GUILayout.MaxWidth(40)); newLine.Value = EditorGUILayout.IntSlider(newLine.Value, 1, 100, GUILayout.MaxWidth(300)); //AddRemoveWordButton(_currentLine); EditorGUILayout.EndHorizontal(); AddVerticalSeparator(); EditorGUILayout.EndVertical(); }
public void AddNewWord(int _line, WordLine _ds) { if (lines.ContainsKey(_line)) { IncreaseSentenceLineNumber(_line); lines[_line] = _ds; } else { lines.Add(_line, _ds); } }
// The old one with a xml // public void ExportFile(string _filePath) public void ExportFile(string _lettersToUse) { // int maxDifficulty = GetMaxDifficulty(); //Debug.Log(maxDifficulty); //List<FreqWord>[] wordLists = new List<FreqWord>[maxDifficulty]; List <string>[] wordLists = new List <string> [maxDifficulty]; for (int i = 0; i < maxDifficulty; i++) { wordLists[i] = new List <string>(); } // for (int i = 0; i < lines.Count; i++) { WordLine nextWord = (WordLine)lines[i]; //FreqWord newFreqWord = new FreqWord(nextWord.Word, nextWord.charLetter); string wordWithLetter = nextWord.Word + nextWord.charLetter; wordLists[nextWord.Value - 1].Add(wordWithLetter); } // TextObject[] textObjects = new TextObject[maxDifficulty]; //FreqWordsObject[] textObjects = new FreqWordsObject[maxDifficulty]; for (int i = 0; i < maxDifficulty; i++) { textObjects[i] = new TextObject(); textObjects[i].entries = wordLists[i].ToArray(); } // if (!AssetDatabase.IsValidFolder("Assets/Resources/" + _lettersToUse)) { string guid = AssetDatabase.CreateFolder("Assets/Resources", _lettersToUse); string newFolderPath = AssetDatabase.GUIDToAssetPath(guid); } // for (int i = 0; i < maxDifficulty; i++) { string fileName = _lettersToUse + i.ToString(); // string jsonList = JsonUtility.ToJson(textObjects[i]); // string path = Application.dataPath + "/Resources/" + _lettersToUse + "/" + fileName + ".json"; //Debug.Log(path); Debug.Log(jsonList); using (StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.UTF8)) { sw.WriteLine(jsonList); } } }
//public void ImportFile(string _filePath) public void ImportFile(int _numWords, string _lettersToUse) { // TODO: Poner aqui para coger los nuevos objetos // Poner un tope de palabras que queremos coger (para aligerar cargas) FreqWord[] freqWords = GameFunctions.GetWordsAndFreqsJson(_numWords, _lettersToUse); for (int i = 0; i < freqWords.Length; i++) { WordLine nextWord = new WordLine(freqWords[i].word); nextWord.charLetter = freqWords[i].keyLetter; nextWord.Value = SetWordDifficulty(difficultyCriterias, nextWord.Word, Int32.Parse(freqWords[i].frequency)); lines.Add(i, nextWord); } //dictionaryFile.Close(); }
// public List <string>[] GetInWordWithLetterFormat(List <WordLine>[] listsForLevels) { List <string>[] wordLists = new List <string> [maxLevels]; // Tantas listas como niveles for (int i = 0; i < listsForLevels.Length; i++) { // Tantas palabras como toquen por nivel wordLists[i] = new List <string>(wordsPerLevel); for (int j = 0; j < wordsPerLevel; j++) { WordLine nextWord = listsForLevels[i][j]; FreqWord newFreqWord = new FreqWord(nextWord.Word, nextWord.charLetter); wordLists[i].Add(nextWord.Word + nextWord.charLetter); } } return(wordLists); }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\ openFileDialog.Filter = "文本文件|*.txt"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { string path = openFileDialog.FileName; string[] lines = File.ReadAllLines(path, Encoding.UTF8); int contextCount = 0; List <WordLine> words = new List <WordLine>(); bool isContext = true; for (int i = 0, imax = lines.Length; i < imax; i++) { string line = lines[i]; //检查到以下部分为单词部分 if (line == "----------") { isContext = false; continue; } lines[i] = line + "<br>" + string.Format("<div id=\"{0}\"></div>", i + 1); if (isContext) { contextCount++; } else { if (lines[i][0] == '>') { WordLine wl = new WordLine(); wl.line = i + 1; wl.word = line.Substring(1).Trim(); words.Add(wl); } } } List <WordLine> tmpWords = new List <WordLine>(words); for (int i = 0; i < contextCount; i++) { string line = lines[i]; for (int j = words.Count - 1; j >= 0; j--) { var wl = words[j]; if (line.Contains(wl.word)) { line = line.Replace(wl.word, wl.ToString()); wl.firstLine = i + 1; words.RemoveAt(j); lines[wl.line - 1] = lines[wl.line - 1].Replace(wl.word, wl.value); } } lines[i] = line; } File.WriteAllLines(path, lines, Encoding.UTF8); MessageBox.Show("转换成功"); } }