From 38bd6d47b9c2cf21f99ddd87effd1b9f9dc1cac4 Mon Sep 17 00:00:00 2001 From: cmod31 Date: Tue, 7 Feb 2023 15:48:55 +0100 Subject: [PATCH] way better dialogue system code --- dialogue/npcs/villager_normal.json | 60 +++++++++++++------ .../dialogue-system/dialog_bubble.cs | 53 ++++++++-------- 2 files changed, 68 insertions(+), 45 deletions(-) diff --git a/dialogue/npcs/villager_normal.json b/dialogue/npcs/villager_normal.json index 5a052cd..6aa5878 100644 --- a/dialogue/npcs/villager_normal.json +++ b/dialogue/npcs/villager_normal.json @@ -1,29 +1,51 @@ { "dialogType": "villager", - "playerbeginoptions": { - "talk": [ - "I just wanna talk", - "What's up", - "Can we talk?" - ], - "goaway": [ - "Nevermind!", - "Nothing", - "Have a great day!" - ] - }, "welcome": [ - "Oh hello, {player}... You look great! What do you want from me?", - "Hey, {player}! Hope you have fun today! So what do you want?", - "Hi! What's up {player}?" + [ + "Oh hello, {player}... You look great! What can I do for you?", + { + "I just wanna talk": true, + "Nevermind!": false + } + ], + [ + "Hey, {player}! Hope you have fun today! So what do you want?", + { + "What's up": true, + "Nothing": false + } + ], + [ + "Hi! What's up {player}?", + { + "Can we talk?": true, + "Have a great day!": false + } + ] ], "else": [ - "Do you need something else?", - "So can i help you with something else?" + [ + "Do you need something else?", + { + "Can you tell me something else?": true, + "No, thanks!": false + } + ], + [ + "So can i help you with something else?", + { + "Tell me a bit more maybe": true, + "I'm good, thank you!": false + } + ] ], "goodbye": [ - "Was nice talking to you goodbye!", - "Have a great day, {player}!" + [ + "Was nice talking to you goodbye!" + ], + [ + "Have a great day, {player}!" + ] ], "tipp": [ [ diff --git a/src/scene-scripts/dialogue-system/dialog_bubble.cs b/src/scene-scripts/dialogue-system/dialog_bubble.cs index 7c48e07..bf4a538 100644 --- a/src/scene-scripts/dialogue-system/dialog_bubble.cs +++ b/src/scene-scripts/dialogue-system/dialog_bubble.cs @@ -1,15 +1,14 @@ using Godot; +using Godot.Collections; using System; -using System.Collections; using System.Text.RegularExpressions; public partial class dialog_bubble : CanvasLayer { public Variant parsedDlg; - public ArrayList dlgLines = new ArrayList(); + public Variant dlgLines; public int dlgPointer = 0; public RichTextLabel richText; - public int dialogOptionsLength = 1; public override void _Ready() { @@ -20,25 +19,23 @@ public partial class dialog_bubble : CanvasLayer playerName = "[color=blue]" + playerName + "[/color]"; parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText().Replace("{player}", playerName)); GetNode