Skip to main content

rusteal_codegen/rust_gen/
prelude.rs

1use std::collections::HashSet;
2use std::path::Path;
3
4use crate::context::CodegenContext;
5
6const ENTRIES: &[(&str, &str)] = &[
7    (
8        "core",
9        "crate::core_ue::{\n    \
10             FVector, FVectorExt,\n    \
11             FVector2D, FVector2DExt,\n    \
12             FVector4, FVector4Ext,\n    \
13             FQuat, FQuatExt,\n    \
14             FRotator, FRotatorExt,\n    \
15             FTransform, FTransformExt,\n    \
16             FLinearColor, FLinearColorExt,\n    \
17             FColor, FColorExt,\n    \
18             FPlane, FPlaneExt,\n    \
19             FBox2D, FBox2DExt,\n\
20         }",
21    ),
22    ("core", "crate::manual::vector::OwnedFVectorExt"),
23    ("core", "crate::manual::vector2d::OwnedFVector2DExt"),
24    ("core", "crate::manual::vector4::OwnedFVector4Ext"),
25    ("core", "crate::manual::quat::OwnedFQuatExt"),
26    ("core", "crate::manual::rotator::OwnedFRotatorExt"),
27    ("core", "crate::manual::transform::OwnedFTransformExt"),
28    ("core", "crate::manual::linear_color::OwnedFLinearColorExt"),
29    ("core", "crate::manual::color::OwnedFColorExt"),
30    ("core", "crate::manual::plane::OwnedFPlaneExt"),
31    ("core", "crate::manual::ue_box2d::OwnedFBox2DExt"),
32    (
33        "engine",
34        "crate::engine::{Actor, ActorExt, World, WorldExt}",
35    ),
36    (
37        "engine",
38        "crate::manual::world_ext::{ObjectWorldExt, SpawnCollisionMethod, SpawnParams, WorldSpawnExt, find_object, load_class, load_object}",
39    ),
40    ("engine", "crate::manual::collision::object_type_query"),
41    (
42        "engine",
43        "crate::manual::data_table::{DataTableRowHandleRowExt, find_data_table_row}",
44    ),
45    (
46        "umg",
47        "crate::manual::widget_ext::{create_widget, create_widget_of_class}",
48    ),
49    ("input", "crate::input_core::FKey"),
50    ("input", "crate::manual::fkey::FKeyExt"),
51    (
52        "enhanced-input",
53        "crate::manual::input_ext::{InputActionValueExt, bind_action, enhanced_input_subsystem}",
54    ),
55];
56
57pub fn write_prelude(src_dir: &Path, ctx: &CodegenContext) {
58    let available: HashSet<&str> = ctx
59        .enabled_modules
60        .iter()
61        .filter_map(|module| ctx.feature_for_module(module))
62        .collect();
63
64    let mut out = String::from(
65        "// Auto-generated by rusteal-codegen. Do not edit.\n\
66         //\n\
67         // One-import access to the engine types used most often:\n\
68         //\n\
69         //     use rusteal_runtime::prelude::*;\n\
70         //     use bindings::prelude::*;\n\n",
71    );
72
73    for (feature, path) in ENTRIES {
74        if !available.contains(feature) {
75            continue;
76        }
77
78        out.push_str(&format!(
79            "#[cfg(feature = \"{feature}\")]\npub use {path};\n"
80        ));
81    }
82
83    let path = src_dir.join("prelude.rs");
84
85    crate::write_if_changed(&path, &out)
86        .unwrap_or_else(|e| panic!("Failed to write {}: {e}", path.display()));
87}