Skip to content

Commit

Permalink
Update player_actions.cairo
Browse files Browse the repository at this point in the history
  • Loading branch information
0xibs authored Oct 6, 2024
1 parent e072840 commit ed09603
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions onchain/src/systems/player_actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ mod PlayerActions {
let caller: ContractAddress = get_caller_address();
let zero_address: ContractAddress = contract_address_const::<0x0>();

// assert(caller != zero_address, 'Cannot create from zero address');
assert(caller != zero_address, Errors::ADDRESS_ZERO);


let new_player: Player = PlayerTrait::new(username, caller);

// Ensure player username is unique
let mut existing_player = get!(world, username, (Player));

// assert(existing_player.owner == 0.try_into().unwrap(), 'username already taken');
assert(existing_player.owner == 0.try_into().unwrap(), Errors::USERNAME_TAKEN);

set!(world, (new_player));
Expand All @@ -57,7 +54,6 @@ mod PlayerActions {
let mut player: Player = get!(world, username, (Player));

// Validate username
// assert(player.owner != 0.try_into().unwrap(), 'player with username not found');
assert(player.owner != 0.try_into().unwrap(), Errors::USERNAME_NOT_FOUND);

player.owner
Expand Down Expand Up @@ -86,17 +82,15 @@ mod PlayerActions {
let mut player: Player = get!(world, old_username, (Player));

// Only allow the player to update their own username
// assert(player.owner == caller, 'only user can udpate username');
assert(player.owner == caller, Errors::ONLY_OWNER_USERNAME);

// Check if the new username is already taken
let mut existing_player = get!(world, new_username, (Player));
// assert(existing_player.owner == 0.try_into().unwrap(), 'username already exist');
assert(existing_player.owner == 0.try_into().unwrap(), Errors::USERNAME_EXIST);

// Update the player's username
player.username = new_username;
set!(world, (player));
}
}
}
}

0 comments on commit ed09603

Please sign in to comment.