Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,166 changes: 1,453 additions & 713 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/bevy_plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_yarnspinner"
version = "0.7.0"
version = "0.8.0"
edition = "2024"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -21,7 +21,7 @@ anyhow = "1"
csv = "1"
serde = { version = "1", features = [ "derive" ] }
yarnspinner_internal_shared = { path = "../internal_shared", version = "0.1.0" }
yarnspinner = { path = "../yarnspinner", features = [ "bevy", "serde" ], version = "0.7.0" }
yarnspinner = { path = "../yarnspinner", features = [ "bevy", "serde" ], version = "0.8.0" }
sha2 = "0.10"
variadics_please = "1"

Expand All @@ -40,4 +40,4 @@ default-features = false
features = [ "bevy_core_pipeline", "bevy_audio" ]

[target.'cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))'.dependencies]
glob = "0.3.1"
glob = "0.3.3"
4 changes: 2 additions & 2 deletions crates/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ name = "generate_proto"
required-features = ["proto"]

[dependencies]
prost = { version = "0.12", optional = true }
prost-build = { version = "0.12", optional = true }
prost = { version = "0.14", optional = true }
prost-build = { version = "0.14", optional = true }
10 changes: 5 additions & 5 deletions crates/compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yarnspinner_compiler"
version = "0.7.0"
version = "0.8.0"
edition = "2024"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -19,17 +19,17 @@ antlr-rust = "=0.3.0-beta"
better_any = "=0.2.0"
regex = "1"
yarnspinner_internal_shared = { path = "../internal_shared", version = "0.1.0" }
yarnspinner_core = { path = "../core", version = "0.7.0" }
annotate-snippets = "0.10"
yarnspinner_core = { path = "../core", version = "0.8.0" }
annotate-snippets = "0.12"
serde = { version = "1", features = [ "derive" ], optional = true }
serde_json = { version = "1", optional = true }
bevy = { version = "0.18", default-features = false, optional = true }
rand = { version = "0.9", features = [ "small_rng" ] }
rand = { version = "0.10", default-features = false }
crc32fast = "1.5"
globset = "0.4"
walkdir = "2.5"

[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { version = "0.1.12", features = [
instant = { version = "0.1.13", features = [
"wasm-bindgen",
] } # see https://github.com/Amanieu/parking_lot/issues/269, pulled in by (unmaintained) anltr-rust
48 changes: 19 additions & 29 deletions crates/compiler/src/listeners/error_listener/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::parser_rule_context_ext::ParserRuleContextExt;
use crate::prelude::*;
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
use annotate_snippets::renderer::DecorStyle;
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet};
use antlr_rust::rule_context::CustomRuleContext;
use antlr_rust::token::Token;
use antlr_rust::token_factory::TokenFactory;
Expand Down Expand Up @@ -108,43 +109,32 @@ impl Diagnostic {
impl Display for Diagnostic {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let label = &self.message;
let annotation_type = match self.severity {
DiagnosticSeverity::Error => AnnotationType::Error,
DiagnosticSeverity::Warning => AnnotationType::Warning,
let level = match self.severity {
DiagnosticSeverity::Error => Level::ERROR,
DiagnosticSeverity::Warning => Level::WARNING,
};
let snippet = Snippet {
title: Some(Annotation {
label: Some(label),
id: None,
annotation_type,
}),
footer: vec![],
slices: vec![Slice {
source: self.context.as_deref().unwrap_or("<unknown line>"),
line_start: self.start_line + 1,
origin: self.file_name.as_deref(),
fold: false,
annotations: vec![SourceAnnotation {
label: "",
annotation_type,
range: convert_absolute_range_to_relative(self),
}],
}],
};
let renderer = Renderer::styled();
let annotations = renderer.render(snippet);
let report = level.primary_title(label).id("Y001").element(
Snippet::source(self.context.as_deref().unwrap_or("<unknown line>"))
.line_start(self.start_line + 1)
.path(self.file_name.as_deref())
.fold(false)
.annotation(AnnotationKind::Primary.span(convert_absolute_range_to_relative(self))),
);
// Using `plain` until https://github.com/tokio-rs/tracing/issues/3378 is resolved... bleh
let renderer = Renderer::plain().decor_style(DecorStyle::Unicode);
let annotations = renderer.render(&[report]);
writeln!(f, "{annotations}")?;

Ok(())
}
}

fn convert_absolute_range_to_relative(diagnostic: &Diagnostic) -> (usize, usize) {
fn convert_absolute_range_to_relative(diagnostic: &Diagnostic) -> Range<usize> {
let Some(range) = diagnostic.range.as_ref() else {
return (0, 0);
return 0..1;
};
let Some(context) = diagnostic.context.as_ref() else {
return (0, 0);
return 0..1;
};

let relative_start_line = range.start.line - diagnostic.start_line;
Expand All @@ -165,7 +155,7 @@ fn convert_absolute_range_to_relative(diagnostic: &Diagnostic) -> (usize, usize)
let mut char_indices = context.char_indices().map(|(i, _)| i);
let byte_start = char_indices.clone().nth(relative_start).unwrap();
let byte_end = char_indices.nth(relative_end).unwrap_or(byte_start);
(byte_start, byte_end)
byte_start..(byte_end + 1)
}

/// Trait implemented for `Vec<Diagnostic>` to provide utility methods.
Expand Down
6 changes: 4 additions & 2 deletions crates/compiler/src/listeners/untagged_line_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use antlr_rust::parser_rule_context::ParserRuleContext;
use antlr_rust::token::Token;
use antlr_rust::token_stream::TokenStream;
use antlr_rust::tree::ParseTreeListener;
use rand::{Rng, SeedableRng, rngs::SmallRng};
use rand::RngExt as _;
use rand::rngs::SysRng;
use rand::{SeedableRng, rngs::SmallRng};
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::atomic::AtomicBool;
Expand Down Expand Up @@ -42,7 +44,7 @@ impl<'input> UntaggedLineListener<'input> {

/// Generates a new unique line tag that is not present in `existing_line_tags`.
fn generate_string(&self) -> LineId {
let mut rng = SmallRng::from_os_rng();
let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap();
loop {
let line: usize = rng.random_range(0..0x1000000);
let tag = LineId(format!("{LINE_ID_PREFIX}{line}"));
Expand Down
10 changes: 5 additions & 5 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yarnspinner_core"
version = "0.7.0"
version = "0.8.0"
edition = "2024"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
description = "Core concepts for Yarn Spinner for Rust, the friendly tool for writing game dialogue"

[target.wasm32-unknown-unknown.dependencies]
getrandom = { version = "0.3", features = [ "wasm_js" ] }
getrandom = { version = "0.4", features = [ "wasm_js" ] }

[features]
default = [ "std" ]
Expand All @@ -19,12 +19,12 @@ serde = [ "dep:serde", "bevy?/serialize", "hashbrown/serde" ]
bevy = [ "dep:bevy" ]

[dependencies]
rand = { version = "0.9", default-features = false, features = [ "small_rng" ] }
prost = { version = "0.12", default-features = false, features = [ "prost-derive" ] }
rand = { version = "0.10", default-features = false, features = [ "sys_rng" ] }
prost = { version = "0.14", default-features = false, features = [ "derive" ] }
serde = { version = "1", features = [ "derive" ], optional = true }
bevy = { version = "0.18", default-features = false, optional = true, features = [ "std" ] }
variadics_please = "1.1.0"
hashbrown = "0.15.2"
hashbrown = "0.16.1"
yarnspinner_internal_shared = { path = "../internal_shared", version = "0.1.0" }

[dev-dependencies]
Expand Down
15 changes: 9 additions & 6 deletions crates/core/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use alloc::borrow::Cow;
use core::fmt::Display;

use hashbrown::hash_map;
use rand::{Rng, SeedableRng, rngs::SmallRng};
use rand::{
RngExt as _, SeedableRng,
rngs::{SmallRng, SysRng},
};

/// A collection of functions that can be called from Yarn scripts.
///
Expand Down Expand Up @@ -78,21 +81,21 @@ impl Library {
"number" => |value: YarnValue| f32::try_from(value).expect("Failed to convert a Yarn value to a number"),
"bool" => |value: YarnValue| bool::try_from(value).expect("Failed to convert a Yarn value to a bool"),
"format_invariant" => |value: f32| value.to_string(),
"random" => || SmallRng::from_os_rng().random_range(0.0..1.0),
"random" => ||SmallRng::try_from_rng(&mut SysRng).unwrap().random_range(0.0..1.0),
"random_range" => |min: f32, max: f32| {
if let Some(min) = min.as_int()
&& let Some(max_inclusive) = max.as_int()
{
return SmallRng::from_os_rng().random_range(min..=max_inclusive) as f32;
return SmallRng::try_from_rng(&mut SysRng).unwrap().random_range(min..=max_inclusive) as f32;
}
SmallRng::from_os_rng().random_range(min..max)
SmallRng::try_from_rng(&mut SysRng).unwrap().random_range(min..max)
},
"random_range_float" => |min: f32, max: f32| rand::random_range::<f32, _>(min..=max),
"random_range_float" => |min: f32, max: f32| SmallRng::try_from_rng(&mut SysRng).unwrap().random_range::<f32, _>(min..=max),
"dice" => |sides: u32| {
if sides == 0 {
return 1;
}
SmallRng::from_os_rng().random_range(1..=sides)
SmallRng::try_from_rng(&mut SysRng).unwrap().random_range(1..=sides)
},
"round" => |value: f32| value.round() as i32,
"round_places" => |value: f32, places: u32| value.round_places(places),
Expand Down
4 changes: 2 additions & 2 deletions crates/example_dialogue_view/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_yarnspinner_example_dialogue_view"
version = "0.7.0"
version = "0.8.0"
edition = "2024"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -14,7 +14,7 @@ readme = "../../readme.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_yarnspinner = { path = "../bevy_plugin", version = "0.7.0" }
bevy_yarnspinner = { path = "../bevy_plugin", version = "0.8.0" }
unicode-segmentation = "1"

[dependencies.bevy]
Expand Down
14 changes: 6 additions & 8 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yarnspinner_runtime"
version = "0.7.0"
version = "0.8.0"
edition = "2024"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand All @@ -12,8 +12,6 @@ description = "Runtime / VM for Yarn Spinner for Rust, the friendly tool for wri
[features]
default = ["std"]
std = [
"icu_locid/std",
"icu_plurals/std",
"fixed_decimal/ryu",
"unicode-normalization/std",
"bevy_platform/std",
Expand All @@ -22,20 +20,20 @@ serde = [
"dep:serde",
"bevy?/serialize",
"yarnspinner_core/serde",
"icu_locid/serde",
"icu_locale_core/serde",
"bevy_platform/serialize",
]
bevy = ["dep:bevy", "yarnspinner_core/bevy"]

[dependencies]
yarnspinner_internal_shared = { path = "../internal_shared", version = "0.1.0" }
yarnspinner_core = { path = "../core", version = "0.7.0" }
yarnspinner_core = { path = "../core", version = "0.8.0" }
unicode-normalization = { version = "0.1", default-features = false }
unicode-segmentation = "1"
log = "0.4"
icu_plurals = { version = "1.5", features = ["default"] }
icu_locid = { version = "1.5", default-features = false }
fixed_decimal = { version = "0.5", default-features = false, features = [
icu_plurals = { version = "2", features = ["default"] }
icu_locale_core = { version = "2", default-features = false }
fixed_decimal = { version = "0.7", default-features = false, features = [
"ryu",
] }
once_cell = "1"
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/src/language.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;
use core::fmt::Display;
use icu_locid::LanguageIdentifier;
use icu_locale_core::LanguageIdentifier;

/// IETF BCP 47 code.
/// The default is "en-US".
Expand Down
14 changes: 8 additions & 6 deletions crates/runtime/src/pluralization.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::Language;
use fixed_decimal::{DoublePrecision, FixedDecimal};
use icu_plurals::{PluralCategory, PluralRuleType};
use fixed_decimal::{Decimal, DoublePrecision};
use icu_locale_core::Locale;
use icu_plurals::{PluralCategory, PluralRuleType, PluralRulesPreferences};
use icu_plurals::{PluralOperands, PluralRules};

#[derive(Debug)]
Expand All @@ -12,9 +13,10 @@ pub(crate) struct Pluralization {
impl Pluralization {
pub(crate) fn new(language: impl Into<Language>) -> Self {
let language = language.into();
let locale = language.0.into();
let cardinal_rules = PluralRules::try_new(&locale, PluralRuleType::Cardinal).unwrap();
let ordinal_rules = PluralRules::try_new(&locale, PluralRuleType::Ordinal).unwrap();
let locale: Locale = language.0.into();
let locale: PluralRulesPreferences = locale.into();
let cardinal_rules = PluralRules::try_new(locale, PluralRuleType::Cardinal.into()).unwrap();
let ordinal_rules = PluralRules::try_new(locale, PluralRuleType::Ordinal.into()).unwrap();
Self {
cardinal_rules,
ordinal_rules,
Expand All @@ -38,7 +40,7 @@ fn get_into_plural_operand(value: f32) -> PluralOperands {
if floating_point < 1e-5 {
(value as isize).into()
} else {
(&FixedDecimal::try_from_f64(value as f64, DoublePrecision::Floating).unwrap()).into()
(&Decimal::try_from_f64(value as f64, DoublePrecision::RoundTrip).unwrap()).into()
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/yarnspinner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yarnspinner"
version = "0.7.0"
version = "0.8.0"
edition = "2024"
repository = "https://github.com/YarnSpinnerTool/YarnSpinner-Rust"
homepage = "https://docs.yarnspinner.dev/"
Expand Down Expand Up @@ -28,9 +28,9 @@ bevy = [
]

[dependencies]
yarnspinner_core = { path = "../core", version = "0.7.0" }
yarnspinner_compiler = { path = "../compiler", version = "0.7.0" }
yarnspinner_runtime = { path = "../runtime", version = "0.7.0" }
yarnspinner_core = { path = "../core", version = "0.8.0" }
yarnspinner_compiler = { path = "../compiler", version = "0.8.0" }
yarnspinner_runtime = { path = "../runtime", version = "0.8.0" }
log = { version = "0.4", features = ["std"] }
bevy = { version = "0.18", default-features = false, optional = true }

Expand Down
6 changes: 3 additions & 3 deletions demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ publish = false

[dependencies]
bevy = { version = "0.18.0" }
bevy_yarnspinner = { path = "../crates/bevy_plugin", version = "0.7.0" }
bevy_yarnspinner_example_dialogue_view = { path = "../crates/example_dialogue_view", version = "0.7.0" }
bevy_yarnspinner = { path = "../crates/bevy_plugin", version = "0.8.0" }
bevy_yarnspinner_example_dialogue_view = { path = "../crates/example_dialogue_view", version = "0.8.0" }
bevy_sprite3d = "8.0.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.3", features = ["wasm_js"] }
getrandom = { version = "0.4", features = ["wasm_js"] }
4 changes: 2 additions & 2 deletions examples/bevy_yarnspinner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ publish = false

[dependencies]
bevy = { version = "0.18", features = ["file_watcher"] }
bevy_yarnspinner = { path = "../../crates/bevy_plugin", version = "0.7" }
bevy_yarnspinner_example_dialogue_view = { path = "../../crates/example_dialogue_view", version = "0.7" }
bevy_yarnspinner = { path = "../../crates/bevy_plugin", version = "0.8" }
bevy_yarnspinner_example_dialogue_view = { path = "../../crates/example_dialogue_view", version = "0.8" }

[[bin]]
name = "access_variables"
Expand Down
6 changes: 3 additions & 3 deletions examples/yarnspinner_without_bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ authors = ["Joe Clay <27cupsofcoffee@gmail.com>"]
publish = false

[dependencies]
crossterm = "0.27"
ratatui = "0.26"
crossterm = "0.29"
ratatui = "0.30"
anyhow = "1.0"
yarnspinner = { path = "../../crates/yarnspinner", version = "0.7.0" }
yarnspinner = { path = "../../crates/yarnspinner", version = "0.8.0" }

[[bin]]
name = "access_variables"
Expand Down
2 changes: 1 addition & 1 deletion examples/yarnspinner_without_bevy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl TuiDialogueRunner {
fn draw(&mut self, terminal: &mut Terminal) -> anyhow::Result<()> {
terminal.draw(|f| {
let layout = Layout::vertical([Constraint::Fill(1), Constraint::Length(5)]);
let [output_area, options_area] = layout.areas(f.size());
let [output_area, options_area] = layout.areas(f.area());

if let Some(line) = &self.last_line {
f.render_widget(LineView::new(line).bg(self.background_color), output_area);
Expand Down
Loading