add: user achievements

This commit is contained in:
trisua 2025-06-27 03:45:50 -04:00
parent e7c4cf14aa
commit b860f74124
15 changed files with 318 additions and 11 deletions

View file

@ -58,6 +58,9 @@ pub struct User {
/// Secondary permissions because the regular permissions struct ran out of possible bits.
#[serde(default)]
pub secondary_permissions: SecondaryPermission,
/// Users collect achievements through little actions across the site.
#[serde(default)]
pub achievements: Vec<Achievement>,
}
pub type UserConnections =
@ -297,6 +300,7 @@ impl User {
associated: Vec::new(),
invite_code: 0,
secondary_permissions: SecondaryPermission::DEFAULT,
achievements: Vec::new(),
}
}
@ -470,6 +474,92 @@ pub struct ExternalConnectionData {
pub data: HashMap<String, String>,
}
/// The total number of achievements needed to 100% Tetratto!
pub const ACHIEVEMENTS: usize = 8;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum AchievementName {
/// Create your first post.
CreatePost,
/// Follow somebody.
FollowUser,
/// Create your 50th post.
Create50Posts,
/// Create your 100th post.
Create100Posts,
/// Create your 1000th post.
Create1000Posts,
/// Ask your first question.
CreateQuestion,
/// Edit your settings.
EditSettings,
/// Create your first journal.
CreateJournal,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum AchievementRarity {
Common,
Uncommon,
Rare,
}
impl AchievementName {
pub fn title(&self) -> &str {
match self {
Self::CreatePost => "Dear friends,",
Self::FollowUser => "Virtual connections...",
Self::Create50Posts => "Hello, world!",
Self::Create100Posts => "It's my world",
Self::Create1000Posts => "Timeline domination",
Self::CreateQuestion => "Big questions...",
Self::EditSettings => "Just how I like it!",
Self::CreateJournal => "Dear diary...",
}
}
pub fn description(&self) -> &str {
match self {
Self::CreatePost => "Create your first post!",
Self::FollowUser => "Follow somebody!",
Self::Create50Posts => "Create your 50th post.",
Self::Create100Posts => "Create your 100th post.",
Self::Create1000Posts => "Create your 1000th post.",
Self::CreateQuestion => "Ask your first question!",
Self::EditSettings => "Edit your settings.",
Self::CreateJournal => "Create your first journal.",
}
}
pub fn rarity(&self) -> AchievementRarity {
match self {
Self::CreatePost => AchievementRarity::Common,
Self::FollowUser => AchievementRarity::Common,
Self::Create50Posts => AchievementRarity::Uncommon,
Self::Create100Posts => AchievementRarity::Uncommon,
Self::Create1000Posts => AchievementRarity::Rare,
Self::CreateQuestion => AchievementRarity::Common,
Self::EditSettings => AchievementRarity::Common,
Self::CreateJournal => AchievementRarity::Uncommon,
}
}
}
impl Into<Achievement> for AchievementName {
fn into(self) -> Achievement {
Achievement {
name: self,
unlocked: unix_epoch_timestamp(),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Achievement {
pub name: AchievementName,
pub unlocked: usize,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Notification {
pub id: usize,