Skip to content

Commit

Permalink
removed crypto-kitties dependency from crypto-zombies
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed May 7, 2024
1 parent ebd0826 commit df58c72
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ to = "kitty"
path = "../../crypto-zombies/src/kitty_ownership_proxy.rs"
[[proxy.path-rename]]
from = "kitty::kitty"
to = "kitty"
to = "crate::kitty_obj"
4 changes: 0 additions & 4 deletions contracts/examples/crypto-zombies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ path = "../../../framework/base"
[dev-dependencies.multiversx-sc-scenario]
version = "0.49.0"
path = "../../../framework/scenario"

[dependencies.kitty]
version = "0.0.0"
path = "../../../contracts/examples/crypto-kitties/common/kitty"
40 changes: 40 additions & 0 deletions contracts/examples/crypto-zombies/src/kitty_obj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use multiversx_sc::derive_imports::*;

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)]
pub struct Kitty {
pub genes: KittyGenes,
pub birth_time: u64, // timestamp
pub cooldown_end: u64, // timestamp, used for pregnancy timer and siring cooldown
pub matron_id: u32,
pub sire_id: u32,
pub siring_with_id: u32, // for pregnant cats, 0 otherwise
pub nr_children: u16, // cooldown period increases exponentially with every breeding/siring
pub generation: u16, // max(sire_gen, matron_gen) + 1. Generation also influences cooldown.
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)]
pub struct KittyGenes {
pub fur_color: Color,
pub eye_color: Color,
pub meow_power: u8, // the higher the value, the louder the cat
}

#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}

impl KittyGenes {
pub fn get_as_u64(&self) -> u64 {
(self.fur_color.as_u64() << 12 | self.eye_color.as_u64()) << 4
| self.meow_power.to_be() as u64
}
}

impl Color {
pub fn as_u64(&self) -> u64 {
((self.r.to_be() as u64) << 4 | self.r.to_be() as u64) << 4 | self.r.to_be() as u64
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ where
>(
self,
kitty_id: Arg0,
) -> TxProxyCall<Env, From, To, Gas, kitty::Kitty> {
) -> TxProxyCall<Env, From, To, Gas, crate::kitty_obj::Kitty> {
self.wrapped_tx
.raw_call("getKittyById")
.argument(&kitty_id)
Expand Down
1 change: 1 addition & 0 deletions contracts/examples/crypto-zombies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use multiversx_sc::imports::*;

pub mod kitty_obj;
pub mod kitty_ownership_proxy;
pub mod proxy_crypto_zombies;
mod storage;
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/crypto-zombies/src/zombie_feeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait ZombieFeeding:
#[callback]
fn get_kitty_callback(
&self,
#[call_result] result: ManagedAsyncCallResult<kitty::Kitty>,
#[call_result] result: ManagedAsyncCallResult<crate::kitty_obj::Kitty>,
zombie_id: usize,
) {
match result {
Expand Down

0 comments on commit df58c72

Please sign in to comment.