-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration to flip node (#37)
- Loading branch information
Showing
13 changed files
with
282 additions
and
69 deletions.
There are no files selected for viewing
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,34 @@ | ||
name: DryRun | ||
|
||
on: {} | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
# Run cargo publish pipeline as a dry run | ||
dry_run: | ||
name: Dry Run Publish | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v4 | ||
- name: Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.toml') }} | ||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
- name: Install Dependencies | ||
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev | ||
- name: Run cargo publish dry run for library | ||
run: cargo publish --dry-run -p bevy_animation_graph | ||
- name: Run cargo publish dry run for editor | ||
run: cargo publish --dry-run -p bevy_animation_graph_editor |
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
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
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,140 @@ | ||
use bevy::reflect::{std_traits::ReflectDefault, Reflect}; | ||
use regex::{escape, Regex}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Default, Reflect, Clone, Serialize, Deserialize)] | ||
#[reflect(Default)] | ||
pub struct FlipConfig { | ||
pub name_mapper: FlipNameMapper, | ||
} | ||
|
||
#[derive(Debug, Reflect, Clone)] | ||
#[reflect(Default)] | ||
pub struct PatternMapper { | ||
key_1: String, | ||
key_2: String, | ||
pattern_before: String, | ||
pattern_after: String, | ||
#[reflect(ignore, default = "default_regex")] | ||
regex: Regex, | ||
} | ||
|
||
pub fn default_regex() -> Regex { | ||
Regex::new("").unwrap() | ||
} | ||
|
||
impl TryFrom<PatternMapperSerial> for PatternMapper { | ||
type Error = regex::Error; | ||
|
||
fn try_from(value: PatternMapperSerial) -> Result<Self, Self::Error> { | ||
let regex = Regex::new(&format!( | ||
"({})({}|{})({})", | ||
&value.pattern_before, | ||
escape(&value.key_1), | ||
escape(&value.key_2), | ||
&value.pattern_after, | ||
))?; | ||
|
||
Ok(Self { | ||
key_1: value.key_1, | ||
key_2: value.key_2, | ||
pattern_before: value.pattern_before, | ||
pattern_after: value.pattern_after, | ||
regex, | ||
}) | ||
} | ||
} | ||
|
||
impl From<PatternMapper> for PatternMapperSerial { | ||
fn from(value: PatternMapper) -> Self { | ||
Self { | ||
key_1: value.key_1, | ||
key_2: value.key_2, | ||
pattern_before: value.pattern_before, | ||
pattern_after: value.pattern_after, | ||
} | ||
} | ||
} | ||
|
||
impl Default for PatternMapper { | ||
fn default() -> Self { | ||
Self::try_from(PatternMapperSerial::default()).unwrap() | ||
} | ||
} | ||
|
||
impl Serialize for PatternMapper { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
PatternMapperSerial::from(self.clone()).serialize(serializer) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for PatternMapper { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
PatternMapperSerial::deserialize(deserializer).map(|r| r.try_into().unwrap()) | ||
} | ||
} | ||
|
||
impl PatternMapper { | ||
pub fn flip(&self, input: &str) -> Option<String> { | ||
if let Some(captures) = self.regex.captures(input) { | ||
let key_capture = captures.get(2).unwrap().as_str(); | ||
let replacement_key = if key_capture == self.key_1 { | ||
&self.key_2 | ||
} else { | ||
&self.key_1 | ||
}; | ||
Some( | ||
self.regex | ||
.replace(input, format!("${{1}}{replacement_key}${{3}}")) | ||
.into(), | ||
) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Reflect, Serialize, Deserialize, Clone)] | ||
pub struct PatternMapperSerial { | ||
pub key_1: String, | ||
pub key_2: String, | ||
pub pattern_before: String, | ||
pub pattern_after: String, | ||
} | ||
|
||
impl Default for PatternMapperSerial { | ||
fn default() -> Self { | ||
Self { | ||
key_1: "L".into(), | ||
key_2: "R".into(), | ||
pattern_before: r"^.*".into(), | ||
pattern_after: r"$".into(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Reflect, Clone, Serialize, Deserialize)] | ||
#[reflect(Default)] | ||
pub enum FlipNameMapper { | ||
Pattern(PatternMapper), | ||
} | ||
|
||
impl Default for FlipNameMapper { | ||
fn default() -> Self { | ||
Self::Pattern(PatternMapper::default()) | ||
} | ||
} | ||
|
||
impl FlipNameMapper { | ||
pub fn flip(&self, input: &str) -> Option<String> { | ||
match self { | ||
Self::Pattern(pattern) => pattern.flip(input), | ||
} | ||
} | ||
} |
Oops, something went wrong.