diff --git a/packages/achievement/src/components/achievable.cairo b/packages/achievement/src/components/achievable.cairo index 4a3b397..3953831 100644 --- a/packages/achievement/src/components/achievable.cairo +++ b/packages/achievement/src/components/achievable.cairo @@ -41,7 +41,7 @@ mod AchievableComponent { world: IWorldDispatcher, id: felt252, hidden: bool, - page_count: u8, + index: u8, points: u16, group: felt252, icon: felt252, @@ -54,10 +54,7 @@ mod AchievableComponent { let store: Store = StoreTrait::new(world); // [Event] Emit achievement creation - store - .create( - id, hidden, page_count, points, group, icon, title, description, tasks, data - ); + store.create(id, hidden, index, points, group, icon, title, description, tasks, data); } fn update( diff --git a/packages/achievement/src/events/index.cairo b/packages/achievement/src/events/index.cairo index dcedfbb..5af296a 100644 --- a/packages/achievement/src/events/index.cairo +++ b/packages/achievement/src/events/index.cairo @@ -5,7 +5,7 @@ pub struct Trophy { #[key] id: felt252, hidden: bool, - page_count: u8, + index: u8, points: u16, group: felt252, icon: felt252, @@ -21,7 +21,6 @@ pub struct Trophy { pub struct Task { #[key] id: felt252, - page: u8, total: u32, description: ByteArray, } diff --git a/packages/achievement/src/events/task.cairo b/packages/achievement/src/events/task.cairo index 8275acd..65811c0 100644 --- a/packages/achievement/src/events/task.cairo +++ b/packages/achievement/src/events/task.cairo @@ -8,7 +8,6 @@ pub mod errors { pub const TROPHY_INVALID_ID: felt252 = 'Task: invalid id'; pub const TROPHY_INVALID_DESCRIPTION: felt252 = 'Task: invalid description'; pub const TROPHY_INVALID_TOTAL: felt252 = 'Task: invalid total'; - pub const TROPHY_INVALID_PAGE: felt252 = 'Task: invalid page'; } // Implementations @@ -16,14 +15,13 @@ pub mod errors { #[generate_trait] impl TaskImpl of TaskTrait { #[inline] - fn new(id: felt252, page: u8, total: u32, description: ByteArray,) -> Task { + fn new(id: felt252, total: u32, description: ByteArray,) -> Task { // [Check] Inputs TaskAssert::assert_valid_id(id); - TaskAssert::assert_valid_page(page); TaskAssert::assert_valid_total(total); TaskAssert::assert_valid_description(@description); // [Return] Task - Task { id, page, total, description } + Task { id, total, description } } } @@ -34,11 +32,6 @@ impl TaskAssert of AssertTrait { assert(id != 0, errors::TROPHY_INVALID_ID); } - #[inline] - fn assert_valid_page(page: u8) { - assert(page > 0, errors::TROPHY_INVALID_PAGE); - } - #[inline] fn assert_valid_total(total: u32) { assert(total > 0, errors::TROPHY_INVALID_TOTAL); @@ -59,14 +52,12 @@ mod tests { // Constants const ID: felt252 = 'TROPHY'; - const PAGE: u8 = 1; const TOTAL: u32 = 100; #[test] fn test_achievement_creation_new() { - let achievement = TaskTrait::new(ID, PAGE, TOTAL, "DESCRIPTION"); + let achievement = TaskTrait::new(ID, TOTAL, "DESCRIPTION"); assert_eq!(achievement.id, ID); - assert_eq!(achievement.page, PAGE); assert_eq!(achievement.total, TOTAL); assert_eq!(achievement.description, "DESCRIPTION"); } @@ -74,25 +65,20 @@ mod tests { #[test] #[should_panic(expected: ('Task: invalid id',))] fn test_achievement_creation_new_invalid_id() { - TaskTrait::new(0, PAGE, TOTAL, "DESCRIPTION"); + TaskTrait::new(0, TOTAL, "DESCRIPTION"); } - #[test] - #[should_panic(expected: ('Task: invalid page',))] - fn test_achievement_creation_new_invalid_page() { - TaskTrait::new(ID, 0, TOTAL, "DESCRIPTION"); - } #[test] #[should_panic(expected: ('Task: invalid total',))] fn test_achievement_creation_new_invalid_total() { - TaskTrait::new(ID, PAGE, 0, "DESCRIPTION"); + TaskTrait::new(ID, 0, "DESCRIPTION"); } #[test] #[should_panic(expected: ('Task: invalid description',))] fn test_achievement_creation_new_invalid_description() { - TaskTrait::new(ID, PAGE, TOTAL, ""); + TaskTrait::new(ID, TOTAL, ""); } } diff --git a/packages/achievement/src/events/trophy.cairo b/packages/achievement/src/events/trophy.cairo index c4bb113..05a2835 100644 --- a/packages/achievement/src/events/trophy.cairo +++ b/packages/achievement/src/events/trophy.cairo @@ -11,7 +11,6 @@ pub mod errors { pub const TROPHY_INVALID_TITLE: felt252 = 'Trophy: invalid title'; pub const TROPHY_INVALID_DESCRIPTION: felt252 = 'Trophy: invalid desc.'; pub const TROPHY_INVALID_TASKS: felt252 = 'Trophy: invalid tasks.'; - pub const TROPHY_INVALID_PAGE_COUNT: felt252 = 'Trophy: invalid page count'; } // Implementations @@ -22,7 +21,7 @@ impl TrophyImpl of TrophyTrait { fn new( id: felt252, hidden: bool, - page_count: u8, + index: u8, points: u16, group: felt252, icon: felt252, @@ -34,11 +33,10 @@ impl TrophyImpl of TrophyTrait { // [Check] Inputs // [Info] We don't check points here, leave free the game to decide TrophyAssert::assert_valid_id(id); - TrophyAssert::assert_valid_page_count(page_count); TrophyAssert::assert_valid_title(title); TrophyAssert::assert_valid_description(@description); // [Return] Trophy - Trophy { id, hidden, page_count, points, group, icon, title, description, tasks, data } + Trophy { id, hidden, index, points, group, icon, title, description, tasks, data } } } @@ -49,11 +47,6 @@ impl TrophyAssert of AssertTrait { assert(id != 0, errors::TROPHY_INVALID_ID); } - #[inline] - fn assert_valid_page_count(page_count: u8) { - assert(page_count > 0, errors::TROPHY_INVALID_PAGE_COUNT); - } - #[inline] fn assert_valid_title(title: felt252) { assert(title != 0, errors::TROPHY_INVALID_TITLE); @@ -80,8 +73,7 @@ mod tests { // Constants const ID: felt252 = 'TROPHY'; - const PAGE_COUNT: u8 = 1; - const PAGE: u8 = 1; + const INDEX: u8 = 0; const GROUP: felt252 = 'GROUP'; const HIDDEN: bool = false; const POINTS: u16 = 100; @@ -92,13 +84,13 @@ mod tests { #[test] fn test_achievement_creation_new() { - let tasks: Array = array![TaskTrait::new(TASK_ID, PAGE, TOTAL, "TASK DESCRIPTION"),]; + let tasks: Array = array![TaskTrait::new(TASK_ID, TOTAL, "TASK DESCRIPTION"),]; let achievement = TrophyTrait::new( - ID, HIDDEN, PAGE_COUNT, POINTS, GROUP, ICON, TITLE, "DESCRIPTION", tasks.span(), "DATA" + ID, HIDDEN, INDEX, POINTS, GROUP, ICON, TITLE, "DESCRIPTION", tasks.span(), "DATA" ); assert_eq!(achievement.id, ID); assert_eq!(achievement.hidden, HIDDEN); - assert_eq!(achievement.page_count, PAGE_COUNT); + assert_eq!(achievement.index, INDEX); assert_eq!(achievement.points, POINTS); assert_eq!(achievement.group, GROUP); assert_eq!(achievement.icon, ICON); @@ -111,35 +103,26 @@ mod tests { #[test] #[should_panic(expected: ('Trophy: invalid id',))] fn test_achievement_creation_new_invalid_id() { - let tasks: Array = array![TaskTrait::new(TASK_ID, PAGE, TOTAL, "TASK DESCRIPTION"),]; - TrophyTrait::new( - 0, HIDDEN, PAGE_COUNT, POINTS, GROUP, ICON, TITLE, "DESCRIPTION", tasks.span(), "" - ); - } - - #[test] - #[should_panic(expected: ('Trophy: invalid page count',))] - fn test_achievement_creation_new_invalid_page_count() { - let tasks: Array = array![TaskTrait::new(TASK_ID, PAGE, TOTAL, "TASK DESCRIPTION"),]; + let tasks: Array = array![TaskTrait::new(TASK_ID, TOTAL, "TASK DESCRIPTION"),]; TrophyTrait::new( - ID, HIDDEN, 0, POINTS, GROUP, ICON, TITLE, "DESCRIPTION", tasks.span(), "" + 0, HIDDEN, INDEX, POINTS, GROUP, ICON, TITLE, "DESCRIPTION", tasks.span(), "" ); } #[test] #[should_panic(expected: ('Trophy: invalid title',))] fn test_achievement_creation_new_invalid_title() { - let tasks: Array = array![TaskTrait::new(TASK_ID, PAGE, TOTAL, "TASK DESCRIPTION"),]; + let tasks: Array = array![TaskTrait::new(TASK_ID, TOTAL, "TASK DESCRIPTION"),]; TrophyTrait::new( - ID, HIDDEN, PAGE_COUNT, POINTS, GROUP, ICON, 0, "DESCRIPTION", tasks.span(), "" + ID, HIDDEN, INDEX, POINTS, GROUP, ICON, 0, "DESCRIPTION", tasks.span(), "" ); } #[test] #[should_panic(expected: ('Trophy: invalid desc.',))] fn test_achievement_creation_new_invalid_description() { - let tasks: Array = array![TaskTrait::new(TASK_ID, PAGE, TOTAL, "TASK DESCRIPTION"),]; - TrophyTrait::new(ID, HIDDEN, PAGE_COUNT, POINTS, GROUP, ICON, TITLE, "", tasks.span(), ""); + let tasks: Array = array![TaskTrait::new(TASK_ID, TOTAL, "TASK DESCRIPTION"),]; + TrophyTrait::new(ID, HIDDEN, INDEX, POINTS, GROUP, ICON, TITLE, "", tasks.span(), ""); } } diff --git a/packages/achievement/src/store.cairo b/packages/achievement/src/store.cairo index e5a9b88..d101d8c 100644 --- a/packages/achievement/src/store.cairo +++ b/packages/achievement/src/store.cairo @@ -62,7 +62,7 @@ impl StoreImpl of StoreTrait { self: Store, id: felt252, hidden: bool, - page_count: u8, + index: u8, points: u16, group: felt252, icon: felt252, @@ -72,7 +72,7 @@ impl StoreImpl of StoreTrait { data: ByteArray, ) { let _event: Trophy = TrophyTrait::new( - id, hidden, page_count, points, group, icon, title, description, tasks, data + id, hidden, index, points, group, icon, title, description, tasks, data ); emit!(self.world, (_event,)); } diff --git a/packages/achievement/src/tests/mocks/achiever.cairo b/packages/achievement/src/tests/mocks/achiever.cairo index 05c2436..432c61e 100644 --- a/packages/achievement/src/tests/mocks/achiever.cairo +++ b/packages/achievement/src/tests/mocks/achiever.cairo @@ -8,7 +8,7 @@ trait IAchiever { self: @TContractState, id: felt252, hidden: bool, - page_count: u8, + index: u8, points: u16, group: felt252, icon: felt252, @@ -63,7 +63,7 @@ pub mod Achiever { self: @ContractState, id: felt252, hidden: bool, - page_count: u8, + index: u8, points: u16, group: felt252, icon: felt252, @@ -78,7 +78,7 @@ pub mod Achiever { self.world(), id, hidden, - page_count, + index, points, group, icon, diff --git a/packages/achievement/src/tests/test_achievable.cairo b/packages/achievement/src/tests/test_achievable.cairo index d26e200..0114678 100644 --- a/packages/achievement/src/tests/test_achievable.cairo +++ b/packages/achievement/src/tests/test_achievable.cairo @@ -21,8 +21,7 @@ use achievement::tests::setup::setup::{spawn_game, clear_events, Systems, PLAYER const TROPHY_ID: felt252 = 'TROPHY'; const TASK_ID: felt252 = 'TASK'; const HIDDEN: bool = false; -const PAGE_COUNT: u8 = 1; -const PAGE: u8 = 1; +const INDEX: u8 = 0; const POINTS: u16 = 10; const TOTAL: u32 = 100; const COUNT: u32 = 1; @@ -35,15 +34,14 @@ const TITLE: felt252 = 'Title'; fn test_achievable_create() { let (world, systems, _context) = spawn_game(); clear_events(world.contract_address); - let tasks = array![TaskTrait::new(TASK_ID, PAGE, TOTAL, "Description")].span(); + let tasks = array![TaskTrait::new(TASK_ID, TOTAL, "Description")].span(); systems .achiever - .create( - TROPHY_ID, HIDDEN, PAGE_COUNT, POINTS, GROUP, ICON, TITLE, "Description", tasks, "" - ); + .create(TROPHY_ID, HIDDEN, INDEX, POINTS, GROUP, ICON, TITLE, "Description", tasks, ""); let event = starknet::testing::pop_log::(world.contract_address).unwrap(); // FIXME: Cannot check keys because they are shifted due to dojo macros assert_eq!(event.hidden, HIDDEN); + assert_eq!(event.index, INDEX); assert_eq!(event.points, POINTS); assert_eq!(event.group, GROUP); assert_eq!(event.title, TITLE);