Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👽️ Upgrade to dojo v0.6.0.alpha.6 #49

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -45,7 +45,7 @@ dependencies = [

[[package]]
name = "origami"
version = "0.6.0-alpha.2"
version = "0.6.0-alpha.6"
dependencies = [
"cubit",
"dojo",
Expand Down
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
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 = ["[email protected]"]

[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" }
48 changes: 29 additions & 19 deletions examples/hex_map/src/actions.cairo
Original file line number Diff line number Diff line change
@@ -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<TContractState> {
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
Expand All @@ -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]
Expand All @@ -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<ContractState> {
#[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> {
// 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();

Expand All @@ -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));
Expand Down
20 changes: 6 additions & 14 deletions examples/market/src/systems/liquidity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ use dojo::world::IWorldDispatcher;

use cubit::f128::types::fixed::Fixed;

#[starknet::interface]
trait ILiquidity<TContractState> {
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]
Expand All @@ -29,13 +27,7 @@ mod Liquidity {

#[abi(embed_v0)]
impl LiquidityImpl of ILiquidity<ContractState> {
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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions examples/market/src/systems/trade.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use dojo::world::IWorldDispatcher;

#[starknet::interface]
#[dojo::interface]
trait ITrade<TContractState> {
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]
Expand All @@ -20,7 +20,7 @@ mod Trade {

#[abi(embed_v0)]
impl TradeImpl of ITrade<ContractState> {
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);
Expand Down Expand Up @@ -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);
Expand Down