Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple icons per line #77

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler-core/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ tasks:
- src/lang/tempstr/grammar.rs
- src/lang/rich/grammar.rs
- src/lang/preset/grammar.rs

watch:
desc: Run compiler core tests in watch mode
cmds:
- cargo watch -x test
6 changes: 5 additions & 1 deletion compiler-core/src/comp/comp_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ impl Compiler {
if let Some(i) = ref_stack.last() {
if let CompMovement::To { to, .. } = &output.movements[*i] {
output.map_coord = to.clone();
self.coord = to.clone();
} else {
unreachable!();
}
Expand Down Expand Up @@ -1242,7 +1243,7 @@ mod test {
"".to_string(),
GameCoord(1.0, 2.0, 3.0),
);
let mut compiler = builder.build();
let mut compiler = builder.clone().build();

test_comp_ok(
&mut compiler,
Expand All @@ -1259,7 +1260,9 @@ mod test {
},
)
.await;
assert_eq!(compiler.coord, GameCoord(4.0, 5.0, 6.0));

let mut compiler = builder.clone().build();
test_comp_ok(
&mut compiler,
json!({
Expand All @@ -1284,6 +1287,7 @@ mod test {
)
.await;

let mut compiler = builder.build();
test_comp_err(
&mut compiler,
json!({
Expand Down
70 changes: 70 additions & 0 deletions compiler-core/src/comp/comp_movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ pub enum CompMovement {
To {
/// The target coord to move to
to: GameCoord,

/// If the movement is a warp
warp: bool,

/// If the movement coord should be excluded
///
/// This affects if the map will consider this coord when
/// changing view to the line
exclude: bool,

/// Optional color to override the color of the line
color: Option<String>,

/// Optional icon at the movement point
icon: Option<String>,
},
Push,
Pop,
Expand All @@ -37,6 +43,7 @@ impl CompMovement {
warp: false,
exclude: false,
color: None,
icon: None,
}
}
}
Expand Down Expand Up @@ -80,6 +87,7 @@ impl Compiler {
let mut warp = false;
let mut exclude = false;
let mut color = None;
let mut icon = None;

let mut should_fail = false;

Expand Down Expand Up @@ -121,6 +129,14 @@ impl Compiler {
)));
}
},
prop::ICON => match value {
Value::Array(_) | Value::Object(_) => {
errors.push(CompilerError::InvalidLinePropertyType(format!(
"{prop_name}.{}", prop::ICON
)));
}
_ => icon = Some(value.coerce_to_string()),
}
_ => {
errors
.push(CompilerError::UnusedProperty(format!("{prop_name}.{key}")));
Expand All @@ -142,6 +158,7 @@ impl Compiler {
warp,
exclude,
color,
icon,
})
}
}
Expand Down Expand Up @@ -244,6 +261,7 @@ mod test {
warp: true,
exclude: false,
color: None,
icon: None,
})
);
assert_eq!(errors, vec![]);
Expand All @@ -266,6 +284,7 @@ mod test {
warp: true,
exclude: true,
color: None,
icon: None,
})
);
assert_eq!(errors, vec![]);
Expand All @@ -288,6 +307,7 @@ mod test {
warp: false,
exclude: true,
color: Some("red".to_string()),
icon: None,
})
);
assert_eq!(errors, vec![]);
Expand All @@ -309,10 +329,60 @@ mod test {
warp: false,
exclude: false,
color: None,
icon: None,
})
);
assert_eq!(errors, vec![]);

errors.clear();
assert_eq!(
compiler
.comp_movement(
"",
json!({
"to": [1, 2, 4],
"icon": "something",
}),
&mut errors
)
.await,
Some(CompMovement::To {
to: GameCoord(1.0, 2.0, 4.0),
warp: false,
exclude: false,
color: None,
icon: Some("something".to_string()),
})
);
assert_eq!(errors, vec![]);

errors.clear();
assert_eq!(
compiler
.comp_movement(
"te",
json!({
"to": [1, 2, 4],
"icon": []
}),
&mut errors
)
.await,
Some(CompMovement::To {
to: GameCoord(1.0, 2.0, 4.0),
warp: false,
exclude: false,
color: None,
icon: None,
})
);
assert_eq!(
errors,
vec![CompilerError::InvalidLinePropertyType(
"te.icon".to_string()
)]
);

errors.clear();
assert_eq!(
compiler
Expand Down
16 changes: 8 additions & 8 deletions compiler-core/src/comp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ pub enum CompilerError {
/// When a line property type is invalid.
///
/// Arg is property name or path
#[error("Line property {0} has invalid type")]
#[error("Line property `{0}` has invalid type")]
InvalidLinePropertyType(String),

/// When a preset string is malformed, like `foo` or `_foo::` or `_bar<foo`
#[error("Preset string {0} is malformed")]
#[error("Preset string `{0}` is malformed")]
InvalidPresetString(String),

/// When a preset is not found
#[error("Preset {0} is not found")]
#[error("Preset `{0}` is not found")]
PresetNotFound(String),

/// When presets recurse too much
#[error("Maximum preset depth exceeded when processing the preset {0}. Did you have circular references in your presets?")]
#[error("Maximum preset depth exceeded when processing the preset `{0}`. Did you have circular references in your presets?")]
MaxPresetDepthExceeded(String),

/// When an unexpected property is specified and not used by compiler
#[error("Property {0} is unused. Did you misspell it?")]
#[error("Property `{0}` is unused. Did you misspell it?")]
UnusedProperty(String),

/// When the counter property has rich text with more than one tag
Expand All @@ -102,19 +102,19 @@ pub enum CompilerError {
InvalidMovementType,

/// When the coordinate specified as part of movement is not an array
#[error("The coordinate specified by {0} is not an array.")]
#[error("The coordinate specified by `{0}` is not an array.")]
InvalidCoordinateType(String),

/// When the coordinate specified as part of movement has too few or too many elements
#[error("Some of the coordinates specified may not be valid. Coordinates must have either 2 or 3 components.")]
InvalidCoordinateArray,

/// When the coordinate value inside coordinate array is not valid
#[error("{0} is not a valid coordinate value.")]
#[error("`{0}` is not a valid coordinate value.")]
InvalidCoordinateValue(String),

/// When a preset specified as part of a movement does not contain the `movements` property
#[error("Preset {0} cannot be used inside hte `movements` property because it does not contain any movement.")]
#[error("Preset `{0}` cannot be used inside hte `movements` property because it does not contain any movement.")]
InvalidMovementPreset(String),

/// When the value specified as part of marker is invalid
Expand Down
2 changes: 1 addition & 1 deletion compiler-core/src/exec/exec_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl CompDoc {
map_builder.add_coord("", &self.project.map.initial_coord);
let mut sections = vec![];
async_for!((index, section) in self.route.into_iter().enumerate(), {
let exec_section = section.exec(index, &mut map_builder).await?;
let exec_section = section.exec(&self.project, index, &mut map_builder).await?;
sections.push(exec_section);
})?;
Ok(ExecDoc {
Expand Down
Loading