-
Notifications
You must be signed in to change notification settings - Fork 1
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
19 changed files
with
240 additions
and
296 deletions.
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
use cc_starknet::utils::pack::{Pack, PackTrait}; | ||
use starknet::ContractAddress; | ||
|
||
#[derive(Model, Copy, Drop, Serde)] | ||
struct MapCC { | ||
#[key] | ||
id: u32, | ||
token_id: u64, | ||
size: u8, | ||
obstacles_1: felt252, | ||
obstacles_2: felt252, | ||
obstacles_3: felt252, | ||
owner: felt252, | ||
width: u64, | ||
height: u64, | ||
} | ||
|
||
trait MapCCTrait { | ||
fn is_inside(self: MapCC, position: (u64, u64)) -> bool; | ||
fn is_walkable(self: MapCC, position: (u64, u64)) -> bool; | ||
fn get_value(self: MapCC, position: (u64, u64)) -> ByteArray; | ||
} | ||
|
||
impl MapCCImpl of MapCCTrait { | ||
fn is_inside(self: MapCC, position: (u64, u64)) -> bool { | ||
let (x, y) = position; | ||
x >= 0 && x < self.width && y >= 0 && y < self.height | ||
} | ||
|
||
fn is_walkable(self: MapCC, position: (u64, u64)) -> bool { | ||
let mut pack = Pack { | ||
first: self.obstacles_1, second: self.obstacles_2, third: self.obstacles_3 | ||
}; | ||
let (x, y) = position; | ||
!PackTrait::get_bit(ref pack, (y * 25 + x).into()) | ||
} | ||
|
||
fn get_value(self: MapCC, position: (u64, u64)) -> ByteArray { | ||
let mut pack = Pack { | ||
first: self.obstacles_1, second: self.obstacles_2, third: self.obstacles_3 | ||
}; | ||
let (x, y) = position; | ||
if PackTrait::get_bit(ref pack, (y * 25 + x).into()) { | ||
"X" | ||
} else { | ||
"_" | ||
} | ||
} | ||
} | ||
|
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
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
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,60 @@ | ||
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; | ||
|
||
#[starknet::interface] | ||
trait IMapCCSystem<TContractState> { | ||
fn init(ref self: TContractState); | ||
} | ||
|
||
#[dojo::contract] | ||
mod map_cc_system { | ||
use super::IMapCCSystem; | ||
use starknet::{get_caller_address, ContractAddress}; | ||
use starkane::models::entities::map_cc::MapCC; | ||
use starkane::store::{Store, StoreTrait}; | ||
use cc_starknet::{Dungeons, utils::pack::Pack}; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[external(v0)] | ||
impl MapCCSystem of IMapCCSystem<ContractState> { | ||
fn init(ref self: ContractState) { | ||
// [Setup] Datastore | ||
let world = self.world(); | ||
let mut store: Store = StoreTrait::new(world); | ||
|
||
let mut state = Dungeons::unsafe_new_contract_state(); | ||
Dungeons::mint(ref state); | ||
// let dungeon = Dungeons::generate_dungeon_dojo(@state, 1); | ||
let player = get_caller_address(); | ||
|
||
let (pack, size) = Dungeons::get_layout( | ||
@state, | ||
2736342820117253318139212381411529799466697035823955982763560346397174457569, | ||
26 | ||
); | ||
// let (pack, size) = Dungeons::get_layout(@state, 5472685640234506636278424762823059598933394071647911965527120692794348915138, 25); | ||
// println!("first: {}", pack.first); | ||
// println!("second: {}", pack.second); | ||
// println!("third: {}", pack.third); | ||
|
||
set!( | ||
world, | ||
MapCC { | ||
id: 1, | ||
token_id: 1, | ||
size: 25, | ||
obstacles_1: pack.first, | ||
obstacles_2: pack.second, | ||
obstacles_3: pack.third, | ||
// obstacles_1: dungeon.layout.first, | ||
// obstacles_2: dungeon.layout.second, | ||
// obstacles_3: dungeon.layout.third, | ||
owner: Dungeons::ERC721Impl::owner_of(@state, 1).into(), | ||
width: 25, | ||
height: 25, | ||
} | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.