Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ClanCo committed Mar 29, 2024
1 parent dafa067 commit 11cc69d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/systems/play.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use dojo::world::IWorldDispatcher;
#[starknet::interface]
trait IPlay<TContractState> {
fn emote(
self: @TContractState, world: IWorldDispatcher, game_id: u32, player_index: u32, emote: u32
self: @TContractState,
world: IWorldDispatcher,
game_id: u32,
player_index: u32,
emote_index: u8
);
fn attack(
self: @TContractState,
Expand Down Expand Up @@ -160,9 +164,9 @@ mod play {
world: IWorldDispatcher,
game_id: u32,
player_index: u32,
emote: u32
emote_index: u8
) {
// Initialisation du datastore
// Init datastore
let mut store: Store = StoreTrait::new(world);

let game: Game = store.game(game_id);
Expand All @@ -172,9 +176,11 @@ mod play {
let player = store.player(game, player_index);
assert(player.address == caller.into(), errors::EMOTE_INVALID_PLAYER);

// Une fois les vérifications passées, vous pouvez émettre un événement avec les détails de l'émoticône envoyée
// [Event] Emote
emit!(world, Emote { game_id: game_id, player_index: player_index, emote: emote, });
emit!(
world,
Emote { game_id: game_id, player_index: player_index, emote_index: emote_index, }
);
}

fn attack(
Expand Down
4 changes: 2 additions & 2 deletions src/tests/emote.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const PRICE: u256 = 1_000_000_000_000_000_000;
const PENALTY: u64 = 60;
const PLAYER_COUNT: u8 = 2;
const PLAYER_INDEX: u32 = 0;
const EMOTE_INDEX: u8 = 12;


#[test]
Expand All @@ -51,9 +52,8 @@ fn test_emote_revert_invalid_player() {
let current_player: Player = store.current_player(game);
let player: Player = store.next_player(game);

let emote = 12;
let contract_address = starknet::contract_address_try_from_felt252(player.address);
set_contract_address(contract_address.unwrap());
// Execute the emote function
systems.play.emote(world, game_id, current_player.index, emote);
systems.play.emote(world, game_id, current_player.index, EMOTE_INDEX);
}

0 comments on commit 11cc69d

Please sign in to comment.