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
//! This module introduces struct [`OptionObjects`], which manages vendor-specific BMS player configuration and that events.
use crate::bms::{parse::Result, prelude::*};
use std::collections::{BTreeMap, HashMap, btree_map::Entry};
#[derive(Debug, Default, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// This aggregate manages vendor-specific BMS player configuration and that events.
pub struct OptionObjects {
/// The message for overriding options of some BMS player.
pub options: Option<Vec<String>>,
/// The option messages corresponding to the id of the change option object.
pub change_options: HashMap<ObjId, String>,
/// Option events, indexed by time. #A6
pub option_events: BTreeMap<ObjTime, OptionObj>,
}
impl OptionObjects {
/// Adds a new option object to the notes.
///
/// # Errors
///
/// Returns [`ParseWarning`] if a conflict is found and the
/// provided [`Prompter`] decides to treat it as an error.
pub fn push_option_event(
&mut self,
option_obj: OptionObj,
prompt_handler: &impl Prompter,
) -> Result<()> {
match self.option_events.entry(option_obj.time) {
Entry::Vacant(entry) => {
entry.insert(option_obj);
Ok(())
}
Entry::Occupied(mut entry) => {
use crate::bms::parse::prompt::ChannelDuplication;
let existing = entry.get();
prompt_handler
.handle_channel_duplication(ChannelDuplication::OptionEvent {
time: option_obj.time,
older: existing,
newer: &option_obj,
})
.apply_channel(
entry.get_mut(),
option_obj.clone(),
option_obj.time,
Channel::OptionChange,
)
}
}
}
}