Creation
Getting Started
Emit events to define your achievements.
The package provides a way to define achievements leveraging Starknet components.
#[dojo::contract]
pub mod Actions {
use arcade_trophy::components::achievable::AchievableComponent;
use arcade_trophy::types::task::{Task, TaskTrait};
component!(path: AchievableComponent, storage: achievable, event: AchievableEvent);
impl AchievableInternalImpl = AchievableComponent::InternalImpl<ContractState>;
#[storage]
struct Storage {
#[substorage(v0)]
achievable: AchievableComponent::Storage,
}
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
AchievableEvent: AchievableComponent::Event,
}
// Constructor
fn dojo_init(self: @ContractState) {
// [Event] Emit all Achievement creation events
let world = self.world("<YOUR-NAMESPACE>");
let task_id = 'TASK_IDENTIFIER';
let task_target = 100;
let task = TaskTrait::new(task_id, task_target, "Do something 100 times");
let tasks: Span<Task> = array![task].span();
self.achievable
.create(
world,
id: 'ACHIEVEMENT_IDENTIFIER',
hidden: false,
index: 0,
points: 10,
start: 0,
end: 0,
group: 'Group',
title: "Achievement title",
description: "The achievement description",
tasks: tasks,
data: "",
icon: 'fa-trophy',
);
}
}
}
API References
AchievableComponent.create
AchievableComponent.create(
self: @ComponentState<TContractState>,
world: WorldStorage,
id: felt252,
hidden: bool,
index: u8,
points: u16,
start: u64,
end: u64,
group: felt252,
icon: felt252,
title: felt252,
description: ByteArray,
tasks: Span<Task>,
data: ByteArray,
)
See also AchievableComponent
Parameters
self
: The component state.world
: The world storage.id
: The achievement identifier, it should be unique.hidden
: Speicify if you want the achievement to be hidden in the controller UI.index
: The achievement index which is the page in which the achievement will be displayed within the group.points
: The achievement points to reward the player.start
: The achievement start timestamp, it should be used for ephemeral achievements,0
for everlasting achievements.end
: The achievement end timestamp, it should be used for ephemeral achievements,0
for everlasting achievements.group
: The achievement group, it should be used to group achievements together (see alsoindex
to define multiple pages).icon
: The achievement icon, it should be a FontAwesome icon name (e.g.fa-trophy
).title
: The achievement title.description
: The achievement global description.tasks
: The achievement tasks (see alsoTask
type).data
: The achievement data, not used yet but could have a future use.
Task
pub struct Task {
id: felt252,
total: u32,
description: ByteArray,
}
See also Task
Parameters
id
: The task identifier, it should be unique but used in several achievements.total
: The task target, once reached the achievement task is completed.description
: The task description.