use crate::domain::module::body::{
Audio, Background, HoverAnimation, Image, ModuleAssist, StickerHidden, ThemeId, Transform,
};
use derive_setters::Setters;
use serde::{Deserialize, Serialize};
pub const DEFAULT_TEXT_VALUE: &str = "Shalom שָׁלוֹם";
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct BaseContent {
pub instructions: ModuleAssist,
#[serde(default)]
pub feedback: ModuleAssist,
pub theme: ThemeId,
pub backgrounds: Backgrounds,
pub stickers: Vec<Sticker>,
}
impl Default for BaseContent {
fn default() -> Self {
Self {
instructions: Default::default(),
feedback: Default::default(),
theme: Default::default(),
backgrounds: Default::default(),
stickers: vec![Sticker::Text(Default::default())],
}
}
}
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
pub struct Backgrounds {
pub layer_1: Option<Background>,
pub layer_2: Option<Background>,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub enum Sticker {
#[serde(alias = "sprite")]
Sprite(Sprite),
#[serde(alias = "text")]
Text(Text),
#[serde(alias = "embed")]
Embed(Embed),
}
impl Sticker {
pub fn transform(&self) -> &Transform {
match self {
Self::Sprite(sprite) => &sprite.transform,
Self::Text(text) => &text.transform,
Self::Embed(embed) => &embed.transform,
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Text {
pub value: String,
pub transform: Transform,
#[serde(default)]
pub hover_animation: Option<HoverAnimation>,
#[serde(default)]
pub hidden: Option<StickerHidden>,
}
impl Default for Text {
fn default() -> Self {
Self::from_str(DEFAULT_TEXT_VALUE)
}
}
impl Text {
pub fn from_str(text: &str) -> Self {
Self::from_value(Self::value_from_str(text))
}
pub fn from_value(value: String) -> Self {
Self {
value,
transform: Transform::identity(),
hover_animation: None,
hidden: None,
}
}
pub fn value_from_str(text: &str) -> String {
format!(
r#"{{"version":"0.1.0","content":[{{"children":[{{"text":"{}","element":"H1"}}]}}]}}"#,
text
)
}
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Sprite {
pub image: Image,
pub transform: Transform,
pub effects: Vec<SpriteEffect>,
pub flip_horizontal: bool,
pub flip_vertical: bool,
#[serde(default)]
pub hover_animation: Option<HoverAnimation>,
#[serde(default)]
pub hidden: Option<StickerHidden>,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum SpriteEffect {
RemoveWhite,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Embed {
pub host: EmbedHost,
pub transform: Transform,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum DoneAction {
Loop,
Next,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub enum EmbedHost {
#[serde(alias = "youtube")]
Youtube(YoutubeEmbed),
Vimeo(VimeoEmbed),
GoogleDoc(GoogleDocsEmbed),
GoogleForm(GoogleFormsEmbed),
GoogleSheet(GoogleSheetsEmbed),
GoogleSlide(GoogleSlidesEmbed),
Edpuzzle(EdpuzzleEmbed),
Puzzel(PuzzelEmbed),
Quizlet(QuizletEmbed),
Thinglink(ThinglinkEmbed),
Sutori(SutoriEmbed),
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Setters)]
pub struct YoutubeEmbed {
pub url: YoutubeUrl,
pub start_at: Option<u32>,
pub end_at: Option<u32>,
pub captions: bool,
pub muted: bool,
pub autoplay: bool,
pub done_action: Option<DoneAction>,
}
impl YoutubeEmbed {
pub fn new(url: YoutubeUrl) -> Self {
Self {
url,
start_at: None,
end_at: None,
captions: false,
muted: false,
autoplay: false,
done_action: None,
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct YoutubeUrl(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Setters)]
pub struct VimeoEmbed {
pub url: VimeoUrl,
pub start_at: Option<u32>,
pub end_at: Option<u32>,
pub captions: bool,
pub muted: bool,
pub autoplay: bool,
pub done_action: Option<DoneAction>,
}
impl VimeoEmbed {
pub fn new(url: VimeoUrl) -> Self {
Self {
url,
start_at: None,
end_at: None,
captions: false,
muted: false,
autoplay: false,
done_action: None,
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct VimeoUrl(pub String);
impl EmbedHost {
pub fn get_url_string(&self) -> String {
match &self {
EmbedHost::Youtube(youtube_video) => {
let YoutubeUrl(url) = &youtube_video.url;
url.to_string()
}
EmbedHost::Vimeo(vimeo_video) => {
let VimeoUrl(url) = &vimeo_video.url;
url.to_string()
}
EmbedHost::GoogleDoc(google_doc) => {
let GoogleDocId(url) = &google_doc.url;
url.to_string()
}
EmbedHost::GoogleForm(google_form) => {
let GoogleFormId(url) = &google_form.url;
url.to_string()
}
EmbedHost::GoogleSheet(google_sheet) => {
let GoogleSheetId(url) = &google_sheet.url;
url.to_string()
}
EmbedHost::GoogleSlide(google_slide) => {
let GoogleSlideId(url) = &google_slide.url;
url.to_string()
}
EmbedHost::Edpuzzle(_) => todo!(),
EmbedHost::Puzzel(_) => todo!(),
EmbedHost::Quizlet(quizlet) => {
let QuizletId(url) = &quizlet.url;
url.to_string()
}
EmbedHost::Thinglink(thinglink) => {
let ThinglinkId(url) = &thinglink.url;
url.to_string()
}
EmbedHost::Sutori(sutori) => {
let SutoriId(url) = &sutori.url;
url.to_string()
}
}
}
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleDocsEmbed {
pub url: GoogleDocId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleDocId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleFormsEmbed {
pub url: GoogleFormId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleFormId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleSheetsEmbed {
pub url: GoogleSheetId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleSheetId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleSlidesEmbed {
pub url: GoogleSlideId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct GoogleSlideId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct EdpuzzleEmbed {
pub url: EdpuzzleId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct EdpuzzleId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct PuzzelEmbed {
pub url: PuzzelId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct PuzzelId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct QuizletEmbed {
pub url: QuizletId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct QuizletId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct ThinglinkEmbed {
pub url: ThinglinkId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct ThinglinkId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct SutoriEmbed {
pub url: SutoriId,
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct SutoriId(pub String);
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Trace {
pub transform: Transform,
pub shape: TraceShape,
pub kind: TraceKind,
pub audio: Option<Audio>,
pub text: Option<String>,
}
#[derive(Clone, Copy, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub enum TraceKind {
#[serde(alias = "wrong")]
Wrong,
#[serde(alias = "correct")]
Correct,
#[serde(alias = "regular")]
Regular,
}
impl AsRef<Trace> for Trace {
fn as_ref(&self) -> &Trace {
self
}
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub enum TraceShape {
#[serde(alias = "rect")]
Rect(f64, f64),
#[serde(alias = "ellipse")]
Ellipse(f64, f64),
#[serde(alias = "path")]
Path(Vec<(f64, f64)>),
#[serde(alias = "pathCommands")]
PathCommands(Vec<(PathCommand, bool)>),
}
#[allow(missing_docs)]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum PathCommand {
MoveTo(f64, f64),
ClosePath,
LineTo(f64, f64),
HorizontalLineTo(f64),
VerticalLineTo(f64),
CurveTo(f64, f64, f64, f64, f64, f64),
SmoothCurveTo(f64, f64, f64, f64),
QuadCurveTo(f64, f64, f64, f64),
SmoothQuadCurveTo(f64, f64),
ArcTo(f64, f64, f64, f64, f64, f64, f64),
}