diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52268791..33ac5ff2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Origami CI on: [push, pull_request] env: - DOJO_VERSION: v0.6.0-alpha.3 + DOJO_VERSION: v0.6.0-alpha.6 SCARB_VERSION: v2.5.4 jobs: diff --git a/Scarb.lock b/Scarb.lock index a98c8024..89cb673a 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -16,7 +16,7 @@ source = "git+https://github.com/notV4l/cubit.git?rev=5aa99005#5aa99005475012a04 [[package]] name = "dojo" version = "0.5.1" -source = "git+https://github.com/dojoengine/dojo?tag=v0.6.0-alpha.3#9b2bf3e465be5efeeb7f41032c15d35c46d90002" +source = "git+https://github.com/dojoengine/dojo?tag=v0.6.0-alpha.6#cfdd17029222b8baacc4efc06d9fe945458686f6" dependencies = [ "dojo_plugin", ] @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "origami" -version = "0.6.0-alpha.2" +version = "0.6.0-alpha.6" dependencies = [ "cubit", "dojo", diff --git a/Scarb.toml b/Scarb.toml index 049c5f45..f9196112 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -2,7 +2,7 @@ members = ["crates", "examples/*", "token"] [workspace.package] -version = "0.6.0-alpha.3" +version = "0.6.0-alpha.6" description = "Community-maintained libraries for Cairo" homepage = "https://github.com/dojoengine/origami" authors = ["bal7hazar@proton.me"] @@ -10,6 +10,6 @@ authors = ["bal7hazar@proton.me"] [workspace.dependencies] # cubit = { git = "https://github.com/influenceth/cubit.git" } cubit = { git = "https://github.com/notV4l/cubit.git", rev = "5aa99005" } -dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.6.0-alpha.3" } +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.6.0-alpha.6" } origami = { path = "crates" } token = { path = "token" } diff --git a/examples/hex_map/src/actions.cairo b/examples/hex_map/src/actions.cairo index 49d6d179..1b21ab53 100644 --- a/examples/hex_map/src/actions.cairo +++ b/examples/hex_map/src/actions.cairo @@ -1,12 +1,18 @@ // internal imports use core::Into; use origami::map::hex::{types::Direction}; +use hex_map::models::Position; // define the interface -#[starknet::interface] -trait IActions { - fn spawn(self: @TContractState); - fn move(self: @TContractState, direction: Direction); +#[dojo::interface] +trait IActions { + fn spawn(); + fn move(direction: Direction); +} + +#[dojo::interface] +trait IActionsComputed { + fn next_position(position: Position, direction: Direction) -> Position; } // dojo decorator @@ -18,7 +24,7 @@ mod actions { use hex_map::models::{Position, Vec2}; use hex_map::noise::{ITile}; - use super::IActions; + use super::{IActions, IActionsComputed}; // declaring custom event struct #[event] @@ -34,34 +40,38 @@ mod actions { direction: Direction } - fn next_position(position: Position, direction: Direction) -> Position { - let mut new_position = position; + #[abi(embed_v0)] + impl ActionsComputedImpl of IActionsComputed { + #[computed(Position)] + fn next_position(position: Position, direction: Direction) -> Position { + let mut new_position = position; - // convert to Hex - let hex_tile = IHexTile::new(position.vec.x, position.vec.y); + // convert to Hex + let hex_tile = IHexTile::new(position.vec.x, position.vec.y); - // get next next tile - let next_hex = hex_tile.neighbor(direction); + // get next next tile + let next_hex = hex_tile.neighbor(direction); - // check movable - ITile::check_moveable(next_hex); + // check movable + ITile::check_moveable(next_hex); - // convert back to Position - new_position.vec = Vec2 { x: next_hex.col, y: next_hex.row }; + // convert back to Position + new_position.vec = Vec2 { x: next_hex.col, y: next_hex.row }; - new_position + new_position + } } #[abi(embed_v0)] impl ActionsImpl of IActions { // ContractState is defined by system decorator expansion - fn spawn(self: @ContractState) { // Access the world dispatcher for reading. + fn spawn() { // Access the world dispatcher for reading. let world = self.world_dispatcher.read(); set!(world, (Position { player: get_caller_address(), vec: Vec2 { x: 10, y: 10 } })); } // Moves player in the provided direction. - fn move(self: @ContractState, direction: Direction) { + fn move(direction: Direction) { // Access the world dispatcher for reading. let world = self.world_dispatcher.read(); @@ -72,7 +82,7 @@ mod actions { let mut position = get!(world, player, (Position)); // // Calculate the player's next position based on the provided direction. - let next = next_position(position, direction); + let next = self.next_position(position, direction); // Update the world state with the new moves data and position. set!(world, (next)); diff --git a/examples/market/src/systems/liquidity.cairo b/examples/market/src/systems/liquidity.cairo index 6a9ee495..1ff4f910 100644 --- a/examples/market/src/systems/liquidity.cairo +++ b/examples/market/src/systems/liquidity.cairo @@ -6,12 +6,10 @@ use dojo::world::IWorldDispatcher; use cubit::f128::types::fixed::Fixed; -#[starknet::interface] -trait ILiquidity { - fn add( - self: @TContractState, world: IWorldDispatcher, item_id: u32, amount: u128, quantity: u128 - ); - fn remove(self: @TContractState, world: IWorldDispatcher, item_id: u32, shares: Fixed); +#[dojo::interface] +trait ILiquidity { + fn add(item_id: u32, amount: u128, quantity: u128); + fn remove(item_id: u32, shares: Fixed); } #[dojo::contract] @@ -29,13 +27,7 @@ mod Liquidity { #[abi(embed_v0)] impl LiquidityImpl of ILiquidity { - fn add( - self: @ContractState, - world: IWorldDispatcher, - item_id: u32, - amount: u128, - quantity: u128 - ) { + fn add(world: IWorldDispatcher, item_id: u32, amount: u128, quantity: u128) { let player = starknet::get_caller_address(); let item = get!(world, (player, item_id), Item); @@ -83,7 +75,7 @@ mod Liquidity { } - fn remove(self: @ContractState, world: IWorldDispatcher, item_id: u32, shares: Fixed) { + fn remove(world: IWorldDispatcher, item_id: u32, shares: Fixed) { let player = starknet::get_caller_address(); let player_liquidity = get!(world, (player, item_id), Liquidity); diff --git a/examples/market/src/systems/trade.cairo b/examples/market/src/systems/trade.cairo index 6c4efde4..77554e16 100644 --- a/examples/market/src/systems/trade.cairo +++ b/examples/market/src/systems/trade.cairo @@ -2,10 +2,10 @@ use dojo::world::IWorldDispatcher; -#[starknet::interface] +#[dojo::interface] trait ITrade { - fn buy(self: @TContractState, world: IWorldDispatcher, item_id: u32, quantity: u128); - fn sell(self: @TContractState, world: IWorldDispatcher, item_id: u32, quantity: u128); + fn buy(item_id: u32, quantity: u128); + fn sell(item_id: u32, quantity: u128); } #[dojo::contract] @@ -20,7 +20,7 @@ mod Trade { #[abi(embed_v0)] impl TradeImpl of ITrade { - fn buy(self: @ContractState, world: IWorldDispatcher, item_id: u32, quantity: u128) { + fn buy(world: IWorldDispatcher, item_id: u32, quantity: u128) { let player = starknet::get_caller_address(); let player_cash = get!(world, (player), Cash); @@ -52,7 +52,7 @@ mod Trade { } - fn sell(self: @ContractState, world: IWorldDispatcher, item_id: u32, quantity: u128) { + fn sell(world: IWorldDispatcher, item_id: u32, quantity: u128) { let player = starknet::get_caller_address(); let item = get!(world, (player, item_id), Item);