Skip to content

Commit

Permalink
workspace file
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Aug 22, 2024
1 parent 12662df commit 5c5aa5f
Show file tree
Hide file tree
Showing 14 changed files with 52,604 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
target
node_modules
1 change: 1 addition & 0 deletions clients/react-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@dojoengine/core": "1.0.0-alpha.5",
"@dojoengine/recs": "^2.0.13",
"@dojoengine/create-burner": "1.0.0-alpha.5",
"@dojoengine/torii-client": "1.0.0-alpha.5",
"@radix-ui/react-slot": "^1.1.0",
"@types/node": "^22.4.2",
Expand Down
3 changes: 3 additions & 0 deletions contracts/target/CACHEDIR.TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by sozo.
# For information about cache directory tags see https://bford.info/cachedir/
129 changes: 129 additions & 0 deletions contracts/target/dev/contracts/dojo_starter_rpg-actions-4afbdb7a.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#[starknet::contract]
pub mod actions {
use dojo::world;
use dojo::world::IWorldDispatcher;
use dojo::world::IWorldDispatcherTrait;
use dojo::world::IWorldProvider;
use dojo::contract::IContract;
use starknet::storage::{
StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess,
StoragePointerWriteAccess
};

component!(
path: dojo::contract::upgradeable::upgradeable,
storage: upgradeable,
event: UpgradeableEvent
);

#[abi(embed_v0)]
pub impl ContractImpl of IContract<ContractState> {
fn contract_name(self: @ContractState) -> ByteArray {
"actions"
}

fn namespace(self: @ContractState) -> ByteArray {
"dojo_starter_rpg"
}

fn tag(self: @ContractState) -> ByteArray {
"dojo_starter_rpg-actions"
}

fn name_hash(self: @ContractState) -> felt252 {
2086192618380495284091910654139796563008957181282529006110721547110208160990
}

fn namespace_hash(self: @ContractState) -> felt252 {
478818318480335965857378696073169770196363091739687234837836645523859370417
}

fn selector(self: @ContractState) -> felt252 {
2119759012706724827775869657687441349302555895191611646984125534702989689384
}
}

#[abi(embed_v0)]
impl WorldProviderImpl of IWorldProvider<ContractState> {
fn world(self: @ContractState) -> IWorldDispatcher {
self.world_dispatcher.read()
}
}

#[abi(embed_v0)]
impl UpgradableImpl =
dojo::contract::upgradeable::upgradeable::UpgradableImpl<ContractState>;

// Component imports

use rpg::components::playable::PlayableComponent;

// Internal imports

use rpg::types::mode::Mode;

// Local imports

use super::IActions;

// Components

component!(path: PlayableComponent, storage: playable, event: PlayableEvent);
impl PlayableInternalImpl = PlayableComponent::InternalImpl<ContractState>;

#[storage]
struct Storage {
world_dispatcher: IWorldDispatcher,
#[substorage(v0)]
upgradeable: dojo::contract::upgradeable::upgradeable::Storage,
#[substorage(v0)]
playable: PlayableComponent::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
UpgradeableEvent: dojo::contract::upgradeable::upgradeable::Event,
#[flat]
PlayableEvent: PlayableComponent::Event
}

// Implementations

#[abi(embed_v0)]
impl ActionsImpl of IActions<ContractState> {
fn spawn(self: @ContractState, name: felt252, role: u8) {
self.playable.spawn(self.world(), name, role, Mode::Medium.into())
}
fn move(self: @ContractState, direction: u8) {
self.playable.move(self.world(), direction)
}
fn attack(self: @ContractState) {
self.playable.attack(self.world())
}
fn heal(self: @ContractState, quantity: u8) {
self.playable.heal(self.world(), quantity)
}
}
#[starknet::interface]
trait IDojoInit<ContractState> {
fn dojo_init(self: @ContractState);
}

#[abi(embed_v0)]
impl IDojoInitImpl of IDojoInit<ContractState> {
fn dojo_init(self: @ContractState) {
assert(
starknet::get_caller_address() == self.world().contract_address,
'Only world can init'
);
assert(
self
.world()
.is_owner(self.selector(), starknet::get_tx_info().account_contract_address),
'Only owner can init'
);
}
}
}

Loading

0 comments on commit 5c5aa5f

Please sign in to comment.