Skip to content

Commit

Permalink
chore: remove local io
Browse files Browse the repository at this point in the history
  • Loading branch information
YishiMichael committed Jan 27, 2025
1 parent 6b88191 commit ea9e662
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 102 deletions.
106 changes: 25 additions & 81 deletions morphing/src/toplevel/app.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
pub mod storyboard {
use std::io::BufRead;
use std::io::Read;
// use std::future::Future;
use std::io::BufReader;
use std::io::Read;
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;
use std::sync::Arc;

use super::super::super::timelines::timeline::PresentationEntries;
use super::super::super::timelines::timeline::TimelineEntries;
use super::super::scene::SceneTimelineCollection;
use super::super::settings::Settings;
use super::super::settings::VideoSettings;

pub(crate) struct StoryboardManager {
storyboards: indexmap::IndexMap<PathBuf, StoryboardState>,
// storyboard_id_counter: RangeFrom<u32>,
}

impl StoryboardManager {
pub(crate) fn update(
&mut self,
message: StoryboardMessage,
settings: Arc<Settings>,
device: Arc<wgpu::Device>,
) -> iced::Task<StoryboardMessage> {
match message {
Expand All @@ -46,31 +47,13 @@ pub mod storyboard {
StoryboardMessage::Compile(path) => {
if let Some(state) = self.storyboards.get_mut(&path) {
*&mut state.status = StoryboardStatus::OnCompile;
iced::Task::perform(Self::compile(path.clone()), move |result| {
StoryboardMessage::CompileResult(path.clone(), result)
})
iced::Task::perform(
Self::compile(path.clone(), settings.clone()),
move |result| StoryboardMessage::CompileResult(path.clone(), result),
)
} else {
iced::Task::none()
}

// .storyboards
// .iter_mut()
// .find(|state| state.path == path)
// .map(|state| &mut state.status).unwrap();
// iced::Task::perform(Self::compile(path.clone()), move |result| {
// match result {
// Err(err) => {}
// }
// *status = result.map_or_else(StoryboardStatus::CompileError, |scene_timeline_collections| StoryboardStatus::AfterCompile(
// scene_timeline_collections.into_iter().map(|scene_timeline_collection| SceneState {
// name: scene_timeline_collection.name.to_string(),
// video_settings: scene_timeline_collection.video_settings,
// duration: scene_timeline_collection.duration,
// status: SceneStatus::BeforePrecut(scene_timeline_collection.timeline_entries),
// })
// ));
// iced::Task::none()
// })
}
StoryboardMessage::CompileResult(path, compile_result) => {
if let Some(state) = self.storyboards.get_mut(&path) {
Expand All @@ -81,29 +64,6 @@ pub mod storyboard {
}
iced::Task::none()
}
// StoryboardMessage::Execute(path, compile_result) => {
// if let Some(status) = self
// .storyboards
// .iter_mut()
// .find(|state| state.path == path)
// .map(|state| &mut state.status)
// {
// match compile_result {
// Err(err) => {
// *status = StoryboardStatus::CompileError(err);
// iced::Task::none()
// }
// Ok(()) => {
// *status = StoryboardStatus::Execute;
// iced::Task::perform(Self::execute(path.clone()), move |result| {
// StoryboardMessage::Precut(path, result)
// })
// }
// }
// } else {
// iced::Task::none()
// }
// }
StoryboardMessage::Precut(path, name) => {
if let Some(state) = self.storyboards.get_mut(&path)
&& let StoryboardStatus::AfterCompile(scenes) = &mut state.status
Expand Down Expand Up @@ -146,14 +106,23 @@ pub mod storyboard {
}
}

async fn compile(path: PathBuf) -> anyhow::Result<indexmap::IndexMap<String, SceneState>> {
async fn compile(
path: PathBuf,
settings: Arc<Settings>,
) -> anyhow::Result<indexmap::IndexMap<String, SceneState>> {
let mut child = Command::new("cargo")
.arg("run")
.arg("--quiet")
.current_dir(path)
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn()?;
writeln!(
child.stdin.take().unwrap(),
"{}",
ron::ser::to_string(&settings.scene)?
)?;
if !child.wait()?.success() {
let mut stderr = BufReader::new(child.stderr.take().unwrap());
let mut buf = String::new();
Expand All @@ -177,24 +146,6 @@ pub mod storyboard {
buf.clear();
}
Ok(scenes)

// let mut run
// scene_timeline_collections
// .into_iter()
// .map(|scene_timeline_collection| {
// (
// scene_timeline_collection.name.to_string(),
// SceneState {
// video_settings: scene_timeline_collection
// .video_settings,
// duration: scene_timeline_collection.duration,
// status: SceneStatus::BeforePrecut(
// scene_timeline_collection.timeline_entries,
// ),
// },
// )
// })
// .collect()
}

async fn precut(
Expand All @@ -219,34 +170,23 @@ pub mod storyboard {
}

struct StoryboardState {
// id: StoryboardId,
// path: PathBuf,
status: StoryboardStatus,
}

// #[derive(Clone, Copy, PartialEq)]
// struct StoryboardId(u32);

enum StoryboardStatus {
BeforeCompile,
OnCompile,
AfterCompile(indexmap::IndexMap<String, SceneState>),
CompileError(anyhow::Error),
// ExecuteError(anyhow::Error),
}

struct SceneState {
// id: SceneId,
// name: String,
pub(crate) struct SceneState {
video_settings: VideoSettings,
duration: f32,
status: SceneStatus,
timeline_entries: Arc<TimelineEntries>,
}

// #[derive(Clone, Copy, PartialEq)]
// struct SceneId(u32);

enum SceneStatus {
BeforePrecut,
OnPrecut,
Expand Down Expand Up @@ -389,7 +329,7 @@ pub mod app {
// scene: Arc<SceneState>,
// }
struct State {
settings: Settings,
settings: Arc<Settings>,
// active_scene: Option<ActiveScene>,
device: Arc<wgpu::Device>,
storyboard_manager: StoryboardManager,
Expand All @@ -405,7 +345,11 @@ pub mod app {
match message {
Message::StoryboardMessage(storyboard_message) => self
.storyboard_manager
.update(storyboard_message, self.device.clone())
.update(
storyboard_message,
self.settings.clone(),
self.device.clone(),
)
.map(Message::StoryboardMessage),
}
}
Expand Down
15 changes: 0 additions & 15 deletions morphing/src/toplevel/io.rs

This file was deleted.

1 change: 0 additions & 1 deletion morphing/src/toplevel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod app;
pub mod io;
pub mod palette;
pub mod renderer;
pub mod scene;
Expand Down
14 changes: 9 additions & 5 deletions morphing/src/toplevel/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub use morphing_macros::scene;

use super::super::timelines::alive::Supervisor;
use super::super::timelines::timeline::TimelineEntries;
use super::io::read_from_stdin;
use super::io::write_to_stdout;
use super::settings::SceneSettings;
use super::settings::VideoSettings;
use super::world::World;
Expand All @@ -28,7 +26,9 @@ pub(crate) struct SceneTimelineCollection {
}

pub fn export_scenes() {
let scene_settings: SceneSettings = read_from_stdin();
let mut buf = String::new();
std::io::stdin().read_line(&mut buf).unwrap();
let scene_settings: SceneSettings = ron::de::from_str(&buf).unwrap();
let mut override_settings_map = HashMap::new();
for scene_module in inventory::iter::<SceneModule>() {
let (video_settings, world) = override_settings_map
Expand All @@ -47,11 +47,15 @@ pub fn export_scenes() {
});
let supervisor = Supervisor::new(world);
(scene_module.scene_fn)(&supervisor);
write_to_stdout(SceneTimelineCollection {
let scene_timeline_collection = SceneTimelineCollection {
name: scene_module.name.to_string(),
video_settings: video_settings.clone(),
duration: *supervisor.get_time(),
timeline_entries: supervisor.into_timeline_entries(),
});
};
println!(
"{}",
ron::ser::to_string(&scene_timeline_collection).unwrap()
);
}
}

0 comments on commit ea9e662

Please sign in to comment.