fmod/studio/event_description/
user_property.rs

1// Copyright (c) 2024 Lily Lyons
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use fmod_sys::*;
8use lanyard::Utf8CStr;
9use std::{ffi::c_int, mem::MaybeUninit};
10
11use crate::studio::{EventDescription, UserProperty};
12
13impl EventDescription {
14    /// Retrieves a user property by name.
15    pub fn get_user_property(&self, name: &Utf8CStr) -> Result<UserProperty> {
16        let mut property = MaybeUninit::uninit();
17        unsafe {
18            FMOD_Studio_EventDescription_GetUserProperty(
19                self.inner,
20                name.as_ptr(),
21                property.as_mut_ptr(),
22            )
23            .to_result()?;
24
25            let property = UserProperty::from_ffi(property.assume_init());
26            Ok(property)
27        }
28    }
29
30    /// Retrieves a user property by index.
31    ///
32    /// May be used in combination with [`EventDescription::user_property_count`] to enumerate event user properties.
33    pub fn get_user_property_by_index(&self, index: c_int) -> Result<UserProperty> {
34        let mut property = MaybeUninit::uninit();
35        unsafe {
36            FMOD_Studio_EventDescription_GetUserPropertyByIndex(
37                self.inner,
38                index,
39                property.as_mut_ptr(),
40            )
41            .to_result()?;
42
43            let property = UserProperty::from_ffi(property.assume_init());
44            Ok(property)
45        }
46    }
47
48    pub fn user_property_count(&self) -> Result<c_int> {
49        let mut count = 0;
50        unsafe {
51            FMOD_Studio_EventDescription_GetUserPropertyCount(self.inner, &mut count)
52                .to_result()?;
53        }
54        Ok(count)
55    }
56}