more dialog garbage testing code

This commit is contained in:
2022-12-02 21:12:25 +01:00
parent c4500b09f4
commit 29d3a7d130
4 changed files with 48 additions and 22 deletions

View File

@@ -1,12 +1,47 @@
using Godot;
using Godot.Collections;
using System;
public partial class dialog_bubble : CanvasLayer
{
public void ImportString(string dialogTitle, string printedDialog)
public string printedDialog;
public int debugCounter;
public void ImportString(string dialogTitle, string dialogFile, string playerName)
{
Visible = !Visible;
Visible = true;
GD.Print("test");
GetNode("/root/main/player").Call("ChangeProcess",false);
string currentKey = "randomWelcomeText";
using var file = FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read);
string text = file.GetAsText();
var jsonFile = JSON.ParseString(text);
Dictionary allDialog = (Dictionary)jsonFile;
if (currentKey.BeginsWith("random"))
{
string[] dialogPart = allDialog[currentKey].AsStringArray();
printedDialog = dialogPart[GD.Randi() % dialogPart.Length];
}
else printedDialog = allDialog[currentKey].AsString();
printedDialog = String.Format(printedDialog, playerName);
GetNode<Label>("TextLabel").Text = printedDialog;
GetNode<Label>("NameLabel").Text = dialogTitle;
}
public void EndDialog()
{
Visible = false;
GetNode("/root/main/player").Call("ChangeProcess", true);
}
public override void _Process(double delta)
{
if (Input.IsActionJustPressed("ui_accept"))
{
debugCounter++;
}
if(debugCounter == 2)
{
EndDialog();
debugCounter = 0;
}
}
}