Skip to content

Commit

Permalink
use regular strings for speakers
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed Aug 17, 2024
1 parent 8cdcdd7 commit 74609dd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 55 deletions.
4 changes: 0 additions & 4 deletions pets-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ chrono = { version = "0.4.38", features = ["serde"] }
concat-idents = "1.1.5"
derive_more = "0.99.17"
derived-deref = "2.1.0"
dialogical = "=0.13.1"
# godot = { version = "0.1.3", features = ["api-4-3", "experimental-threads", "experimental-godot-api"] }
godot = { git = "https://github.com/godot-rust/gdext", rev = "c6d5205", features = ["api-4-3", "experimental-threads", "experimental-godot-api"] }
indoc = "2.0.4"
Expand All @@ -27,6 +26,3 @@ strum = { version = "0.26.1", features = ["derive"] }
toml = "0.8.15"
typetag = "0.2.15"

[build-dependencies]
dialogical = "=0.13.1"

69 changes: 24 additions & 45 deletions pets-lib/src/dialogue/dbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! Dialog box class for menus and dialogue text
//!
use dialogical::prelude::*;
use godot::classes::{
AnimationPlayer, Control, HBoxContainer, IPanelContainer, InputEvent,
PanelContainer, RichTextLabel, Timer,
Expand All @@ -27,9 +26,7 @@ pub struct DialogBox {
#[init(node = "VBox/Choices/ChoiceAgent")]
choice_agent: OnReady<Gd<ChoiceAgent>>,

#[init(val = Speaker::Narrator)]
speaker: Speaker,

speaker: String,
message: String,

#[init(val = DEFAULT_VOX.to_owned())]
Expand Down Expand Up @@ -58,20 +55,7 @@ impl DialogBox {

#[func]
fn set_speaker(&mut self, spk: String) {
self.speaker = Speaker::Named(spk);
}

// Godot doesn't have fancy-pants enums like Rust, so
// these 2 methods are for the "special" speakers

#[func]
fn set_speaker_narrator(&mut self) {
self.speaker = Speaker::Narrator;
}

#[func]
fn set_speaker_unknown(&mut self) {
self.speaker = Speaker::Unknown;
self.speaker = spk;
}

// --------------------------------------------------------------
Expand Down Expand Up @@ -143,13 +127,8 @@ impl DialogBox {
/// The current speaker's name, processed.
/// First processes placeholders, then translation keys.
fn translated_speaker(&self) -> GString {
use Speaker::*;

match &self.speaker {
Named(name) => tr(placeholders::process_placeholders(&name)),
Narrator => "".into(),
Unknown => tr("DG_SPK_UNKNOWN"),
}
// Unknown => tr("DG_SPK_UNKNOWN"),
tr(placeholders::process_placeholders(&self.speaker))
}

fn translated_message(&self) -> GString {
Expand Down Expand Up @@ -302,26 +281,26 @@ impl DialogBox {
}

/// delete old labels and create new default ones
pub fn recreate_choice_labels(&mut self, choices: &[DialogueChoice]) {
self.free_choice_labels();

let mut cont = self.choice_container();

for (i, choice) in choices.iter().enumerate() {
let mut dchoice = DChoice::new_container(i, &choice.text);

self.choice_agent
.bind_mut()
.bind_callables_for(&mut dchoice);

cont.add_child(dchoice.clone());

// put label below the window
dchoice.bind().put_label_under();
}

self.set_choice_label_focus_directions();
}
// pub fn recreate_choice_labels(&mut self, choices: &[DialogueChoice]) {
// self.free_choice_labels();
//
// let mut cont = self.choice_container();
//
// for (i, choice) in choices.iter().enumerate() {
// let mut dchoice = DChoice::new_container(i, &choice.text);
//
// self.choice_agent
// .bind_mut()
// .bind_callables_for(&mut dchoice);
//
// cont.add_child(dchoice.clone());
//
// // put label below the window
// dchoice.bind().put_label_under();
// }
//
// self.set_choice_label_focus_directions();
// }

/// makes it so that all the choice labels refer to each
/// other in their focus neighbor properties
Expand Down
16 changes: 10 additions & 6 deletions pets-lib/src/dialogue/dbox/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ pub fn pchar_display_name(pchar: &PChar) -> String {
}

const PLACEHOLDERS: &[(&'static str, fn() -> String)] = &[
("[PLAYER]", || "Cherry".to_string()),
("[PLAYER]", || "Cherry".to_owned()),
("[LEVEL]", || 123.to_string()),
// "special" speakers
("[NARRATOR]", || "".to_owned()),
("[???]", || "DG_SPK_UNKNOWN".to_owned()),
// character names
("[ETHAN]", || pchar_display_name(&PChar::ETHAN)),
("[LYEMBO]", || pchar_display_name(&PChar::LYEMBO)),
("[QUOLO]", || pchar_display_name(&PChar::QUOLO)),
Expand All @@ -27,33 +31,33 @@ const PLACEHOLDERS: &[(&'static str, fn() -> String)] = &[
PChar::ETHAN => "DG_SPK_MOM",
_ => "DG_SPK_JUNIPER",
}
.to_string()
.to_owned()
}),
("[CLAY]", || {
match party_leader() {
PChar::ETHAN => "DG_SPK_DAD",
_ => "DG_SPK_CLAY",
}
.to_string()
.to_owned()
}),
("[MR_TULIVAE]", || {
match party_leader() {
PChar::SIVA => "DG_SPK_DAD",
_ => "DG_SPK_MR_TULIVAE",
}
.to_string()
.to_owned()
}),
("[MRS_TULIVAE]", || {
match party_leader() {
PChar::SIVA => "DG_SPK_MOM",
_ => "DG_SPK_MRS_TULIVAE",
}
.to_string()
.to_owned()
}),
];

pub fn process_placeholders(text: &str) -> String {
let mut out = text.to_string();
let mut out = text.to_owned();

for (keyword, mapper) in PLACEHOLDERS {
out = out.replace(keyword, &mapper());
Expand Down

0 comments on commit 74609dd

Please sign in to comment.