Skip to main content

uika_codegen/
schema.rs

1// JSON schema types matching UHT exporter output.
2
3#![allow(dead_code)] // Schema fields are deserialized from JSON; some reserved for future codegen use.
4
5use serde::{Deserialize, Deserializer};
6
7// ---------------------------------------------------------------------------
8// Top-level file wrappers
9// ---------------------------------------------------------------------------
10
11#[derive(Deserialize)]
12pub struct ClassesFile {
13    pub classes: Vec<ClassInfo>,
14}
15
16#[derive(Deserialize)]
17pub struct StructsFile {
18    pub structs: Vec<StructInfo>,
19}
20
21#[derive(Deserialize)]
22pub struct EnumsFile {
23    pub enums: Vec<EnumInfo>,
24}
25
26// ---------------------------------------------------------------------------
27// Class
28// ---------------------------------------------------------------------------
29
30#[derive(Deserialize, Clone)]
31pub struct ClassInfo {
32    pub name: String,
33    pub cpp_name: String,
34    pub package: String,
35    pub header: String,
36    #[serde(deserialize_with = "deser_flags_u32")]
37    pub class_flags: u32,
38    #[serde(rename = "super")]
39    pub super_class: Option<String>,
40    #[serde(default)]
41    pub interfaces: Vec<String>,
42    #[serde(default)]
43    pub props: Vec<PropertyInfo>,
44    #[serde(default)]
45    pub funcs: Vec<FunctionInfo>,
46}
47
48// ---------------------------------------------------------------------------
49// Struct
50// ---------------------------------------------------------------------------
51
52#[derive(Deserialize, Clone)]
53pub struct StructInfo {
54    pub name: String,
55    pub cpp_name: String,
56    pub package: String,
57    #[serde(deserialize_with = "deser_flags_u32")]
58    pub struct_flags: u32,
59    #[serde(rename = "super")]
60    pub super_struct: Option<String>,
61    #[serde(default)]
62    pub has_static_struct: bool,
63    #[serde(default)]
64    pub props: Vec<PropertyInfo>,
65}
66
67// ---------------------------------------------------------------------------
68// Enum
69// ---------------------------------------------------------------------------
70
71#[derive(Deserialize, Clone)]
72pub struct EnumInfo {
73    pub name: String,
74    pub cpp_name: String,
75    pub package: String,
76    pub underlying_type: String,
77    pub cpp_form: u32,
78    pub pairs: Vec<(String, i64)>,
79}
80
81// ---------------------------------------------------------------------------
82// Property (used in both class props and struct props)
83// ---------------------------------------------------------------------------
84
85#[derive(Deserialize, Clone)]
86pub struct PropertyInfo {
87    pub name: String,
88    #[serde(rename = "type")]
89    pub prop_type: String,
90    pub prop_flags: u64,
91    #[serde(default = "default_array_dim")]
92    pub array_dim: u32,
93    pub enum_name: Option<String>,
94    pub enum_cpp_name: Option<String>,
95    pub enum_cpp_form: Option<u32>,
96    pub enum_underlying_type: Option<String>,
97    pub class_name: Option<String>,
98    pub meta_class_name: Option<String>,
99    pub struct_name: Option<String>,
100    pub interface_name: Option<String>,
101    pub func_info: Option<serde_json::Value>,
102    pub inner_prop: Option<Box<PropertyInfo>>,
103    pub key_prop: Option<Box<PropertyInfo>>,
104    pub value_prop: Option<Box<PropertyInfo>>,
105    pub element_prop: Option<Box<PropertyInfo>>,
106    pub getter: Option<String>,
107    pub setter: Option<String>,
108    pub default: Option<String>,
109}
110
111fn default_array_dim() -> u32 {
112    1
113}
114
115// ---------------------------------------------------------------------------
116// Function
117// ---------------------------------------------------------------------------
118
119#[derive(Deserialize, Clone)]
120pub struct FunctionInfo {
121    pub name: String,
122    #[serde(deserialize_with = "deser_flags_u32")]
123    pub func_flags: u32,
124    #[serde(default)]
125    pub is_static: bool,
126    #[serde(default)]
127    pub params: Vec<ParamInfo>,
128    /// Original UE function name (before overload renaming). Set by filter.
129    #[serde(skip)]
130    pub ue_name: String,
131}
132
133// ---------------------------------------------------------------------------
134// Function parameter
135// ---------------------------------------------------------------------------
136
137#[derive(Deserialize, Clone)]
138pub struct ParamInfo {
139    pub name: String,
140    #[serde(rename = "type")]
141    pub prop_type: String,
142    pub prop_flags: u64,
143    pub enum_name: Option<String>,
144    pub enum_cpp_name: Option<String>,
145    pub enum_cpp_form: Option<u32>,
146    pub enum_underlying_type: Option<String>,
147    pub class_name: Option<String>,
148    pub meta_class_name: Option<String>,
149    pub struct_name: Option<String>,
150    pub interface_name: Option<String>,
151    pub func_info: Option<serde_json::Value>,
152    pub inner_prop: Option<Box<PropertyInfo>>,
153    pub key_prop: Option<Box<PropertyInfo>>,
154    pub value_prop: Option<Box<PropertyInfo>>,
155    pub element_prop: Option<Box<PropertyInfo>>,
156    pub default: Option<String>,
157}
158
159// ---------------------------------------------------------------------------
160// Flag constants — sourced from uika-ue-flags (single source of truth)
161// ---------------------------------------------------------------------------
162
163pub use uika_ue_flags::{
164    CPF_CONST_PARM, CPF_OUT_PARM, CPF_REFERENCE_PARM, CPF_RETURN_PARM,
165    CPF_NATIVE_ACCESS_SPECIFIER_PRIVATE as CPF_NATIVE_ACCESS_PRIVATE,
166    CPF_NATIVE_ACCESS_SPECIFIER_PROTECTED as CPF_NATIVE_ACCESS_PROTECTED,
167    FUNC_NATIVE, FUNC_STATIC, FUNC_BLUEPRINT_EVENT,
168};
169
170// ---------------------------------------------------------------------------
171// Serde helpers — the C# exporter sign-extends uint32 flags via
172// `(long)(int)flags`, so JSON values can be negative.  We read as i64
173// and truncate to u32 to recover the original bits.
174// ---------------------------------------------------------------------------
175
176fn deser_flags_u32<'de, D: Deserializer<'de>>(d: D) -> Result<u32, D::Error> {
177    let v = i64::deserialize(d)?;
178    Ok(v as u32)
179}