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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use crate::{
    c::{spEvent, spEventData},
    c_interface::{NewFromPtr, SyncPtr},
    TrackEntry,
};

#[allow(unused_imports)]
use crate::AnimationState;

/// A wrapper for [`Event`] that makes events slightly nicer to work with in Rust.
///
/// To receive events, see [`AnimationState::set_listener`].
pub enum AnimationEvent<'a> {
    Start {
        /// The track this event originated from.
        track_entry: TrackEntry,
    },
    Interrupt {
        /// The track this event originated from.
        track_entry: TrackEntry,
    },
    End {
        /// The track this event originated from.
        track_entry: TrackEntry,
    },
    Complete {
        /// The track this event originated from.
        track_entry: TrackEntry,
    },
    Dispose {
        /// The track this event originated from.
        track_entry: TrackEntry,
    },
    Event {
        /// The track this event originated from.
        track_entry: TrackEntry,
        /// The name of the event, which is unique across all events in the skeleton.
        name: &'a str,
        /// The animation time this event was keyed.
        time: f32,
        /// The event's int value.
        int: i32,
        /// The event's float value.
        float: f32,
        /// The event's string value or an empty string.
        string: &'a str,
        /// The event's audio path or an empty string.
        audio_path: &'a str,
        /// The event's audio volume.
        volume: f32,
        /// The event's audio balance.
        balance: f32,
        /// The raw event data.
        event: Event,
    },
}

/// Events fired from animations.
///
/// [Spine API Reference](http://esotericsoftware.com/spine-api-reference#Event)
///
/// To receive events, see [`AnimationState::set_listener`].
#[derive(Debug)]
pub struct Event {
    c_event: SyncPtr<spEvent>,
}

impl NewFromPtr<spEvent> for Event {
    unsafe fn new_from_ptr(c_event: *mut spEvent) -> Self {
        Self {
            c_event: SyncPtr(c_event),
        }
    }
}

impl Event {
    c_accessor_tmp_ptr_mut!(
        /// The events's setup pose data.
        data,
        /// The events's mutable setup pose data.
        data_mut,
        data,
        EventData,
        spEventData
    );
    c_accessor!(
        /// The animation time this event was keyed.
        time,
        time,
        f32
    );
    c_accessor!(
        /// The event's int value.
        int_value,
        intValue,
        i32
    );
    c_accessor!(
        /// The event's float value.
        float_value,
        floatValue,
        f32
    );
    c_accessor_string!(
        /// The event's string value or an empty string.
        string_value,
        stringValue
    );
    c_accessor!(
        /// The event's audio volume value.
        volume,
        volume,
        f32
    );
    c_accessor!(
        /// The event's audio balance value.
        balance,
        balance,
        f32
    );
    c_ptr!(c_event, spEvent);
}

/// Static event data imported from Spine.
///
/// [Spine API Reference](http://esotericsoftware.com/spine-api-reference#EventData)
#[derive(Debug)]
pub struct EventData {
    c_event_data: SyncPtr<spEventData>,
}

impl NewFromPtr<spEventData> for EventData {
    unsafe fn new_from_ptr(c_event_data: *mut spEventData) -> Self {
        Self {
            c_event_data: SyncPtr(c_event_data),
        }
    }
}

impl EventData {
    c_accessor_string!(
        ///The name of the event, which is unique across all events in the skeleton.
        name,
        name
    );
    c_accessor!(
        /// The event's int value.
        int_value,
        intValue,
        i32
    );
    c_accessor!(
        /// The event's float value.
        float_value,
        floatValue,
        f32
    );
    c_accessor_string!(
        /// The event's string value or an empty string.
        string_value,
        stringValue
    );
    c_accessor_string!(
        /// The event's audio path.
        audio_path,
        audioPath
    );
    c_accessor!(
        /// The event's audio volume value.
        volume,
        volume,
        f32
    );
    c_accessor!(
        /// The event's audio balance value.
        balance,
        balance,
        f32
    );
    c_ptr!(c_event_data, spEventData);
}