feat: ensure that bluearch-recruitment is a library

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-02-10 16:30:40 -06:00
parent 9f443dd364
commit c209e32bdf
6 changed files with 21 additions and 184 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/target /target
/Cargo.lock
/.vscode

175
Cargo.lock generated
View File

@ -1,175 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "bluearch-recruitment"
version = "0.1.0"
dependencies = [
"rand",
"serde",
"serde_json",
"serde_repr",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "itoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "libc"
version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "proc-macro2"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c026d7df8b298d90ccbbc5190bd04d85e159eaf5576caeacf8741da93ccbd2e5"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
"rand_core",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "serde"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_repr"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"

View File

@ -15,7 +15,7 @@ file.read_to_string(&mut json).unwrap();
let students: Vec<Student> = serde_json::from_str(&json).unwrap(); let students: Vec<Student> = serde_json::from_str(&json).unwrap();
``` ```
This Repo contains `students.json` which is an Array where each object within the arry contains a Student's Japanese name, English TL name and rarity. This Repo contains `students.json` (in the examples directory) which is an Array where each object within the array contains a Student's Japanese name, English TL name and rarity.
```rust ```rust
let banner_students: Vec<Student> = students let banner_students: Vec<Student> = students
@ -46,7 +46,7 @@ This example creates the ピックアップ募集 Banner which ran from 2021-02-
After this, we want to determine which units are on rate-up if there are any. In this example, ホシノ and シロコ have increased pull rates. After this, we want to determine which units are on rate-up if there are any. In this example, ホシノ and シロコ have increased pull rates.
The Rest of the code consists of instantiating the Gacha and Banner Structs using their respective Builders. The Rest of the code consists of instantiating the Gacha and Banner structs using their respective Builders.
After this: After this:
@ -55,4 +55,4 @@ let student: Student = pickup_banner.roll();
// or // or
let students: [Student; 10] = pickup_banner.roll10(); let students: [Student; 10] = pickup_banner.roll10();
``` ```
can be called (when the `Recruitment` trait is in scope) to allow for acurate simulation of Blue Archive's Gacha. can be called (when the `Recruitment` trait is in scope) to allow for accurate simulation of Blue Archive's Gacha.

View File

@ -5,18 +5,20 @@ use bluearch_recruitment::student::Student;
use std::{fs::File, io::Read}; use std::{fs::File, io::Read};
fn main() { fn main() {
let mut file = File::open("students.json").unwrap(); let mut file = File::open("./examples/students.json").unwrap();
let mut json = String::new(); let mut json = String::new();
file.read_to_string(&mut json).unwrap(); file.read_to_string(&mut json).unwrap();
let students: Vec<Student> = serde_json::from_str(&json).unwrap(); let students: Vec<Student> = serde_json::from_str(&json).unwrap();
// This particular banner consists of everyone BUT Nozomi.
let banner_students: Vec<Student> = students let banner_students: Vec<Student> = students
.iter() .iter()
.filter(|student| student.name != "ノゾミ") .filter(|student| student.name != "ノゾミ")
.map(|student| student.clone()) .map(|student| student.clone())
.collect(); .collect();
// Both Hoshino and Shiroko have an increased chance of being pulled.
let hoshino = find_student(&students, "ホシノ").unwrap(); let hoshino = find_student(&students, "ホシノ").unwrap();
let shiroko = find_student(&students, "シロコ").unwrap(); let shiroko = find_student(&students, "シロコ").unwrap();
let rate_up_students = vec![shiroko, hoshino]; let rate_up_students = vec![shiroko, hoshino];
@ -27,15 +29,23 @@ fn main() {
.finish() .finish()
.unwrap(); .unwrap();
let pickup_banner = BannerBuilder::new("ピックアップ募集") let banner = BannerBuilder::new("ピックアップ募集")
.with_name_translation(Language::English, "Rate-Up Registration") .with_name_translation(Language::English, "Rate-Up Registration")
.with_sparkable_students(&rate_up_students) .with_sparkable_students(&rate_up_students)
.with_gacha(&gacha) .with_gacha(&gacha)
.finish() .finish()
.unwrap(); .unwrap();
// let student = pickup_banner.roll(); let students = banner.roll10();
// let students = pickup_banner.roll10();
println!("{} 10-pull: \n", banner.name);
for student in students.iter() {
println!(
"{} {}",
student.name.get(Language::English).unwrap(),
student.rarity
);
}
} }
pub fn find_student(students: &[Student], jpn_name: &str) -> Option<Student> { pub fn find_student(students: &[Student], jpn_name: &str) -> Option<Student> {

View File

@ -107,7 +107,7 @@ impl GachaBuilder {
/// Attaches a pool of Students who have increased rates /// Attaches a pool of Students who have increased rates
/// ///
/// # Arugments /// # Arguments
/// * `students` - A Vector of Students who have increased rates /// * `students` - A Vector of Students who have increased rates
/// * `rate` - The rate of the students in the previous argument /// * `rate` - The rate of the students in the previous argument
/// ///
@ -130,7 +130,7 @@ impl GachaBuilder {
} }
} }
/// Consumes a GachaBuilder and retuns a Gacha Struct. /// Consumes a GachaBuilder and returns a Gacha Struct.
/// ///
/// Will return `None` if the `rates` or `pool` property of /// Will return `None` if the `rates` or `pool` property of
/// GachaBuilder have not been set. /// GachaBuilder have not been set.