-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add mist export plugin * implement suggestions --------- Co-authored-by: LtPeriwinkle <[email protected]>
- Loading branch information
1 parent
2ca0c1e
commit 6642eae
Showing
9 changed files
with
168 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
//! Exporter plugin for mist split files | ||
|
||
use std::borrow::Cow; | ||
use std::collections::BTreeSet; | ||
|
||
use mist_core::timer::Run; | ||
|
||
use serde_json::Value; | ||
|
||
use super::should_split_on; | ||
|
||
use crate::comp::CompDoc; | ||
use crate::expo::{ExpoBlob, ExpoDoc, ExportIcon, ExportMetadata}; | ||
use crate::export_error; | ||
use crate::json::Coerce; | ||
use crate::macros::async_trait; | ||
use crate::plugin::{PluginResult, Runtime}; | ||
|
||
pub struct ExportMist; | ||
|
||
#[async_trait(auto)] | ||
impl Runtime for ExportMist { | ||
fn get_id(&self) -> Cow<'static, str> { | ||
Cow::Owned(super::Native::ExportMist.id()) | ||
} | ||
|
||
async fn on_prepare_export(&mut self) -> PluginResult<Option<Vec<ExportMetadata>>> { | ||
let meta = ExportMetadata { | ||
plugin_id: self.get_id().into_owned(), | ||
name: "mist".into(), | ||
description: "Export to a mist split file".into(), | ||
icon: ExportIcon::Data, | ||
extension: Some("msf".into()), | ||
export_id: None, | ||
example_config: Some(include_str!("./export_mist.yaml").into()), | ||
learn_more: Some("/docs/plugin/export-mist#export-mist".into()), | ||
}; | ||
Ok(Some(vec![meta])) | ||
} | ||
|
||
async fn on_export_comp_doc<'p>( | ||
&mut self, | ||
_: &str, | ||
payload: &Value, | ||
doc: &CompDoc<'p>, | ||
) -> PluginResult<Option<ExpoDoc>> { | ||
let payload = match payload.as_object() { | ||
Some(payload) => payload, | ||
None => return export_error!("Invalid payload"), | ||
}; | ||
let mut split_types = BTreeSet::new(); | ||
if let Some(x) = payload.get("split-types") { | ||
let x = match x.as_array() { | ||
Some(x) => x, | ||
_ => return export_error!("Invalid split types"), | ||
}; | ||
let names: BTreeSet<String> = x.iter().map(|x| x.coerce_to_string()).collect(); | ||
for (tag_name, tag) in doc.config.tags.iter() { | ||
if let Some(split_type) = &tag.split_type { | ||
if names.contains(split_type) { | ||
split_types.insert(tag_name.clone()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if split_types.is_empty() { | ||
return export_error!("No splits to export. Make sure you selected at least one split type in the settings."); | ||
} | ||
|
||
let mut run = Run::empty(); | ||
let mut splits = vec![]; | ||
for section in &doc.route { | ||
for line in section.lines.iter() { | ||
if should_split_on(line, &split_types) { | ||
splits.push(line.split_name.as_ref().unwrap_or(&line.text).to_string()) | ||
} | ||
} | ||
} | ||
|
||
if splits.is_empty() { | ||
return export_error!("No splits to export. Make sure you selected at least one split type in the settings."); | ||
} | ||
|
||
run.set_splits(&splits); | ||
let content = run.to_string(); | ||
if content.is_err() { | ||
return export_error!("Failed to serialize split file"); | ||
} | ||
|
||
Ok(Some(ExpoDoc::Success { | ||
file_name: format!("{}.msf", doc.config.meta.title), | ||
file_content: ExpoBlob::from_utf8(content.unwrap()), | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Keep this as-is to use the splits configured in the settings | ||
split-types: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
# Export mist | ||
The `export-mist` plugin lets you export the route to a split file (.msf) for mist. | ||
|
||
This plugin comes pre-configured in the web app: | ||
|
||
1. Click on <FluentIcon name="Settings20Regular" /> `Settings`. | ||
2. Select the <FluentIcon name="Wrench20Regular" /> `Plugins` category. | ||
3. Under `App Plugins`, make sure `Export split files` is checked. | ||
|
||
Alternatively, you can add it to the route configuration: | ||
```yaml | ||
config: | ||
- plugins: | ||
- use: export-mist | ||
``` | ||
## Extra Options | ||
This plugin provides the same split type configuration as [the LiveSplit plugin](/plugin/export-livesplit#split-types). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters