-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
409 additions
and
1 deletion.
There are no files selected for viewing
Submodule HelloDojo
deleted from
c6dfe4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cairo1.languageServerPath": "~/.dojo/bin/dojo-language-server", | ||
"cairo1.enableLanguageServer": true, | ||
"cairo1.enableScarb": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Dojo | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<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"> | ||
</picture> | ||
|
||
<a href="https://twitter.com/dojostarknet"> | ||
<img src="https://img.shields.io/twitter/follow/dojostarknet?style=social"/> | ||
</a> | ||
<a href="https://github.com/dojoengine/dojo"> | ||
<img src="https://img.shields.io/github/stars/dojoengine/dojo?style=social"/> | ||
</a> | ||
|
||
[![discord](https://img.shields.io/badge/join-dojo-green?logo=discord&logoColor=white)](https://discord.gg/PwDa2mKhR4) | ||
[![Telegram Chat][tg-badge]][tg-url] | ||
|
||
[tg-badge]: https://img.shields.io/endpoint?color=neon&logo=telegram&label=chat&style=flat-square&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fdojoengine | ||
[tg-url]: https://t.me/dojoengine | ||
|
||
|
||
# Hello Dojo : an Onchain Game | ||
In this project, I tried to create an on-chain game, which means that the entire game logic, assets, and interactions are decentralized and stored on a **blockchain**. This approach offers transparency, security, and unique ownership of in-game items or assets, ultimately revolutionizing how we play and experience games in the digital world. | ||
|
||
## Basic Overview | ||
We will be using **Dojo Game Engine**, Dojo is a provable game engine and toolchain for building onchain games and autonomous worlds. Dojo | ||
|
||
--- | ||
|
||
# How To Start | ||
In this section, I will just give you a quick setup, I highly recommand reading the official documentations, you will find it at the last section of this ReadMe file. | ||
|
||
## Installing the requirements | ||
1. **Install Scarb** | ||
- First you need to have Scarb, Scarb is Cairo Package Manger it's heavily inspired by cargo so you get the idea (I hope XD), you can simply install it by running `curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh` | ||
|
||
- Scarb will set up everything you will need to run your project, If you will use vscode make sure to go to your settings > search for cairo > and enable Scarb | ||
|
||
- If you have any errors like | ||
``` | ||
error: compiler plugin could not be loaded `dojo_plugin v0.3.0-rc8 (git+https://github.com/dojoengine/dojo) | ||
``` | ||
you can simply run `dojoup -v 0.2.3` and replace the old dependecies in `Scrab.toml` with | ||
``` | ||
[dependencies] | ||
dojo = { git = "https://github.com/dojoengine/dojo.git", tag = "v0.2.3" } | ||
``` | ||
## Conclusion | ||
I think I mentioned everything you need to know before starting working on this project, now you can jump to the next section and start working on **Hello Dojo** ! | ||
--- | ||
# Dojo Starter: Official Guide | ||
The official Dojo Starter guide, the quickest and most streamlined way to get your Dojo Autonomous World up and running. This guide will assist you with the initial setup, from cloning the repository to deploying your world. | ||
Read the full tutorial [here](https://book.dojoengine.org/cairo/hello-dojo.html) | ||
--- | ||
## 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. | ||
2. **Request a Feature** | ||
- You can also request for a feature [here](https://github.com/dojoengine/dojo-starter/issues), and if it's viable, it will be picked for development. | ||
3. **Create a Pull Request** | ||
- It can't get better then this, your pull request will be appreciated by the community. | ||
For any other questions, feel free to reach out to us [here](https://dojoengine.org/contact). | ||
Happy coding! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
cairo-version = "2.2.0" | ||
name = "dojo_examples" | ||
version = "0.1.0" | ||
|
||
[cairo] | ||
sierra-replace-ids = true | ||
|
||
[dependencies] | ||
dojo = { git = "https://github.com/dojoengine/dojo.git", tag = "v0.2.3" } | ||
|
||
[[target.dojo]] | ||
|
||
[tool.dojo] | ||
initializer_class_hash = "0xbeef" | ||
|
||
[tool.dojo.env] | ||
rpc_url = "http://localhost:5050/" | ||
# Default account for katana with seed = 0 | ||
account_address = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973" | ||
private_key = "0x1800000000300000180000000000030000000000003006001800006600" | ||
# world_address = "0x7d1f066a910bd86f532fa9ca66766722c20d47462fb99fb2fb0e1030262f9c5" | ||
|
||
# Madara testnet | ||
# rpc_url = "https://api.cartridge.gg/x/shinai/madara" | ||
# account_address = "0x2" | ||
# private_key = "0xc1cf1490de1352865301bb8705143f3ef938f97fdf892f1090dcb5ac7bcd1d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
pushd $(dirname "$0")/.. | ||
|
||
export WORLD_ADDRESS="0x7d1f066a910bd86f532fa9ca66766722c20d47462fb99fb2fb0e1030262f9c5"; | ||
|
||
# enable system -> component authorizations | ||
COMPONENTS=("Position" "Moves" ) | ||
|
||
for component in ${COMPONENTS[@]}; do | ||
sozo auth writer $component spawn --world $WORLD_ADDRESS | ||
done | ||
|
||
for component in ${COMPONENTS[@]}; do | ||
sozo auth writer $component move --world $WORLD_ADDRESS | ||
done | ||
|
||
echo "Default authorizations have been successfully set." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use starknet::ContractAddress; | ||
|
||
#[derive(Component, Copy, Drop, Serde, SerdeLen)] | ||
struct Moves { | ||
#[key] | ||
player: ContractAddress, | ||
remaining: u8, | ||
} | ||
|
||
#[derive(Component, Copy, Drop, Serde, SerdeLen)] | ||
struct Position { | ||
#[key] | ||
player: ContractAddress, | ||
x: u32, | ||
y: u32 | ||
} | ||
|
||
trait PositionTrait { | ||
fn is_zero(self: Position) -> bool; | ||
fn is_equal(self: Position, b: Position) -> bool; | ||
} | ||
|
||
impl PositionImpl of PositionTrait { | ||
fn is_zero(self: Position) -> bool { | ||
if self.x - self.y == 0 { | ||
return true; | ||
} | ||
false | ||
} | ||
|
||
fn is_equal(self: Position, b: Position) -> bool { | ||
self.x == b.x && self.y == b.y | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::{Position, PositionTrait}; | ||
|
||
#[test] | ||
#[available_gas(100000)] | ||
fn test_position_is_zero() { | ||
let player = starknet::contract_address_const::<0x0>(); | ||
assert(PositionTrait::is_zero(Position { player, x: 0, y: 0 }), 'not zero'); | ||
} | ||
|
||
#[test] | ||
#[available_gas(100000)] | ||
fn test_position_is_equal() { | ||
let player = starknet::contract_address_const::<0x0>(); | ||
let position = Position { player, x: 420, y: 0 }; | ||
assert(PositionTrait::is_equal(position, Position { player, x: 420, y: 0 }), 'not equal'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const OFFSET: felt252 = 1000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use starknet::ContractAddress; | ||
|
||
#[derive(Drop, Clone, Serde, PartialEq, starknet::Event)] | ||
struct Moved { | ||
player: ContractAddress, | ||
x: u32, | ||
y: u32 | ||
} | ||
|
||
#[derive(Drop, Clone, Serde, PartialEq, starknet::Event)] | ||
enum Event { | ||
Moved: Moved | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod components; | ||
mod systems; | ||
mod tests; | ||
mod constants; | ||
mod events; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#[system] | ||
mod spawn { | ||
use dojo::world::Context; | ||
|
||
use dojo_examples::components::Position; | ||
use dojo_examples::components::Moves; | ||
use dojo_examples::constants::OFFSET; | ||
|
||
#[event] | ||
use dojo_examples::events::{Event, Moved}; | ||
|
||
|
||
// so we don't go negative | ||
|
||
fn execute(ctx: Context) { | ||
// cast the offset to a u32 | ||
let offset: u32 = OFFSET.try_into().unwrap(); | ||
|
||
set!( | ||
ctx.world, | ||
( | ||
Moves { player: ctx.origin, remaining: 100 }, | ||
Position { player: ctx.origin, x: offset, y: offset }, | ||
) | ||
); | ||
|
||
emit!(ctx.world, Moved { player: ctx.origin, x: offset, y: offset, }); | ||
|
||
return (); | ||
} | ||
} | ||
|
||
#[system] | ||
mod move { | ||
use dojo::world::Context; | ||
|
||
use dojo_examples::components::Position; | ||
use dojo_examples::components::Moves; | ||
|
||
#[event] | ||
use dojo_examples::events::{Event, Moved}; | ||
|
||
#[derive(Serde, Drop)] | ||
enum Direction { | ||
Left: (), | ||
Right: (), | ||
Up: (), | ||
Down: (), | ||
} | ||
|
||
impl DirectionIntoFelt252 of Into<Direction, felt252> { | ||
fn into(self: Direction) -> felt252 { | ||
match self { | ||
Direction::Left(()) => 0, | ||
Direction::Right(()) => 1, | ||
Direction::Up(()) => 2, | ||
Direction::Down(()) => 3, | ||
} | ||
} | ||
} | ||
|
||
fn execute(ctx: Context, direction: Direction) { | ||
let (mut position, mut moves) = get!(ctx.world, ctx.origin, (Position, Moves)); | ||
moves.remaining -= 1; | ||
let next = next_position(position, direction); | ||
set!(ctx.world, (moves, next)); | ||
emit!(ctx.world, Moved { player: ctx.origin, x: next.x, y: next.y, }); | ||
return (); | ||
} | ||
|
||
fn next_position(mut position: Position, direction: Direction) -> Position { | ||
match direction { | ||
Direction::Left(()) => { | ||
position.x -= 1; | ||
}, | ||
Direction::Right(()) => { | ||
position.x += 1; | ||
}, | ||
Direction::Up(()) => { | ||
position.y -= 1; | ||
}, | ||
Direction::Down(()) => { | ||
position.y += 1; | ||
}, | ||
}; | ||
|
||
position | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod move; |
Oops, something went wrong.