From 3a282bb7d29a29c5f17233c8ce00b0a4bc93c8ab Mon Sep 17 00:00:00 2001 From: RobDavenport Date: Mon, 22 Apr 2024 01:58:09 +0900 Subject: [PATCH] progress game management --- gamercade_app/src/app.rs | 12 ++- .../src/local_directory/game_footprint.rs | 4 +- gamercade_app/src/local_directory/mod.rs | 8 +- .../modes/arcade_mode/creator_dashboard.rs | 78 ++++++++++++++----- .../src/modes/arcade_mode/manage_game.rs | 74 ++++++++++++++++++ gamercade_app/src/modes/arcade_mode/mod.rs | 1 + gamercade_app/src/modes/arcade_mode/online.rs | 1 - gamercade_interface/src/lib.rs | 3 + 8 files changed, 150 insertions(+), 31 deletions(-) create mode 100644 gamercade_app/src/modes/arcade_mode/manage_game.rs diff --git a/gamercade_app/src/app.rs b/gamercade_app/src/app.rs index 5a19a13..683beeb 100644 --- a/gamercade_app/src/app.rs +++ b/gamercade_app/src/app.rs @@ -4,7 +4,10 @@ use gamercade_interface::{platform::FrontPageRequest, CRC}; use crate::{ local_directory::LocalDirectory, modes::{AppMode, ArcadeModeView, LibraryModeView, SettingsModeView}, - task_manager::{AuthState, GameResponse, PlatformResponse, SuperTaskManager, TaskNotification}, + task_manager::{ + AuthState, GameResponse, PlatformRequest, PlatformResponse, SuperTaskManager, + TaskNotification, + }, }; #[derive(Default)] @@ -82,12 +85,15 @@ impl App { self.directory.upsert_permission_levesl(&permissions, true); } TaskNotification::AuthStateChanged(new_state) => { - println!("Auth State Changed: {new_state:?}"); self.auth_state = new_state; match self.auth_state { AuthState::Unauthorized => self.modes.arcade.logged_out(), - AuthState::SessionHeld(_) => self.modes.arcade.logged_in(), + AuthState::SessionHeld(_) => { + self.modes.arcade.logged_in(); + self.tasks.platform.send(PlatformRequest::VotedGames); + self.tasks.platform.send(PlatformRequest::EditableGames); + } } } TaskNotification::LoginFailed => self.modes.arcade.logged_out(), diff --git a/gamercade_app/src/local_directory/game_footprint.rs b/gamercade_app/src/local_directory/game_footprint.rs index d5c6beb..a8e0985 100644 --- a/gamercade_app/src/local_directory/game_footprint.rs +++ b/gamercade_app/src/local_directory/game_footprint.rs @@ -5,8 +5,8 @@ use super::{game::GameId, Dictionary, DictionaryTrait, LocalDirectory}; #[derive(Default)] pub struct GameFootprint { - permission_level: Option, - vote: Option, + pub permission_level: Option, + pub vote: Option, } pub enum Vote { diff --git a/gamercade_app/src/local_directory/mod.rs b/gamercade_app/src/local_directory/mod.rs index 4fda523..53bcdb1 100644 --- a/gamercade_app/src/local_directory/mod.rs +++ b/gamercade_app/src/local_directory/mod.rs @@ -9,16 +9,12 @@ mod permission_level; mod tag; mod user; -use game::Game; - +pub use game::{Game, GameId}; pub use permission_level::{PermissionLevel, PermissionLevelId}; pub use tag::{Tag, TagId}; pub use user::{User, UserId}; -use self::{ - game::{upsert_games_table, GameId}, - game_footprint::GameFootprint, -}; +use self::{game::upsert_games_table, game_footprint::GameFootprint}; const LOCAL_DB_PATH: &str = "./local.db"; diff --git a/gamercade_app/src/modes/arcade_mode/creator_dashboard.rs b/gamercade_app/src/modes/arcade_mode/creator_dashboard.rs index be4a322..2c07502 100644 --- a/gamercade_app/src/modes/arcade_mode/creator_dashboard.rs +++ b/gamercade_app/src/modes/arcade_mode/creator_dashboard.rs @@ -1,18 +1,21 @@ -use gamercade_interface::game::UpdateGameRequest; +use eframe::egui; +use gamercade_interface::{game::UpdateGameRequest, PERMISSION_LEVEL_EDITOR}; use rfd::FileDialog; use crate::{ app::AppDrawContext, + local_directory::{GameId, IsDictionary}, task_manager::{GameRequest, UploadRom}, urls::WithSession, }; -use super::new_game::NewGameView; +use super::{manage_game::ManageGameView, new_game::NewGameView}; #[derive(Default)] pub struct CreatorDashboardView { - pub view: DashboardView, + view: DashboardView, pub new_game_view: NewGameView, + pub manage_game_view: ManageGameView, } #[derive(Default)] @@ -20,6 +23,7 @@ enum DashboardView { #[default] Main, NewGameView, + ManageGameView, } impl CreatorDashboardView { @@ -39,6 +43,11 @@ impl CreatorDashboardView { self.view = DashboardView::Main } } + DashboardView::ManageGameView => { + if self.manage_game_view.draw(context) { + self.view = DashboardView::Main + } + } } // ui.separator(); @@ -51,27 +60,58 @@ impl CreatorDashboardView { // } // let game_id = self.game_id.parse(); - - // if ui.button("Upload Game").clicked() { - // if let Ok(game_id) = game_id { - // if let Some(file) = FileDialog::new() - // .add_filter("gcrom (.gcrom)", &["gcrom"]) - // .pick_file() - // { - // let bytes = std::fs::read(file).unwrap(); - - // context.task_manager.rom.try_upload_rom( - // UploadRom { game_id, bytes }, - // &context.auth_state.get_session().unwrap(), - // ) - // } - // } - // } } fn draw_main_view(&mut self, context: &mut AppDrawContext) { let ui = &mut context.ui; + egui::Grid::new("editable_grid") + .num_columns(3) + .spacing([40.0, 4.0]) + .striped(true) + .show(ui, |ui| { + ui.label("Editable Games:"); + ui.end_row(); + + ui.label("Title"); + ui.label("Rom Details"); + ui.label("Manage"); + ui.end_row(); + + // Only iterate games which we are able to edit + for game in context.directory.iter_games().filter(|game| { + context + .directory + .game_footprint + .get_map() + .get(&GameId(game.id)) + .map(|game| { + if let Some(level) = game.permission_level { + level <= PERMISSION_LEVEL_EDITOR + } else { + false + } + }) + .unwrap_or_default() + }) { + ui.label(&game.title); + + let rom_exists = + if let (Some(_), Some(size)) = (game.file_checksum, game.rom_size) { + let size = size as f32 / (1024.0 * 1024.0); + format!("{size}mb") + } else { + format!("N/A") + }; + ui.label(rom_exists); + + if ui.button("Manage Game").clicked() { + self.manage_game_view = ManageGameView::new(game); + self.view = DashboardView::ManageGameView; + } + } + }); + ui.separator(); if ui.button("Create New Game").clicked() { self.view = DashboardView::NewGameView; diff --git a/gamercade_app/src/modes/arcade_mode/manage_game.rs b/gamercade_app/src/modes/arcade_mode/manage_game.rs new file mode 100644 index 0000000..85a8b6c --- /dev/null +++ b/gamercade_app/src/modes/arcade_mode/manage_game.rs @@ -0,0 +1,74 @@ +use rfd::FileDialog; + +use crate::{app::AppDrawContext, local_directory::Game, task_manager::UploadRom}; + +#[derive(Default)] +pub struct ManageGameView { + awaiting_upload: bool, + game_id: i64, + title: String, + short_description: String, + long_description: String, + tags: Vec, +} + +impl ManageGameView { + pub fn new(game: &Game) -> Self { + Self { + awaiting_upload: false, + game_id: game.id, + title: game.title.clone(), + short_description: game.short_description.clone(), + long_description: game.long_description.as_ref().cloned().unwrap_or_default(), + tags: game.tags.clone(), + } + } + + pub fn draw(&mut self, context: &mut AppDrawContext) -> bool { + let mut done = false; + let ui = &mut context.ui; + + ui.set_enabled(!self.awaiting_upload); + + ui.label("Manage Game View:"); + ui.separator(); + + ui.label("Game Title: "); + ui.text_edit_singleline(&mut self.title); + ui.separator(); + + ui.label("Short Description: "); + ui.text_edit_singleline(&mut self.short_description); + + ui.label("Long Description: "); + ui.text_edit_singleline(&mut self.long_description); + ui.separator(); + + if ui.button("Upload Game").clicked() { + if let Some(file) = FileDialog::new() + .add_filter("gcrom (.gcrom)", &["gcrom"]) + .pick_file() + { + let bytes = std::fs::read(file).unwrap(); + + context.task_manager.rom.try_upload_rom( + UploadRom { + game_id: self.game_id, + bytes, + }, + &context.auth_state.get_session().unwrap(), + ) + } + } + + if self.awaiting_upload { + ui.spinner(); + } + + if ui.button("Go Back").clicked() { + done = true; + } + + done + } +} diff --git a/gamercade_app/src/modes/arcade_mode/mod.rs b/gamercade_app/src/modes/arcade_mode/mod.rs index c52f48c..8e9d66d 100644 --- a/gamercade_app/src/modes/arcade_mode/mod.rs +++ b/gamercade_app/src/modes/arcade_mode/mod.rs @@ -2,6 +2,7 @@ use crate::app::AppDrawContext; mod creator_dashboard; mod login; +mod manage_game; mod new_game; mod online; mod sign_up; diff --git a/gamercade_app/src/modes/arcade_mode/online.rs b/gamercade_app/src/modes/arcade_mode/online.rs index 515de3b..eda31da 100644 --- a/gamercade_app/src/modes/arcade_mode/online.rs +++ b/gamercade_app/src/modes/arcade_mode/online.rs @@ -4,7 +4,6 @@ use super::{ArcadeActiveView, CreatorDashboardView}; #[derive(Default)] pub struct OnlineView { - release_id: String, active_mode: OnlineViewMode, pub arcade: ArcadeView, diff --git a/gamercade_interface/src/lib.rs b/gamercade_interface/src/lib.rs index 37d1aea..d99477f 100644 --- a/gamercade_interface/src/lib.rs +++ b/gamercade_interface/src/lib.rs @@ -20,6 +20,9 @@ pub const RELEASE_NAME_MAX_LENGTH: usize = 123; pub const AUTHOR_TITLE_MAX_LENGTH: usize = 31; pub const REVIEW_COMMENTS_MAX_LENGTH: usize = 1027; +pub const PERMISSION_LEVEL_EDITOR: i32 = 10; +pub const PERMISSION_LEVEL_OWNER: i32 = 0; + pub const SESSION_METADATA_KEY: &str = "gc-session-bin"; pub const URL_RADIX: usize = 16;