more dialog garbage testing code
This commit is contained in:
@@ -16,6 +16,7 @@ radius = 21.0
|
|||||||
height = 66.0
|
height = 66.0
|
||||||
|
|
||||||
[node name="player" type="CharacterBody2D"]
|
[node name="player" type="CharacterBody2D"]
|
||||||
|
process_mode = 1
|
||||||
script = ExtResource("1_qehox")
|
script = ExtResource("1_qehox")
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
public partial class dialog_trigger_area : Area2D
|
public partial class dialog_trigger_area : Area2D
|
||||||
@@ -8,21 +7,8 @@ public partial class dialog_trigger_area : Area2D
|
|||||||
string dialogFile;
|
string dialogFile;
|
||||||
[Export]
|
[Export]
|
||||||
string dialogTitle;
|
string dialogTitle;
|
||||||
public string printedDialog;
|
|
||||||
public void OnInteraction(string playerName)
|
public void OnInteraction(string playerName)
|
||||||
{
|
{
|
||||||
string currentKey = "randomWelcomeText";
|
GetNode("/root/main/dialog_bubble").Call("ImportString",dialogTitle,dialogFile,playerName);
|
||||||
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("/root/main/dialog_bubble").Call("ImportString",dialogTitle, printedDialog);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,47 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
public partial class dialog_bubble : CanvasLayer
|
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>("TextLabel").Text = printedDialog;
|
||||||
GetNode<Label>("NameLabel").Text = dialogTitle;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
public partial class player : CharacterBody2D
|
public partial class player : CharacterBody2D
|
||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
public int speed = 400;
|
|
||||||
[Export]
|
|
||||||
public string playerName;
|
public string playerName;
|
||||||
|
[Export]
|
||||||
|
public int speed = 400;
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
@@ -19,6 +21,7 @@ public partial class player : CharacterBody2D
|
|||||||
* speed * (float)delta
|
* speed * (float)delta
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
public void ChangeProcess(bool process){ if(process) ProcessMode = ProcessModeEnum.Inherit; else ProcessMode = ProcessModeEnum.Disabled; }
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
//set ray_cast target position
|
//set ray_cast target position
|
||||||
@@ -28,7 +31,8 @@ public partial class player : CharacterBody2D
|
|||||||
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -64);
|
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -64);
|
||||||
|
|
||||||
//call event in raycasted object
|
//call event in raycasted object
|
||||||
if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding()) {
|
if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding())
|
||||||
|
{
|
||||||
var raycastedObject = GetNode<RayCast2D>("ray_cast_2d").GetCollider();
|
var raycastedObject = GetNode<RayCast2D>("ray_cast_2d").GetCollider();
|
||||||
raycastedObject.Call("OnInteraction", playerName);
|
raycastedObject.Call("OnInteraction", playerName);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user