Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: u256 and ns for unity bindgen #2635

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions crates/dojo/bindgen/src/plugins/unity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
using System.Collections.Generic;
using System.Linq;
using Enum = Dojo.Starknet.Enum;
using BigInteger = System.Numerics.BigInteger;

Check warning on line 107 in crates/dojo/bindgen/src/plugins/unity/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/bindgen/src/plugins/unity/mod.rs#L107

Added line #L107 was not covered by tests
"
.to_string()
}
Expand All @@ -116,6 +117,7 @@
using System.Linq;
using System.Collections.Generic;
using Enum = Dojo.Starknet.Enum;
using BigInteger = System.Numerics.BigInteger;

Check warning on line 120 in crates/dojo/bindgen/src/plugins/unity/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/bindgen/src/plugins/unity/mod.rs#L120

Added line #L120 was not covered by tests
"
.to_string()
}
Expand Down Expand Up @@ -201,23 +203,22 @@

format!(
"
namespace {namespace} {{
// Model definition for `{}` model
public class {} : ModelInstance {{
{}

// Start is called before the first frame update
void Start() {{
}}

// Update is called once per frame
void Update() {{
}}
// Model definition for `{}` model
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Model definition for `{}` model
// Model definition for `{}_{}` model

public class {}_{} : ModelInstance {{
{}

// Start is called before the first frame update
void Start() {{
}}

// Update is called once per frame
void Update() {{

Check warning on line 215 in crates/dojo/bindgen/src/plugins/unity/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/bindgen/src/plugins/unity/mod.rs#L206-L215

Added lines #L206 - L215 were not covered by tests
Comment on lines +206 to +215
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ohayo, sensei! Consider using C# namespaces instead of prefixing class names

Currently, the model class name includes the namespace appended with an underscore (e.g., namespace_ModelName). In C#, it's conventional to use the namespace keyword to define namespaces, which improves code organization and adheres to best practices.

 public class {}_{} : ModelInstance {{
+// Suggested change:
+namespace {} {{
+    public class {} : ModelInstance {{
         {}
     }}
+}}

Committable suggestion skipped: line range outside the PR's diff.

}}
}}

",
model.type_path,
namespace,

Check warning on line 221 in crates/dojo/bindgen/src/plugins/unity/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/bindgen/src/plugins/unity/mod.rs#L221

Added line #L221 was not covered by tests
model.type_name(),
fields
)
Expand Down Expand Up @@ -343,6 +344,18 @@
true,
enum_variant,
)],
CompositeType::Unknown if t.type_name() == "U256" => vec![
(
format!("new FieldElement({}.high).Inner", arg_name),
false,
enum_variant.clone(),
),
(
format!("new FieldElement({}.low).Inner", arg_name),
false,
enum_variant,
),
],

Check warning on line 358 in crates/dojo/bindgen/src/plugins/unity/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/bindgen/src/plugins/unity/mod.rs#L347-L358

Added lines #L347 - L358 were not covered by tests
CompositeType::Struct => {
let mut tokens = vec![];
t.inners.iter().for_each(|f| {
Expand Down
Loading