Skip to content

Commit

Permalink
♻️ Update names to avoid clashes
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Nov 3, 2024
1 parent fb0ff09 commit a5e0651
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
4 changes: 2 additions & 2 deletions packages/trophy/src/components/achievable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod AchievableComponent {
store.create(id, hidden, index, points, group, icon, title, description, tasks, data);
}

fn update(
fn progress(
self: @ComponentState<TContractState>,
world: WorldStorage,
player_id: felt252,
Expand All @@ -69,7 +69,7 @@ mod AchievableComponent {

// [Event] Emit achievement completion
let time: u64 = get_block_timestamp();
store.update(player_id, task_id, count, time);
store.progress(player_id, task_id, count, time);
}
}
}
8 changes: 4 additions & 4 deletions packages/trophy/src/events/index.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use bushido_trophy::types::task::Task;

#[derive(Clone, Drop, Serde, Introspect)]
#[derive(Clone, Drop, Serde)]
#[dojo::event(historical: true)]
pub struct Trophy {
pub struct TrophyCreation {
#[key]
id: felt252,
hidden: bool,
Expand All @@ -20,9 +20,9 @@ pub struct Trophy {
data: ByteArray,
}

#[derive(Copy, Drop, Serde, Introspect)]
#[derive(Copy, Drop, Serde)]
#[dojo::event(historical: true)]
pub struct Progress {
pub struct TrophyProgression {
#[key]
player_id: felt252,
#[key]
Expand Down
6 changes: 3 additions & 3 deletions packages/trophy/src/events/progress.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Internal imports

use bushido_trophy::events::index::Progress;
use bushido_trophy::events::index::TrophyProgression;

// Errors

Expand All @@ -13,11 +13,11 @@ pub mod errors {
#[generate_trait]
impl ProgressImpl of ProgressTrait {
#[inline]
fn new(player_id: felt252, task_id: felt252, count: u32, time: u64,) -> Progress {
fn new(player_id: felt252, task_id: felt252, count: u32, time: u64,) -> TrophyProgression {
// [Check] Inputs
ProgressAssert::assert_valid_id(task_id);
// [Return] Progress
Progress { player_id, task_id, count, time }
TrophyProgression { player_id, task_id, count, time }
}
}

Expand Down
22 changes: 11 additions & 11 deletions packages/trophy/src/events/trophy.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Internal imports

use bushido_trophy::events::index::Trophy;
use bushido_trophy::events::index::TrophyCreation;
use bushido_trophy::types::task::{Task, TaskTrait};

// Errors

pub mod errors {
pub const TROPHY_INVALID_ID: felt252 = 'Trophy: invalid id';
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_ID: felt252 = 'TrophyCreation: invalid id';
pub const TROPHY_INVALID_TITLE: felt252 = 'TrophyCreation: invalid title';
pub const TROPHY_INVALID_DESCRIPTION: felt252 = 'TrophyCreation: invalid desc.';
pub const TROPHY_INVALID_TASKS: felt252 = 'TrophyCreation: invalid tasks.';
}

// Implementations
Expand All @@ -28,14 +28,14 @@ impl TrophyImpl of TrophyTrait {
description: ByteArray,
tasks: Span<Task>,
data: ByteArray,
) -> Trophy {
) -> TrophyCreation {
// [Check] Inputs
// [Info] We don't check points here, leave free the game to decide
TrophyAssert::assert_valid_id(id);
TrophyAssert::assert_valid_title(title);
TrophyAssert::assert_valid_description(@description);
// [Return] Trophy
Trophy { id, hidden, index, points, group, icon, title, description, tasks, data }
// [Return] TrophyCreation
TrophyCreation { id, hidden, index, points, group, icon, title, description, tasks, data }
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('Trophy: invalid id',))]
#[should_panic(expected: ('TrophyCreation: invalid id',))]
fn test_achievement_creation_new_invalid_id() {
let tasks: Array<Task> = array![TaskTrait::new(TASK_ID, TOTAL, "TASK DESCRIPTION"),];
TrophyTrait::new(
Expand All @@ -109,7 +109,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('Trophy: invalid title',))]
#[should_panic(expected: ('TrophyCreation: invalid title',))]
fn test_achievement_creation_new_invalid_title() {
let tasks: Array<Task> = array![TaskTrait::new(TASK_ID, TOTAL, "TASK DESCRIPTION"),];
TrophyTrait::new(
Expand All @@ -118,7 +118,7 @@ mod tests {
}

#[test]
#[should_panic(expected: ('Trophy: invalid desc.',))]
#[should_panic(expected: ('TrophyCreation: invalid desc.',))]
fn test_achievement_creation_new_invalid_description() {
let tasks: Array<Task> = array![TaskTrait::new(TASK_ID, TOTAL, "TASK DESCRIPTION"),];
TrophyTrait::new(ID, HIDDEN, INDEX, POINTS, GROUP, ICON, TITLE, "", tasks.span(), "");
Expand Down
10 changes: 5 additions & 5 deletions packages/trophy/src/store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use dojo::event::EventStorage;

// Events imports

use bushido_trophy::events::trophy::{Trophy, TrophyTrait};
use bushido_trophy::events::progress::{Progress, ProgressTrait};
use bushido_trophy::events::trophy::{TrophyCreation, TrophyTrait};
use bushido_trophy::events::progress::{TrophyProgression, ProgressTrait};

// Internal imports

Expand Down Expand Up @@ -48,15 +48,15 @@ impl StoreImpl of StoreTrait {
tasks: Span<Task>,
data: ByteArray,
) {
let event: Trophy = TrophyTrait::new(
let event: TrophyCreation = TrophyTrait::new(
id, hidden, index, points, group, icon, title, description, tasks, data
);
self.world.emit_event(@event);
}

#[inline]
fn update(mut self: Store, player_id: felt252, task_id: felt252, count: u32, time: u64,) {
let event: Progress = ProgressTrait::new(player_id, task_id, count, time);
fn progress(mut self: Store, player_id: felt252, task_id: felt252, count: u32, time: u64,) {
let event: TrophyProgression = ProgressTrait::new(player_id, task_id, count, time);
self.world.emit_event(@event);
}
}
6 changes: 3 additions & 3 deletions packages/trophy/src/tests/mocks/achiever.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait IAchiever<TContractState> {
tasks: Span<Task>,
data: ByteArray,
);
fn update(self: @TContractState, player_id: felt252, task_id: felt252, count: u32,);
fn progress(self: @TContractState, player_id: felt252, task_id: felt252, count: u32,);
}

#[dojo::contract]
Expand Down Expand Up @@ -90,8 +90,8 @@ pub mod Achiever {
);
}

fn update(self: @ContractState, player_id: felt252, task_id: felt252, count: u32,) {
self.achievable.update(self.world_storage(), player_id, task_id, count);
fn progress(self: @ContractState, player_id: felt252, task_id: felt252, count: u32,) {
self.achievable.progress(self.world_storage(), player_id, task_id, count);
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/trophy/src/tests/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ mod setup {
fn setup_namespace() -> NamespaceDef {
NamespaceDef {
namespace: "namespace", resources: [
TestResource::Event(events::e_Trophy::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Event(events::e_Progress::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Event(events::e_TrophyCreation::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Event(
events::e_TrophyProgression::TEST_CLASS_HASH.try_into().unwrap()
),
TestResource::Contract(
ContractDefTrait::new(Achiever::TEST_CLASS_HASH, "Achiever")
.with_writer_of([dojo::utils::bytearray_hash(@"namespace")].span())
Expand Down
8 changes: 4 additions & 4 deletions packages/trophy/src/tests/test_achievable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use dojo::world::world::Event;
// Internal imports

use bushido_trophy::types::task::{Task, TaskTrait};
use bushido_trophy::events::trophy::{Trophy, TrophyTrait};
use bushido_trophy::events::progress::{Progress, ProgressTrait};
use bushido_trophy::events::trophy::{TrophyCreation, TrophyTrait};
use bushido_trophy::events::progress::{TrophyProgression, ProgressTrait};
use bushido_trophy::tests::mocks::achiever::{
Achiever, IAchieverDispatcher, IAchieverDispatcherTrait
};
Expand Down Expand Up @@ -70,10 +70,10 @@ fn test_achievable_create() {
}
}
#[test]
fn test_achievable_update() {
fn test_achievable_progress() {
let (world, systems, context) = spawn_game();
clear_events(world.dispatcher.contract_address);
systems.achiever.update(context.player_id, TASK_ID, COUNT);
systems.achiever.progress(context.player_id, TASK_ID, COUNT);
let contract_event = starknet::testing::pop_log::<Event>(world.dispatcher.contract_address)
.unwrap();
match contract_event {
Expand Down

0 comments on commit a5e0651

Please sign in to comment.