Skip to content

Commit

Permalink
ui: Activate the save button.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Oct 20, 2023
1 parent b12a5b0 commit a3d21cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[?25l ▄▄▄▄▄▄▄▄▄
  ▄▄▄▄▄▄▄▄
[?25l ▄▄▄▄▄▄▄▄▄▄▄▄
 ▄▄▄▄▄▄▄▄▄▄▄▄
 
 
 
Expand Down
1 change: 1 addition & 0 deletions all-is-cubes-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ displaydoc = { workspace = true }
exhaust = { workspace = true }
futures-core = { workspace = true }
futures-task = { workspace = true }
futures-util = { workspace = true }
indoc = { workspace = true }
log = { workspace = true }

Expand Down
40 changes: 30 additions & 10 deletions all-is-cubes-ui/src/apps/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::mpsc::{self, TryRecvError};
use futures_core::future::BoxFuture;
use futures_task::noop_waker_ref;

use all_is_cubes::arcstr::ArcStr;
use all_is_cubes::arcstr::{self, ArcStr};
use all_is_cubes::camera::{GraphicsOptions, StandardCameras, UiViewState, Viewport};
use all_is_cubes::character::{Character, Cursor};
use all_is_cubes::fluff::Fluff;
Expand All @@ -21,7 +21,7 @@ use all_is_cubes::space::{self, Space};
use all_is_cubes::time::{self, Duration};
use all_is_cubes::transaction::{self, Transaction as _};
use all_is_cubes::universe::{self, URef, Universe, UniverseStepInfo};
use all_is_cubes::util::{Fmt, Refmt as _, StatusText};
use all_is_cubes::util::{Fmt, Refmt as _, StatusText, YieldProgressBuilder};

use crate::apps::{FpsCounter, FrameClock, InputProcessor, InputTargets};
use crate::ui_content::Vui;
Expand Down Expand Up @@ -230,7 +230,7 @@ impl<I: time::Instant> Session<I> {
pub fn maybe_step_universe(&mut self) -> Option<UniverseStepInfo> {
self.sync_character_space();

loop {
'handle_message: loop {
match self.control_channel.try_recv() {
Ok(msg) => match msg {
ControlMessage::Back => {
Expand All @@ -240,10 +240,33 @@ impl<I: time::Instant> Session<I> {
}
}
ControlMessage::Save => {
todo!("Need to await the future or make saving synchronous");
// let u = &self.game_universe;
// let _fut = u.whence.save(u, YieldProgressBuilder::new().build());
// // TODO: need to await the future
// TODO: Make this asynchronous. We will need to suspend normal
// stepping during that period.
let u = &self.game_universe;
let fut = u.whence.save(
u,
YieldProgressBuilder::new()
.yield_using(|_| async {}) // noop yield
.build(),
);
match futures_util::FutureExt::now_or_never(fut) {
Some(Ok(())) => {
// TODO: show a momentary "Saved!" message
}
Some(Err(e)) => {
self.show_modal_message(arcstr::format!(
"{}",
all_is_cubes::util::ErrorChain(&*e)
));
continue 'handle_message;
}
None => {
self.show_modal_message(
"unsupported: saving did not complete synchronously".into(),
);
continue 'handle_message;
}
}
}
ControlMessage::TogglePause => {
self.paused.set(!*self.paused.get());
Expand Down Expand Up @@ -620,9 +643,6 @@ pub(crate) enum ControlMessage {
Back,

/// Save the game universe back to its [`WhenceUniverse`].
///
/// TODO: This is not yet implemented and its usage in the UI is disabled.
#[allow(dead_code)]
Save,

TogglePause,
Expand Down
4 changes: 1 addition & 3 deletions all-is-cubes-ui/src/ui_content/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ pub(crate) fn control_bar(hud_inputs: &HudInputs) -> WidgetTree {
hud_inputs.hud_blocks.blocks[UiBlocks::AboutButtonLabel].clone(),
)),
LayoutTree::leaf(pause_toggle_button(hud_inputs)),
// TODO: Actually saving is not yet implemented.
// LayoutTree::leaf(save_button(hud_inputs)),
LayoutTree::leaf(save_button(hud_inputs)),
LayoutTree::leaf(widgets::ToggleButton::new(
hud_inputs.mouselook_mode.clone(),
|&value| value,
Expand Down Expand Up @@ -129,7 +128,6 @@ pub(crate) fn control_bar(hud_inputs: &HudInputs) -> WidgetTree {
}
}

#[allow(dead_code)] // TODO: use this once saving actually works
fn save_button(hud_inputs: &HudInputs) -> Arc<dyn Widget> {
let cc = hud_inputs.app_control_channel.clone();
widgets::ActionButton::new(
Expand Down

0 comments on commit a3d21cd

Please sign in to comment.