diff --git a/Cargo.lock b/Cargo.lock index 31a2f3d559..595b54e48d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2255,7 +2255,7 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "dojo-lang" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -2302,7 +2302,7 @@ dependencies = [ [[package]] name = "dojo-languge-server" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -2324,7 +2324,7 @@ dependencies = [ [[package]] name = "dojo-signers" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "starknet", @@ -2332,7 +2332,7 @@ dependencies = [ [[package]] name = "dojo-test-utils" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "assert_fs", @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "dojo-types" -version = "0.3.6" +version = "0.3.7" dependencies = [ "crypto-bigint", "hex", @@ -2378,7 +2378,7 @@ dependencies = [ [[package]] name = "dojo-world" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "assert_fs", @@ -4806,7 +4806,7 @@ dependencies = [ [[package]] name = "katana" -version = "0.3.6" +version = "0.3.7" dependencies = [ "assert_matches", "clap", @@ -4824,7 +4824,7 @@ dependencies = [ [[package]] name = "katana-core" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "assert_matches", @@ -4855,7 +4855,7 @@ dependencies = [ [[package]] name = "katana-rpc" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "assert_matches", @@ -7190,7 +7190,7 @@ dependencies = [ [[package]] name = "sozo" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "assert_fs", @@ -8221,7 +8221,7 @@ dependencies = [ [[package]] name = "torii-client" -version = "0.3.6" +version = "0.3.7" dependencies = [ "async-trait", "camino", @@ -8247,7 +8247,7 @@ dependencies = [ [[package]] name = "torii-core" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -8282,7 +8282,7 @@ dependencies = [ [[package]] name = "torii-graphql" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "async-graphql", @@ -8319,7 +8319,7 @@ dependencies = [ [[package]] name = "torii-grpc" -version = "0.3.6" +version = "0.3.7" dependencies = [ "bytes", "dojo-types", @@ -8356,7 +8356,7 @@ dependencies = [ [[package]] name = "torii-server" -version = "0.3.6" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", diff --git a/crates/dojo-lang/src/plugin.rs b/crates/dojo-lang/src/plugin.rs index 9869615cc0..bc73c24ce5 100644 --- a/crates/dojo-lang/src/plugin.rs +++ b/crates/dojo-lang/src/plugin.rs @@ -63,11 +63,7 @@ impl GeneratedFileAuxData for DojoAuxData { self } fn eq(&self, other: &dyn GeneratedFileAuxData) -> bool { - if let Some(other) = other.as_any().downcast_ref::() { - self == other - } else { - false - } + if let Some(other) = other.as_any().downcast_ref::() { self == other } else { false } } } diff --git a/crates/dojo-lang/src/plugin_test_data/print b/crates/dojo-lang/src/plugin_test_data/print index 629aec58a5..bd35031b94 100644 --- a/crates/dojo-lang/src/plugin_test_data/print +++ b/crates/dojo-lang/src/plugin_test_data/print @@ -91,6 +91,7 @@ struct Player { name: felt252, } + #[cfg(test)] impl PlayerPrintImpl of debug::PrintTrait { fn print(self: Player) { @@ -133,6 +134,13 @@ struct Player { name: felt252, } + +#[derive(Print, Copy, Drop, Serde)] +enum Enemy { + Unknown, + Bot: felt252, + OtherPlayer: ContractAddress, +} impl PositionCopy of Copy::; impl PositionDrop of Drop::; impl PositionSerde of Serde:: { @@ -175,3 +183,23 @@ impl PlayerSerde of Serde:: { }) } } +impl EnemyCopy of Copy::; +impl EnemyDrop of Drop::; +impl EnemySerde of Serde:: { + fn serialize(self: @Enemy, ref output: array::Array) { + match self { + Enemy::Unknown(x) => { serde::Serde::serialize(@0, ref output); serde::Serde::serialize(x, ref output); }, + Enemy::Bot(x) => { serde::Serde::serialize(@1, ref output); serde::Serde::serialize(x, ref output); }, + Enemy::OtherPlayer(x) => { serde::Serde::serialize(@2, ref output); serde::Serde::serialize(x, ref output); }, + } + } + fn deserialize(ref serialized: array::Span) -> Option { + let idx: felt252 = serde::Serde::deserialize(ref serialized)?; + Option::Some( + if idx == 0 { Enemy::Unknown(serde::Serde::deserialize(ref serialized)?) } + else if idx == 1 { Enemy::Bot(serde::Serde::deserialize(ref serialized)?) } + else if idx == 2 { Enemy::OtherPlayer(serde::Serde::deserialize(ref serialized)?) } + else { return Option::None; } + ) + } +} \ No newline at end of file diff --git a/crates/dojo-lang/src/print.rs b/crates/dojo-lang/src/print.rs index ea22c496e7..7db61eb7b4 100644 --- a/crates/dojo-lang/src/print.rs +++ b/crates/dojo-lang/src/print.rs @@ -48,21 +48,22 @@ pub fn handle_print_struct(db: &dyn SyntaxGroup, struct_ast: ItemStruct) -> Rewr /// Returns: /// * A RewriteNode containing the generated code. pub fn handle_print_enum(db: &dyn SyntaxGroup, enum_ast: ItemEnum) -> RewriteNode { + let enum_name = enum_ast.name(db).text(db); let prints: Vec<_> = enum_ast .variants(db) .elements(db) .iter() .map(|m| { format!( - "{} => {{ debug::PrintTrait::print('{}'); }}", + "{}::{}(value) => {{ debug::PrintTrait::print('{}'); \ + debug::PrintTrait::print(value); }}", + enum_name, m.name(db).text(db).to_string(), m.name(db).text(db).to_string() ) }) .collect(); - dbg!(&prints); - RewriteNode::interpolate_patched( "#[cfg(test)] impl $type_name$EnumPrintImpl of debug::PrintTrait<$type_name$> {