use std::ops::Range;
use uuid::Uuid;
use crate::{
AnimOP, CodeAnimationStyle, CodeHighlightAction, Color, Ease, IntoAnimOp, Sfx, Time,
};
pub struct CodeAddLinesBuilder {
pub(crate) uuid: Uuid,
pub(crate) text: String,
pub(crate) from_line: usize,
pub(crate) duration: Time,
pub(crate) ease: Ease,
pub(crate) style: CodeAnimationStyle,
}
impl CodeAddLinesBuilder {
#[must_use]
pub fn str(mut self, text: impl Into<String>) -> Self {
self.text = text.into();
self
}
#[must_use]
pub const fn from_line(mut self, line: usize) -> Self {
self.from_line = line;
self
}
#[must_use]
pub const fn over(mut self, duration: Time) -> Self {
self.duration = duration;
self
}
#[must_use]
pub const fn ease(mut self, ease: Ease) -> Self {
self.ease = ease;
self
}
#[must_use]
pub const fn style(mut self, style: CodeAnimationStyle) -> Self {
self.style = style;
self
}
}
impl From<CodeAddLinesBuilder> for AnimOP {
fn from(b: CodeAddLinesBuilder) -> Self {
Self::CodeAddLines(
b.uuid,
b.text,
b.from_line,
b.duration,
b.ease,
b.style,
None,
)
}
}
impl IntoAnimOp for CodeAddLinesBuilder {
fn into_anim_op(self) -> AnimOP {
self.into()
}
}
pub struct CodeModifyLineBuilder {
pub(crate) uuid: Uuid,
pub(crate) line: u32,
pub(crate) text: String,
pub(crate) duration: Time,
pub(crate) ease: Ease,
pub(crate) style: CodeAnimationStyle,
}
impl CodeModifyLineBuilder {
#[must_use]
pub fn str(mut self, text: impl Into<String>) -> Self {
self.text = text.into();
self
}
#[must_use]
pub const fn line(mut self, line: u32) -> Self {
self.line = line;
self
}
#[must_use]
pub const fn over(mut self, duration: Time) -> Self {
self.duration = duration;
self
}
#[must_use]
pub const fn ease(mut self, ease: Ease) -> Self {
self.ease = ease;
self
}
#[must_use]
pub const fn style(mut self, style: CodeAnimationStyle) -> Self {
self.style = style;
self
}
}
impl From<CodeModifyLineBuilder> for AnimOP {
fn from(b: CodeModifyLineBuilder) -> Self {
Self::CodeModifyLine(b.uuid, b.line, b.text, b.duration, b.ease, b.style, None)
}
}
impl IntoAnimOp for CodeModifyLineBuilder {
fn into_anim_op(self) -> AnimOP {
self.into()
}
}
pub struct CodeRemoveLinesBuilder {
pub(crate) uuid: Uuid,
pub(crate) range: Range<u32>,
pub(crate) duration: Time,
pub(crate) ease: Ease,
pub(crate) style: CodeAnimationStyle,
}
impl CodeRemoveLinesBuilder {
#[must_use]
pub const fn range(mut self, range: Range<u32>) -> Self {
self.range = range;
self
}
#[must_use]
pub const fn over(mut self, duration: Time) -> Self {
self.duration = duration;
self
}
#[must_use]
pub const fn ease(mut self, ease: Ease) -> Self {
self.ease = ease;
self
}
#[must_use]
pub const fn style(mut self, style: CodeAnimationStyle) -> Self {
self.style = style;
self
}
}
impl From<CodeRemoveLinesBuilder> for AnimOP {
fn from(b: CodeRemoveLinesBuilder) -> Self {
Self::CodeRemoveLines(b.uuid, b.range, b.duration, b.ease, b.style, None)
}
}
impl IntoAnimOp for CodeRemoveLinesBuilder {
fn into_anim_op(self) -> AnimOP {
self.into()
}
}
pub struct CodeHighlightBuilder {
pub(crate) uuid: Uuid,
pub(crate) ranges: Vec<Range<usize>>,
pub(crate) regex: Option<String>,
pub(crate) color: Color,
pub(crate) duration: Time,
pub(crate) ease: Ease,
}
impl CodeHighlightBuilder {
#[must_use]
pub fn lines(mut self, range: Range<usize>) -> Self {
self.ranges.push(range);
self
}
#[must_use]
pub fn pattern(mut self, regex: impl Into<String>) -> Self {
self.regex = Some(regex.into());
self
}
#[must_use]
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
#[must_use]
pub fn over(mut self, duration: Time) -> Self {
self.duration = duration;
self
}
#[must_use]
pub fn ease(mut self, ease: Ease) -> Self {
self.ease = ease;
self
}
}
impl From<CodeHighlightBuilder> for AnimOP {
fn from(b: CodeHighlightBuilder) -> Self {
let action = if let Some(regex) = b.regex {
CodeHighlightAction::Pattern {
regex,
color: b.color,
duration: b.duration,
curve: b.ease,
}
} else {
CodeHighlightAction::Lines {
ranges: b.ranges,
color: b.color,
duration: b.duration,
curve: b.ease,
}
};
Self::CodeHighlight(b.uuid, action, None)
}
}
impl IntoAnimOp for CodeHighlightBuilder {
fn into_anim_op(self) -> AnimOP {
self.into()
}
}
pub struct PlaySoundBuilder {
pub(crate) sfx: Sfx,
pub(crate) delay: Time,
}
impl PlaySoundBuilder {
#[must_use]
pub fn after(mut self, delay: Time) -> AnimOP {
self.delay = delay;
self.into()
}
#[must_use]
pub fn delay(mut self, delay: Time) -> AnimOP {
self.delay = delay;
self.into()
}
}
impl From<PlaySoundBuilder> for AnimOP {
fn from(b: PlaySoundBuilder) -> AnimOP {
AnimOP::PlaySound(b.sfx, b.delay, None)
}
}
impl IntoAnimOp for PlaySoundBuilder {
fn into_anim_op(self) -> AnimOP {
self.into()
}
}