Skip to content

Commit

Permalink
♻️ Split achievement and registry
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Nov 2, 2024
1 parent 81db6ee commit baf0fb2
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 89 deletions.
8 changes: 8 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ dependencies = [
"dojo_cairo_test",
]

[[package]]
name = "bushido_registry"
version = "0.0.0"
dependencies = [
"dojo",
"dojo_cairo_test",
]

[[package]]
name = "dojo"
version = "1.0.0-rc.0"
Expand Down
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["packages/achievement"]
members = ["packages/achievement", "packages/registry"]
description = "Dojo achievement library"
homepage = "https://github.com/cartridge-gg/bushido/"
cairo-version = "2.8.4"
Expand Down
4 changes: 2 additions & 2 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version = 1

[[package]]
name = "achievement"
name = "bushido_registry"
version = "0.0.0"
dependencies = [
"dojo",
Expand Down Expand Up @@ -33,7 +33,7 @@ source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-rc.0#f4199aec570a395
name = "game_center"
version = "0.0.0"
dependencies = [
"achievement",
"bushido_registry",
"dojo",
"dojo_cairo_test",
]
8 changes: 3 additions & 5 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dev = "sozo clean && sozo build --typescript && sozo migrate plan && sozo migrat

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" }
achievement = { path = ".." }
bushido_registry = { path = ".." }
starknet = "2.8.4"
cairo_test = "2.8.4"

Expand All @@ -21,10 +21,8 @@ dojo_cairo_test = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc
[[target.starknet-contract]]
build-external-contracts = [
"dojo::world::world_contract::world",
"achievement::models::index::m_Game",
"achievement::models::index::m_Achievement",
"achievement::events::index::e_Trophy",
"achievement::events::index::e_Progress",
"bushido_registry::models::index::m_Game",
"bushido_registry::models::index::m_Achievement",
]

[profile.slot]
4 changes: 2 additions & 2 deletions contracts/src/systems/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ mod Actions {

// Component imports

use achievement::components::controllable::ControllableComponent;
use achievement::components::registrable::RegistrableComponent;
use bushido_registry::components::controllable::ControllableComponent;
use bushido_registry::components::registrable::RegistrableComponent;

// Local imports

Expand Down
12 changes: 0 additions & 12 deletions packages/achievement/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ mod types {
mod task;
}

mod models {
mod index;
mod game;
mod achievement;
}

mod events {
mod index;
mod trophy;
Expand All @@ -20,20 +14,14 @@ mod events {

mod components {
mod achievable;
mod controllable;
mod registrable;
}

#[cfg(test)]
mod tests {
mod setup;
mod test_achievable;
mod test_controllable;
mod test_registrable;

mod mocks {
mod achiever;
mod controller;
mod registrer;
}
}
27 changes: 0 additions & 27 deletions packages/achievement/src/store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ use starknet::SyscallResultTrait;
// Dojo imports

use dojo::world::WorldStorage;
use dojo::model::ModelStorage;
use dojo::event::EventStorage;
// Models imports

use achievement::models::game::Game;
use achievement::models::achievement::Achievement;

// Events imports

Expand All @@ -39,28 +34,6 @@ impl StoreImpl of StoreTrait {
Store { world: world }
}

#[inline]
fn get_game(self: Store, world_address: felt252, namespace: felt252) -> Game {
self.world.read_model((world_address, namespace))
}

#[inline]
fn get_achievement(
self: Store, world_address: felt252, namespace: felt252, id: felt252
) -> Achievement {
self.world.read_model((world_address, namespace, id))
}

#[inline]
fn set_game(ref self: Store, game: Game) {
self.world.write_model(@game);
}

#[inline]
fn set_achievement(ref self: Store, achievement: Achievement) {
self.world.write_model(@achievement);
}

#[inline]
fn create(
mut self: Store,
Expand Down
19 changes: 0 additions & 19 deletions packages/achievement/src/tests/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ mod setup {

// Internal imports

use achievement::models::{index as models};
use achievement::events::{index as events};
use achievement::tests::mocks::achiever::{Achiever, IAchiever, IAchieverDispatcher};
use achievement::tests::mocks::controller::{Controller, IController, IControllerDispatcher};
use achievement::tests::mocks::registrer::{Registrer, IRegistrer, IRegistrerDispatcher};

// Constant

Expand All @@ -35,8 +32,6 @@ mod setup {
#[derive(Copy, Drop)]
struct Systems {
achiever: IAchieverDispatcher,
controller: IControllerDispatcher,
registrer: IRegistrerDispatcher,
}

#[derive(Copy, Drop)]
Expand All @@ -58,22 +53,12 @@ mod setup {
fn setup_namespace() -> NamespaceDef {
NamespaceDef {
namespace: "namespace", resources: [
TestResource::Model(models::m_Game::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Model(models::m_Achievement::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Event(events::e_Trophy::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Event(events::e_Progress::TEST_CLASS_HASH.try_into().unwrap()),
TestResource::Contract(
ContractDefTrait::new(Achiever::TEST_CLASS_HASH, "Achiever")
.with_writer_of([dojo::utils::bytearray_hash(@"namespace")].span())
),
TestResource::Contract(
ContractDefTrait::new(Controller::TEST_CLASS_HASH, "Controller")
.with_writer_of([dojo::utils::bytearray_hash(@"namespace")].span())
),
TestResource::Contract(
ContractDefTrait::new(Registrer::TEST_CLASS_HASH, "Registrer")
.with_writer_of([dojo::utils::bytearray_hash(@"namespace")].span())
),
].span()
}
}
Expand All @@ -86,12 +71,8 @@ mod setup {
let world = spawn_test_world([namespace_def].span());
// [Setup] Systems
let (achiever_address, _) = world.dns(@"Achiever").unwrap();
let (controller_address, _) = world.dns(@"Controller").unwrap();
let (registrer_address, _) = world.dns(@"Registrer").unwrap();
let systems = Systems {
achiever: IAchieverDispatcher { contract_address: achiever_address },
controller: IControllerDispatcher { contract_address: controller_address },
registrer: IRegistrerDispatcher { contract_address: registrer_address },
};

// [Setup] Context
Expand Down
1 change: 1 addition & 0 deletions packages/registry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
64 changes: 64 additions & 0 deletions packages/registry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<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

# 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.

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

## Running Locally

#### Terminal one (Make sure this is running)

```bash
# Run Katana
katana --disable-fee --allowed-origins "*"
```

#### Terminal two

```bash
# Build the example
sozo build

# Migrate the example
sozo migrate apply

# Start Torii
torii --world 0x5d475a9221f6cbf1a016b12400a01b9a89935069aecd57e9876fcb2a7bb29da --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.

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.

Happy coding!
9 changes: 9 additions & 0 deletions packages/registry/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "bushido_registry"
version.workspace = true

[dependencies]
dojo.workspace = true

[dev-dependencies]
dojo_cairo_test.workspace = true
19 changes: 19 additions & 0 deletions packages/registry/dojo_dev.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[world]
name = "registry"
description = "Dojo Registry Library"
website = "https://github.com/dojoengine/dojo-starter"
seed = "registry"

[world.socials]
x = "https://x.com/ohayo_dojo"
discord = "https://discord.gg/FB2wR6uF"
github = "https://github.com/dojoengine/dojo-starter"
telegram = "https://t.me/dojoengine"

[namespace]
default = "registry"

[env]
rpc_url = "http://localhost:5050/"
account_address = "0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca"
private_key = "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a"
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mod ControllableComponent {

// Internal imports

use achievement::store::{Store, StoreTrait};
use achievement::models::game::Game;
use bushido_registry::store::{Store, StoreTrait};
use bushido_registry::models::game::Game;

// Storage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ mod RegistrableComponent {

// Internal imports

use achievement::store::{Store, StoreTrait};
use achievement::models::game::{Game, GameTrait, GameAssert};
use achievement::models::achievement::{Achievement, AchievementTrait, AchievementAssert};
use bushido_registry::store::{Store, StoreTrait};
use bushido_registry::models::game::{Game, GameTrait, GameAssert};
use bushido_registry::models::achievement::{Achievement, AchievementTrait, AchievementAssert};

// Storage

Expand Down
5 changes: 5 additions & 0 deletions packages/registry/src/constants.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Points threshold for achievements

pub const MAX_GAME_KARMA: u16 = 1000;
pub const MIN_ACHIEVEMENT_KARMA: u16 = 10;
pub const MAX_ACHIEVEMENT_KARMA: u16 = 100;
25 changes: 25 additions & 0 deletions packages/registry/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mod constants;
mod store;

mod models {
mod index;
mod game;
mod achievement;
}

mod components {
mod controllable;
mod registrable;
}

#[cfg(test)]
mod tests {
mod setup;
mod test_controllable;
mod test_registrable;

mod mocks {
mod controller;
mod registrer;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Intenral imports

use achievement::models::index::Achievement;
use achievement::constants;
use bushido_registry::models::index::Achievement;
use bushido_registry::constants;

// Errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Intenral imports

use achievement::models::index::Game;
use achievement::constants;
use bushido_registry::models::index::Game;
use bushido_registry::constants;

// Errors

Expand Down
File renamed without changes.
Loading

0 comments on commit baf0fb2

Please sign in to comment.