Exemplo n.º 1
0
    public void ImportJSON()
    {
        Debug.Log("Trying to import " + fileToTest.name);
        TokenDictionary dic = new TokenDictionary();

        dic.fileContents = fileToTest.text;
        dic.filePath     = fileToTest.name;
        if (dic.ImportJSON())
        {
            Debug.Log("Imported successfully.");
        }
    }
Exemplo n.º 2
0
    string RunGeneration(bool generateBook = false)
    {
        allDictionaries.Clear();
        allNames.Clear();
        foreach (TextAsset text in AllDictionaryFiles)
        {
            if (text == null)
            {
                continue;
            }
            Debug.Log("Importing " + text.name);
            TokenDictionary dic = new TokenDictionary();
            dic.fileContents = text.text;
            dic.filePath     = text.name;
            dic.ImportJSON();

            foreach (string key in dic.phrases.Keys)
            {
                if (allDictionaries.ContainsKey(key))
                {
                    Debug.LogError("Key " + key + " from " + text.name + " has already been added previously");
                    continue;
                }
                allDictionaries[key] = dic.phrases[key];
            }
        }
        Debug.Log("Finished importing.");

        if (generateBook)
        {
            beastFormula = "%entry";
            StreamWriter bookWriter = new StreamWriter("Assets/Aviary.txt");
            bookWriter.Write(bookIntroduction.text);

            int generatedEntries = 0;
            currentSeason = Season.Summer;
            // Write season introduction
            bookWriter.Write("\n\n" + SectionSeparator + "\n\n" + currentSeason.ToString().ToUpper() + "\n\n");
            bookWriter.Write(GenerateOneEntry("%seasonLine"));
            for (; generatedEntries < EntriesInBook / 4; generatedEntries++)
            {
                bookWriter.Write("\n\n" + SectionSeparator + "\n\n");
                bookWriter.Write(GenerateOneEntry(beastFormula));
            }

            currentSeason = Season.Fall;
            // Write season introduction
            bookWriter.Write("\n\n" + SectionSeparator + "\n\n" + currentSeason.ToString().ToUpper() + "\n\n");
            bookWriter.Write(GenerateOneEntry("%seasonLine"));
            for (; generatedEntries < 2 * EntriesInBook / 4; generatedEntries++)
            {
                bookWriter.Write("\n\n" + SectionSeparator + "\n\n");
                bookWriter.Write(GenerateOneEntry(beastFormula));
            }

            currentSeason = Season.Winter;
            // Write season introduction
            bookWriter.Write("\n\n" + SectionSeparator + "\n\n" + currentSeason.ToString().ToUpper() + "\n\n");
            bookWriter.Write(GenerateOneEntry("%seasonLine"));
            for (; generatedEntries < 3 * EntriesInBook / 4; generatedEntries++)
            {
                bookWriter.Write("\n\n" + SectionSeparator + "\n\n");
                bookWriter.Write(GenerateOneEntry(beastFormula));
            }

            currentSeason = Season.Spring;
            // Write season introduction
            bookWriter.Write("\n\n" + SectionSeparator + "\n\n" + currentSeason.ToString().ToUpper() + "\n\n");
            bookWriter.Write(GenerateOneEntry("%seasonLine"));
            for (; generatedEntries < EntriesInBook; generatedEntries++)
            {
                bookWriter.Write("\n\n" + SectionSeparator + "\n\n");
                bookWriter.Write(GenerateOneEntry(beastFormula));
            }

            bookWriter.Write(bookConclusion.text);
            bookWriter.Close();

            string result = "Book written to Aviary.txt file with " + generatedEntries + " entries.";
            Debug.Log("Names list has " + allNames.Count + " entries");
            Debug.Log(result);
            return(result);
        }
        else
        {
            Debug.Log("Generating text");
            string bird = GenerateOneEntry(beastFormula);
            Debug.Log(bird);
            return(bird);
        }
    }