Skip to content

Commit

Permalink
feat: teams
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Oct 18, 2024
1 parent 833f2dc commit aa5ab14
Show file tree
Hide file tree
Showing 34 changed files with 53 additions and 46 deletions.
3 changes: 2 additions & 1 deletion Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = 1
[[package]]
name = "dojo"
version = "1.0.0-alpha.4"
source = "git+https://github.com/Larkooo/dojo-lobotomized#c747a806387e3ae8d67108af0af64fe07f2d06be"

[[package]]
name = "flippyflop"
Expand All @@ -16,7 +17,7 @@ dependencies = [
[[package]]
name = "origami_token"
version = "1.0.0-alpha.16"
source = "git+https://github.com/Larkooo/origami?rev=fec3209#fec3209bdfae6a4c9bf42ad6ea7c2312a3eedbca"
source = "git+https://github.com/Larkooo/origami#103005159acd6cbb773b55fe8a7d411c8016e7ea"
dependencies = [
"dojo",
]
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ spawn = "./scripts/spawn.sh"
move = "./scripts/move.sh"

[dependencies]
dojo = { path = "/Users/nasr/Documents/development.nosync/dojo/crates/dojo-core" }
origami_token = { git = "https://github.com/Larkooo/origami", rev = "fec3209" }
dojo = { git = "https://github.com/Larkooo/dojo-lobotomized" }
origami_token = { git = "https://github.com/Larkooo/origami" }

[[target.dojo]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
{
"name": "y",
"type": "core::integer::u32"
},
{
"name": "team",
"type": "core::integer::u8"
}
],
"outputs": [],
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind = "DojoContract"
class_hash = "0x722b2e1264d639fbcd8063f2a886d97758c02a0d616a7eb81c22c519adcc8c0"
original_class_hash = "0x722b2e1264d639fbcd8063f2a886d97758c02a0d616a7eb81c22c519adcc8c0"
base_class_hash = "0x0"
abi = "manifests/katana/base/abis/contracts/flippyflop-Flip-6bd3ed9d.json"
abi = "manifests/dev/base/abis/contracts/flippyflop-Flip-6bd3ed9d.json"
reads = []
writes = []
init_calldata = []
Expand Down
15 changes: 15 additions & 0 deletions manifests/dev/base/contracts/flippyflop-actions-4407e5f5.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
kind = "DojoContract"
class_hash = "0x71ff3db9b03a630288fa3c3d9841120077f75a90019ddc5b94e7ebdf0799c11"
original_class_hash = "0x71ff3db9b03a630288fa3c3d9841120077f75a90019ddc5b94e7ebdf0799c11"
base_class_hash = "0x0"
abi = "manifests/dev/base/abis/contracts/flippyflop-actions-4407e5f5.json"
reads = []
writes = []
init_calldata = []
tag = "flippyflop-actions"
systems = [
"flip",
"flop",
"claim",
]
manifest_name = "flippyflop-actions-4407e5f5"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind = "DojoContract"
class_hash = "0x36d96eb5c3aef927391a701ea9219357af7d964d1ec3c0c4519615d30bcb955"
original_class_hash = "0x36d96eb5c3aef927391a701ea9219357af7d964d1ec3c0c4519615d30bcb955"
base_class_hash = "0x0"
abi = "manifests/katana/base/abis/contracts/flippyflop-game-23e1ad43.json"
abi = "manifests/dev/base/abis/contracts/flippyflop-game-23e1ad43.json"
reads = []
writes = []
init_calldata = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
original_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
abi = "manifests/katana/base/abis/dojo-base.json"
abi = "manifests/dev/base/abis/dojo-base.json"
tag = "dojo-base"
manifest_name = "dojo-base"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x39bb4d21b2faebdf6c7db4eef6ba65bc652ecef957f1ad2fca0ab4c6d559e50"
original_class_hash = "0x39bb4d21b2faebdf6c7db4eef6ba65bc652ecef957f1ad2fca0ab4c6d559e50"
abi = "manifests/katana/base/abis/dojo-world.json"
abi = "manifests/dev/base/abis/dojo-world.json"
tag = "dojo-world"
manifest_name = "dojo-world"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x7416d8eddcdb8106e3574223f03624a8290f2f012c5c4d628383d3ccb8a56a0"
original_class_hash = "0x7416d8eddcdb8106e3574223f03624a8290f2f012c5c4d628383d3ccb8a56a0"
abi = "manifests/katana/base/abis/models/flippyflop-Claim-c098f39e.json"
abi = "manifests/dev/base/abis/models/flippyflop-Claim-c098f39e.json"
tag = "flippyflop-Claim"
qualified_path = "flippyflop::models::claim"
manifest_name = "flippyflop-Claim-c098f39e"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x491a48fb74ba9e09baa7cd0c7b518557a4c422b85bb7a72782a98ab8c89bcf2"
original_class_hash = "0x491a48fb74ba9e09baa7cd0c7b518557a4c422b85bb7a72782a98ab8c89bcf2"
abi = "manifests/katana/base/abis/models/flippyflop-ERC20AllowanceModel-55d0c41e.json"
abi = "manifests/dev/base/abis/models/flippyflop-ERC20AllowanceModel-55d0c41e.json"
tag = "flippyflop-ERC20AllowanceModel"
qualified_path = "origami_token::components::token::erc20::erc20_allowance::erc_20_allowance_model"
manifest_name = "flippyflop-ERC20AllowanceModel-55d0c41e"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x45f6ca7de5a298e2de95705cafee47fbee607c06f8791992ad3ded1d25f25cf"
original_class_hash = "0x45f6ca7de5a298e2de95705cafee47fbee607c06f8791992ad3ded1d25f25cf"
abi = "manifests/katana/base/abis/models/flippyflop-ERC20BalanceModel-7866fe9f.json"
abi = "manifests/dev/base/abis/models/flippyflop-ERC20BalanceModel-7866fe9f.json"
tag = "flippyflop-ERC20BalanceModel"
qualified_path = "origami_token::components::token::erc20::erc20_balance::erc_20_balance_model"
manifest_name = "flippyflop-ERC20BalanceModel-7866fe9f"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x4f60ae83d8ae292f332022f258e627e52e113cb5377ec9b01dc3912dae63c42"
original_class_hash = "0x4f60ae83d8ae292f332022f258e627e52e113cb5377ec9b01dc3912dae63c42"
abi = "manifests/katana/base/abis/models/flippyflop-ERC20BridgeableModel-1ad0a3e6.json"
abi = "manifests/dev/base/abis/models/flippyflop-ERC20BridgeableModel-1ad0a3e6.json"
tag = "flippyflop-ERC20BridgeableModel"
qualified_path = "flippyflop::tokens::flip::erc_20_bridgeable_model"
manifest_name = "flippyflop-ERC20BridgeableModel-1ad0a3e6"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x4ba53f974c845d0048f7921668d9da6cf864ef5b79760c4d3b43c34b58ecc7c"
original_class_hash = "0x4ba53f974c845d0048f7921668d9da6cf864ef5b79760c4d3b43c34b58ecc7c"
abi = "manifests/katana/base/abis/models/flippyflop-ERC20MetadataModel-1fc3dc07.json"
abi = "manifests/dev/base/abis/models/flippyflop-ERC20MetadataModel-1fc3dc07.json"
tag = "flippyflop-ERC20MetadataModel"
qualified_path = "origami_token::components::token::erc20::erc20_metadata::erc_20_metadata_model"
manifest_name = "flippyflop-ERC20MetadataModel-1fc3dc07"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x1bdb38d9c7364a47133d55ff8e304bdfd79e7f41db50ebbe9305daf9722f2eb"
original_class_hash = "0x1bdb38d9c7364a47133d55ff8e304bdfd79e7f41db50ebbe9305daf9722f2eb"
abi = "manifests/katana/base/abis/models/flippyflop-Game-54c54faf.json"
abi = "manifests/dev/base/abis/models/flippyflop-Game-54c54faf.json"
tag = "flippyflop-Game"
qualified_path = "flippyflop::models::game"
manifest_name = "flippyflop-Game-54c54faf"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x69800345431696738834bc1aa3ade287b67e44391138f473748fbbd4c95bd9a"
original_class_hash = "0x69800345431696738834bc1aa3ade287b67e44391138f473748fbbd4c95bd9a"
abi = "manifests/katana/base/abis/models/flippyflop-InitializableModel-4239d2f3.json"
abi = "manifests/dev/base/abis/models/flippyflop-InitializableModel-4239d2f3.json"
tag = "flippyflop-InitializableModel"
qualified_path = "origami_token::components::security::initializable::initializable_model"
manifest_name = "flippyflop-InitializableModel-4239d2f3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x4a4abfcb39d8c9935eaf1c96eda1ee3df8d448992e11a58fb3bc62821a14d20"
original_class_hash = "0x4a4abfcb39d8c9935eaf1c96eda1ee3df8d448992e11a58fb3bc62821a14d20"
abi = "manifests/katana/base/abis/models/flippyflop-Tile-61fb9291.json"
abi = "manifests/dev/base/abis/models/flippyflop-Tile-61fb9291.json"
tag = "flippyflop-Tile"
qualified_path = "flippyflop::models::tile"
manifest_name = "flippyflop-Tile-61fb9291"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x69a62266a511f2937f5c08976de5b8a2455acbe622bc8d6060616282832eb66"
original_class_hash = "0x69a62266a511f2937f5c08976de5b8a2455acbe622bc8d6060616282832eb66"
abi = "manifests/katana/base/abis/models/flippyflop-User-25ca4606.json"
abi = "manifests/dev/base/abis/models/flippyflop-User-25ca4606.json"
tag = "flippyflop-User"
qualified_path = "flippyflop::models::user"
manifest_name = "flippyflop-User-25ca4606"
Expand Down
15 changes: 0 additions & 15 deletions manifests/katana/base/contracts/flippyflop-actions-4407e5f5.toml

This file was deleted.

5 changes: 3 additions & 2 deletions src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pub const X_BOUND: u32 = 256;
pub const Y_BOUND: u32 = 256;
pub const ADDRESS_MASK: u256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000;
pub const POWERUP_MASK: u256 = 0xFF00;
pub const POWERUP_DATA_MASK: u256 = 0x00FF;
pub const POWERUP_MASK: u256 = 0xF000;
pub const POWERUP_DATA_MASK: u256 = 0x0FF0;
pub const TILE_TYPE_MASK: u256 = 0x000F;

pub const TILE_MODEL_SELECTOR: felt252 = selector_from_tag!("flippyflop-Tile");
pub const GAME_ID: u32 = 0x0;
17 changes: 9 additions & 8 deletions src/packing.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use starknet::ContractAddress;
use flippyflop::models::PowerUp;
use flippyflop::constants::{ADDRESS_MASK, POWERUP_MASK, POWERUP_DATA_MASK};
use flippyflop::constants::{ADDRESS_MASK, POWERUP_MASK, POWERUP_DATA_MASK, TILE_TYPE_MASK};

fn pack_flipped_data(address: felt252, powerup: PowerUp) -> felt252 {
fn pack_flipped_data(address: felt252, powerup: PowerUp, team: u8) -> felt252 {
let address_bits: u256 = address.into();
let (powerup_type, powerup_data) = match powerup {
PowerUp::None => (0_u256, 0_u256),
Expand All @@ -12,17 +12,18 @@ fn pack_flipped_data(address: felt252, powerup: PowerUp) -> felt252 {

let mut packed: u256 = 0_u256;
packed = packed | (address_bits & ADDRESS_MASK);
packed = packed | ((powerup_type * 256_u256) & POWERUP_MASK);
packed = packed | ((powerup_type * 0x1000_u256) & POWERUP_MASK);
packed = packed | (powerup_data & POWERUP_DATA_MASK);

packed = packed | (team.into() & TILE_TYPE_MASK);
packed.try_into().unwrap()
}

fn unpack_flipped_data(flipped: felt252) -> (felt252, PowerUp) {
fn unpack_flipped_data(flipped: felt252) -> (felt252, PowerUp, u8) {
let flipped_u256: u256 = flipped.into();
let address: felt252 = (flipped_u256 & ADDRESS_MASK).try_into().unwrap();
let powerup_type: felt252 = ((flipped_u256 & POWERUP_MASK) / 256_u256).try_into().unwrap();
let powerup_data = flipped_u256 & POWERUP_DATA_MASK;
let powerup_type: felt252 = ((flipped_u256 & POWERUP_MASK) / 0x1000).try_into().unwrap();
let powerup_data = (flipped_u256 & POWERUP_DATA_MASK) / 0x10;
let team: u8 = (flipped_u256 & TILE_TYPE_MASK).try_into().unwrap();

let powerup = match powerup_type {
0 => PowerUp::None,
Expand All @@ -31,5 +32,5 @@ fn unpack_flipped_data(flipped: felt252) -> (felt252, PowerUp) {
_ => PowerUp::None,
};

(address, powerup)
(address, powerup, team)
}
10 changes: 5 additions & 5 deletions src/systems/actions.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// define the interface
#[dojo::interface]
trait IActions {
fn flip(ref world: IWorldDispatcher, x: u32, y: u32);
fn flip(ref world: IWorldDispatcher, x: u32, y: u32, team: u8);
fn flop(ref world: IWorldDispatcher);
fn claim(ref world: IWorldDispatcher, flipped_tiles: Array<(u32, u32)>);
}
Expand Down Expand Up @@ -59,7 +59,7 @@ mod actions {
#[abi(embed_v0)]
impl ActionsImpl of IActions<ContractState> {
// Humans can only flip unflipped tiles, but they can chose their tile to unflip.
fn flip(ref world: IWorldDispatcher, x: u32, y: u32) {
fn flip(ref world: IWorldDispatcher, x: u32, y: u32, team: u8) {
assert!(x < X_BOUND, "X is out of bounds");
assert!(y < Y_BOUND, "Y is out of bounds");

Expand All @@ -70,7 +70,7 @@ mod actions {
assert!(tile == 0, "Tile already flipped");

let powerup = get_random_powerup(hash);
let packed_data = pack_flipped_data(player.into(), powerup);
let packed_data = pack_flipped_data(player.into(), powerup, team);

world
.set_entity_lobotomized(
Expand All @@ -93,7 +93,7 @@ mod actions {
let tile = world.entity_lobotomized(TILE_MODEL_SELECTOR, entity_hash);

// Check if the tile has a powerup
let (_, powerup) = unpack_flipped_data(tile);
let (_, powerup, _) = unpack_flipped_data(tile);
if powerup == PowerUp::None {
world
.set_entity_lobotomized(
Expand Down Expand Up @@ -129,7 +129,7 @@ mod actions {
let tile = world.entity_lobotomized(TILE_MODEL_SELECTOR, entity_hash);

// Verify the tile belongs to the player
let (tile_owner, powerup) = unpack_flipped_data(tile);
let (tile_owner, powerup, _) = unpack_flipped_data(tile);
assert!(tile_owner == masked_player, "Tile does not belong to the player");

// Calculate tokens for this tile
Expand Down

0 comments on commit aa5ab14

Please sign in to comment.