Skip to content

Commit

Permalink
feat: achievements models and logic (#41)
Browse files Browse the repository at this point in the history
* feat: add enums, test and first models for achievements workflow

* feat: add enums, models, functions and tests for achievements
  • Loading branch information
coxmars authored Sep 15, 2024
1 parent acc9b14 commit 0a56d5d
Show file tree
Hide file tree
Showing 8 changed files with 1,510 additions and 0 deletions.
517 changes: 517 additions & 0 deletions manifests/dev/base/abis/models/bytebeasts-Achievement-58a03b97.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions manifests/dev/base/models/bytebeasts-Achievement-58a03b97.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
kind = "DojoModel"
class_hash = "0x41f50347f6f957bc556346a2cdea3f31523f3c25966826e7ca7dea1de185c40"
original_class_hash = "0x41f50347f6f957bc556346a2cdea3f31523f3c25966826e7ca7dea1de185c40"
abi = "manifests/dev/base/abis/models/bytebeasts-Achievement-58a03b97.json"
tag = "bytebeasts-Achievement"
manifest_name = "bytebeasts-Achievement-58a03b97"

[[members]]
name = "achievement_id"
type = "u64"
key = true

[[members]]
name = "achievement_type"
type = "AchievementType"
key = false

[[members]]
name = "rarity"
type = "AchievementRarity"
key = false

[[members]]
name = "name"
type = "felt252"
key = false

[[members]]
name = "description"
type = "ByteArray"
key = false

[[members]]
name = "is_hidden"
type = "bool"
key = false

[[members]]
name = "is_unlocked"
type = "bool"
key = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
kind = "DojoModel"
class_hash = "0x494e5a6534846cd68b493aab6f9954333c64c854dbe99144c427f4301477f15"
original_class_hash = "0x494e5a6534846cd68b493aab6f9954333c64c854dbe99144c427f4301477f15"
abi = "manifests/dev/base/abis/models/bytebeasts-AchievementProgress-221f2719.json"
tag = "bytebeasts-AchievementProgress"
manifest_name = "bytebeasts-AchievementProgress-221f2719"

[[members]]
name = "player_id"
type = "u64"
key = true

[[members]]
name = "achievement_id"
type = "u64"
key = false

[[members]]
name = "progress"
type = "u32"
key = false

[[members]]
name = "is_unlocked"
type = "bool"
key = false
3 changes: 3 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ mod models {
mod potion;
mod role;
mod world_elements;
mod achievement_rarity;
mod achievement_type;
mod achievements;
}

mod tests {
Expand Down
42 changes: 42 additions & 0 deletions src/models/achievement_rarity.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#[derive(Serde, Copy, Drop, Introspect, PartialEq)]
pub enum AchievementRarity {
Common,
Uncommon,
Rare,
Epic,
Legendary,
}

impl AchievementRarityIntoFelt252 of Into<AchievementRarity, felt252> {
fn into(self: AchievementRarity) -> felt252 {
match self {
AchievementRarity::Common => 0,
AchievementRarity::Uncommon => 1,
AchievementRarity::Rare => 2,
AchievementRarity::Epic => 3,
AchievementRarity::Legendary => 4,
}
}
}


#[cfg(test)]
mod tests {
use super::{AchievementRarity, AchievementRarityIntoFelt252};

#[test]
fn test_achievement_rarity_into_felt252() {

let common = AchievementRarity::Common;
let uncommon = AchievementRarity::Uncommon;
let rare = AchievementRarity::Rare;
let epic = AchievementRarity::Epic;
let legendary = AchievementRarity::Legendary;

assert_eq!(common.into(), 0, "AchievementRarity::Common deberia convertirse a 0");
assert_eq!(uncommon.into(), 1, "AchievementRarity::Uncommon deberia convertirse a 1");
assert_eq!(rare.into(), 2, "AchievementRarity::Rare deberia convertirse a 2");
assert_eq!(epic.into(), 3, "AchievementRarity::Epic deberia convertirse a 3");
assert_eq!(legendary.into(), 4, "AchievementRarity::Legendary deberia convertirse a 4");
}
}
65 changes: 65 additions & 0 deletions src/models/achievement_type.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#[derive(Serde, Copy, Drop, Introspect, PartialEq)]
pub enum AchievementType {
FirstWin,
TenWins,
HundredWins,
FirstBeast,
TenBeasts,
RareBeast,
FirstNPCInteraction,
RandomBattleChampion,
BeastMaster,
LegendaryPlayer,
TopScorer,
}

impl AchievementTypeIntoFelt252 of Into<AchievementType, felt252> {
fn into(self: AchievementType) -> felt252 {
match self {
AchievementType::FirstWin => 0,
AchievementType::TenWins => 1,
AchievementType::HundredWins => 2,
AchievementType::FirstBeast => 3,
AchievementType::TenBeasts => 4,
AchievementType::RareBeast => 5,
AchievementType::FirstNPCInteraction => 6,
AchievementType::RandomBattleChampion => 7,
AchievementType::BeastMaster => 8,
AchievementType::LegendaryPlayer => 9,
AchievementType::TopScorer => 10,
}
}
}

#[cfg(test)]
mod tests {
use super::{AchievementType, AchievementTypeIntoFelt252};

#[test]
fn test_achievement_type_into_felt252() {

let first_win = AchievementType::FirstWin;
let ten_wins = AchievementType::TenWins;
let hundred_wins = AchievementType::HundredWins;
let first_beast = AchievementType::FirstBeast;
let ten_beast = AchievementType::TenBeasts;
let rare_beast = AchievementType::RareBeast;
let first_npc_interaction = AchievementType::FirstNPCInteraction;
let random_battle = AchievementType::RandomBattleChampion;
let beast_master = AchievementType::BeastMaster;
let legendary_player = AchievementType::LegendaryPlayer;
let top_scorer = AchievementType::TopScorer;

assert_eq!(first_win.into(), 0, "AchievementType::FirstWin deberia convertirse a 0");
assert_eq!(ten_wins.into(), 1, "AchievementType::TenWins deberia convertirse a 1");
assert_eq!(hundred_wins.into(), 2, "AchievementType::HundredWins deberia convertirse a 2");
assert_eq!(first_beast.into(), 3, "AchievementType::FirstBeast deberia convertirse a 3");
assert_eq!(ten_beast.into(), 4, "AchievementType::TenBeasts deberia convertirse a 4");
assert_eq!(rare_beast.into(), 5, "AchievementType::RareBeast deberia convertirse a 5");
assert_eq!(first_npc_interaction.into(), 6, "AchievementType::FirstNPCInteraction deberia convertirse a 6");
assert_eq!(random_battle.into(), 7, "AchievementType::RandomBattleChampion deberia convertirse a 7");
assert_eq!(beast_master.into(), 8, "AchievementType::BeastMaster deberia convertirse a 8");
assert_eq!(legendary_player.into(), 9, "AchievementType::LegendaryPlayer deberia convertirse a 9");
assert_eq!(top_scorer.into(), 10, "AchievementType::TopScorer deberia convertirse a 10");
}
}
Loading

0 comments on commit 0a56d5d

Please sign in to comment.