(
&mut self,
lines: &[(usize, String)],
block_index: &mut usize,
)
| 151 | } |
| 152 | "choose" => { |
| 153 | let num = arg.parse::<usize>().map_err(ScriptError::from)?; |
| 154 | let mut choose_branch = HashMap::with_capacity(num); |
| 155 | let explain = lines[index + 1].1.clone(); |
| 156 | for (i, line) in lines.iter().take(index + num + 1 + 1).skip(index + 2) |
| 157 | { |
| 158 | if let Some((choice, script)) = line.split_once(' ') { |
| 159 | let (choice, label) = match script.split_once(":") { |
| 160 | Some((name, label)) |
| 161 | if !name.is_empty() && !label.is_empty() => |
| 162 | { |
| 163 | ( |
| 164 | choice.to_string(), |
| 165 | (name.to_string(), label.to_string()), |
| 166 | ) |
| 167 | } |
| 168 | Some((name, "")) if !name.is_empty() => ( |
| 169 | choice.to_string(), |
| 170 | (name.to_string(), "start".to_string()), |
| 171 | ), |
| 172 | Some(("", label)) => ( |
| 173 | choice.to_string(), |
| 174 | (self.name().to_string(), label.to_string()), |
| 175 | ), |
| 176 | None => ( |
| 177 | choice.to_string(), |
| 178 | (script.to_string(), "start".to_string()), |
| 179 | ), |
| 180 | _ => unreachable!(), |
| 181 | }; |
| 182 | choose_branch.insert(choice.clone(), label.clone()); |
| 183 | self.insert_choice(choice, label); |
| 184 | } else { |
| 185 | return Err(EngineError::from(ScriptError::Choice(format!( |
| 186 | "Invalid choice at line {i}: {line}" |
| 187 | )))); |
| 188 | } |
| 189 | } |
| 190 | block_commands.push(Choice((explain, choose_branch))); |
| 191 | break; |
| 192 | } |
| 193 | "voice" => { |
| 194 | if let Some((name, voice)) = arg.split_once('|') { |
| 195 | PlayVoice { |
| 196 | name: name.to_string(), |
| 197 | voice: voice.to_string(), |
| 198 | } |
| 199 | } else { |
| 200 | return Err(EngineError::from(ScriptError::ArgsTooShort { |
| 201 | cmd: "voice".to_string(), |
| 202 | line: *line_num, |
| 203 | content: line.to_string(), |
| 204 | })); |
| 205 | } |
| 206 | } |
| 207 | "video" => { |
| 208 | let name = arg.trim(); |
| 209 | if name.is_empty() { |
| 210 | return Err(EngineError::from(ScriptError::ArgsTooShort { |
no test coverage detected