1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use std::marker::PhantomData;

use const_combine::bounded::const_combine as combine;

use crate::raw::root::RED4ext as red;
use crate::NativeRepr;

// temporary module, we should split it up into separate files

#[repr(transparent)]
pub struct LocalizationString(red::LocalizationString);

#[derive(Debug)]
#[repr(transparent)]
pub struct NodeRef(red::NodeRef);

#[derive(Debug)]
#[repr(transparent)]
pub struct DataBuffer(red::DataBuffer);

#[derive(Debug)]
#[repr(transparent)]
pub struct DeferredDataBuffer(red::DeferredDataBuffer);

#[derive(Debug)]
#[repr(transparent)]
pub struct SharedDataBuffer(red::SharedDataBuffer);

#[derive(Debug, Default, Copy, Clone)]
#[repr(transparent)]
pub struct DateTime(red::CDateTime);

#[derive(Debug, Default, Copy, Clone)]
#[repr(transparent)]
pub struct Guid(red::CGUID);

#[derive(Debug)]
#[repr(transparent)]
pub struct EditorObjectId(red::EditorObjectID);

#[derive(Debug, Default, Copy, Clone)]
#[repr(transparent)]
pub struct MessageResourcePath(red::MessageResourcePath);

#[repr(transparent)]
pub struct Variant(red::Variant);

#[derive(Debug)]
#[repr(transparent)]
pub struct ResourceRef<T>(red::ResourceReference<T>);

#[derive(Debug)]
#[repr(transparent)]
pub struct Curve<T>(red::CurveData, PhantomData<T>);

#[derive(Debug)]
#[repr(transparent)]
pub struct MultiChannelCurve<T>([u8; 56], PhantomData<T>);

#[derive(Debug)]
#[repr(C)]
pub struct StaticArray<T, const N: usize> {
    entries: [T; N],
    size: u32,
}

const fn const_digit_str<const N: usize>() -> &'static str {
    match N {
        1 => "1",
        2 => "2",
        3 => "3",
        4 => "4",
        5 => "5",
        6 => "6",
        7 => "7",
        8 => "8",
        _ => unimplemented!(),
    }
}

unsafe impl<T: NativeRepr, const N: usize> NativeRepr for StaticArray<T, N> {
    const NAME: &'static str = combine!(
        combine!(combine!("[", const_digit_str::<N>()), "]"),
        T::NAME
    );
}

impl<T, const N: usize> From<[T; N]> for StaticArray<T, N> {
    fn from(entries: [T; N]) -> Self {
        Self {
            size: entries.len() as u32,
            entries,
        }
    }
}

impl<T, const N: usize> StaticArray<T, N> {
    #[inline]
    pub fn entries(&self) -> &[T] {
        &self.entries[..self.size as usize]
    }

    #[inline]
    pub fn size(&self) -> u32 {
        self.size
    }
}