use serde::{Deserialize, Serialize}; #[cfg(feature = "spacetime-types")] use spacetimedb::SpacetimeType; pub const SQUARE_HOLE_SESSION_ID_PREFIX: &str = "square-hole-session-"; pub const SQUARE_HOLE_MESSAGE_ID_PREFIX: &str = "square-hole-message-"; pub const SQUARE_HOLE_PROFILE_ID_PREFIX: &str = "square-hole-profile-"; pub const SQUARE_HOLE_WORK_ID_PREFIX: &str = "square-hole-work-"; pub const SQUARE_HOLE_RUN_ID_PREFIX: &str = "square-hole-run-"; pub const SQUARE_HOLE_MIN_SHAPE_COUNT: u32 = 6; pub const SQUARE_HOLE_MAX_SHAPE_COUNT: u32 = 24; pub const SQUARE_HOLE_MIN_DIFFICULTY: u32 = 1; pub const SQUARE_HOLE_MAX_DIFFICULTY: u32 = 10; pub const SQUARE_HOLE_DEFAULT_DURATION_LIMIT_MS: u64 = 60_000; pub const SQUARE_HOLE_MIN_SHAPE_OPTION_COUNT: usize = 6; pub const SQUARE_HOLE_MIN_HOLE_OPTION_COUNT: usize = 3; pub const SQUARE_HOLE_MAX_HOLE_OPTION_COUNT: usize = 6; #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum SquareHoleCreationStage { CollectingConfig, DraftReady, ReadyToPublish, Published, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum SquareHolePublicationStatus { Draft, Published, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum SquareHoleRunStatus { Running, Won, Failed, Stopped, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum SquareHoleDropRejectReason { RunNotActive, SnapshotVersionMismatch, HoleNotFound, Incompatible, TimeUp, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleCreatorConfig { pub theme_text: String, pub twist_rule: String, pub shape_count: u32, pub difficulty: u32, #[serde(default)] pub shape_options: Vec, #[serde(default)] pub hole_options: Vec, #[serde(default)] pub background_prompt: String, #[serde(default)] pub cover_image_src: Option, #[serde(default)] pub background_image_src: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleShapeOption { pub option_id: String, pub shape_kind: String, pub label: String, #[serde(default)] pub target_hole_id: String, pub image_prompt: String, #[serde(default)] pub image_src: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleHoleOption { pub hole_id: String, pub hole_kind: String, pub label: String, #[serde(default)] pub image_prompt: String, #[serde(default)] pub image_src: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleResultDraft { pub profile_id: String, pub game_name: String, pub theme_text: String, pub twist_rule: String, pub summary: String, pub tags: Vec, #[serde(default)] pub cover_image_src: Option, #[serde(default)] pub background_prompt: String, #[serde(default)] pub background_image_src: Option, #[serde(default)] pub shape_options: Vec, #[serde(default)] pub hole_options: Vec, pub shape_count: u32, pub difficulty: u32, pub publish_ready: bool, pub blockers: Vec, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleWorkProfile { pub work_id: String, pub profile_id: String, pub owner_user_id: String, pub source_session_id: Option, pub game_name: String, pub theme_text: String, pub twist_rule: String, pub summary: String, pub tags: Vec, pub cover_image_src: Option, pub background_prompt: String, pub background_image_src: Option, pub shape_options: Vec, pub hole_options: Vec, pub shape_count: u32, pub difficulty: u32, pub publication_status: SquareHolePublicationStatus, pub play_count: u32, pub updated_at_micros: i64, pub published_at_micros: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleShapeSnapshot { pub shape_id: String, pub shape_kind: String, pub label: String, #[serde(default)] pub target_hole_id: String, pub color: String, #[serde(default)] pub image_src: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct SquareHoleHoleSnapshot { pub hole_id: String, pub hole_kind: String, pub label: String, pub x: f32, pub y: f32, #[serde(default)] pub image_src: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleDropFeedback { pub accepted: bool, pub reject_reason: Option, pub message: String, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct SquareHoleRunSnapshot { pub run_id: String, pub profile_id: String, pub owner_user_id: String, pub status: SquareHoleRunStatus, pub snapshot_version: u64, pub started_at_ms: u64, pub duration_limit_ms: u64, pub remaining_ms: u64, pub total_shape_count: u32, pub completed_shape_count: u32, pub combo: u32, pub best_combo: u32, pub score: u32, pub rule_label: String, #[serde(default)] pub background_image_src: Option, #[serde(default)] pub shape_options: Vec, pub current_shape: Option, pub holes: Vec, pub last_feedback: Option, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct SquareHoleDropInput { pub run_id: String, pub owner_user_id: String, pub hole_id: String, pub client_snapshot_version: u64, pub client_event_id: String, pub dropped_at_ms: u64, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct SquareHoleDropConfirmation { pub feedback: SquareHoleDropFeedback, pub run: SquareHoleRunSnapshot, } impl SquareHoleCreationStage { pub fn as_str(self) -> &'static str { match self { Self::CollectingConfig => "collecting_config", Self::DraftReady => "draft_ready", Self::ReadyToPublish => "ready_to_publish", Self::Published => "published", } } } impl SquareHolePublicationStatus { pub fn as_str(self) -> &'static str { match self { Self::Draft => "draft", Self::Published => "published", } } } impl SquareHoleRunStatus { pub fn as_str(self) -> &'static str { match self { Self::Running => "running", Self::Won => "won", Self::Failed => "failed", Self::Stopped => "stopped", } } } impl SquareHoleDropRejectReason { pub fn as_str(self) -> &'static str { match self { Self::RunNotActive => "run_not_active", Self::SnapshotVersionMismatch => "snapshot_version_mismatch", Self::HoleNotFound => "hole_not_found", Self::Incompatible => "incompatible", Self::TimeUp => "time_up", } } }