unrust_inbuilt/
inbuilt.rs1mod entity;
2mod guid;
3mod parent;
4mod transform;
5use genco::fmt;
6use genco::prelude::*;
7use std::fs::File;
8
9use bevy::ecs::world::EntityMut;
10pub use entity::*;
11pub use guid::*;
12pub use parent::*;
13pub use transform::*;
14use unrust_proc_macro::generate_inbuilt;
15
16generate_inbuilt!((UnityParent, UnityEntity, UnityGUID, UnityTransform));
17
18pub fn write_csharp_inbuilt(path: &str) -> anyhow::Result<()> {
19 let struct_layout = &csharp::import("System.Runtime.InteropServices", "StructLayout");
20 let layout_kind = &csharp::import("System.Runtime.InteropServices", "LayoutKind");
21 let unity_types = UNITY_TYPES;
22 let unity_union = UNITY_UNION;
23 let unity_count = UNITY_COUNT;
24 let inbuilt_tokens = get_inbuilt_csharp_tokens();
25 let output: csharp::Tokens = genco::prelude::quote! {
26 namespace unrust.runtime
27 {
28 $(for n in inbuilt_tokens => $n)
29
30 [$struct_layout($layout_kind.Sequential)]
31 public struct UnityData
32 {
33 public UnityTypes ty;
34 public UnityComponents value;
35 }
36
37 public enum UnityTypes : sbyte
38 {
39 $(unity_types)
40 }
41
42 [$struct_layout($layout_kind.Explicit)]
43 public unsafe struct UnityComponents
44 {
45 public const int ComponentCount = $unity_count;
46
47 $(unity_union)
48 }
49
50 [$struct_layout($layout_kind.Sequential)]
51 public unsafe struct EntityData
52 {
53 public UnityEntity entity;
54 public UnityData* data;
55 public nuint len;
56 }
57 }
58 };
59
60 let fmt = fmt::Config::from_lang::<Csharp>().with_indentation(fmt::Indentation::Space(4));
61 let config = csharp::Config::default();
62
63 let file = File::create(path)?;
64 let mut w = fmt::IoWriter::new(file);
65 output.format_file(&mut w.as_formatter(&fmt), &config)?;
66
67 Ok(())
68}