Add initial card info structs and dataframe library
This commit is contained in:
@@ -27,6 +27,9 @@ pub fn Layout<'a, G: Html>(
|
||||
a(href = "inventory",
|
||||
class = "mt-3 text-gray-600 hover:underline sm:mx-3 sm:mt-0"
|
||||
) { "Inventory" }
|
||||
a(href = "tournaments",
|
||||
class = "mt-3 text-gray-600 hover:underline sm:mx-3 sm:mt-0"
|
||||
) { "Tournaments" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
102
src/data/card.rs
Normal file
102
src/data/card.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use polars::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::Cursor;
|
||||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
#[cfg(engine)]
|
||||
use std::fs;
|
||||
#[cfg(engine)]
|
||||
use std::path::Path;
|
||||
|
||||
enum CartType {
|
||||
NormalMonster,
|
||||
EffectMonster,
|
||||
SpellCard,
|
||||
TrapCard,
|
||||
Unknown { name: String },
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct CardSet {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ArchetypeInfo {
|
||||
pub name: String,
|
||||
pub num_cards: u32,
|
||||
pub cards: Vec<u32>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct CardInfo {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
pub card_sets: Vec<CardSet>,
|
||||
pub archetype: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct CardInstance {
|
||||
card_id: u32,
|
||||
set_id: String,
|
||||
}
|
||||
|
||||
pub struct CardTable {
|
||||
pub cards: HashMap<u32, CardInfo>,
|
||||
pub sets: HashMap<u32, CardSet>,
|
||||
pub archetypes: HashMap<String, ArchetypeInfo>,
|
||||
pub df: DataFrame,
|
||||
}
|
||||
|
||||
impl CardTable {
|
||||
#[cfg(engine)]
|
||||
pub fn new_from_server_json(path: &Path) -> Self {
|
||||
// First load json into initial dataframe
|
||||
// TODO list all required files
|
||||
let raw_df = JsonReader::new(std::fs::File::open("./data/cardinfo.json").unwrap())
|
||||
.finish()
|
||||
.unwrap();
|
||||
let raw_df = raw_df
|
||||
.lazy()
|
||||
.select(&[col("data")])
|
||||
.explode(vec!["data"])
|
||||
.unnest(vec!["data"])
|
||||
.collect()
|
||||
.unwrap();
|
||||
log::info!("{:?}", &raw_df);
|
||||
|
||||
let id_col = UInt32Chunked::new("id_row", &[1]).into_series();
|
||||
|
||||
let cards = HashMap::new();
|
||||
let sets = HashMap::new();
|
||||
let archetypes = HashMap::new();
|
||||
|
||||
let df = DataFrame::new(vec![id_col]).unwrap();
|
||||
|
||||
Self {
|
||||
cards,
|
||||
sets,
|
||||
archetypes,
|
||||
df,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(client)]
|
||||
pub fn new_from_client_json() -> Self {
|
||||
let id_col = UInt32Chunked::new("id_row", &[1]).into_series();
|
||||
|
||||
let cards = HashMap::new();
|
||||
let sets = HashMap::new();
|
||||
let archetypes = HashMap::new();
|
||||
let df = DataFrame::new(vec![id_col]).unwrap();
|
||||
|
||||
Self {
|
||||
cards,
|
||||
sets,
|
||||
archetypes,
|
||||
df,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod user;
|
||||
pub mod card;
|
||||
|
||||
#[cfg(engine)]
|
||||
pub mod store;
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -6,9 +6,16 @@ mod error_views;
|
||||
mod server;
|
||||
mod templates;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use data::card::CardTable;
|
||||
use perseus::prelude::*;
|
||||
use sycamore::prelude::view;
|
||||
|
||||
extern crate strum;
|
||||
#[macro_use]
|
||||
extern crate strum_macros;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(engine)] {
|
||||
use std::net::SocketAddr;
|
||||
@@ -35,6 +42,9 @@ pub async fn dflt_server<M: MutableStore + 'static, T: TranslationsManager + 'st
|
||||
|
||||
app = register_routes(app);
|
||||
|
||||
// TODO move to server global
|
||||
CardTable::new_from_server_json(Path::new("./data/cardinfo.json"));
|
||||
|
||||
axum::Server::bind(&addr)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
|
||||
@@ -13,7 +13,9 @@ cfg_if::cfg_if! {
|
||||
|
||||
#[derive(Serialize, Deserialize, ReactiveState, Clone)]
|
||||
#[rx(alias = "AppStateRx")]
|
||||
pub struct AppState {}
|
||||
pub struct AppState {
|
||||
|
||||
}
|
||||
|
||||
pub fn get_global_state_creator() -> GlobalStateCreator {
|
||||
GlobalStateCreator::new()
|
||||
|
||||
Reference in New Issue
Block a user