From 6f74f5b54c4b6aa029460f960372cea69a9522de Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Thu, 18 Jan 2024 10:36:33 -0500 Subject: [PATCH] refactor: migrate spawn-and-move to new proposed syntax --- examples/spawn-and-move/src/actions.cairo | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/examples/spawn-and-move/src/actions.cairo b/examples/spawn-and-move/src/actions.cairo index ea94cde00f..44f5b65f4e 100644 --- a/examples/spawn-and-move/src/actions.cairo +++ b/examples/spawn-and-move/src/actions.cairo @@ -1,13 +1,13 @@ -#[starknet::interface] -trait IActions { - fn spawn(self: @TContractState); - fn move(self: @TContractState, direction: dojo_examples::models::Direction); +#[dojo::interface] +trait IActions { + fn spawn(); + fn move(direction: dojo_examples::models::Direction); } #[dojo::contract] mod actions { use super::IActions; - + use starknet::{ContractAddress, get_caller_address}; use dojo_examples::models::{Position, Moves, Direction, Vec2}; use dojo_examples::utils::next_position; @@ -26,13 +26,13 @@ mod actions { #[external(v0)] #[computed] - fn tile_terrain(self: @ContractState, vec: Vec2) -> felt252 { + fn tile_terrain(vec: Vec2) -> felt252 { 'land' } #[external(v0)] #[computed(Position)] - fn quadrant(self: @ContractState, pos: Position) -> u8 { + fn quadrant(pos: Position) -> u8 { // 10 is zero if pos.vec.x < 10 { if pos.vec.y < 10 { @@ -51,10 +51,8 @@ mod actions { // impl: implement functions specified in trait #[external(v0)] - impl ActionsImpl of IActions { - // ContractState is defined by system decorator expansion - fn spawn(self: @ContractState) { - let world = self.world_dispatcher.read(); + impl ActionsImpl of IActions { + fn spawn(world: IWorldDispatcher) { let player = get_caller_address(); let position = get!(world, player, (Position)); let moves = get!(world, player, (Moves)); @@ -72,8 +70,7 @@ mod actions { ); } - fn move(self: @ContractState, direction: Direction) { - let world = self.world_dispatcher.read(); + fn move(world: IWorldDispatcher, direction: Direction) { let player = get_caller_address(); let (mut position, mut moves) = get!(world, player, (Position, Moves)); moves.remaining -= 1;