I have an
NPC class with a
DialogueTree object as a field.
DialogueTree objects are automatically constructed recursively by loading in the contents of
.xml files where they're stored.
In building my
XMLDialogueLoader class, I see two main approaches:
- Load in every dialogues for every NPC on game start, available as a sort of pool from which any components that depend on it can access. Sort of like a global dictionary, when NPCs are constructed they index their ID in that Dialogue pool to retrieve their dialogues.
dialogue_pool: dict[str, DialogueTree] = dialogue_loader.load('dialogues/') npc = NPC('John', dialogue_pool['John'] npc = NPC('Tom', dialogue_pool['Tom']
- Load in every dialogue for NPCs only when they are being constructed. I would likely do this by creating an
NPCFactoryobject that takes in a
DialogueLoaderwith a method to load in a specific NPC's dialogue at a time, like
class NPCFactory: dialogue_loader: DialogueLoader build(self, name: str): dialogue_tree = dialogue_loader.load(name) return NPC(name, dialogue_tree)
I suppose another set of variations would be loading in specific dialogues just in time rather than all at once, but that seems maybe excessive.
What advantages and disadvantages exist in these approaches? What is typical in industry? Are there better ways of doing this or alternative approaches?