#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "actor.rpg.sprite",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Sprite<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_sprite_animation_speed")]
pub animation_speed: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub columns: Option<i64>,
pub created_at: Datetime,
pub engine: SpriteEngine<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub frame_height: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub frame_width: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub frames: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rows: Option<i64>,
pub sprite_sheet: BlobRef<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<i64>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SpriteEngine<S: BosStr = DefaultStr> {
Rmmz,
Rmmv,
Rpgmaker2003,
Custom,
Other(S),
}
impl<S: BosStr> SpriteEngine<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Rmmz => "rmmz",
Self::Rmmv => "rmmv",
Self::Rpgmaker2003 => "rpgmaker2003",
Self::Custom => "custom",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"rmmz" => Self::Rmmz,
"rmmv" => Self::Rmmv,
"rpgmaker2003" => Self::Rpgmaker2003,
"custom" => Self::Custom,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for SpriteEngine<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for SpriteEngine<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for SpriteEngine<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for SpriteEngine<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for SpriteEngine<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for SpriteEngine<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = SpriteEngine<S::Output>;
fn into_static(self) -> Self::Output {
match self {
SpriteEngine::Rmmz => SpriteEngine::Rmmz,
SpriteEngine::Rmmv => SpriteEngine::Rmmv,
SpriteEngine::Rpgmaker2003 => SpriteEngine::Rpgmaker2003,
SpriteEngine::Custom => SpriteEngine::Custom,
SpriteEngine::Other(v) => SpriteEngine::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SpriteGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Sprite<S>,
}
impl<S: BosStr> Sprite<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, SpriteRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SpriteRecord;
impl XrpcResp for SpriteRecord {
const NSID: &'static str = "actor.rpg.sprite";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = SpriteGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<SpriteGetRecordOutput<S>> for Sprite<S> {
fn from(output: SpriteGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Sprite<S> {
const NSID: &'static str = "actor.rpg.sprite";
type Record = SpriteRecord;
}
impl Collection for SpriteRecord {
const NSID: &'static str = "actor.rpg.sprite";
type Record = SpriteRecord;
}
impl<S: BosStr> LexiconSchema for Sprite<S> {
fn nsid() -> &'static str {
"actor.rpg.sprite"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_actor_rpg_sprite()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.animation_speed {
if *value > 2000i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("animation_speed"),
max: 2000i64,
actual: *value,
});
}
}
if let Some(ref value) = self.animation_speed {
if *value < 50i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("animation_speed"),
min: 50i64,
actual: *value,
});
}
}
if let Some(ref value) = self.columns {
if *value > 16i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("columns"),
max: 16i64,
actual: *value,
});
}
}
if let Some(ref value) = self.columns {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("columns"),
min: 1i64,
actual: *value,
});
}
}
if let Some(ref value) = self.frame_height {
if *value > 512i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("frame_height"),
max: 512i64,
actual: *value,
});
}
}
if let Some(ref value) = self.frame_height {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("frame_height"),
min: 1i64,
actual: *value,
});
}
}
if let Some(ref value) = self.frame_width {
if *value > 512i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("frame_width"),
max: 512i64,
actual: *value,
});
}
}
if let Some(ref value) = self.frame_width {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("frame_width"),
min: 1i64,
actual: *value,
});
}
}
if let Some(ref value) = self.frames {
if *value > 64i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("frames"),
max: 64i64,
actual: *value,
});
}
}
if let Some(ref value) = self.frames {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("frames"),
min: 1i64,
actual: *value,
});
}
}
if let Some(ref value) = self.height {
if *value > 4096i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("height"),
max: 4096i64,
actual: *value,
});
}
}
if let Some(ref value) = self.height {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("height"),
min: 1i64,
actual: *value,
});
}
}
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.name {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 50usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("name"),
max: 50usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.rows {
if *value > 16i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("rows"),
max: 16i64,
actual: *value,
});
}
}
if let Some(ref value) = self.rows {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("rows"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.sprite_sheet;
{
let size = value.blob().size;
if size > 10000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("sprite_sheet"),
max: 10000000usize,
actual: size,
});
}
}
}
{
let value = &self.sprite_sheet;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/png"];
let matched = accepted.iter().any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix) && mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("sprite_sheet"),
accepted: vec!["image/png".to_string()],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.width {
if *value > 4096i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("width"),
max: 4096i64,
actual: *value,
});
}
}
if let Some(ref value) = self.width {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("width"),
min: 1i64,
actual: *value,
});
}
}
Ok(())
}
}
fn _default_sprite_animation_speed() -> Option<i64> {
Some(200i64)
}
pub mod sprite_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Engine;
type CreatedAt;
type SpriteSheet;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Engine = Unset;
type CreatedAt = Unset;
type SpriteSheet = Unset;
}
pub struct SetEngine<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEngine<St> {}
impl<St: State> State for SetEngine<St> {
type Engine = Set<members::engine>;
type CreatedAt = St::CreatedAt;
type SpriteSheet = St::SpriteSheet;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type Engine = St::Engine;
type CreatedAt = Set<members::created_at>;
type SpriteSheet = St::SpriteSheet;
}
pub struct SetSpriteSheet<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSpriteSheet<St> {}
impl<St: State> State for SetSpriteSheet<St> {
type Engine = St::Engine;
type CreatedAt = St::CreatedAt;
type SpriteSheet = Set<members::sprite_sheet>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct engine(());
pub struct created_at(());
pub struct sprite_sheet(());
}
}
pub struct SpriteBuilder<S: BosStr, St: sprite_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<i64>,
Option<i64>,
Option<Datetime>,
Option<SpriteEngine<S>>,
Option<i64>,
Option<i64>,
Option<i64>,
Option<i64>,
Option<S>,
Option<i64>,
Option<BlobRef<S>>,
Option<Datetime>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Sprite<S> {
pub fn new() -> SpriteBuilder<S, sprite_state::Empty> {
SpriteBuilder::new()
}
}
impl<S: BosStr> SpriteBuilder<S, sprite_state::Empty> {
pub fn new() -> Self {
SpriteBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn animation_speed(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_animation_speed(mut self, value: Option<i64>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn columns(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_columns(mut self, value: Option<i64>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> SpriteBuilder<S, St>
where
St: sprite_state::State,
St::CreatedAt: sprite_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> SpriteBuilder<S, sprite_state::SetCreatedAt<St>> {
self._fields.2 = Option::Some(value.into());
SpriteBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SpriteBuilder<S, St>
where
St: sprite_state::State,
St::Engine: sprite_state::IsUnset,
{
pub fn engine(
mut self,
value: impl Into<SpriteEngine<S>>,
) -> SpriteBuilder<S, sprite_state::SetEngine<St>> {
self._fields.3 = Option::Some(value.into());
SpriteBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn frame_height(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_frame_height(mut self, value: Option<i64>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn frame_width(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_frame_width(mut self, value: Option<i64>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn frames(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_frames(mut self, value: Option<i64>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn height(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_height(mut self, value: Option<i64>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn rows(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_rows(mut self, value: Option<i64>) -> Self {
self._fields.9 = value;
self
}
}
impl<S: BosStr, St> SpriteBuilder<S, St>
where
St: sprite_state::State,
St::SpriteSheet: sprite_state::IsUnset,
{
pub fn sprite_sheet(
mut self,
value: impl Into<BlobRef<S>>,
) -> SpriteBuilder<S, sprite_state::SetSpriteSheet<St>> {
self._fields.10 = Option::Some(value.into());
SpriteBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.11 = value;
self
}
}
impl<S: BosStr, St: sprite_state::State> SpriteBuilder<S, St> {
pub fn width(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.12 = value.into();
self
}
pub fn maybe_width(mut self, value: Option<i64>) -> Self {
self._fields.12 = value;
self
}
}
impl<S: BosStr, St> SpriteBuilder<S, St>
where
St: sprite_state::State,
St::Engine: sprite_state::IsSet,
St::CreatedAt: sprite_state::IsSet,
St::SpriteSheet: sprite_state::IsSet,
{
pub fn build(self) -> Sprite<S> {
Sprite {
animation_speed: self._fields.0.or_else(|| Some(200i64)),
columns: self._fields.1,
created_at: self._fields.2.unwrap(),
engine: self._fields.3.unwrap(),
frame_height: self._fields.4,
frame_width: self._fields.5,
frames: self._fields.6,
height: self._fields.7,
name: self._fields.8,
rows: self._fields.9,
sprite_sheet: self._fields.10.unwrap(),
updated_at: self._fields.11,
width: self._fields.12,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Sprite<S> {
Sprite {
animation_speed: self._fields.0.or_else(|| Some(200i64)),
columns: self._fields.1,
created_at: self._fields.2.unwrap(),
engine: self._fields.3.unwrap(),
frame_height: self._fields.4,
frame_width: self._fields.5,
frames: self._fields.6,
height: self._fields.7,
name: self._fields.8,
rows: self._fields.9,
sprite_sheet: self._fields.10.unwrap(),
updated_at: self._fields.11,
width: self._fields.12,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_actor_rpg_sprite() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("actor.rpg.sprite"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A user's RPG character sprite. One record per user (rkey: self).",
),
),
key: Some(CowStr::new_static("literal:self")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("spriteSheet"),
SmolStr::new_static("engine"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("animationSpeed"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(50i64),
maximum: Some(2000i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("columns"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(16i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this record was first created"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("engine"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The game engine format this sprite is designed for. Determines animation interpretation.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("frameHeight"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(512i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("frameWidth"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(512i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("frames"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(64i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("height"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(4096i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Display name for the character (optional, can differ from Bluesky display name)",
),
),
max_length: Some(100usize),
max_graphemes: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rows"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(16i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("spriteSheet"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this record was last modified"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("width"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(4096i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}