From b08e514b1277b746ddb589f0bfbd454faf2c2d81 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Wed, 24 Jun 2020 19:43:36 +0100 Subject: [PATCH] add_dialogue() --- src/game.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/game.rs b/src/game.rs index e1b80d1..44607e7 100644 --- a/src/game.rs +++ b/src/game.rs @@ -548,6 +548,17 @@ impl Game { new_id } + /// adds a dialogue safely and returns the new dialogue ID + #[inline] + pub fn add_dialogue(&mut self, mut dialogue: Dialogue) -> String { + let new_id = try_id(self.dialogue_ids(), dialogue.id.clone()); + if new_id != dialogue.id { + dialogue.id = new_id.clone(); + } + self.dialogues.push(dialogue); + new_id + } + #[inline] fn version_line(&self) -> String { if self.version.is_some() {