monorepo/kifu/core/src/library.rs

51 lines
1.5 KiB
Rust
Raw Normal View History

2024-03-22 02:39:28 +00:00
/*
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
This file is part of Kifu.
Kifu is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Kifu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along with Kifu. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::{Core, Config};
use serde::{Deserialize, Serialize};
use sgf::GameInfo;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum LibraryRequest {
ListGames
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum LibraryResponse {
Games(Vec<GameInfo>)
}
async fn handle_list_games(model: &Core) -> LibraryResponse {
println!("handle_list_games");
let library = model.library();
println!("library: {:?}", *library);
match *library {
Some(ref library) => {
let info = library.all_games().map(|g| g.info.clone()).collect::<Vec<GameInfo>>();
LibraryResponse::Games(info)
}
None => LibraryResponse::Games(vec![]),
}
}
pub async fn handle(model: &Core, request: LibraryRequest) -> LibraryResponse {
match request {
LibraryRequest::ListGames => handle_list_games(model).await,
}
}