Skip to content

Commit

Permalink
progress game management
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Apr 21, 2024
1 parent adaecf9 commit 3a282bb
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 31 deletions.
12 changes: 9 additions & 3 deletions gamercade_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions gamercade_app/src/local_directory/game_footprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use super::{game::GameId, Dictionary, DictionaryTrait, LocalDirectory};

#[derive(Default)]
pub struct GameFootprint {
permission_level: Option<i32>,
vote: Option<Vote>,
pub permission_level: Option<i32>,
pub vote: Option<Vote>,
}

pub enum Vote {
Expand Down
8 changes: 2 additions & 6 deletions gamercade_app/src/local_directory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
78 changes: 59 additions & 19 deletions gamercade_app/src/modes/arcade_mode/creator_dashboard.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
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)]
enum DashboardView {
#[default]
Main,
NewGameView,
ManageGameView,
}

impl CreatorDashboardView {
Expand All @@ -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();
Expand All @@ -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;
Expand Down
74 changes: 74 additions & 0 deletions gamercade_app/src/modes/arcade_mode/manage_game.rs
Original file line number Diff line number Diff line change
@@ -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<i32>,
}

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
}
}
1 change: 1 addition & 0 deletions gamercade_app/src/modes/arcade_mode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::app::AppDrawContext;

mod creator_dashboard;
mod login;
mod manage_game;
mod new_game;
mod online;
mod sign_up;
Expand Down
1 change: 0 additions & 1 deletion gamercade_app/src/modes/arcade_mode/online.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{ArcadeActiveView, CreatorDashboardView};

#[derive(Default)]
pub struct OnlineView {
release_id: String,
active_mode: OnlineViewMode,

pub arcade: ArcadeView,
Expand Down
3 changes: 3 additions & 0 deletions gamercade_interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3a282bb

Please sign in to comment.