use serde::{Deserialize, Serialize}; #[cfg(feature = "spacetime-types")] use spacetimedb::SpacetimeType; pub const JUMP_HOP_SESSION_ID_PREFIX: &str = "jump-hop-session-"; pub const JUMP_HOP_PROFILE_ID_PREFIX: &str = "jump-hop-profile-"; pub const JUMP_HOP_WORK_ID_PREFIX: &str = "jump-hop-work-"; pub const JUMP_HOP_RUN_ID_PREFIX: &str = "jump-hop-run-"; #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum JumpHopDifficulty { Easy, Standard, Advanced, Challenge, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum JumpHopTileType { Start, Normal, Target, Finish, Bonus, Accent, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum JumpHopRunStatus { Playing, Failed, Cleared, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum JumpHopJumpResultKind { Miss, Hit, Perfect, Finish, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct JumpHopScoring { pub charge_to_distance_ratio: f32, pub max_charge_ms: u32, pub hit_bonus: u32, pub perfect_bonus: u32, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct JumpHopPlatform { pub platform_id: String, pub tile_type: JumpHopTileType, pub x: f32, pub y: f32, pub width: f32, pub height: f32, pub landing_radius: f32, pub perfect_radius: f32, pub score_value: u32, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct JumpHopPath { pub seed: String, pub difficulty: JumpHopDifficulty, pub platforms: Vec, pub finish_index: u32, pub camera_preset: String, pub scoring: JumpHopScoring, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct JumpHopLastJump { pub charge_ms: u32, pub jump_distance: f32, pub target_platform_index: u32, pub landed_x: f32, pub landed_y: f32, pub result: JumpHopJumpResultKind, } #[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct JumpHopRunSnapshot { pub run_id: String, pub profile_id: String, pub owner_user_id: String, pub status: JumpHopRunStatus, pub current_platform_index: u32, pub score: u32, pub combo: u32, pub last_jump: Option, pub started_at_ms: u64, pub finished_at_ms: Option, pub path: JumpHopPath, } impl JumpHopDifficulty { pub fn as_str(self) -> &'static str { match self { Self::Easy => "easy", Self::Standard => "standard", Self::Advanced => "advanced", Self::Challenge => "challenge", } } } impl JumpHopTileType { pub fn as_str(self) -> &'static str { match self { Self::Start => "start", Self::Normal => "normal", Self::Target => "target", Self::Finish => "finish", Self::Bonus => "bonus", Self::Accent => "accent", } } } impl JumpHopRunStatus { pub fn as_str(self) -> &'static str { match self { Self::Playing => "playing", Self::Failed => "failed", Self::Cleared => "cleared", } } } impl JumpHopJumpResultKind { pub fn as_str(self) -> &'static str { match self { Self::Miss => "miss", Self::Hit => "hit", Self::Perfect => "perfect", Self::Finish => "finish", } } }