public static void Extract() { //obtain resource collections DialogueDatabase[] dialDbs = Resources.FindObjectsOfTypeAll <DialogueDatabase>(); LanguageSourceAsset[] langAssets = Resources.FindObjectsOfTypeAll <LanguageSourceAsset>(); //mark extraction as successful if (dialDbs.Length == 0 || langAssets.Length == 0) { return; } Extracted = true; //extract resources DT2.TranslationDatabase transDatabase = new DT2.TranslationDatabase(); ExtractConversations(dialDbs[0], ref transDatabase); ExtractRemaining(langAssets, ref transDatabase); //write obtained translation database to file string json = JsonConvert.SerializeObject(transDatabase); string path = (string)DiscoTranslator2.PluginConfig["Translation", "Database path"].BoxedValue; File.WriteAllText(Path.Combine(path, "database.json"), json); }
static void ExtractConversations(DialogueDatabase database, ref DT2.TranslationDatabase output) { //extract English conversations foreach (var conversation in database.conversations) { //create conversation entry and assign helper title DT2.Conversation conversationEntry = new DT2.Conversation(); conversationEntry.title = conversation.Title; //get conversation root DialogueEntry rootEntry = conversation.GetFirstDialogueEntry(); ResolveLeads(rootEntry, conversation, ref conversationEntry.roots); //detect special conversation types if (Field.LookupValue(conversation.fields, "subtask_title_01") != null) { conversationEntry.type = "journal"; } else if (Field.LookupValue(conversation.fields, "orbSoundVolume") != null) { conversationEntry.type = "orb"; } else if (conversation.Title.ToLower().Contains("barks")) { conversationEntry.type = "barks"; } //obtain conversation metadata foreach (var field in conversation.fields) { //skip empty entries if (String.IsNullOrWhiteSpace(field.value)) { continue; } //skip irrelevant fields string articyId = Field.LookupValue(conversation.fields, "Articy Id"); string id = EncodeConvesationId(articyId, field.title); if (id == null) { continue; } //update conversation metadata conversationEntry.metadata[id] = field.value; } //obtain conversation dialogue entry list foreach (var entry in conversation.dialogueEntries) { //create dialogue entry DT2.DialogueEntry dialogueEntry = new DT2.DialogueEntry(); string entryId = Field.LookupValue(entry.fields, "Articy Id"); //obtain translatable fields foreach (var field in entry.fields) { //skip emprt or irrelevant fields if (string.IsNullOrWhiteSpace(field.value)) { continue; } string fieldId = EncodeDialogueId(entryId, field.title); if (fieldId == null) { continue; } dialogueEntry.fields[fieldId] = field.value; } //skip empty entries if (dialogueEntry.fields.Count == 0) { continue; } //find where the entry leads to dialogueEntry.actor = database.GetActor(entry.ActorID).Name; ResolveLeads(entry, conversation, ref dialogueEntry.leadsTo); conversationEntry.entries[entryId] = dialogueEntry; } //add conversation to list, skip empty dialogues if (conversationEntry.type != "dialogue" || conversationEntry.entries.Count != 0) { output.conversations.Add(conversationEntry); } } }
static void ExtractRemaining(LanguageSourceAsset[] langSource, ref DT2.TranslationDatabase output) { //find a language source with English strings LanguageSourceData englishSource = null; int englishIndex = -1; //iterate over sources foreach (var source in langSource) { //only search miscellaneous sources if (!source.name.Contains("General")) { continue; } //skip if English unavailable int index = source.mSource.GetLanguageIndex("English"); if (index != -1) { englishSource = source.mSource; englishIndex = index; break; } } //initialize type-specific dictionary foreach (KeyValuePair <string, string> kvp in typeDictionary) { if (!output.miscellaneous.ContainsKey(kvp.Value)) { output.miscellaneous.Add(kvp.Value, new Dictionary <string, string>()); } } output.miscellaneous.Add("misc", new Dictionary <string, string>()); //extract remaining terms foreach (var term in englishSource.mTerms) { //skip entries covered by conversations and empty entries if (term.Term.StartsWith("Conversation/")) { continue; } if (string.IsNullOrWhiteSpace(term.Languages[englishIndex])) { continue; } //detect special types string entryType = "misc"; foreach (KeyValuePair <string, string> kvp in typeDictionary) { if (term.Term.StartsWith(kvp.Key)) { entryType = kvp.Value; break; } } //skip redundant actor entries if (entryType == "actors" && char.IsDigit(term.Term, 26)) { continue; } //add entry to database output.miscellaneous[entryType].Add(term.Term, term.Languages[englishIndex]); } }