Skip to content

Commit

Permalink
Added proper parsing and error propagation to dialog loading :3
Browse files Browse the repository at this point in the history
  • Loading branch information
QueenOfSquiggles committed Jan 6, 2024
1 parent ed31dcb commit f7f68e8
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 43 deletions.
5 changes: 5 additions & 0 deletions scenes/testing_scene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends Node

func _ready() -> void:
CoreDialog.load_track("res://Dialogic/example.json")
get_tree().quit()
6 changes: 6 additions & 0 deletions scenes/testing_scene.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dye2udaumkvuo"]

[ext_resource type="Script" path="res://addons/squiggles_core/scenes/testing_scene.gd" id="1_aa00h"]

[node name="Node" type="Node"]
script = ExtResource("1_aa00h")
2 changes: 1 addition & 1 deletion squiggles_core.gdextension
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[configuration]
entry_symbol = "gdext_rust_init"
compatibility_minimum = 4.2

reloadable = true


[libraries]
Expand Down
2 changes: 1 addition & 1 deletion src/scene/dialog/dialog_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl ICanvasLayer for DialogGUI {
//pass
}

fn input(&mut self, event: Gd<InputEvent>) {}
fn input(&mut self, _event: Gd<InputEvent>) {}

fn exit_tree(&mut self) {
//pass
Expand Down
38 changes: 24 additions & 14 deletions src/scene/dialog/dialog_manager.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use godot::{engine::Engine, prelude::*};

use super::{dialog_gui::DialogGUI, dialog_track::DialogTrack};
use super::{
dialog_gui::DialogGUI,
dialog_track::{DialogError, DialogTrack},
};

#[derive(GodotClass)]
#[class(init, base=Node)]
pub struct CoreDialog {
#[var]
current_track: Option<Gd<DialogTrack>>,
current_track: Option<DialogTrack>,
#[var]
current_line_index: i32,
gui: Option<DialogGUI>,
Expand All @@ -25,22 +27,30 @@ impl CoreDialog {
pub const SINGLETON_NAME: &'static str = "CoreDialog";

#[signal]
fn track_ended(track: Gd<DialogTrack>) {}
fn track_ended(track: GString) {}
#[signal]
fn track_signal(name: GString, args: Array<Variant>) {}
#[signal]
fn track_started(track: Gd<DialogTrack>) {}
fn track_started(track: GString) {}

#[func]
pub fn load_track(&mut self, track: Gd<DialogTrack>) {
self.current_track = Some(track.clone());
self.current_line_index = 0;
self.base.emit_signal(
StringName::from(Self::SIGNAL_TRACK_STARTED),
&[track.to_variant()],
);

// Start playing dialog
pub fn load_track(&mut self, file_path: GString) {
match DialogTrack::load_from_json(file_path) {
Err(error) => Self::handle_dialog_error(error),
Ok(track) => self.current_track = Some(track),
}
let Some(track) = &self.current_track else {
return;
};
for (index, line) in track.lines.iter().enumerate() {
println!("Dialog Track [line {}] {:#?}", index, line);
}
}

fn handle_dialog_error(err: DialogError) {
let reason = format!("{:#?}", err);
godot_error!("DialogError: {}", reason);
// godot_print!("DialogError : {}", reason);
}

pub fn singleton() -> Gd<CoreDialog> {
Expand Down
Loading

0 comments on commit f7f68e8

Please sign in to comment.