From db979d5d329cf8b791fb1a626c7c27e80b0fa21c Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Fri, 24 Nov 2023 14:21:47 +0100 Subject: [PATCH 1/4] added hex map and example with noise --- Scarb.lock | 18 +++- Scarb.toml | 13 +-- crates/src/lib.cairo | 7 ++ crates/src/map/hex/hex.cairo | 134 +++++++++++++++++++++++++ crates/src/map/hex/types.cairo | 28 ++++++ examples/hex_map/Scarb.toml | 10 ++ examples/hex_map/src/actions.cairo | 151 +++++++++++++++++++++++++++++ examples/hex_map/src/lib.cairo | 3 + examples/hex_map/src/models.cairo | 52 ++++++++++ examples/hex_map/src/noise.cairo | 72 ++++++++++++++ examples/market/Scarb.lock | 27 ------ examples/projectile/Scarb.lock | 22 ----- 12 files changed, 475 insertions(+), 62 deletions(-) create mode 100644 crates/src/map/hex/hex.cairo create mode 100644 crates/src/map/hex/types.cairo create mode 100644 examples/hex_map/Scarb.toml create mode 100644 examples/hex_map/src/actions.cairo create mode 100644 examples/hex_map/src/lib.cairo create mode 100644 examples/hex_map/src/models.cairo create mode 100644 examples/hex_map/src/noise.cairo delete mode 100644 examples/market/Scarb.lock delete mode 100644 examples/projectile/Scarb.lock diff --git a/Scarb.lock b/Scarb.lock index 222ed0fe..78602e2b 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -8,15 +8,25 @@ source = "git+https://github.com/influenceth/cubit?rev=b459053#b4590530d5aeae9aa [[package]] name = "dojo" -version = "0.3.10" -source = "git+https://github.com/dojoengine/dojo?tag=v0.3.10#be1676252c41f8188465741edcbcb381d2c12080" +version = "0.3.12" +source = "git+https://github.com/dojoengine/dojo?tag=v0.3.12#12d58f29ec53454317f1f6d265007a053d279288" dependencies = [ "dojo_plugin", ] [[package]] name = "dojo_plugin" -version = "0.3.10" +version = "0.3.11" +source = "git+https://github.com/dojoengine/dojo?tag=v0.3.11#1e651b5d4d3b79b14a7d8aa29a92062fcb9e6659" + +[[package]] +name = "hex_map" +version = "0.0.0" +dependencies = [ + "cubit", + "dojo", + "origami", +] [[package]] name = "market" @@ -28,7 +38,7 @@ dependencies = [ [[package]] name = "origami" -version = "0.0.0" +version = "0.1.0" dependencies = [ "cubit", "dojo", diff --git a/Scarb.toml b/Scarb.toml index 58e2f8ac..679a9605 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,18 +1,13 @@ [workspace] -members = [ - "crates", - "examples/*", -] +members = ["crates", "examples/*"] [workspace.package] -version = "0.0.0" +version = "0.1.0" description = "Community-maintained libraries for Cairo" homepage = "https://github.com/dojoengine/origami" -authors = [ - "bal7hazar@proton.me", -] +authors = ["bal7hazar@proton.me"] [workspace.dependencies] cubit = { git = "https://github.com/influenceth/cubit", rev = "b459053" } -dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.3.10" } +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.3.12" } origami = { path = "crates" } diff --git a/crates/src/lib.cairo b/crates/src/lib.cairo index ab74b522..8c56b3c6 100644 --- a/crates/src/lib.cairo +++ b/crates/src/lib.cairo @@ -20,3 +20,10 @@ mod random { mod security { mod commitment; } + +mod map { + mod hex { + mod hex; + mod types; + } +} diff --git a/crates/src/map/hex/hex.cairo b/crates/src/map/hex/hex.cairo new file mode 100644 index 00000000..a7b3928d --- /dev/null +++ b/crates/src/map/hex/hex.cairo @@ -0,0 +1,134 @@ +use origami::map::hex::{types::{HexTile, Direction, DirectionIntoFelt252}}; + +trait IHexTile { + fn new(col: u32, row: u32) -> HexTile; + fn neighbor(self: HexTile, direction: Direction) -> HexTile; + fn neighbors(self: HexTile) -> Array; + fn is_neighbor(self: HexTile, other: HexTile) -> bool; +} + +impl ImplHexTile of IHexTile { + fn new(col: u32, row: u32) -> HexTile { + HexTile { col, row } + } + + fn neighbor(self: HexTile, direction: Direction) -> HexTile { + match direction { + Direction::East(()) => HexTile { col: self.col + 1, row: self.row }, + Direction::NorthEast(()) => HexTile { col: self.col + 1, row: self.row - 1 }, + Direction::NorthWest(()) => HexTile { col: self.col, row: self.row - 1 }, + Direction::West(()) => HexTile { col: self.col - 1, row: self.row }, + Direction::SouthWest(()) => HexTile { col: self.col, row: self.row + 1 }, + Direction::SouthEast(()) => HexTile { col: self.col + 1, row: self.row + 1 }, + } + } + + fn neighbors(self: HexTile) -> Array { + array![ + self.neighbor(Direction::East(())), + self.neighbor(Direction::NorthEast(())), + self.neighbor(Direction::NorthWest(())), + self.neighbor(Direction::West(())), + self.neighbor(Direction::SouthWest(())), + self.neighbor(Direction::SouthEast(())) + ] + } + + fn is_neighbor(self: HexTile, other: HexTile) -> bool { + let mut neighbors = self.neighbors(); + + loop { + if (neighbors.len() == 0) { + break false; + } + + let curent_neighbor = neighbors.pop_front().unwrap(); + + if (curent_neighbor.col == other.col) { + if (curent_neighbor.row == other.row) { + break true; + } + }; + } + } +} + + +// tests ----------------------------------------------------------------------- // + +#[cfg(test)] +mod tests { + use super::{IHexTile, ImplHexTile, Direction, HexTile}; + #[test] + #[available_gas(500000)] + fn test_row_col() { + let mut hex_tile = ImplHexTile::new(5, 5); + + assert(hex_tile.col == 5, 'col should be 5'); + assert(hex_tile.row == 5, 'row should be 5'); + } + + + #[test] + #[available_gas(500000)] + fn test_hex_tile_neighbors() { + let mut hex_tile = ImplHexTile::new(5, 5); + + let east_neighbor = hex_tile.neighbor(Direction::East(())); + + assert(east_neighbor.col == 6, 'col should be 7'); + assert(east_neighbor.row == 5, 'row should be 5'); + + let north_east_neighbor = hex_tile.neighbor(Direction::NorthEast(())); + + assert(north_east_neighbor.col == 6, 'col should be 6'); + assert(north_east_neighbor.row == 4, 'row should be 4'); + + let north_west_neighbor = hex_tile.neighbor(Direction::NorthWest(())); + + assert(north_west_neighbor.col == 5, 'col should be 5'); + assert(north_west_neighbor.row == 4, 'row should be 4'); + + let west_neighbor = hex_tile.neighbor(Direction::West(())); + + assert(west_neighbor.col == 4, 'col should be 3'); + assert(west_neighbor.row == 5, 'row should be 5'); + + let south_west_neighbor = hex_tile.neighbor(Direction::SouthWest(())); + + assert(south_west_neighbor.col == 5, 'col should be 4'); + assert(south_west_neighbor.row == 6, 'row should be 6'); + + let south_east_neighbor = hex_tile.neighbor(Direction::SouthEast(())); + + assert(south_east_neighbor.col == 6, 'col should be 5'); + assert(south_east_neighbor.row == 6, 'row should be 6'); + } + + #[test] + #[available_gas(501230000)] + fn test_is_neighbor() { + let mut hex_tile = ImplHexTile::new(5, 5); + + assert(hex_tile.is_neighbor(HexTile { col: hex_tile.col + 1, row: hex_tile.row }), 'east'); + + assert( + hex_tile.is_neighbor(HexTile { col: hex_tile.col, row: hex_tile.row + 1 }), 'north east' + ); + + assert( + hex_tile.is_neighbor(HexTile { col: hex_tile.col, row: hex_tile.row - 1 }), 'north west' + ); + + assert(hex_tile.is_neighbor(HexTile { col: hex_tile.col - 1, row: hex_tile.row }), 'west'); + + assert( + hex_tile.is_neighbor(HexTile { col: hex_tile.col, row: hex_tile.row - 1 }), 'south west' + ); + + assert( + hex_tile.is_neighbor(HexTile { col: hex_tile.col + 1, row: hex_tile.row - 1 }), + 'south east' + ); + } +} diff --git a/crates/src/map/hex/types.cairo b/crates/src/map/hex/types.cairo new file mode 100644 index 00000000..a1d28a84 --- /dev/null +++ b/crates/src/map/hex/types.cairo @@ -0,0 +1,28 @@ +#[derive(Drop, Copy, Serde)] +struct HexTile { + col: u32, + row: u32, +} + +#[derive(Drop, Copy, Serde)] +enum Direction { + East: (), + NorthEast: (), + NorthWest: (), + West: (), + SouthWest: (), + SouthEast: (), +} + +impl DirectionIntoFelt252 of Into { + fn into(self: Direction) -> felt252 { + match self { + Direction::East => 0, + Direction::NorthEast => 1, + Direction::NorthWest => 2, + Direction::West => 3, + Direction::SouthWest => 4, + Direction::SouthEast => 5, + } + } +} diff --git a/examples/hex_map/Scarb.toml b/examples/hex_map/Scarb.toml new file mode 100644 index 00000000..1e6bd713 --- /dev/null +++ b/examples/hex_map/Scarb.toml @@ -0,0 +1,10 @@ +[package] +name = "hex_map" +version = "0.0.0" +description = "Example Hex Map with noise" +homepage = "https://github.com/dojoengine/origami/tree/examples/hex_map" + +[dependencies] +cubit.workspace = true +dojo.workspace = true +origami.workspace = true diff --git a/examples/hex_map/src/actions.cairo b/examples/hex_map/src/actions.cairo new file mode 100644 index 00000000..4787d783 --- /dev/null +++ b/examples/hex_map/src/actions.cairo @@ -0,0 +1,151 @@ +// internal imports +use core::Into; +use origami::map::hex::{types::Direction}; + +// define the interface +#[starknet::interface] +trait IActions { + fn spawn(self: @TContractState); + fn move(self: @TContractState, direction: Direction); +} + +// dojo decorator +#[dojo::contract] +mod actions { + use starknet::{ContractAddress, get_caller_address}; + use origami::map::hex::{hex::{IHexTile}, types::{Direction, DirectionIntoFelt252}}; + + use hex_map::models::{Position, Vec2}; + use hex_map::noise::{ITile}; + + use super::IActions; + + // declaring custom event struct + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + Moved: Moved, + } + + // declaring custom event struct + #[derive(Drop, starknet::Event)] + struct Moved { + player: ContractAddress, + direction: Direction + } + + fn next_position(position: Position, direction: Direction) -> Position { + let mut new_position = position; + + // convert to Hex + let hex_tile = IHexTile::new(position.vec.x, position.vec.y); + + // get next next tile + let next_hex = hex_tile.neighbor(direction); + + // check movable + ITile::check_moveable(next_hex); + + // convert back to Position + new_position.vec = Vec2 { x: next_hex.col, y: next_hex.row }; + + new_position + } + + // impl: implement functions specified in trait + #[external(v0)] + impl ActionsImpl of IActions { + // ContractState is defined by system decorator expansion + fn spawn(self: @ContractState) { // Access the world dispatcher for reading. + let world = self.world_dispatcher.read(); + + // Get the address of the current caller, possibly the player's address. + let player = get_caller_address(); + + // Retrieve the player's current position from the world. + let position = get!(world, player, (Position)); + + // Update the world state with the new data. + // 1. Set players moves to 10 + // 2. Move the player's position 100 units in both the x and y direction. + set!(world, (Position { player, vec: Vec2 { x: 10, y: 10 } },)); + } + // Implementation of the move function for the ContractState struct. + fn move(self: @ContractState, direction: Direction) { + // Access the world dispatcher for reading. + let world = self.world_dispatcher.read(); + + // Get the address of the current caller, possibly the player's address. + let player = get_caller_address(); + + // Retrieve the player's current position and moves data from the world. + let mut position = get!(world, player, (Position)); + + // // Calculate the player's next position based on the provided direction. + let next = next_position(position, direction); + + // Update the world state with the new moves data and position. + set!(world, (next)); + + // Emit an event to the world to notify about the player's move. + emit!(world, Moved { player, direction }); + } + } +} +#[cfg(test)] +mod tests { + use starknet::class_hash::Felt252TryIntoClassHash; + + // import world dispatcher + use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; + + // import test utils + use dojo::test_utils::{spawn_test_world, deploy_contract}; + + // import models + use hex_map::models::{position}; + use hex_map::models::{Position, Direction, Vec2}; + + // import actions + use super::{actions, IActionsDispatcher, IActionsDispatcherTrait}; + + fn setup_world() -> (IWorldDispatcher, IActionsDispatcher) { + // models + let mut models = array![position::TEST_CLASS_HASH]; + + // deploy world with models + let world = spawn_test_world(models); + + // deploy systems contract + let contract_address = world + .deploy_contract('salt', actions::TEST_CLASS_HASH.try_into().unwrap()); + let actions_system = IActionsDispatcher { contract_address }; + + (world, actions_system) + } + + #[test] + #[available_gas(30000000)] + fn test_north_east() { + // caller + let caller = starknet::contract_address_const::<0x0>(); + + let (world, actions_system) = setup_world(); + + // call spawn() + actions_system.spawn(); + + // call move with direction right + actions_system.move(Direction::East(())); + + // get new_position + let new_position = get!(world, caller, Position); + + // check new position x + assert(new_position.vec.x == 11, 'position x is wrong'); + + // check new position y + assert(new_position.vec.y == 10, 'position y is wrong'); + } +} + diff --git a/examples/hex_map/src/lib.cairo b/examples/hex_map/src/lib.cairo new file mode 100644 index 00000000..d25852da --- /dev/null +++ b/examples/hex_map/src/lib.cairo @@ -0,0 +1,3 @@ +mod models; +mod actions; +mod noise; diff --git a/examples/hex_map/src/models.cairo b/examples/hex_map/src/models.cairo new file mode 100644 index 00000000..64256048 --- /dev/null +++ b/examples/hex_map/src/models.cairo @@ -0,0 +1,52 @@ +use starknet::ContractAddress; +use origami::map::hex::{types::{Direction}}; + +#[derive(Copy, Drop, Serde, Introspect)] +struct Vec2 { + x: u32, + y: u32 +} + +#[derive(Model, Copy, Drop, Serde)] +struct Position { + #[key] + player: ContractAddress, + vec: Vec2, +} + +trait Vec2Trait { + fn is_zero(self: Vec2) -> bool; + fn is_equal(self: Vec2, b: Vec2) -> bool; +} + +impl Vec2Impl of Vec2Trait { + fn is_zero(self: Vec2) -> bool { + if self.x - self.y == 0 { + return true; + } + false + } + + fn is_equal(self: Vec2, b: Vec2) -> bool { + self.x == b.x && self.y == b.y + } +} +// #[cfg(test)] +// mod tests { +// use super::{Position, Vec2, Vec2Trait}; + +// #[test] +// #[available_gas(100000)] +// fn test_vec_is_zero() { +// assert(Vec2Trait::is_zero(Vec2 { x: 0, y: 0 }), 'not zero'); +// } + +// #[test] +// #[available_gas(100000)] +// fn test_vec_is_equal() { +// let position = Vec2 { x: 420, y: 0 }; +// assert(position.is_equal(Vec2 { x: 420, y: 0 }), 'not equal'); +// } +// } + + diff --git a/examples/hex_map/src/noise.cairo b/examples/hex_map/src/noise.cairo new file mode 100644 index 00000000..b71aa6f5 --- /dev/null +++ b/examples/hex_map/src/noise.cairo @@ -0,0 +1,72 @@ +use cubit::f64::procgen::simplex3; +use cubit::f64::types::vec3::{Vec3, Vec3Trait}; +use cubit::f64::types::fixed::{Fixed, FixedTrait, FixedPrint, FixedImpl, ONE}; + +use origami::map::hex::{types::{Direction, HexTile}}; +use origami::map::hex::{hex::{IHexTile, ImplHexTile}}; + +mod TileType { + const WATER: u8 = 0; + const LAND: u8 = 1; + const HILL: u8 = 2; + const MOUNTAIN: u8 = 3; +} + +#[generate_trait] +impl ImplTile of ITile { + fn terrain_type(self: HexTile) -> u8 { + let simplex = simplex3::noise( + Vec3Trait::new( + FixedTrait::new_unscaled(self.col.into(), false), + FixedTrait::new_unscaled(self.row.into(), false), + FixedTrait::from_felt(0) + ) + ); + + let mag = simplex.mag; + let one: u64 = ONE.into(); + + if mag > (one * 3 / 4) { + TileType::MOUNTAIN + } else if mag > (one * 2 / 4) { + TileType::HILL + } else if mag > (one * 1 / 4) { + TileType::LAND + } else { + TileType::WATER + } + } + fn check_moveable(self: HexTile) { + assert(self.terrain_type() != TileType::WATER, 'Cannot walk on water'); + } +} + +#[cfg(test)] +mod tests { + use traits::{TryInto, Into}; + use option::OptionTrait; + use debug::PrintTrait; + use super::{Direction, HexTile, ImplHexTile, ITile}; + + #[test] + #[available_gas(500000000)] + fn test_gradient() { + let mut i = 5; + + let mut tile = ImplHexTile::new(7, 5); + + let neighbors = tile.neighbors(); + + let mut j = 0; + loop { + if (j >= neighbors.len()) { + break; + } + let n = *neighbors.at(j); + + j += 1; + }; + + i += 1; + } +} diff --git a/examples/market/Scarb.lock b/examples/market/Scarb.lock deleted file mode 100644 index f74da0a2..00000000 --- a/examples/market/Scarb.lock +++ /dev/null @@ -1,27 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "cubit" -version = "1.2.0" -source = "git+https://github.com/influenceth/cubit?rev=b459053#b4590530d5aeae9aabd36740cc2a3d9e6adc5fde" - -[[package]] -name = "dojo" -version = "0.3.3" -source = "git+https://github.com/dojoengine/dojo.git?tag=v0.3.3#3c9f109e667ca5d12739e6553fdb8261378f4ecf" -dependencies = [ - "dojo_plugin", -] - -[[package]] -name = "dojo_plugin" -version = "0.3.3" - -[[package]] -name = "market" -version = "0.0.0" -dependencies = [ - "cubit", - "dojo", -] diff --git a/examples/projectile/Scarb.lock b/examples/projectile/Scarb.lock deleted file mode 100644 index b518dd7b..00000000 --- a/examples/projectile/Scarb.lock +++ /dev/null @@ -1,22 +0,0 @@ -# Code generated by scarb DO NOT EDIT. -version = 1 - -[[package]] -name = "algebra" -version = "0.0.0" -dependencies = [ - "cubit", -] - -[[package]] -name = "cubit" -version = "1.2.0" -source = "git+https://github.com/influenceth/cubit?rev=b459053#b4590530d5aeae9aabd36740cc2a3d9e6adc5fde" - -[[package]] -name = "projectile" -version = "0.0.0" -dependencies = [ - "algebra", - "cubit", -] From 3db662ab4bab3813e6032c10d01d7355e9db2178 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Fri, 24 Nov 2023 14:38:55 +0100 Subject: [PATCH 2/4] more tests --- examples/hex_map/readme.md | 5 ++ examples/hex_map/src/actions.cairo | 122 ++++++++++++++++++++++++++--- examples/hex_map/src/noise.cairo | 8 ++ 3 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 examples/hex_map/readme.md diff --git a/examples/hex_map/readme.md b/examples/hex_map/readme.md new file mode 100644 index 00000000..4c9cd554 --- /dev/null +++ b/examples/hex_map/readme.md @@ -0,0 +1,5 @@ +## Hex map with noise + +This example uses the hex grid origami component along with cubits simplex noise. + +You can replicate the noise in a client to mirror the onchain noise with the offchain noise to provide users with a rich map to explore. diff --git a/examples/hex_map/src/actions.cairo b/examples/hex_map/src/actions.cairo index 4787d783..db502eca 100644 --- a/examples/hex_map/src/actions.cairo +++ b/examples/hex_map/src/actions.cairo @@ -52,25 +52,15 @@ mod actions { new_position } - // impl: implement functions specified in trait #[external(v0)] impl ActionsImpl of IActions { // ContractState is defined by system decorator expansion fn spawn(self: @ContractState) { // Access the world dispatcher for reading. let world = self.world_dispatcher.read(); - // Get the address of the current caller, possibly the player's address. - let player = get_caller_address(); - - // Retrieve the player's current position from the world. - let position = get!(world, player, (Position)); - - // Update the world state with the new data. - // 1. Set players moves to 10 - // 2. Move the player's position 100 units in both the x and y direction. - set!(world, (Position { player, vec: Vec2 { x: 10, y: 10 } },)); + set!(world, (Position { player: get_caller_address(), vec: Vec2 { x: 10, y: 10 } })); } - // Implementation of the move function for the ContractState struct. + // Moves player in the provided direction. fn move(self: @ContractState, direction: Direction) { // Access the world dispatcher for reading. let world = self.world_dispatcher.read(); @@ -94,6 +84,7 @@ mod actions { } #[cfg(test)] mod tests { + use debug::PrintTrait; use starknet::class_hash::Felt252TryIntoClassHash; // import world dispatcher @@ -126,7 +117,7 @@ mod tests { #[test] #[available_gas(30000000)] - fn test_north_east() { + fn test_east() { // caller let caller = starknet::contract_address_const::<0x0>(); @@ -147,5 +138,110 @@ mod tests { // check new position y assert(new_position.vec.y == 10, 'position y is wrong'); } + + + #[test] + #[should_panic(expected: ('Cannot walk on water', 'ENTRYPOINT_FAILED'))] + #[available_gas(30000000)] + fn test_south_east() { + // caller + let caller = starknet::contract_address_const::<0x0>(); + + let (world, actions_system) = setup_world(); + + // call spawn() + actions_system.spawn(); + + // call move with direction right + actions_system.move(Direction::SouthEast(())); + + // get new_position + let new_position = get!(world, caller, Position); + } + + #[test] + #[available_gas(30000000)] + fn test_south() { + // caller + let caller = starknet::contract_address_const::<0x0>(); + + let (world, actions_system) = setup_world(); + + // call spawn() + actions_system.spawn(); + + // call move with direction right + actions_system.move(Direction::SouthWest(())); + + // get new_position + let new_position = get!(world, caller, Position); + + // check new position x + assert(new_position.vec.x == 10, 'position x is wrong'); + + // check new position y + assert(new_position.vec.y == 11, 'position y is wrong'); + } + #[test] + #[should_panic(expected: ('Cannot walk on water', 'ENTRYPOINT_FAILED'))] + #[available_gas(30000000)] + fn test_north() { + // caller + let caller = starknet::contract_address_const::<0x0>(); + + let (world, actions_system) = setup_world(); + + // call spawn() + actions_system.spawn(); + + // call move with direction right + actions_system.move(Direction::West(())); + + // get new_position + let new_position = get!(world, caller, Position); + } + + #[test] + #[available_gas(30000000)] + fn test_north_west() { + // caller + let caller = starknet::contract_address_const::<0x0>(); + + let (world, actions_system) = setup_world(); + + // call spawn() + actions_system.spawn(); + + // call move with direction right + actions_system.move(Direction::NorthWest(())); + + // get new_position + let new_position = get!(world, caller, Position); + + // check new position x + assert(new_position.vec.x == 10, 'position x is wrong'); + + // check new position y + assert(new_position.vec.y == 9, 'position y is wrong'); + } + + #[test] + #[should_panic(expected: ('Cannot walk on water', 'ENTRYPOINT_FAILED'))] + #[available_gas(30000000)] + fn test_north_east() { + // caller + let caller = starknet::contract_address_const::<0x0>(); + + let (world, actions_system) = setup_world(); + + // call spawn() + actions_system.spawn(); + + // call move with direction right + actions_system.move(Direction::NorthEast(())); + + // get new_position + let new_position = get!(world, caller, Position); + } } diff --git a/examples/hex_map/src/noise.cairo b/examples/hex_map/src/noise.cairo index b71aa6f5..dcebe720 100644 --- a/examples/hex_map/src/noise.cairo +++ b/examples/hex_map/src/noise.cairo @@ -1,3 +1,9 @@ +// +// +// Unique buisness logic of your world. It imports both the hex from origami and the simplex from cubit +// +// + use cubit::f64::procgen::simplex3; use cubit::f64::types::vec3::{Vec3, Vec3Trait}; use cubit::f64::types::fixed::{Fixed, FixedTrait, FixedPrint, FixedImpl, ONE}; @@ -5,6 +11,7 @@ use cubit::f64::types::fixed::{Fixed, FixedTrait, FixedPrint, FixedImpl, ONE}; use origami::map::hex::{types::{Direction, HexTile}}; use origami::map::hex::{hex::{IHexTile, ImplHexTile}}; +// You can expand this to add more types mod TileType { const WATER: u8 = 0; const LAND: u8 = 1; @@ -26,6 +33,7 @@ impl ImplTile of ITile { let mag = simplex.mag; let one: u64 = ONE.into(); + // how tiles are defined if mag > (one * 3 / 4) { TileType::MOUNTAIN } else if mag > (one * 2 / 4) { From 09d7cdc7e14246ace58958e523e77a5cbbfef14f Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Fri, 24 Nov 2023 14:54:30 +0100 Subject: [PATCH 3/4] add logo to readme: --- .github/Origami.svg | 6 ++++++ README.md | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 .github/Origami.svg diff --git a/.github/Origami.svg b/.github/Origami.svg new file mode 100644 index 00000000..40c80afe --- /dev/null +++ b/.github/Origami.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/README.md b/README.md index c866cc59..7160499e 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,53 @@ -## Origami + +
+ +
+
+
+ -### The magic of origami is in seeing a single piece of cairo evolve into a masterpiece through careful folds. + + + + + + -### Easy Integration into Your Project +[![discord](https://img.shields.io/badge/join-dojo-green?logo=discord&logoColor=white)](https://discord.gg/PwDa2mKhR4) +![Github Actions][gha-badge] [![Telegram Chat][tg-badge]][tg-url] + +[gha-badge]: https://img.shields.io/github/actions/workflow/status/dojoengine/dojo/ci.yml?branch=main +[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 + +
+ +# Origami - Primitives for onchain Gaming + +#### "The magic of origami is in seeing a single piece of cairo evolve into a masterpiece through careful folds" - Sensei + +--- + +### Crates + +- [algebra](./crates/src/algebra) +- [defi](./crates//src/defi/) +- [hex map](./crates/src/map/hex) +- [random](./crates/src/random) +- [security](./crates/src/security) + +### Easy integration into your project Incorporate `origami` seamlessly into your projects using Scarb.toml. Add the following to your `[dependencies]`: -``` +```toml +[dependencies] origami = { git = "https://github.com/OpenZeppelin/cairo-contracts.git" } ``` -Now you will be able to use origami like any other Cairo package. +Now you will be able to use origami like any other Cairo package! ### 🏗️ Join Our Contributors From 61e54952ae93b77d9a554af9aa7a14599aa598b2 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Fri, 24 Nov 2023 14:55:15 +0100 Subject: [PATCH 4/4] bump version in CI --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bbbb7d7..994cfbc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Origami CI on: [push, pull_request] env: - DOJO_VERSION: v0.3.10 + DOJO_VERSION: v0.3.12 SCARB_VERSION: v2.3.1 jobs: @@ -41,7 +41,6 @@ jobs: run: sozo test -f origami shell: bash - market: needs: [check, build] runs-on: ubuntu-latest @@ -62,4 +61,4 @@ jobs: - uses: ./.github/actions/setup - name: Test run: sozo test -f projectile - shell: bash \ No newline at end of file + shell: bash