Skip to content

Commit

Permalink
Release 0.2.1 - Rust API Guideline
Browse files Browse the repository at this point in the history
Merge pull request #10 from Fabinistere/release-0.2.1
  • Loading branch information
Wabtey authored Aug 17, 2023
2 parents bd7b357 + ad05989 commit a755e69
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 39 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## API Guideline - [v0.2.1](https://github.com/Fabinistere/yml_dialog/releases/tag/v0.2.1) - 2023-08-18

[![v0.2.1](https://img.shields.io/badge/v0.2.1-gray?style=flat&logo=github&logoColor=181717&link=https://github.com/Fabinistere/yml_dialog/releases/tag/v0.2.1)](https://github.com/Fabinistere/yml_dialog/releases/tag/v0.2.1)
[![**Full Commits History**](https://img.shields.io/badge/GitHubLog-gray?style=flat&logo=github&logoColor=181717&link=https://github.com/fabinistere/yml_dialog/commits/v0.2.1)](https://github.com/fabinistere/yml_dialog/commits/v0.2.1)

### Changed

- `Cargo.toml` includes all common metadata ([C-METADATA](https://rust-lang.github.io/api-guidelines/documentation.html#c-metadata))
- authors, description, license, homepage, documentation, repository, keywords, categories
- Types eagerly implement common traits ([C-COMMON-TRAITS](https://rust-lang.github.io/api-guidelines/interoperability.html#c-common-traits))
- rename `DialogNodeYML` to `DialogNode`

## YML Dialog - [v0.2.0](https://github.com/Fabinistere/yml_dialog/releases/tag/v0.2.0) - 2023-08-17

[![v0.2.0](https://img.shields.io/badge/v0.2.0-gray?style=flat&logo=github&logoColor=181717&link=https://github.com/Fabinistere/yml_dialog/releases/tag/v0.2.0)](https://github.com/Fabinistere/yml_dialog/releases/tag/v0.2.0)
Expand Down
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
name = "yml_dialog"
version = "0.2.0"
authors = ["Olf EPAIN <wabtey@disroot.org>", "Morgan Van Amerongen <vanamerongen.morgan@gmail.com>"]
description = "A very light base structure to implement an Rust Dialog using YML (file) format"
keywords = ["game", "rust", "structure", "dialog", "yml", "bevy", "serialize", "deserialize"]
categories = ["game-development", ]
readme = "README.md"
repository = "https://github.com/Fabinistere/yml_dialog"
homepage = "fabinistere.github.io"
documentation = "https://docs.rs/yml_dialog"
license = "MIT OR Apache-2.0"
edition = "2021"

Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# YML based Dialog Structure

<!-- [![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-released%20version-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking) -->
<!-- [![v0.1.0](https://img.shields.io/badge/v0.1.0-gray?style=flat&logo=github&logoColor=181717&link=https://github.com/Fabinistere/bevy_turn-based_combat/releases/tag/v0.1.0)](https://github.com/Fabinistere/bevy_turn-based_combat/releases/tag/v0.1.0) -->
[![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-0.10-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking)
[![v0.2.1](https://img.shields.io/badge/v0.2.1-gray?style=flat&logo=github&logoColor=181717&link=https://github.com/Fabinistere/bevy_turn-based_combat/releases/tag/v0.2.1)](https://github.com/Fabinistere/bevy_turn-based_combat/releases/tag/v0.2.1)
<!-- [![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-0.10-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking) -->
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/fabinistere/bevy_turn-based_combat#license)

<!--
| bevy | yml_dialog |
|------|------------|
| 0.10 | 0.2.1 |
| 0.10 | 0.2.0 |
-->

## Example

Expand All @@ -27,11 +30,18 @@ clone the repo, extract the assets in the root of the repo and run `cargo run --
- [ ] [Dynamic Macros](https://stackoverflow.com/a/63849405)
- [x] Exclude Bevy dependency
- [ ] Follow all guidelines from [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/checklist.html)
- [ ] Documentation
- [ ] **Documentation**
- [ ] Examples use `?`, not `try!`, not `unwrap` ([C-QUESTION-MARK](https://rust-lang.github.io/api-guidelines/documentation.html#c-question-mark))
- [x] Crate level docs are thorough and include examples ([C-CRATE-DOC](https://rust-lang.github.io/api-guidelines/documentation.html#c-crate-doc))
- [x] create an example
- [ ] Interoperability
- [x] **Interoperability**
- [x] Types eagerly implement common traits
- [ ] Macros
- [x] ...
- [ ] **Future proofing** (crate is free to improve without breaking users' code)
- [ ] Sealed traits protect against downstream implementations ([C-SEALED](https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed))
- [x] Structs have private fields ([C-STRUCT-PRIVATE](https://rust-lang.github.io/api-guidelines/future-proofing.html#c-struct-private))
- [ ] Newtypes encapsulate implementation details ([C-NEWTYPE-HIDE](https://rust-lang.github.io/api-guidelines/future-proofing.html#c-newtype-hide))
- [ ] Data structures do not duplicate derived trait bounds ([C-STRUCT-BOUNDS](https://rust-lang.github.io/api-guidelines/future-proofing.html#c-struct-bounds))

## Contribute

Expand Down Expand Up @@ -63,14 +73,14 @@ See the very good reasons for including both [here](https://github.com/bevyengin
- [Wikipedia: Nonlinear Gameplay](https://en.wikipedia.org/wiki/Nonlinear_gameplay)
- [Bevy's SubReddit: Bevy Dialog Discussion](https://www.reddit.com/r/bevy/comments/wr22n5/ideas_on_the_basic_interface_for_a_dialogue_system/)

I began coding this as a tree strucutre dialog but a graph based is much more suited for a dialog. Maybe after this migration this crate is not needed anymore and will just do a devlog.
I began coding this as a tree strucutre dialog but a graph based is much more suited for a dialog. Maybe after this migration this crate is not needed anymore and will just do a devlog. (and free this name :)

## Naming

Accordingly to this [discussion](https://github.com/bevyengine/bevy/discussions/1202),
this is not a trivial question.

- yml-dialog
- ***yml-dialog***
- dialog-structure
- md-to-dialog-tree
- fto-dialog
Expand Down
10 changes: 5 additions & 5 deletions examples/complete_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bevy::{
use rand::seq::SliceRandom;
use std::{collections::BTreeMap, fmt, str::FromStr};

use yml_dialog::{Content, DialogNodeYML};
use yml_dialog::{Content, DialogNode};

// dark purple #25131a = 39/255, 19/255, 26/255
const CLEAR: bevy::render::color::Color = bevy::render::color::Color::rgb(0.153, 0.07, 0.102);
Expand Down Expand Up @@ -75,7 +75,7 @@ impl FromStr for WorldEvent {
/// - `key`: interlocutor
/// - `value`: (current state, BinaryTreeMap of the dialog)
#[derive(Debug, Deref, DerefMut, Default, Resource)]
struct DialogMap(BTreeMap<Entity, (usize, BTreeMap<usize, DialogNodeYML>)>);
struct DialogMap(BTreeMap<Entity, (usize, BTreeMap<usize, DialogNode>)>);

/// Contains all the line of the current monolog
///
Expand Down Expand Up @@ -717,7 +717,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut dialogs: Re
))
.id();
// DOC: unwrap use
let old_frog_deserialized_map: BTreeMap<usize, DialogNodeYML> =
let old_frog_deserialized_map: BTreeMap<usize, DialogNode> =
serde_yaml::from_str(OLD_FROG_DIALOG).unwrap();
dialogs.insert(
old_frog_portrait,
Expand Down Expand Up @@ -747,7 +747,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut dialogs: Re
))
.id();
// DOC: unwrap use
let frog_deserialized_map: BTreeMap<usize, DialogNodeYML> =
let frog_deserialized_map: BTreeMap<usize, DialogNode> =
serde_yaml::from_str(FROG_DIALOG).unwrap();
dialogs.insert(
frog_portrait,
Expand Down Expand Up @@ -777,7 +777,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut dialogs: Re
))
.id();
// DOC: unwrap use
let warrior_frog_deserialized_map: BTreeMap<usize, DialogNodeYML> =
let warrior_frog_deserialized_map: BTreeMap<usize, DialogNode> =
serde_yaml::from_str(WARRIOR_DIALOG).unwrap();
dialogs.insert(
warrior_frog_portrait,
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ use serde::{
};

/// This correspond to a unique key
#[derive(Serialize, Deserialize, PartialEq, Debug, Default)]
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[serde(default)]
pub struct DialogNodeYML {
pub struct DialogNode {
source: String,
content: Content,
/// REFACTOR: Turn this into a generic type `extra`
trigger_event: Vec<String>,
}

impl DialogNodeYML {
impl DialogNode {
/// Constructs a new DialogNode with the given
/// - `source`,
/// - `content`,
/// - `trigger_event` vector
pub fn new(source: String, content: Content, trigger_event: Vec<String>) -> Self {
DialogNodeYML {
DialogNode {
source,
content,
trigger_event,
Expand Down Expand Up @@ -83,7 +83,7 @@ impl DialogNodeYML {
/// let mut map = BTreeMap::new();
/// map.insert(
/// 1,
/// DialogNodeYML::new(
/// DialogNode::new(
/// "The Frog".to_string(),
/// Content::Choices(vec![
/// Choice::new(String::from("Hello HomeGirl"), None, 2),
Expand All @@ -94,7 +94,7 @@ impl DialogNodeYML {
/// );
/// map.insert(
/// 2,
/// DialogNodeYML::new(
/// DialogNode::new(
/// "Random Frog".to_string(),
/// Content::Monolog {
/// text: vec![String::from("Yo Homie")],
Expand All @@ -105,7 +105,7 @@ impl DialogNodeYML {
/// );
/// map.insert(
/// 3,
/// DialogNodeYML::new(
/// DialogNode::new(
/// "Random Frog".to_string(),
/// Content::Monolog {
/// text: vec![String::from("KeroKero")],
Expand Down Expand Up @@ -149,7 +149,7 @@ impl DialogNodeYML {
/// # Note
///
/// TODO: Custom impl Serialization
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[serde(untagged)]
pub enum Content {
/// A vector of Choice
Expand Down Expand Up @@ -198,7 +198,7 @@ impl Default for Content {
/// - a `text` line,
/// - a `condition` and
/// - an `exit_state` corresponding to the continue of this choice.
#[derive(Serialize, Deserialize, PartialEq, Debug, Default)]
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[serde(default)]
pub struct Choice {
text: String,
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Choice {
// }

/// REFACTOR: Turn this into a Generic Type
#[derive(Serialize, Deserialize, Hash, PartialEq, Eq, PartialOrd, Ord, Default, Debug, Clone)]
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct Condition {
events: Vec<String>,
karma_threshold: Option<(i32, i32)>,
Expand Down
34 changes: 17 additions & 17 deletions tests/yaml_serde_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn test_yaml_monolog_serialize_1() {
let mut map = BTreeMap::new();
map.insert(
1,
DialogNodeYML::new(
DialogNode::new(
"Le Pape".to_string(),
Content::Monolog {
text: vec![String::from("Hello Homie")],
Expand Down Expand Up @@ -81,7 +81,7 @@ fn test_yaml_monolog_serialize_2() {
let mut map = BTreeMap::new();
map.insert(
1,
DialogNodeYML::new(
DialogNode::new(
"The Frog".to_string(),
Content::Monolog {
text: vec![
Expand All @@ -96,7 +96,7 @@ fn test_yaml_monolog_serialize_2() {
);
map.insert(
2,
DialogNodeYML::new(
DialogNode::new(
"Random Frog".to_string(),
Content::Monolog {
text: vec![String::from("KeroKero")],
Expand Down Expand Up @@ -136,7 +136,7 @@ fn test_yaml_choices_serialize_1() {
let mut map = BTreeMap::new();
map.insert(
1,
DialogNodeYML::new(
DialogNode::new(
"The Frog".to_string(),
Content::Choices(vec![
Choice::new(String::from("Hello HomeGirl"), None, 2),
Expand All @@ -147,7 +147,7 @@ fn test_yaml_choices_serialize_1() {
);
map.insert(
2,
DialogNodeYML::new(
DialogNode::new(
"Random Frog".to_string(),
Content::Monolog {
text: vec![String::from("Yo Homie")],
Expand All @@ -158,7 +158,7 @@ fn test_yaml_choices_serialize_1() {
);
map.insert(
3,
DialogNodeYML::new(
DialogNode::new(
"Random Frog".to_string(),
Content::Monolog {
text: vec![String::from("KeroKero")],
Expand Down Expand Up @@ -206,7 +206,7 @@ fn test_yaml_choices_condition_serialize() {
let mut map = BTreeMap::new();
map.insert(
1,
DialogNodeYML::new(
DialogNode::new(
"The Frog".to_string(),
Content::Choices(vec![
Choice::new(
Expand All @@ -224,7 +224,7 @@ fn test_yaml_choices_condition_serialize() {
);
map.insert(
2,
DialogNodeYML::new(
DialogNode::new(
"Random Frog".to_string(),
Content::Monolog {
text: vec![String::from("Yo Homie")],
Expand All @@ -235,7 +235,7 @@ fn test_yaml_choices_condition_serialize() {
);
map.insert(
3,
DialogNodeYML::new(
DialogNode::new(
"Random Frog".to_string(),
Content::Monolog {
text: vec![String::from("KeroKero")],
Expand Down Expand Up @@ -293,7 +293,7 @@ fn test_yaml_monolog_deserialize_field_missing() {
let mut map = BTreeMap::new();
map.insert(
1,
DialogNodeYML::new(
DialogNode::new(
"Le Pape".to_string(),
Content::Monolog {
text: vec![String::from("Hello Homie")],
Expand All @@ -303,7 +303,7 @@ fn test_yaml_monolog_deserialize_field_missing() {
),
);

let deserialized_map: BTreeMap<usize, DialogNodeYML> = serde_yaml::from_str(&yaml).unwrap();
let deserialized_map: BTreeMap<usize, DialogNode> = serde_yaml::from_str(&yaml).unwrap();

assert_eq!(map, deserialized_map)
}
Expand Down Expand Up @@ -343,7 +343,7 @@ fn test_generic_type_deserialize() {
let mut map = BTreeMap::new();
map.insert(
1,
DialogNodeYML::new(
DialogNode::new(
"Le Pape".to_string(),
Content::Monolog {
text: vec![String::from("Hello Homie")],
Expand All @@ -354,7 +354,7 @@ fn test_generic_type_deserialize() {
);
map.insert(
2,
DialogNodeYML::new(
DialogNode::new(
"The Frog".to_string(),
Content::Choices(vec![
Choice::new(
Expand All @@ -368,7 +368,7 @@ fn test_generic_type_deserialize() {
),
);
let deserialized_map: BTreeMap<usize, DialogNodeYML> = serde_yaml::from_str(&yaml).unwrap();
let deserialized_map: BTreeMap<usize, DialogNode> = serde_yaml::from_str(&yaml).unwrap();
assert_eq!(map, deserialized_map)
}
Expand All @@ -378,7 +378,7 @@ fn test_custom_serialize() {
let mut map = BTreeMap::new();
map.insert(
1,
DialogNodeYML::new(
DialogNode::new(
"The Frog".to_string(),
Content::Choices(vec![
Choice::new(String::from("Hello HomeGirl"), None, 2),
Expand All @@ -389,7 +389,7 @@ fn test_custom_serialize() {
);
map.insert(
2,
DialogNodeYML::new(
DialogNode::new(
"Random Frog".to_string(),
Content::Monolog {
text: vec![String::from("Yo Homie")],
Expand All @@ -400,7 +400,7 @@ fn test_custom_serialize() {
);
map.insert(
3,
DialogNodeYML::new(
DialogNode::new(
"Random Frog".to_string(),
Content::Monolog {
text: vec![String::from("KeroKero")],
Expand Down

0 comments on commit a755e69

Please sign in to comment.