Skip to content

Commit

Permalink
Merge pull request #34 from gianalarcon/update
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus authored Dec 16, 2023
2 parents f098b64 + 0a0b338 commit 2a7cfaa
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version = 1

[[package]]
name = "dojo"
version = "0.4.0"
source = "git+https://github.com/dojoengine/dojo#17c1b42910cb751fe3986ed44ce4e3a6a16b1e51"
version = "0.4.1"
source = "git+https://github.com/dojoengine/dojo#3de37a62cfbd81063bd5eb1ad39f028b2d482049"
dependencies = [
"dojo_plugin",
]
Expand Down
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.4.0"
sierra-replace-ids = true

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", version = "0.4.0" }
dojo = { git = "https://github.com/dojoengine/dojo", version = "0.4.1" }

[[target.dojo]]

Expand Down
6 changes: 3 additions & 3 deletions src/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod actions {
set!(
world,
(
Moves { player, remaining: 100, last_direction: Direction::None(()) },
Moves { player, remaining: 100, last_direction: Direction::None },
Position { player, vec: Vec2 { x: 10, y: 10 } },
)
);
Expand Down Expand Up @@ -125,13 +125,13 @@ mod tests {
actions_system.spawn();

// call move with direction right
actions_system.move(Direction::Right(()));
actions_system.move(Direction::Right);

// Check world state
let moves = get!(world, caller, Moves);

// casting right direction
let right_dir_felt: felt252 = Direction::Right(()).into();
let right_dir_felt: felt252 = Direction::Right.into();

// check moves
assert(moves.remaining == 99, 'moves is wrong');
Expand Down
20 changes: 10 additions & 10 deletions src/models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use starknet::ContractAddress;

#[derive(Serde, Copy, Drop, Introspect)]
enum Direction {
None: (),
Left: (),
Right: (),
Up: (),
Down: (),
None,
Left,
Right,
Up,
Down,
}

impl DirectionIntoFelt252 of Into<Direction, felt252> {
fn into(self: Direction) -> felt252 {
match self {
Direction::None(()) => 0,
Direction::Left(()) => 1,
Direction::Right(()) => 2,
Direction::Up(()) => 3,
Direction::Down(()) => 4,
Direction::None => 0,
Direction::Left => 1,
Direction::Right => 2,
Direction::Up => 3,
Direction::Down => 4,
}
}
}
Expand Down
21 changes: 5 additions & 16 deletions src/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ use dojo_examples::models::{Position, Direction};

fn next_position(mut position: Position, direction: Direction) -> Position {
match direction {
Direction::None(()) => {
return position;
},
Direction::Left(()) => {
position.vec.x -= 1;
},
Direction::Right(()) => {
position.vec.x += 1;
},
Direction::Up(()) => {
position.vec.y -= 1;
},
Direction::Down(()) => {
position.vec.y += 1;
},
Direction::None => { return position; },
Direction::Left => { position.vec.x -= 1; },
Direction::Right => { position.vec.x += 1; },
Direction::Up => { position.vec.y -= 1; },
Direction::Down => { position.vec.y += 1; },
};

position
}

0 comments on commit 2a7cfaa

Please sign in to comment.