stop being a dumbass
This commit is contained in:
parent
3f4ceb3fa0
commit
788bf5b00e
3 changed files with 69 additions and 50 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -2098,9 +2098,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.39.2"
|
version = "1.39.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1"
|
checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn Websocket() -> impl IntoView {
|
||||||
open,
|
open,
|
||||||
close,
|
close,
|
||||||
..
|
..
|
||||||
} = use_websocket::<String, FromToStringCodec>("ws://0.0.0.0:3030/websocket");
|
} = use_websocket::<String, FromToStringCodec>("ws://10.0.0.107:3030/websocket");
|
||||||
|
|
||||||
provide_context(WebSocketContext::new(
|
provide_context(WebSocketContext::new(
|
||||||
ready_state,
|
ready_state,
|
||||||
|
|
|
@ -131,9 +131,13 @@ impl GameHandler {
|
||||||
host: host.clone(),
|
host: host.clone(),
|
||||||
packs: new_game.packs,
|
packs: new_game.packs,
|
||||||
};
|
};
|
||||||
|
tracing::debug!("{:#?}", host.clone().read().unwrap().uuid);
|
||||||
|
|
||||||
// Create game using manifest
|
// Create game using manifest
|
||||||
let new_game_object = Game::new(self.state.clone(), manifest);
|
let mut new_game_object = Game::new(self.state.clone(), manifest);
|
||||||
|
|
||||||
|
// Don't forget to create the host player!!!
|
||||||
|
new_game_object.create_player(host.clone());
|
||||||
|
|
||||||
// Create update for user's game view
|
// Create update for user's game view
|
||||||
let meta = GameStateMeta {
|
let meta = GameStateMeta {
|
||||||
|
@ -201,8 +205,8 @@ impl GameHandler {
|
||||||
/// Card Set
|
/// Card Set
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct CardSet {
|
struct CardSet {
|
||||||
white: Option<Vec<Arc<CardWhite>>>,
|
white: Option<Vec<Arc<CardWhiteWithID>>>,
|
||||||
black: Option<Vec<Arc<CardBlack>>>,
|
black: Option<Vec<Arc<CardBlackWithID>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Card Packs
|
/// Card Packs
|
||||||
|
@ -212,18 +216,18 @@ pub struct CardPacks {
|
||||||
unofficial: HashMap<u8, CardSet>,
|
unofficial: HashMap<u8, CardSet>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A white card
|
/// A raw white card as it exists in the source json
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct CardWhite {
|
struct CardWhiteFromJSON {
|
||||||
/// Card text
|
/// Card text
|
||||||
text: String,
|
text: String,
|
||||||
/// ID of the pack it came from
|
/// ID of the pack it came from
|
||||||
pack: u8,
|
pack: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A black card
|
/// A raw black card as it exists in the source json
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct CardBlack {
|
struct CardBlackFromJSON {
|
||||||
/// Card text
|
/// Card text
|
||||||
text: String,
|
text: String,
|
||||||
/// Amount of cards to submit for judging
|
/// Amount of cards to submit for judging
|
||||||
|
@ -232,6 +236,26 @@ struct CardBlack {
|
||||||
pack: u8,
|
pack: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A processed white card for use server-side
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct CardWhiteWithID {
|
||||||
|
/// Unique identifier
|
||||||
|
uuid: Uuid,
|
||||||
|
/// Card text
|
||||||
|
text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A processed black card for use server-side
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct CardBlackWithID {
|
||||||
|
/// Unique identifier
|
||||||
|
uuid: Uuid,
|
||||||
|
/// Card text
|
||||||
|
text: String,
|
||||||
|
/// Amount of cards to submit for judging
|
||||||
|
pick: u8,
|
||||||
|
}
|
||||||
|
|
||||||
/// A card pack
|
/// A card pack
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct CardPack {
|
struct CardPack {
|
||||||
|
@ -240,9 +264,9 @@ struct CardPack {
|
||||||
/// Whether or not this is an official card pack
|
/// Whether or not this is an official card pack
|
||||||
official: bool,
|
official: bool,
|
||||||
/// White card data
|
/// White card data
|
||||||
white: Option<Vec<CardWhite>>,
|
white: Option<Vec<CardWhiteFromJSON>>,
|
||||||
/// Black card data
|
/// Black card data
|
||||||
black: Option<Vec<CardBlack>>,
|
black: Option<Vec<CardBlackFromJSON>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal manifest for making a new game
|
/// Internal manifest for making a new game
|
||||||
|
@ -262,9 +286,9 @@ pub struct Player {
|
||||||
/// Pointer to user
|
/// Pointer to user
|
||||||
user: Arc<RwLock<User>>,
|
user: Arc<RwLock<User>>,
|
||||||
/// The player's hand
|
/// The player's hand
|
||||||
white: Vec<Arc<CardWhite>>,
|
white: Vec<Arc<CardWhiteWithID>>,
|
||||||
/// The player's wins
|
/// The player's wins
|
||||||
black: Vec<Arc<CardBlack>>,
|
black: Vec<Arc<CardBlackWithID>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The game object
|
/// The game object
|
||||||
|
@ -277,12 +301,12 @@ pub struct Game {
|
||||||
/// The host user of the game
|
/// The host user of the game
|
||||||
pub host: Arc<RwLock<User>>,
|
pub host: Arc<RwLock<User>>,
|
||||||
/// White draw pile
|
/// White draw pile
|
||||||
white: Vec<Arc<CardWhite>>,
|
pub white: Vec<Arc<CardWhiteWithID>>,
|
||||||
/// Black draw pile
|
/// Black draw pile
|
||||||
black: Vec<Arc<CardBlack>>,
|
black: Vec<Arc<CardBlackWithID>>,
|
||||||
pub players: HashMap<Uuid, Player>,
|
pub players: HashMap<Uuid, Player>,
|
||||||
/// Black card for the current round
|
/// Black card for the current round
|
||||||
current_black: Arc<CardBlack>,
|
current_black: Arc<CardBlackWithID>,
|
||||||
pub packs: Vec<u8>,
|
pub packs: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +335,11 @@ impl Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw first black card
|
// Draw first black card
|
||||||
let current_black = black.swap_remove((0..black.len()).choose(&mut thread_rng()).unwrap());
|
let current_black = black.swap_remove(
|
||||||
|
(0..black.len())
|
||||||
|
.choose(&mut thread_rng())
|
||||||
|
.expect("No black cards to draw from!"),
|
||||||
|
);
|
||||||
|
|
||||||
// These are at the largest size they should ever be
|
// These are at the largest size they should ever be
|
||||||
white.shrink_to_fit();
|
white.shrink_to_fit();
|
||||||
|
@ -331,7 +359,7 @@ impl Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw one white card at random from play deck.
|
/// Draw one white card at random from play deck.
|
||||||
fn draw_one_white(&mut self) -> Option<Arc<CardWhite>> {
|
fn draw_one_white(&mut self) -> Option<Arc<CardWhiteWithID>> {
|
||||||
let deck = &mut self.white;
|
let deck = &mut self.white;
|
||||||
|
|
||||||
if let Some(index) = (0..deck.len()).choose(&mut thread_rng()) {
|
if let Some(index) = (0..deck.len()).choose(&mut thread_rng()) {
|
||||||
|
@ -380,7 +408,7 @@ pub fn load_cards_from_json(path: &str) -> Result<(CardPacks, CardPacksMeta)> {
|
||||||
let mut unofficial_meta: Vec<CardPackMeta> = vec![];
|
let mut unofficial_meta: Vec<CardPackMeta> = vec![];
|
||||||
|
|
||||||
// Unpack the json
|
// Unpack the json
|
||||||
for set in jayson {
|
for sets in jayson {
|
||||||
let mut num_white = 0;
|
let mut num_white = 0;
|
||||||
let mut num_black = 0;
|
let mut num_black = 0;
|
||||||
|
|
||||||
|
@ -393,55 +421,47 @@ pub fn load_cards_from_json(path: &str) -> Result<(CardPacks, CardPacksMeta)> {
|
||||||
let mut pack: Option<u8> = Option::None;
|
let mut pack: Option<u8> = Option::None;
|
||||||
|
|
||||||
// Process white cards if there are any
|
// Process white cards if there are any
|
||||||
if let Some(ref white) = set.white {
|
if let Some(ref white) = sets.white {
|
||||||
num_white = white.len();
|
num_white = white.len();
|
||||||
if num_white > 0 {
|
if num_white > 0 {
|
||||||
pack = Some(white[0].pack);
|
pack = Some(white[0].pack);
|
||||||
newset.white = Some(
|
let mut white_buf = vec![];
|
||||||
set.white
|
for card in sets.white.unwrap() {
|
||||||
.unwrap()
|
white_buf.push(Arc::new(CardWhiteWithID {
|
||||||
.iter()
|
uuid: Uuid::now_v7(),
|
||||||
.map(|card| {
|
text: card.text,
|
||||||
Arc::new(CardWhite {
|
}));
|
||||||
text: card.text.clone(),
|
}
|
||||||
pack: card.pack.clone(),
|
newset.white = Some(white_buf);
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process black cards if there are any
|
// Process black cards if there are any
|
||||||
if let Some(ref black) = set.black {
|
if let Some(ref black) = sets.black {
|
||||||
num_black = black.len();
|
num_black = black.len();
|
||||||
if num_black > 0 {
|
if num_black > 0 {
|
||||||
pack = Some(black[0].pack);
|
pack = Some(black[0].pack);
|
||||||
newset.black = Some(
|
let mut black_buf = vec![];
|
||||||
set.black
|
for card in sets.black.unwrap() {
|
||||||
.unwrap()
|
black_buf.push(Arc::new(CardBlackWithID {
|
||||||
.iter()
|
uuid: Uuid::now_v7(),
|
||||||
.map(|card| {
|
text: card.text,
|
||||||
Arc::new(CardBlack {
|
pick: card.pick,
|
||||||
text: card.text.clone(),
|
}));
|
||||||
pick: card.pick.clone(),
|
}
|
||||||
pack: card.pack.clone(),
|
newset.black = Some(black_buf);
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start repackaging
|
// Start repackaging
|
||||||
let meta = CardPackMeta {
|
let meta = CardPackMeta {
|
||||||
name: set.name,
|
name: sets.name,
|
||||||
pack: pack.expect("No card pack number!"),
|
pack: pack.expect("No card pack number!"),
|
||||||
num_white,
|
num_white,
|
||||||
num_black,
|
num_black,
|
||||||
};
|
};
|
||||||
|
|
||||||
if set.official {
|
if sets.official {
|
||||||
official_meta.push(meta);
|
official_meta.push(meta);
|
||||||
official.insert(pack.unwrap(), newset);
|
official.insert(pack.unwrap(), newset);
|
||||||
} else {
|
} else {
|
||||||
|
@ -456,7 +476,6 @@ pub fn load_cards_from_json(path: &str) -> Result<(CardPacks, CardPacksMeta)> {
|
||||||
official_meta.shrink_to_fit();
|
official_meta.shrink_to_fit();
|
||||||
unofficial_meta.shrink_to_fit();
|
unofficial_meta.shrink_to_fit();
|
||||||
|
|
||||||
|
|
||||||
// Package for export
|
// Package for export
|
||||||
let packs = CardPacks {
|
let packs = CardPacks {
|
||||||
official,
|
official,
|
||||||
|
|
Loading…
Add table
Reference in a new issue