Skip to content

Commit

Permalink
change table / admin
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Apr 2, 2024
1 parent 9e51294 commit 9273e15
Show file tree
Hide file tree
Showing 19 changed files with 673 additions and 181 deletions.
87 changes: 63 additions & 24 deletions src/config/config.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use rollyourown::config::{
hustlers::{HustlerConfig, HustlerImpl},
game::{GameConfig}
game::{GameConfig}, drugs::{DrugConfig}
};


#[starknet::interface]
trait IConfig<T> {
fn initialize(ref self: T);
fn get_config(self: @T) -> Config;
// fn update_drug_config(ref self: T);
fn update_game_config(self: @T, game_config: GameConfig);
fn update_drug_config(self: @T, drug_config: DrugConfig);

// fn update_drug_config_meta(ref self: T);
// ...
}
Expand Down Expand Up @@ -37,25 +39,28 @@ struct LayoutItem {

#[dojo::contract]
mod config {
use rollyourown::config::{
game::{initialize_game_config, GameConfig, GameConfigImpl},
drugs::initialize_drug_config, locations::initialize_location_config,
hustlers::{
HustlerConfig, HustlerImpl, initialize_weapons_config, initialize_clothes_config,
initialize_feet_config, initialize_transport_config, initialize_weapons_tiers_config,
initialize_clothes_tiers_config, initialize_feet_tiers_config,
initialize_transport_tiers_config,
}
};

use rollyourown::packing::{
game_store_layout::{
GameStoreLayout, GameStoreLayoutEnumerableImpl, GameStoreLayoutPackableImpl,
GameStoreLayoutIntoBytes31Impl
use starknet::{get_caller_address, get_contract_address};

use rollyourown::{
config::{
game::{initialize_game_config, GameConfig, GameConfigImpl},
drugs::{initialize_drug_config, DrugConfig, Drugs}, locations::initialize_location_config,
hustlers::{
HustlerConfig, HustlerImpl, initialize_weapons_config, initialize_clothes_config,
initialize_feet_config, initialize_transport_config, initialize_weapons_tiers_config,
initialize_clothes_tiers_config, initialize_feet_tiers_config,
initialize_transport_tiers_config,
}
},
player_layout::{
PlayerLayout, PlayerLayoutEnumerableImpl, PlayerLayoutPackableImpl,
PlayerLayoutIntoBytes31Impl
packing::{
game_store_layout::{
GameStoreLayout, GameStoreLayoutEnumerableImpl, GameStoreLayoutPackableImpl,
GameStoreLayoutIntoBytes31Impl
},
player_layout::{
PlayerLayout, PlayerLayoutEnumerableImpl, PlayerLayoutPackableImpl,
PlayerLayoutIntoBytes31Impl
}
}
};

Expand All @@ -64,12 +69,11 @@ mod config {
#[abi(embed_v0)]
impl ConfigImpl of super::IConfig<ContractState> {
fn initialize(ref self: ContractState) {
let world = self.world();
// TODO checks
self.assert_caller_is_owner();

// only world owner
assert(world.is_owner(starknet::get_caller_address(), 0), 'only world owner');

let world = self.world();

// common
initialize_drug_config(world);
initialize_location_config(world);
Expand Down Expand Up @@ -148,5 +152,40 @@ mod config {
//
Config { game_config, layouts: LayoutsConfig { game_store, player }, hustlers }
}

fn update_game_config(self: @ContractState, game_config: GameConfig) {
self.assert_caller_is_owner();
GameConfigImpl::set(self.world(), game_config);
}


fn update_drug_config(self: @ContractState, drug_config: DrugConfig) {
self.assert_caller_is_owner();

let drug: Drugs = drug_config.drug_id.into();
let mut to_update = get!(self.world(), (drug), (DrugConfig));

to_update.base = drug_config.base;
to_update.step = drug_config.step;
to_update.weight = drug_config.weight;
to_update.name = drug_config.name;

set!(self.world(), (to_update));
}


}

#[generate_trait]
impl InternalImpl of InternalTrait {
fn assert_caller_is_owner(self: @ContractState) {
// assert(self.world().is_owner(starknet::get_caller_address(), 0), 'only world owner');

assert(
self.world().is_owner(get_caller_address(), get_contract_address().into()),
'not owner'
);
}

}
}
8 changes: 8 additions & 0 deletions src/config/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ impl GameConfigImpl of GameConfigTrait {
fn get(world: IWorldDispatcher) -> GameConfig {
get!(world, (GAME_CONFIG_KEY), GameConfig)
}

#[inline(always)]
fn set(world: IWorldDispatcher, game_config: GameConfig) {
let mut game_config = game_config;
game_config.key = GAME_CONFIG_KEY;

set!(world, (game_config));
}
}

fn initialize_game_config(world: IWorldDispatcher) {
Expand Down
104 changes: 103 additions & 1 deletion web/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@
{
"name": "rollyourown::config::config::config",
"address": "0x73e5a7b0f2ff860ae67f9edc7709d3dbbee30f84afcccf1f8e3963e128e1bc5",
"class_hash": "0x41dde9b72449ef0e0cb33fa1003a92b88590b9b33aa9c5e6ccb61f65ddf2f95",
"class_hash": "0x52518ade8db331d80706e5a99faa43a82c88a8eeaf6e845f9c80ff2fb60f397",
"abi": [
{
"type": "impl",
Expand Down Expand Up @@ -1850,6 +1850,84 @@
}
]
},
{
"type": "enum",
"name": "rollyourown::config::drugs::Drugs",
"variants": [
{
"name": "Ludes",
"type": "()"
},
{
"name": "Speed",
"type": "()"
},
{
"name": "Weed",
"type": "()"
},
{
"name": "Shrooms",
"type": "()"
},
{
"name": "Acid",
"type": "()"
},
{
"name": "Ketamine",
"type": "()"
},
{
"name": "Heroin",
"type": "()"
},
{
"name": "Cocaine",
"type": "()"
}
]
},
{
"type": "struct",
"name": "rollyourown::utils::bytes16::Bytes16",
"members": [
{
"name": "value",
"type": "core::integer::u128"
}
]
},
{
"type": "struct",
"name": "rollyourown::config::drugs::DrugConfig",
"members": [
{
"name": "drug",
"type": "rollyourown::config::drugs::Drugs"
},
{
"name": "drug_id",
"type": "core::integer::u8"
},
{
"name": "base",
"type": "core::integer::u16"
},
{
"name": "step",
"type": "core::integer::u16"
},
{
"name": "weight",
"type": "core::integer::u16"
},
{
"name": "name",
"type": "rollyourown::utils::bytes16::Bytes16"
}
]
},
{
"type": "interface",
"name": "rollyourown::config::config::IConfig",
Expand All @@ -1871,6 +1949,30 @@
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "update_game_config",
"inputs": [
{
"name": "game_config",
"type": "rollyourown::config::game::GameConfig"
}
],
"outputs": [],
"state_mutability": "view"
},
{
"type": "function",
"name": "update_drug_config",
"inputs": [
{
"name": "drug_config",
"type": "rollyourown::config::drugs::DrugConfig"
}
],
"outputs": [],
"state_mutability": "view"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
"graphql-request": "^5.0.0",
"graphql-ws": "^5.14.1",
"howler": "^2.2.3",
"ka-table": "^8.11.0",
"mobx": "^6.10.2",
"mobx-react-lite": "^4.0.5",
"next": "14.1.4",
"next-pwa": "^5.6.0",
"react": "^18.2.0",
"react-countdown": "^2.3.5",
"react-data-table-component": "^7.6.2",
"react-dom": "^18.2.0",
"react-json-view-lite": "^1.2.1",
"react-query": "^3.39.2",
Expand Down
Loading

0 comments on commit 9273e15

Please sign in to comment.