size = [18.25, 24.25]
item_suffix = "-c"
-sort = "card-playing-c_s"
-desc_template = "the _desc of clubs"
+sort = "card-playing-c${s}"
+desc_template = "the ${desc} of clubs"
occulted.method = "ByBack"
occulted.ilk = "card-back"
[group.diamonds]
inherit = "clubs"
item_suffix = "-d"
-sort = "card-playing-d_s"
-desc_template = "the _desc of diamonds"
+sort = "card-playing-d${s}"
+desc_template = "the ${desc} of diamonds"
[group.hearts]
inherit = "clubs"
-sort = "card-playing-h_s"
+sort = "card-playing-h${s}"
item_suffix = "-h"
-desc_template = "the _desc of hearts"
+desc_template = "the ${desc} of hearts"
[group.spades]
inherit = "clubs"
-sort = "card-playing-s_s"
+sort = "card-playing-s${s}"
item_suffix = "-s"
-desc_template = "the _desc of spades"
+desc_template = "the ${desc} of spades"
outline.size = [14]
item_prefix = "die-image-"
files = """
-d6-_c - a _colour die image
+d6-_c - a ${colour} die image
"""
magic.item_prefix = "die-"
image = !
type = "Die"
labels = 6
-desc = "a _colour die"
+desc = "a ${colour} die"
occult.label = "?"
-occult.ilk = "d6-_colour"
+occult.ilk = "d6-${colour}"
"""
[group.dice.colours.blue]
occulted.colour = "grey"
files = """
-_c-P plt45 a _colour pawn
-_c-B blt45 a _colour bishop
-_c-R rlt45 a _colour rook
-_c-K klt45 the _colour king
-_c-Q qlt45 the _colour queen
-
-_c-elephant elt45 a _colour elephant piece
-_c-mann Mlt45 a _colour Mann piece
+_c-P plt45 a ${colour} pawn
+_c-B blt45 a ${colour} bishop
+_c-R rlt45 a ${colour} rook
+_c-K klt45 the ${colour} king
+_c-Q qlt45 the ${colour} queen
+
+_c-elephant elt45 a ${colour} elephant piece
+_c-mann Mlt45 a ${colour} Mann piece
"""
[group.chess.colours.white]
inherit = "chess"
scale = 0.3461
files = """
-_c-siege-engine tlt26 a _colour siege engine piece
+_c-siege-engine tlt26 a ${colour} siege engine piece
"""
[group.chess-flip]
inherit = "chess"
flip = true
files = """
-_c-N alt45 a _colour knight
+_c-N alt45 a ${colour} knight
-_c-giraffe Glt45 a _colour giraffe piece
-_c-knight-king Cet45 a _colour knight king piece
+_c-giraffe Glt45 a ${colour} giraffe piece
+_c-knight-king Cet45 a ${colour} knight king piece
# ^ wikimedia calls these Centaurs
-_c-ship ship_slt45 a _colour ship piece
-_c-zebra Zlt45 a _colour zebra piece
+_c-ship ship_slt45 a ${colour} ship piece
+_c-zebra Zlt45 a ${colour} zebra piece
"""
[group.chess-flip-26]
inherit = "chess-26"
flip = true
files = """
-_c-flag Blt26 a _colour flag piece
+_c-flag Blt26 a ${colour} flag piece
"""
[group.chess-flip-26-ship-adj]
inherit = "chess-flip-26"
flip = true
files = """
-_c-cannon Clt26 a _colour cannon piece
+_c-cannon Clt26 a ${colour} cannon piece
"""
[group.chess-anomalous-filenames]
inherit = "chess"
stem_prefix = ""
files = """
-_c-commoner Commoner_Transparent a _colour commoner piece
+_c-commoner Commoner_Transparent a ${colour} commoner piece
"""
[group.chess-onecolour]
pub struct Substituting<'s> {
s: Cow<'s, str>,
mformat: materials_format::Version,
+ dollars: bool,
}
impl<'s> Substituting<'s> {
pub fn new<S: Into<Cow<'s, str>>>(mformat: materials_format::Version, s: S)
-> Self {
- Substituting { s: s.into(), mformat }
+ Substituting { s: s.into(), mformat, dollars: false }
}
#[throws(SubstError)]
pub fn finish(self) -> String {
- self.s.into()
+ if self.dollars {
+ subst_general_precisely(&self, "${$}", true, "$")?.0
+ } else {
+ self
+ }.s.into()
}
#[throws(SubstError)]
}
#[throws(SubstError)]
-fn subst_general_mf1<'i>(input: &Substituting<'i>,
- needle: &'static str, replacement: &str)
- -> (Substituting<'i>, usize) {
+fn subst_general_precisely<'i>(input: &Substituting<'i>,
+ needle: & str, dollars: bool,
+ replacement: &str)
+ -> (Substituting<'i>, usize) {
let mut count = 0;
let mut work = (*input.s).to_owned();
for m in input.s.rmatch_indices(needle) {
+ replacement
+ rhs
}
- (Substituting{ s: work.into(), mformat: input.mformat }, count)
+ (Substituting{
+ s: work.into(),
+ mformat: input.mformat,
+ dollars: input.dollars | dollars,
+ }, count)
+}
+
+#[throws(SubstError)]
+fn subst_general_mf2<'i>(input: &Substituting<'i>,
+ needle: &'static str, replacement: &str)
+ -> (Substituting<'i>, usize) {
+ let needle_buf;
+ let (needle, dollars) = if needle != "_c" {
+ let token = needle.strip_prefix('_').expect("needle has no '_'");
+ needle_buf = format!("${{{}}}", token);
+ (&*needle_buf, true)
+ } else {
+ (needle, false)
+ };
+ subst_general_precisely(input, needle, dollars, replacement)?
}
#[throws(SubstError)]
// Substituting and do them all at once.
fn subst_general<'i>(input: &Substituting<'i>,
needle: &'static str, replacement: &str)
- -> (Substituting<'i>, usize) {
- subst_general_mf1(input, needle, replacement)?
+ -> (Substituting<'i>, usize) {
+ if input.mformat == 1 {
+ subst_general_precisely(input, needle, false, replacement)?
+ } else {
+ subst_general_mf2(input, needle, replacement)?
+ }
}
#[throws(SubstError)]