Skip to content

Commit

Permalink
- remove introspectpacked from models with enum
Browse files Browse the repository at this point in the history
- use id alias more
  • Loading branch information
credence0x committed Jul 29, 2024
1 parent 492931b commit 5fd4644
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 56 deletions.
20 changes: 10 additions & 10 deletions contracts/src/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use eternum::alias::ID;


// Config ID to fetch global configs
const WORLD_CONFIG_ID: u32 = 999999999;
const BUILDING_CONFIG_ID: u32 = 999999998;
const TRANSPORT_CONFIG_ID: u32 = 999999996;
const ROAD_CONFIG_ID: u32 = 999999995;
const COMBAT_CONFIG_ID: u32 = 999999994;
const REALM_LEVELING_CONFIG_ID: u32 = 999999993;
const HYPERSTRUCTURE_CONFIG_ID: u32 = 999999992;
const REALM_FREE_MINT_CONFIG_ID: u32 = 999999991;
const BUILDING_CATEGORY_POPULATION_CONFIG_ID: u32 = 999999990;
const POPULATION_CONFIG_ID: u32 = 999999989;
const WORLD_CONFIG_ID: ID = 999999999;
const BUILDING_CONFIG_ID: ID = 999999998;
const TRANSPORT_CONFIG_ID: ID = 999999996;
const ROAD_CONFIG_ID: ID = 999999995;
const COMBAT_CONFIG_ID: ID = 999999994;
const REALM_LEVELING_CONFIG_ID: ID = 999999993;
const HYPERSTRUCTURE_CONFIG_ID: ID = 999999992;
const REALM_FREE_MINT_CONFIG_ID: ID = 999999991;
const BUILDING_CATEGORY_POPULATION_CONFIG_ID: ID = 999999990;
const POPULATION_CONFIG_ID: ID = 999999989;

// 8 bits
const RESOURCE_IDS_PACKED_SIZE: usize = 8_usize;
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/models/buildings.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use eternum::models::resources::{Resource, ResourceCustomImpl, ResourceCost};

//todo we need to define border of innner hexes

#[derive(IntrospectPacked, PartialEq, Copy, Drop, Serde)]
#[derive(PartialEq, Copy, Drop, Serde)]
#[dojo::model]
pub struct Building {
#[key]
Expand All @@ -36,7 +36,7 @@ pub struct Building {
outer_entity_id: ID,
}

#[derive(IntrospectPacked, PartialEq, Copy, Drop, Serde)]
#[derive(PartialEq, Copy, Drop, Serde)]
#[dojo::model]
pub struct BuildingQuantityv2 {
#[key]
Expand Down Expand Up @@ -430,7 +430,7 @@ impl BuildingCustomImpl of BuildingCustomTrait {
assert!(!building.is_active(), "space is occupied");

// set building
building.entity_id = world.uuid().into();
building.entity_id = world.uuid();
building.category = category;
building.outer_entity_id = outer_entity_id;
match produce_resource_type {
Expand Down
20 changes: 10 additions & 10 deletions contracts/src/models/combat.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl ArmyQuantityTracker of ArmyQuantityTrackerTrait {
}
}

#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
#[derive(Copy, Drop, Serde, Default)]
#[dojo::model]
pub struct Army {
#[key]
Expand Down Expand Up @@ -428,7 +428,7 @@ impl ProtecteeCustomImpl of ProtecteeCustomTrait {
}


#[derive(IntrospectPacked, Copy, Drop, Serde, Default)]
#[derive(Copy, Drop, Serde, Default)]
#[dojo::model]
pub struct Battle {
#[key]
Expand Down Expand Up @@ -866,7 +866,7 @@ mod tests {

// recreate army for testing
let attack_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(attack_troop_each, attack_troop_each, attack_troop_each),
battle_id: battle.entity_id,
battle_side: BattleSide::Attack
Expand Down Expand Up @@ -914,7 +914,7 @@ mod tests {

// recreate army for testing
let attack_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(attack_troop_each, attack_troop_each, attack_troop_each),
battle_id: battle.entity_id,
battle_side: BattleSide::Attack
Expand Down Expand Up @@ -969,7 +969,7 @@ mod tests {
///
// recreate defense army for testing
let defence_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(defence_troop_each, defence_troop_each, defence_troop_each),
battle_id: battle.entity_id,
battle_side: BattleSide::Defence
Expand All @@ -989,7 +989,7 @@ mod tests {
///
// recreate army for testing
let attack_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(attack_troop_each, attack_troop_each, attack_troop_each), // has no effect on outcome
battle_id: battle.entity_id,
battle_side: BattleSide::Attack
Expand Down Expand Up @@ -1051,7 +1051,7 @@ mod tests {
///
// recreate defense army for testing
let defence_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(defence_troop_each, defence_troop_each, defence_troop_each),
battle_id: battle.entity_id,
battle_side: BattleSide::Defence
Expand All @@ -1071,7 +1071,7 @@ mod tests {
///
// recreate army for testing
let attack_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(attack_troop_each, attack_troop_each, attack_troop_each),
battle_id: battle.entity_id,
battle_side: BattleSide::Attack
Expand Down Expand Up @@ -1140,7 +1140,7 @@ mod tests {
///
// recreate defense army for testing
let defence_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(defence_troop_each, defence_troop_each, defence_troop_each),
battle_id: battle.entity_id,
battle_side: BattleSide::Defence
Expand All @@ -1160,7 +1160,7 @@ mod tests {
///
// recreate attack army for testing
let attack_army = Army {
entity_id: world.uuid().into(),
entity_id: world.uuid(),
troops: mock_troops(attack_troop_each, attack_troop_each, attack_troop_each),
battle_id: battle.entity_id,
battle_side: BattleSide::Attack
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/models/config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub struct BankConfig {
lp_fee_denom: u128,
}

#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct BuildingConfig {
#[key]
Expand Down Expand Up @@ -316,7 +316,7 @@ impl BattleConfigCustomImpl of BattleConfigCustomTrait {
}


#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct BuildingCategoryPopConfig {
#[key]
Expand Down Expand Up @@ -355,6 +355,6 @@ pub struct HasClaimedStartingResources {
#[key]
entity_id: ID,
#[key]
config_id: u32,
config_id: ID,
claimed: bool,
}
2 changes: 1 addition & 1 deletion contracts/src/models/map.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use eternum::alias::ID;
use eternum::models::position::Coord;
use eternum::utils::map::biomes::Biome;

#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct Tile {
#[key]
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/models/order.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use eternum::alias::ID;
pub struct Orders {
#[key]
order_id: ID,
hyperstructure_count: u128
hyperstructure_count: u32
}

#[generate_trait]
impl OrdersCustomImpl of OrdersCustomTrait {
fn get_bonus_multiplier(self: Orders) -> u128 {
self.hyperstructure_count * 25
self.hyperstructure_count.into() * 25
}

fn get_bonus_denominator(self: Orders) -> u128 {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/production.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Production {
entity_id: ID,
#[key]
resource_type: u8,
building_count: u128,
building_count: u8,
production_rate: u128,
consumption_rate: u128,
last_updated_tick: u64,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/structure.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use eternum::utils::unpack::unpack_resource_types;
use starknet::ContractAddress;
use traits::Into;

#[derive(IntrospectPacked, Copy, Drop, Serde)]
#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct Structure {
#[key]
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/systems/bank/contracts/bank.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod bank_systems {
fn create_bank(
ref world: IWorldDispatcher, realm_entity_id: ID, coord: Coord, owner_fee_num: u128, owner_fee_denom: u128,
) -> ID {
let bank_entity_id: ID = world.uuid().into();
let bank_entity_id: ID = world.uuid();

//todo: check that tile is explored

Expand Down
8 changes: 4 additions & 4 deletions contracts/src/systems/combat/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ mod combat_systems {
let defending_army_position: Position = get!(world, defending_army_id, Position);
attacking_army_position.assert_same_location(defending_army_position.into());

let battle_id: ID = world.uuid().into();
let battle_id: ID = world.uuid();
attacking_army.battle_id = battle_id;
attacking_army.battle_side = BattleSide::Attack;
set!(world, (attacking_army));
Expand Down Expand Up @@ -653,8 +653,8 @@ mod combat_systems {
battle.attack_army_lifetime = attacking_army.into();
battle.defence_army = defending_army.into();
battle.defence_army_lifetime = defending_army.into();
battle.attackers_resources_escrow_id = world.uuid().into();
battle.defenders_resources_escrow_id = world.uuid().into();
battle.attackers_resources_escrow_id = world.uuid();
battle.defenders_resources_escrow_id = world.uuid();
battle.attack_army_health = attacking_army_health.into();
battle.defence_army_health = defending_army_health.into();
battle.last_updated = starknet::get_block_timestamp();
Expand Down Expand Up @@ -1201,7 +1201,7 @@ mod combat_systems {
set!(world, (owner_armies_quantity));

// create army
let mut army_id: ID = world.uuid().into();
let mut army_id: ID = world.uuid();
let army_owner_position: Position = get!(world, army_owner_id, Position);
set!(
world,
Expand Down
16 changes: 8 additions & 8 deletions contracts/src/systems/config/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait IWorldConfig {

#[dojo::interface]
trait IRealmFreeMintConfig {
fn set_mint_config(ref world: IWorldDispatcher, config_id: u32, resources: Span<(u8, u128)>);
fn set_mint_config(ref world: IWorldDispatcher, config_id: ID, resources: Span<(u8, u128)>);
}


Expand Down Expand Up @@ -171,10 +171,10 @@ mod config_systems {

#[abi(embed_v0)]
impl RealmFreeMintConfigCustomImpl of super::IRealmFreeMintConfig<ContractState> {
fn set_mint_config(ref world: IWorldDispatcher, config_id: u32, resources: Span<(u8, u128)>) {
fn set_mint_config(ref world: IWorldDispatcher, config_id: ID, resources: Span<(u8, u128)>) {
assert_caller_is_admin(world);

let detached_resource_id = world.uuid().into();
let detached_resource_id = world.uuid();
let detached_resource_count = resources.len();
let mut resources = resources;
let mut index = 0;
Expand Down Expand Up @@ -305,7 +305,7 @@ mod config_systems {
) {
assert_caller_is_admin(world);

let resource_1_cost_id = world.uuid().into();
let resource_1_cost_id = world.uuid();
let mut index = 0;
loop {
if index == resource_1_costs.len() {
Expand All @@ -320,7 +320,7 @@ mod config_systems {
index += 1;
};

let resource_2_cost_id = world.uuid().into();
let resource_2_cost_id = world.uuid();
let mut index = 0;
loop {
if index == resource_2_costs.len() {
Expand All @@ -335,7 +335,7 @@ mod config_systems {
index += 1;
};

let resource_3_cost_id = world.uuid().into();
let resource_3_cost_id = world.uuid();
let mut index = 0;
loop {
if index == resource_3_costs.len() {
Expand Down Expand Up @@ -432,7 +432,7 @@ mod config_systems {
fn set_road_config(ref world: IWorldDispatcher, resource_costs: Span<(u8, u128)>, speed_up_by: u64) {
assert_caller_is_admin(world);

let resource_cost_id = world.uuid().into();
let resource_cost_id = world.uuid();
let mut index = 0;
loop {
if index == resource_costs.len() {
Expand Down Expand Up @@ -542,7 +542,7 @@ mod config_systems {
) {
assert_caller_is_admin(world);

let resource_cost_id = world.uuid().into();
let resource_cost_id = world.uuid();
let mut index = 0;
loop {
if index == cost_of_building.len() {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/systems/guild/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod guild_systems {
// Add min name length
assert(guild_name != 0, 'Guild name cannot be empty');

let guild_uuid: ID = world.uuid().into();
let guild_uuid: ID = world.uuid();

set!(
world,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/systems/hyperstructure/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod hyperstructure_systems {
creator_resources.burn(hyperstructure_shards_config.amount_for_completion);
creator_resources.save(world);

let new_uuid: ID = world.uuid().into();
let new_uuid: ID = world.uuid();

set!(
world,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/systems/map/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod map_systems {
}

fn create_shard_mine_structure(world: IWorldDispatcher, coord: Coord) -> ID {
let entity_id: ID = world.uuid().into();
let entity_id: ID = world.uuid();
set!(
world,
(
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/systems/map/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ fn test_map_explore() {
assert_eq!(realm_wheat.balance, expected_wheat_balance, "wrong wheat balance");
assert_eq!(realm_fish.balance, expected_fish_balance, "wrong wheat balance");

army_coord = expected_explored_coord;
let mut new_army_coord: Coord = get!(world, realm_army_unit_id, Position).into();
assert_eq!(new_army_coord, expected_explored_coord);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/systems/realm/contracts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait IRealmSystems {
order: u8,
position: eternum::models::position::Position
) -> ID;
fn mint_starting_resources(ref world: IWorldDispatcher, config_id: u32, entity_id: ID) -> ID;
fn mint_starting_resources(ref world: IWorldDispatcher, config_id: ID, entity_id: ID) -> ID;
}


Expand Down Expand Up @@ -47,7 +47,7 @@ mod realm_systems {

#[abi(embed_v0)]
impl RealmSystemsImpl of super::IRealmSystems<ContractState> {
fn mint_starting_resources(ref world: IWorldDispatcher, config_id: u32, entity_id: ID) -> ID {
fn mint_starting_resources(ref world: IWorldDispatcher, config_id: ID, entity_id: ID) -> ID {
get!(world, (entity_id), Realm).assert_is_set();

let mut claimed_resources = get!(world, (entity_id, config_id), HasClaimedStartingResources);
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/systems/realm/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use eternum::alias::ID;
use eternum::constants::MAX_REALMS_PER_ADDRESS;

use eternum::constants::ResourceTypes;
Expand All @@ -25,7 +26,6 @@ use eternum::utils::testing::{
},
config::{set_combat_config}
};

use starknet::contract_address_const;

const TIMESTAMP: u64 = 1000;
Expand All @@ -36,7 +36,7 @@ const INITIAL_RESOURCE_1_AMOUNT: u128 = 800;
const INITIAL_RESOURCE_2_TYPE: u8 = 2;
const INITIAL_RESOURCE_2_AMOUNT: u128 = 700;

const REALM_FREE_MINT_CONFIG_ID: u32 = 0;
const REALM_FREE_MINT_CONFIG_ID: ID = 0;

fn setup() -> (IWorldDispatcher, IRealmSystemsDispatcher) {
let world = spawn_eternum();
Expand Down
Loading

0 comments on commit 5fd4644

Please sign in to comment.