Skip to content

Commit

Permalink
Merge pull request #87 from dojoengine/rc0
Browse files Browse the repository at this point in the history
rc0
  • Loading branch information
glihm authored Oct 31, 2024
2 parents 2f61bce + 165b486 commit 4964f2b
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 96 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v1.0.0)'
required: true
type: string
dojo_version:
description: 'Dojo version to use'
required: true
type: string

jobs:
create-release:
runs-on: ubuntu-latest
env:
DOJO_VERSION: ${{ inputs.dojo_version }}
steps:
- uses: actions/checkout@v3

# Setup and test with specified Dojo version
- run: curl -L https://install.dojoengine.org | bash
- run: /home/runner/.config/.dojo/bin/dojoup -v ${{ env.DOJO_VERSION }}
- run: |
/home/runner/.config/.dojo/bin/sozo build
/home/runner/.config/.dojo/bin/sozo test
# Create tag and release
- name: Create Tag
run: |
git tag ${{ inputs.version }}
git push origin ${{ inputs.version }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ inputs.version }}
name: Release ${{ inputs.version }}
draft: false
prerelease: false
generate_release_notes: true
12 changes: 8 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
name: CI

on:
push:
pull_request:
push:
branches:
- "main"
pull_request:

jobs:
sozo-test:
runs-on: ubuntu-latest
env:
DOJO_VERSION: v1.0.0-rc.0
steps:
- uses: actions/checkout@v3
- run: curl -L https://install.dojoengine.org | bash
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.0-alpha.17
- run: /home/runner/.config/.dojo/bin/dojoup -v ${{ env.DOJO_VERSION }}
- run: |
/home/runner/.config/.dojo/bin/sozo build
/home/runner/.config/.dojo/bin/sozo test
if [[ `git status --porcelain` ]]; then
echo The git repo is dirty
echo "Make sure to run \"sozo build\" after changing Scarb.toml"
exit 1
fi
fi
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Dojo Starter](./assets/cover.png)

<picture>
<source media="(prefers-color-scheme: dark)" srcset=".github/mark-dark.svg">
<img alt="Dojo logo" align="right" width="120" src=".github/mark-light.svg">
Expand All @@ -18,9 +20,9 @@

# Dojo Starter: Official Guide

The official Dojo Starter guide, the quickest and most streamlined way to get your Dojo provable game up and running. This guide will assist you with the initial setup, from cloning the repository to deploying your world.
A quickstart guide to help you build and deploy your first Dojo provable game.

Read the full tutorial [here](https://book.dojoengine.org/tutorial/dojo-starter).
Read the full tutorial [here](https://dojoengine.org/tutorial/dojo-starter).

## Running Locally

Expand All @@ -41,15 +43,14 @@ sozo build
sozo migrate apply

# Start Torii
torii --world 0xc82dfe2cb4f8a90dba1e88dfa24578aeb1c19152d51e3c7cf413be6d65d9e --allowed-origins "*"
# Replace <WORLD_ADDRESS> with the address of the deployed world from the previous step
torii --world <WORLD_ADDRESS> --allowed-origins "*"
```

---

## Contribution

This starter project is a constant work in progress and contributions are greatly appreciated!

1. **Report a Bug**

- If you think you have encountered a bug, and we should know about it, feel free to report it [here](https://github.com/dojoengine/dojo-starter/issues) and we will take care of it.
Expand Down
23 changes: 20 additions & 3 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,29 @@ version = 1

[[package]]
name = "dojo"
version = "1.0.0-alpha.4"
source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.17#e6bab2d0066c3cf1acfc5ee41a27294b5b23697d"
version = "1.0.0-rc.0"
source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-rc.0#f4199aec570a395278b8c8748bc46e2f6be3d0c7"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_cairo_test"
version = "1.0.0-rc.0"
source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-rc.0#f4199aec570a395278b8c8748bc46e2f6be3d0c7"
dependencies = [
"dojo",
]

[[package]]
name = "dojo_plugin"
version = "2.8.4"
source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-rc.0#f4199aec570a395278b8c8748bc46e2f6be3d0c7"

[[package]]
name = "dojo_starter"
version = "0.1.0"
version = "1.0.0-rc.0"
dependencies = [
"dojo",
"dojo_cairo_test",
]
13 changes: 9 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
cairo-version = "=2.7.0"
cairo-version = "=2.8.4"
name = "dojo_starter"
version = "0.1.0"
version = "1.0.0-rc.0"

[cairo]
sierra-replace-ids = true
Expand All @@ -12,6 +12,11 @@ spawn = "./scripts/spawn.sh"
move = "./scripts/move.sh"

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.17" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" }

[[target.dojo]]
[[target.starknet-contract]]
build-external-contracts = ["dojo::world::world_contract::world"]


[dev-dependencies]
dojo_cairo_test = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" }
3 changes: 3 additions & 0 deletions dojo_dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ rpc_url = "http://localhost:5050/"
account_address = "0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec"
private_key = "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912"
# world_address = "0x3b34889efbdf01f707d5d7421f112e8fb85a42fb6f2e5422c75ce3253148b0e"

[writers]
"dojo_starter" = ["dojo_starter-actions"]
3 changes: 3 additions & 0 deletions dojo_release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ rpc_url = "http://localhost:5050/"
account_address = "0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca"
private_key = "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a"
# world_address = "0x3fc79ccfd72c1450d2ccb73c5c521a7ec68b6c6af0caf96a0f1c39ce58876c8" # Uncomment and update this line with your world address.

[writers]
"dojo_starter" = ["dojo_starter-actions"]
6 changes: 0 additions & 6 deletions overlays/dev/actions.toml

This file was deleted.

10 changes: 5 additions & 5 deletions src/models.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use starknet::ContractAddress;

#[derive(Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde, Debug)]
#[dojo::model]
pub struct Moves {
#[key]
Expand All @@ -10,15 +10,15 @@ pub struct Moves {
pub can_move: bool,
}

#[derive(Drop, Serde)]
#[derive(Drop, Serde, Debug)]
#[dojo::model]
pub struct DirectionsAvailable {
#[key]
pub player: ContractAddress,
pub directions: Array<Direction>,
}

#[derive(Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde, Debug)]
#[dojo::model]
pub struct Position {
#[key]
Expand All @@ -27,7 +27,7 @@ pub struct Position {
}


#[derive(Serde, Copy, Drop, Introspect)]
#[derive(Serde, Copy, Drop, Introspect, PartialEq, Debug)]
pub enum Direction {
None,
Left,
Expand All @@ -37,7 +37,7 @@ pub enum Direction {
}


#[derive(Copy, Drop, Serde, Introspect)]
#[derive(Copy, Drop, Serde, IntrospectPacked, Debug)]
pub struct Vec2 {
pub x: u32,
pub y: u32
Expand Down
76 changes: 46 additions & 30 deletions src/systems/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,71 @@ use dojo_starter::models::Direction;
use dojo_starter::models::Position;

// define the interface
#[dojo::interface]
trait IActions {
fn spawn(ref world: IWorldDispatcher);
fn move(ref world: IWorldDispatcher, direction: Direction);
#[starknet::interface]
trait IActions<T> {
fn spawn(ref self: T);
fn move(ref self: T, direction: Direction);
}

// dojo decorator
#[dojo::contract]
mod actions {
pub mod actions {
use super::{IActions, next_position};
use starknet::{ContractAddress, get_caller_address};
use dojo_starter::models::{Position, Vec2, Moves, Direction, DirectionsAvailable};

use dojo::model::{ModelStorage, ModelValueStorage};
use dojo::event::EventStorage;

#[derive(Copy, Drop, Serde)]
#[dojo::model]
#[dojo::event]
struct Moved {
pub struct Moved {
#[key]
player: ContractAddress,
direction: Direction,
pub player: ContractAddress,
pub direction: Direction,
}

#[abi(embed_v0)]
impl ActionsImpl of IActions<ContractState> {
fn spawn(ref world: IWorldDispatcher) {
fn spawn(ref self: ContractState) {
// Get the default world.
let mut world = self.world(@"dojo_starter");

// Get the address of the current caller, possibly the player's address.
let player = get_caller_address();
// Retrieve the player's current position from the world.
let position = get!(world, player, (Position));
let mut position: Position = world.read_model(player);

// Update the world state with the new data.
// 1. Set the player's remaining moves to 100.
// 2. Move the player's position 10 units in both the x and y direction.

set!(
world,
(
Moves {
player, remaining: 100, last_direction: Direction::None(()), can_move: true
},
Position {
player, vec: Vec2 { x: position.vec.x + 10, y: position.vec.y + 10 }
},
)
);

// 1. Move the player's position 10 units in both the x and y direction.
let new_position = Position {
player, vec: Vec2 { x: position.vec.x + 10, y: position.vec.y + 10 }
};

// Write the new position to the world.
world.write_model(@new_position);

// 2. Set the player's remaining moves to 100.
let moves = Moves {
player, remaining: 100, last_direction: Direction::None(()), can_move: true
};

// Write the new moves to the world.
world.write_model(@moves);
}

// Implementation of the move function for the ContractState struct.
fn move(ref world: IWorldDispatcher, direction: Direction) {
fn move(ref self: ContractState, direction: Direction) {
// Get the address of the current caller, possibly the player's address.

let mut world = self.world(@"dojo_starter");

let player = get_caller_address();

// Retrieve the player's current position and moves data from the world.
let (mut position, mut moves) = get!(world, player, (Position, Moves));
let mut position: Position = world.read_model(player);
let mut moves: Moves = world.read_model(player);

// Deduct one from the player's remaining moves.
moves.remaining -= 1;
Expand All @@ -65,10 +77,14 @@ mod actions {
// Calculate the player's next position based on the provided direction.
let next = next_position(position, direction);

// Update the world state with the new moves data and position.
set!(world, (moves, next));
// Write the new position to the world.
world.write_model(@next);

// Write the new moves to the world.
world.write_model(@moves);

// Emit an event to the world to notify about the player's move.
emit!(world, (Moved { player, direction }));
world.emit_event(@Moved { player, direction });
}
}
}
Expand Down
Loading

0 comments on commit 4964f2b

Please sign in to comment.