public void RegenerateLinks(TwineRoot root) { if (links != null) { foreach (var plink in links) { if (!plink.broken) { var linkedPassage = root.Find(plink.pid); if (linkedPassage != null) { passageLinks.Add(linkedPassage); } else { Debug.LogError($"Passage: Failed to find passage with pid {plink.pid}"); } } else { Debug.LogError($"Passage: Found broken link of passage {plink.pid}"); } } } }
protected void ConvertToSnowflake(TwineRoot root) { toParse.Clear(); Passage curP = root.FindPassageWithTag("t:sp"); if (curP == null) { curP = root.FindPassageWithTag("t:sh"); } if (curP == null) { Debug.LogError("DialogueManager: failed to find starting tag."); return; } else { root.startPassage = curP; } toParse.Add(curP); int i = 0; int q = 0; while (i < toParse.Count) { while (q < toParse.Count) { ParsePassage(toParse[q], root); q++; } q = i; i = toParse.Count; while (q < i) { var pLinks = toParse[q].passageLinks; for (int j = 0; j < pLinks.Count; j++) { if (toParse.IndexOf(pLinks[j]) == -1) { toParse.Add(pLinks[j]); } } q++; } } }
protected override void Setup() { toParse = new List <Passage>(); // if (!Inventory.Instance.worldState.Value.companionJsonsLoaded) // { for (int j = 0; j < Inventory.Instance.worldState.Value.companionStates.Count; j++) { currentCompanion = Inventory.Instance.worldState.Value.companionStates[j]; if (!currentCompanion.Data.enabled) { continue; } for (int i = 0; i < currentCompanion.Data.dialogueJsons.Count; i++) { Debug.Log($"~~~ Parsing {currentCompanion.id.ToString()} dialogue {i}"); TwineRoot root = JsonConvert.DeserializeObject <TwineRoot>(currentCompanion.Data.dialogueJsons[i].text); root.PostDeserialize(); ConvertToSnowflake(root); currentCompanion.dialogues[i].root = root; } } // Inventory.Instance.worldState.Value.companionJsonsLoaded = true; Inventory.Instance.worldState.Value.advicesLoaded = true; Inventory.Instance.worldState.Save(); // } // else // { // foreach (var compState in Inventory.Instance.worldState.Value.companionStates) // { // if (!compState.Data.enabled) // { // continue; // } // // for (int i = 0; i < compState.dialogues.Count; i++) // { // TwineRoot tr = compState.dialogues[i].root; // for (int j = 0; j < tr.passages.Count; j++) // { // tr.passages[j].RegenerateLinks(tr); // } // } // } // } }
public void ParsePassage(Passage p, TwineRoot root) { p.RegenerateLinks(root); ParseTags(p); p.parsed = true; }