From 8aeb7ce5a375e21b06d90eb8f086778dea071727 Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Tue, 12 Nov 2024 20:04:32 +0100 Subject: [PATCH] #1322 Make it possible to skip fields marked with #[default = "bla"] in Luau --- api/src/bindings/luau/luau_converter.rs | 14 +++++++++++++- playtime-api/src/persistence/mod.rs | 1 + resources/api/luau/playtime.luau | 12 ++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/api/src/bindings/luau/luau_converter.rs b/api/src/bindings/luau/luau_converter.rs index e2a5c4ed0..03f20a0d3 100644 --- a/api/src/bindings/luau/luau_converter.rs +++ b/api/src/bindings/luau/luau_converter.rs @@ -394,11 +394,23 @@ pub struct SerdeArgs { #[darling(default)] untagged: bool, #[darling(default)] - default: Option<()>, + default: Option, #[darling(default)] flatten: bool, } +#[derive(Debug)] +struct FlagOrStringAttribute; + +impl FromMeta for FlagOrStringAttribute { + fn from_meta(item: &Meta) -> Result { + match item { + Meta::Path(_) | Meta::NameValue(_) => Ok(Self), + _ => Err(darling::Error::unsupported_format("no default")), + } + } +} + impl<'a, H: Hook> Display for LuauEnum<'a, H> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { let args = serde_args(&self.value.attrs).next(); diff --git a/playtime-api/src/persistence/mod.rs b/playtime-api/src/persistence/mod.rs index b3324d778..a064fe7ae 100644 --- a/playtime-api/src/persistence/mod.rs +++ b/playtime-api/src/persistence/mod.rs @@ -1255,6 +1255,7 @@ pub struct Clip { /// It then sets this section to the portion that actually matters. Once set, this section /// rarely changes. #[serde(alias = "section")] + #[serde(default)] pub fixed_section: Section, #[serde(default)] pub pitch_shift: Semitones, diff --git a/resources/api/luau/playtime.luau b/resources/api/luau/playtime.luau index 30f9117c0..262057094 100644 --- a/resources/api/luau/playtime.luau +++ b/resources/api/luau/playtime.luau @@ -248,7 +248,7 @@ export type MatrixClipRecordSettings = { play_start_timing: ClipPlayStartTimingOverrideAfterRecording?, play_stop_timing: ClipPlayStopTimingOverrideAfterRecording?, time_base: ClipRecordTimeBase?, - looped: boolean, + looped: boolean?, midi_settings: MatrixClipRecordMidiSettings?, audio_settings: MatrixClipRecordAudioSettings?, } @@ -747,8 +747,8 @@ function module.ColumnSettings(value: ColumnSettings): ColumnSettings end export type ColumnClipPlaySettings = { - follows_scene: boolean, - exclusive: boolean, + follows_scene: boolean?, + exclusive: boolean?, track: TrackId?, start_timing: ClipPlayStartTiming?, stop_timing: ClipPlayStopTiming?, @@ -1018,11 +1018,11 @@ export type Clip = { start_timing: ClipPlayStartTiming?, stop_timing: ClipPlayStopTiming?, velocity_sensitivity: number?, - looped: boolean, + looped: boolean?, volume: number?, color: ClipColor?, dynamic_section: Section?, - fixed_section: Section, + fixed_section: Section?, pitch_shift: Semitones?, audio_settings: ClipAudioSettings?, midi_settings: ClipMidiSettings?, @@ -1033,7 +1033,7 @@ function module.Clip(value: Clip): Clip end export type ClipAudioSettings = { - apply_source_fades: boolean, + apply_source_fades: boolean?, time_stretch_mode: AudioTimeStretchMode?, resample_mode: VirtualResampleMode?, cache_behavior: AudioCacheBehavior?,