use std::collections::BTreeMap;
use std::path::PathBuf;
use oxframe_core::Color;
use oxframe_protocol::Meta;
use crate::SceneDef;
#[derive(Debug, Clone)]
pub struct Project {
pub(crate) name: String,
pub(crate) scenes: Vec<SceneDef>,
pub(crate) size: (u32, u32),
pub(crate) fps: u32,
pub(crate) background: Color,
pub(crate) seed: u64,
pub(crate) max_scene_seconds: f64,
pub(crate) write_meta: bool,
pub(crate) meta_dir: Option<PathBuf>,
pub(crate) audio: Option<String>,
pub(crate) inline_meta: Option<BTreeMap<String, Meta>>,
}
impl Project {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
scenes: Vec::new(),
size: (1920, 1080),
fps: 60,
background: Color::from_rgba8(0x14, 0x14, 0x14, 0xff),
seed: 0,
max_scene_seconds: 600.0,
write_meta: true,
meta_dir: None,
audio: None,
inline_meta: cfg!(target_arch = "wasm32").then(BTreeMap::new),
}
}
pub fn scene(mut self, scene: SceneDef) -> Self {
self.scenes.push(scene);
self
}
pub fn size(mut self, width: u32, height: u32) -> Self {
self.size = (width.max(1), height.max(1));
self
}
pub fn fps(mut self, fps: u32) -> Self {
self.fps = fps.max(1);
self
}
pub fn background(mut self, color: Color) -> Self {
self.background = color;
self
}
pub fn seed(mut self, seed: u64) -> Self {
self.seed = seed;
self
}
pub fn max_scene_seconds(mut self, seconds: f64) -> Self {
self.max_scene_seconds = seconds.max(0.0);
self
}
pub fn write_meta(mut self, write: bool) -> Self {
self.write_meta = write;
self
}
pub fn meta_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.meta_dir = Some(dir.into());
self
}
pub fn inline_meta(mut self, metas: BTreeMap<String, Meta>) -> Self {
self.inline_meta = Some(metas);
self
}
pub fn audio(mut self, path: impl Into<String>) -> Self {
self.audio = Some(path.into());
self
}
pub fn name(&self) -> &str {
&self.name
}
#[cfg(not(target_arch = "wasm32"))]
pub fn main(self) {
let code = crate::cli::run(self, std::env::args().skip(1).collect());
std::process::exit(code);
}
}