Compare commits

..

2 Commits

15 changed files with 833 additions and 4357 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
# will have compiled files and executables # will have compiled files and executables
debug/ debug/
target/ target/
out/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

4166
index.html

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,335 @@
[
{
"spirit": "Meow Wow",
"routes": [
{
"id": 0,
"name": "Stray",
"color": "#17CBD8"
},
{
"id": 1,
"name": "Smart Cookie",
"color": "#992A9B"
}
],
"abilities": [
{
"name": "Start",
"pos": "A2",
"type": "Start",
"price": "",
"path": ["E"]
},
{
"name": "Link Critical",
"pos": "B2",
"type": "Spirit",
"price": "10 LP",
"path": ["W", "E"]
},
{
"name": "Magic Haste",
"pos": "C1",
"type": "Stat",
"price": "30 LP",
"path": ["S", "E"]
},
{
"name": "Cure",
"pos": "C2",
"type": "Magic",
"price": "50 LP",
"path": ["N", "W", "E", "S"]
},
{
"name": "Item Boost",
"pos": "C3",
"type": "Stat",
"price": "30 LP",
"path": ["E", "N"]
},
{
"name": "Light Screen",
"pos": "D1",
"type": "Stat",
"price": "20 LP",
"path": ["E", "W"]
},
{
"name": "Checkpoint",
"pos": "D2",
"type": "Checkpoint",
"price": "Level 10",
"path": ["E", "W"]
},
{
"name": "Slow",
"pos": "D3",
"type": "Magic",
"price": "50 LP",
"path": ["E", "W"]
},
{
"name": "Defense Boost",
"pos": "E1",
"type": "Stat",
"price": "100 LP",
"path": ["E", "W"]
},
{
"name": "Cura",
"pos": "E2",
"type": "Magic",
"price": "100 LP",
"path": ["E", "W"]
},
{
"name": "Poison Block",
"pos": "E3",
"type": "Stat",
"price": "30 LP",
"path": ["E", "S", "W"]
},
{
"name": "Spark",
"pos": "E4",
"type": "Magic",
"price": "50 LP",
"path": ["N"]
},
{
"name": "Confusion Block",
"pos": "F1",
"type": "Stat",
"price": "30 LP",
"route": 0,
"path": ["E", "W"]
},
{
"name": "Leaf Bracer",
"pos": "F2",
"type": "Support",
"price": "300 LP",
"path": ["E", "W"]
},
{
"name": "Attack Haste",
"pos": "F3",
"type": "Stat",
"price": "30 LP",
"route": 1,
"path": ["E", "W"]
},
{
"name": "HP Boost",
"pos": "G1",
"type": "Stat",
"price": "30 LP",
"route": 0,
"path": ["W"]
},
{
"name": "Checkpoint",
"pos": "G2",
"type": "Checkpoint",
"price": "Level 25",
"path": ["E", "W"]
},
{
"name": "Magic Boost",
"pos": "G3",
"type": "Stat",
"price": "100 LP",
"route": 1,
"path": ["W"]
},
{
"name": "Curaga",
"pos": "H2",
"type": "Magic",
"price": "150 LP",
"path": ["W"]
}
]
},
{
"spirit": "Komory Bat",
"routes": [
{
"id": 0,
"name": "Rescuer",
"color": "#3FE4D1"
},
{
"id": 1,
"name": "Aggro",
"color": "#992A9B"
}
],
"abilities": [
{
"name": "Start",
"pos": "A3",
"type": "Start",
"price": "",
"path": ["E"]
},
{
"name": "Waking Dream",
"pos": "B3",
"type": "Spirit",
"price": "10 LP",
"path": ["E"]
},
{
"name": "Checkpoint",
"pos": "C1",
"type": "Checkpoint",
"price": "Link x2",
"path": ["E", "S"]
},
{
"name": "Zero Gravity",
"pos": "C2",
"type": "Magic",
"price": "50 LP",
"path": ["N", "E", "S"]
},
{
"name": "Confuse",
"pos": "C3",
"type": "Magic",
"price": "50 LP",
"path": ["S", "N", "W", "E"]
},
{
"name": "Dark Screen",
"pos": "C4",
"type": "Stat",
"price": "20 LP",
"path": ["N", "E", "S"]
},
{
"name": "Magic Haste",
"pos": "C5",
"type": "Stat",
"price": "50 LP",
"route": 0,
"path": ["N", "E"]
},
{
"name": "Zero Gravira",
"pos": "D1",
"type": "Magic",
"price": "100 LP",
"path": ["W"]
},
{
"name": "Confusion Block",
"pos": "D2",
"type": "Stat",
"price": "30 LP",
"path": ["W", "S"]
},
{
"name": "Drain Dive",
"pos": "D3",
"type": "Attack",
"price": "50 LP",
"path": ["N", "S", "W", "E"]
},
{
"name": "Magic Boost",
"pos": "D4",
"type": "Stat",
"price": "100 LP",
"path": ["W", "N", "E"]
},
{
"name": "Magic Haste",
"pos": "D5",
"type": "Stat",
"price": "100 LP",
"route": 0,
"path": ["W"]
},
{
"name": "Attack Boost",
"pos": "E2",
"type": "Stat",
"price": "100 LP",
"path": ["S"]
},
{
"name": "Magic Haste",
"pos": "E3",
"type": "Stat",
"price": "30 LP",
"path": ["W", "E", "N"]
},
{
"name": "Attack Haste",
"pos": "E4",
"type": "Stat",
"price": "30 LP",
"route": 1,
"path": ["W"]
},
{
"name": "Dark Screen",
"pos": "F3",
"type": "Stat",
"price": "40 LP",
"path": ["W", "E"]
},
{
"name": "Attack Haste",
"pos": "F4",
"type": "Stat",
"price": "50 LP",
"route": 1,
"path": ["W"]
},
{
"name": "Checkpoint",
"pos": "G3",
"type": "Checkpoint",
"price": "Link x2",
"path": ["W", "E"]
}
]
},
{
"spirit": "Necho Cat",
"routes": [
{
"id": 0,
"name": "Diva",
"color": "#3FE4D1"
},
{
"id": 1,
"name": "Artist",
"color": "#7AE43F"
}
],
"abilities": [
{
"name": "Magic Boost",
"pos": "A4",
"type": "Stat",
"price": "200 LP",
"route": 0,
"path": ["E"]
},
{
"name": "Support Boost",
"pos": "B1",
"type": "Spirit",
"price": "200 LP",
"path": ["E"]
}
]
}
]

164
src/bbs.rs 100644
View File

@ -0,0 +1,164 @@
use std::collections::HashMap;
use askama::Template;
use itertools::Itertools;
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq, Eq)]
enum Character {
#[serde(alias = "A")]
Aqua,
#[serde(alias = "V")]
Ventus,
#[serde(alias = "T")]
Terra,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
struct Ability {
name: String,
from: String,
category: String,
max: u8,
types: Vec<char>,
}
#[derive(Debug, Deserialize)]
struct Command {
name: String,
category: String,
char: Vec<char>,
#[serde(default)]
starting: Option<bool>,
#[serde(default)]
info: Option<String>,
#[serde(default)]
recipes: Vec<CommandRecipe>,
}
impl Command {}
#[derive(Debug, Deserialize)]
struct CommandRecipe {
char: Vec<Character>,
r#type: char,
ingredients: (String, String),
chance: u8,
#[serde(skip_deserializing)]
abilities: Vec<(String, Ability)>,
}
impl CommandRecipe {
pub fn get_ability(&self, crystal: &str) -> Option<Ability> {
if self.r#type == '-' {
return None;
}
for ability in self.abilities.iter() {
if ability.0 == crystal {
return Some(ability.1.clone());
}
}
// This should never happen unless the json files are wrong
panic!(
"No ability found for {} + {} and {}",
self.ingredients.0, self.ingredients.1, crystal
);
}
pub fn can_unlock(&self, char: Character) -> bool {
self.char.contains(&char)
}
pub fn get_unlock_chars(&self) -> String {
let mut id = String::new();
if self.can_unlock(Character::Terra) {
id += "T"
}
if self.can_unlock(Character::Ventus) {
if !id.is_empty() {
id += " ";
}
id += "V";
}
if self.can_unlock(Character::Aqua) {
if !id.is_empty() {
id += " ";
}
id += "A";
}
id
}
pub fn set_abilities(&mut self, abilities: &[Ability]) {
let mut vec: Vec<(String, Ability)> = vec![];
for ability in abilities.iter() {
if ability.types.contains(&self.r#type) {
vec.push((ability.from.clone(), ability.clone()));
}
}
vec.sort();
self.abilities = vec;
}
}
#[derive(Debug, Deserialize)]
struct Finisher {
name: String,
char: Vec<Character>,
level: u8,
#[serde(default)]
follows: Vec<String>,
goal: String,
color: String,
}
#[derive(Template)]
#[template(path = "pages/bbs-commands.html", whitespace = "suppress")]
struct CommandsTemplate {
pub commands: Vec<Command>,
pub crystals: Vec<String>,
}
const ABILITIES_PATH: &str = "./input/bbs/abilities.json";
const FINISHERS_PATH: &str = "./input/bbs/finish-commands.json";
const COMMANDS_PATH: &str = "./input/bbs/commands.json";
pub fn init() {
tracing::info!("Loading abilities json data from {}", ABILITIES_PATH);
let abilities_str = std::fs::read_to_string(ABILITIES_PATH).unwrap();
let abilities = serde_json::from_str::<Vec<Ability>>(&abilities_str).unwrap();
tracing::info!("Loading finishers json data from {}", ABILITIES_PATH);
let finishers_str = std::fs::read_to_string(FINISHERS_PATH).unwrap();
let finishers = serde_json::from_str::<HashMap<String, Finisher>>(&finishers_str).unwrap();
tracing::info!("Loading commands json data from {}", ABILITIES_PATH);
let commands_str = std::fs::read_to_string(COMMANDS_PATH).unwrap();
let mut commands = serde_json::from_str::<Vec<Command>>(&commands_str).unwrap();
// Create a vec with all the crystal variants found in abilities
let crystals = abilities
.iter()
.map(|x| x.from.clone())
.unique()
.sorted()
.collect();
// Create a vec of crystals and what ability they give for each recipe
for cmd in commands.iter_mut() {
for recipe in cmd.recipes.iter_mut() {
recipe.set_abilities(&abilities);
}
}
tracing::info!("Generating the BBS commands table template");
let template = CommandsTemplate { commands, crystals };
std::fs::write("./out/bbs-commands.html", template.render().unwrap()).unwrap();
}

212
src/ddd.rs 100644
View File

@ -0,0 +1,212 @@
use std::panic;
use askama::Template;
use itertools::Itertools;
use serde::{Deserialize, Deserializer};
#[derive(Debug, Deserialize, PartialEq, Eq)]
struct Board {
spirit: String,
routes: Vec<Route>,
abilities: Vec<Ability>,
#[serde(skip_deserializing)]
total_lp: u32,
#[serde(skip_deserializing)]
max_level: u32,
#[serde(skip_deserializing)]
stats: Vec<(usize, String)>,
}
impl Board {
pub fn init_stats(&mut self) {
let v = self
.abilities
.iter()
.filter(|&ability| ability.r#type == AbilityType::Stat)
.sorted_by(|a, b| Ord::cmp(&a.name, &b.name))
.collect_vec();
let mut stats: Vec<(usize, String)> = vec![];
for (key, chunk) in &v.into_iter().chunk_by(|k| k.name.clone()) {
let grouped = chunk.collect_vec();
stats.push((grouped.len(), key));
}
self.stats = stats;
}
pub fn init_total_lp(&mut self) {
self.total_lp = self
.abilities
.iter()
.filter(|&ability| ability.price.contains("LP"))
.map(|ability| {
let mut split = ability.price.split_whitespace();
split.next().unwrap_or("0").parse::<u32>().unwrap_or(0)
})
.sum::<u32>();
}
pub fn init_max_level(&mut self) {
self.max_level = self
.abilities
.iter()
.filter(|&ability| ability.price.starts_with("Level"))
.map(|ability| {
let mut split = ability.price.split_whitespace();
split.nth(1).unwrap_or("0").parse::<u32>().unwrap_or(0)
})
.sorted()
.last()
.unwrap_or(0);
}
pub fn get_size(&self) -> BoardPosition {
let mut x = 1;
let mut y = 1;
for ability in &self.abilities {
if ability.pos.0 > x {
x = ability.pos.0;
}
if ability.pos.1 > y {
y = ability.pos.1;
}
}
(x, y)
}
pub fn get_ability_at(&self, x: &u32, y: &u32) -> Option<&Ability> {
self.abilities
.iter()
.find(|&ability| ability.pos == (*x, *y))
}
pub fn get_char(&self, i: &u32) -> char {
char::from_u32(64 + *i).unwrap_or('0')
}
pub fn get_supports(&self) -> Vec<&Ability> {
self.abilities
.iter()
.filter(|&ability| ability.r#type == AbilityType::Support)
.collect_vec()
}
pub fn get_magics(&self) -> Vec<&Ability> {
self.abilities
.iter()
.filter(|&ability| ability.r#type == AbilityType::Magic)
.collect_vec()
}
pub fn get_spirit(&self) -> Vec<&Ability> {
self.abilities
.iter()
.filter(|&ability| ability.r#type == AbilityType::Spirit)
.collect_vec()
}
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
struct Route {
id: u32,
name: String,
color: String,
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
enum AbilityType {
Start,
Checkpoint,
Stat,
Spirit,
Support,
Attack,
Magic,
}
type BoardPosition = (u32, u32);
#[derive(Debug, Deserialize, PartialEq, Eq)]
struct ParseBoardPositionError;
fn deserialize_position<'de, D>(deserializer: D) -> Result<BoardPosition, D::Error>
where
D: Deserializer<'de>,
{
let str = match String::deserialize(deserializer) {
Ok(v) => v,
Err(e) => {
panic!("Tried deserializing a non-string type\nerror: {}", e);
}
};
let str = str.to_uppercase();
let mut chars = str.chars();
let a = chars.next().unwrap_or('A');
let b = chars.next().unwrap_or('1');
let a = (a.to_ascii_uppercase() as u32).saturating_sub(64);
if a == 0 {
panic!("Second position parameter {} is 0 or lower!", str);
}
let b = b.to_digit(10).unwrap_or(0);
Ok((a, b))
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
struct Ability {
name: String,
#[serde(deserialize_with = "deserialize_position")]
pos: BoardPosition,
r#type: AbilityType,
price: String,
route: Option<u32>,
path: Vec<Direction>,
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
enum Direction {
#[serde(alias = "N")]
North,
#[serde(alias = "S")]
South,
#[serde(alias = "E")]
East,
#[serde(alias = "W")]
West,
}
#[derive(Template)]
#[template(path = "pages/ddd-abilities.html", whitespace = "suppress")]
struct AbilitiesTemplate {
pub boards: Vec<Board>,
}
const ABILITIES_PATH: &str = "./input/ddd/abilities.json";
pub fn init() {
tracing::info!("Loading ability links json data from {}", ABILITIES_PATH);
let boards_str = std::fs::read_to_string(ABILITIES_PATH).unwrap();
let mut boards = serde_json::from_str::<Vec<Board>>(&boards_str).unwrap();
for board in &mut boards {
board.init_total_lp();
board.init_max_level();
board.init_stats();
}
tracing::info!("Generating the DDD ability boards template");
let template = AbilitiesTemplate { boards };
std::fs::write("./out/ddd-abilities.html", template.render().unwrap()).unwrap();
}

View File

@ -1,136 +1,10 @@
#![allow(dead_code)] #![allow(dead_code)]
use std::collections::HashMap;
use askama::Template;
use itertools::Itertools;
use serde::Deserialize;
use tracing_subscriber::EnvFilter; use tracing_subscriber::EnvFilter;
#[derive(Debug, Deserialize, PartialEq, Eq)] mod bbs;
enum Character { mod ddd;
#[serde(alias = "A")]
Aqua,
#[serde(alias = "V")]
Ventus,
#[serde(alias = "T")]
Terra,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
struct Ability {
name: String,
from: String,
category: String,
max: u8,
types: Vec<char>,
}
#[derive(Debug, Deserialize)]
struct Command {
name: String,
category: String,
char: Vec<char>,
#[serde(default)]
starting: Option<bool>,
#[serde(default)]
info: Option<String>,
#[serde(default)]
recipes: Vec<CommandRecipe>,
}
impl Command {}
#[derive(Debug, Deserialize)]
struct CommandRecipe {
char: Vec<Character>,
r#type: char,
ingredients: (String, String),
chance: u8,
#[serde(skip_deserializing)]
abilities: Vec<(String, Ability)>,
}
impl CommandRecipe {
pub fn get_ability(&self, crystal: &str) -> Option<Ability> {
if self.r#type == '-' {
return None;
}
for ability in self.abilities.iter() {
if ability.0 == crystal {
return Some(ability.1.clone());
}
}
// This should never happen unless the json files are wrong
panic!(
"No ability found for {} + {} and {}",
self.ingredients.0, self.ingredients.1, crystal
);
}
pub fn can_unlock(&self, char: Character) -> bool {
self.char.contains(&char)
}
pub fn get_unlock_chars(&self) -> String {
let mut id = String::new();
if self.can_unlock(Character::Terra) {
id += "T"
}
if self.can_unlock(Character::Ventus) {
if !id.is_empty() {
id += " ";
}
id += "V";
}
if self.can_unlock(Character::Aqua) {
if !id.is_empty() {
id += " ";
}
id += "A";
}
id
}
pub fn set_abilities(&mut self, abilities: &[Ability]) {
let mut vec: Vec<(String, Ability)> = vec![];
for ability in abilities.iter() {
if ability.types.contains(&self.r#type) {
vec.push((ability.from.clone(), ability.clone()));
}
}
vec.sort();
self.abilities = vec;
}
}
#[derive(Debug, Deserialize)]
struct Finisher {
name: String,
char: Vec<Character>,
level: u8,
#[serde(default)]
follows: Vec<String>,
goal: String,
color: String,
}
#[derive(Template)]
#[template(path = "pages/commands.html", whitespace = "suppress")]
struct CommandsTemplate {
pub commands: Vec<Command>,
pub crystals: Vec<String>,
}
const ABILITIES_PATH: &str = "./input/abilities.json";
const FINISHERS_PATH: &str = "./input/finish-commands.json";
const COMMANDS_PATH: &str = "./input/commands.json";
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() { fn main() {
@ -140,35 +14,6 @@ fn main() {
.event_format(tracing_subscriber::fmt::format().with_source_location(true)) .event_format(tracing_subscriber::fmt::format().with_source_location(true))
.init(); .init();
tracing::info!("Loading abilities json data from {}", ABILITIES_PATH); bbs::init();
let abilities_str = std::fs::read_to_string(ABILITIES_PATH).unwrap(); ddd::init();
let abilities = serde_json::from_str::<Vec<Ability>>(&abilities_str).unwrap();
tracing::info!("Loading finishers json data from {}", ABILITIES_PATH);
let finishers_str = std::fs::read_to_string(FINISHERS_PATH).unwrap();
let finishers = serde_json::from_str::<HashMap<String, Finisher>>(&finishers_str).unwrap();
tracing::info!("Loading commands json data from {}", ABILITIES_PATH);
let commands_str = std::fs::read_to_string(COMMANDS_PATH).unwrap();
let mut commands = serde_json::from_str::<Vec<Command>>(&commands_str).unwrap();
// Create a vec with all the crystal variants found in abilities
let crystals = abilities
.iter()
.map(|x| x.from.clone())
.unique()
.sorted()
.collect();
// Create a vec of crystals and what ability they give for each recipe
for cmd in commands.iter_mut() {
for recipe in cmd.recipes.iter_mut() {
recipe.set_abilities(&abilities);
}
}
tracing::info!("Generating the commands table template");
let template = CommandsTemplate { commands, crystals };
std::fs::write("./index.html", template.render().unwrap()).unwrap();
} }

View File

@ -35,35 +35,6 @@
thead th { thead th {
background-color: #252525; background-color: #252525;
} }
tbody tr:hover {
background-color: #4f4f4f;
}
& tr,
th,
td {
border: 1px solid #fff;
padding: 7px;
}
.charlist {
display: inline-grid;
grid-template-columns: repeat(3, 1fr);
gap: 15px;
.aqua {
color: #97c8ff;
}
.ventus {
color: #26ff62;
}
.terra {
color: #ff7400;
}
}
} }
</style> </style>

View File

@ -3,6 +3,38 @@
{% block title %}Commands{% endblock %} {% block title %}Commands{% endblock %}
{% block head %} {% block head %}
<style>
table {
.charlist {
display: inline-grid;
grid-template-columns: repeat(3, 1fr);
gap: 15px;
.aqua {
color: #97c8ff;
}
.ventus {
color: #26ff62;
}
.terra {
color: #ff7400;
}
}
tbody tr:hover {
background-color: #4f4f4f;
}
& tr,
th,
td {
border: 1px solid #fff;
padding: 7px;
}
}
</style>
<script> <script>
let charFilter = ""; let charFilter = "";
let typeFilter = ""; let typeFilter = "";
@ -141,11 +173,11 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% include "components/search.html" %} {% include "components/bbs/search.html" %}
<br /> <br />
{% include "components/type-filters.html" %} {% include "components/bbs/type-filters.html" %}
<br /> <br />
{% include "components/char-filters.html" %} {% include "components/bbs/char-filters.html" %}
<table> <table>
<thead> <thead>

View File

@ -0,0 +1,82 @@
{% extends "layouts/base.html" %}
{% block title %}Abilities{% endblock %}
{% block head %}
<style>
table {
width: inherit;
td {
width: 120px;
height: 100px;
}
td.slot-w {
height: 20px;
}
td.slot-h {
width: 20px;
}
}
</style>
<script>
function debounce(callback, wait = 300) {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback(...args);
}, wait);
};
}
</script>
{% endblock %}
{% block content %}
{% for board in boards %}
Total LP Needed: {{+ board.total_lp +}}
<br>
Max Level Needed: {{+ board.max_level +}}
<br><br>
Stats:
<ul>
{% for val in board.stats %}
<li>x{{+ val.0 +}} {{+ val.1 +}}</li>
{% endfor %}
</ul>
Support:
<ul>
{% for support in board.get_supports() %}
<li>{{ support.name }}</li>
{% endfor %}
</ul>
<table>
<tbody>
<tr>
<td class="slot-w slot-h"></td>
{% for x in 1..board.get_size().0 + 1 %}
<td class="slot-w">{{ board.get_char(x) }}</td>
{% endfor %}
</tr>
{% for y in 1..board.get_size().1 + 1 %}
<tr>
<td class="slot-h">{{ y }}</td>
{% for x in 1..board.get_size().0 + 1 %}
{% let ability = board.get_ability_at(x, y) %}
{% match ability %}
{% when Some with (val) %}
<td colspan="1">{{ val.name }}</td>
{% when None %}
<td colspan="1"></td>
{% endmatch %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
{% endblock %}