diff options
author | Griffin Smith <root@gws.fyi> | 2019-07-20T01·55-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-07-20T01·55-0400 |
commit | 29c80ac8ba0d733c6c452d8fd39e9561553495b0 (patch) | |
tree | f8384229d84b0d281c2fbbe976aeb5ebc21bdc24 /src/messages.rs | |
parent | 4e9138aa6ff72e34392e3467c40d5ddf095f0027 (diff) |
Add the beginning of item entities
Add a new Item raw type and entity type, with preliminary, basic support for food. There's a really frustrating toml-rs bug that prevents writing these nicely as toml right now, so I also added support for mixing JSON and TOML in a single config dir
Diffstat (limited to 'src/messages.rs')
-rw-r--r-- | src/messages.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/messages.rs b/src/messages.rs index 9ca78025ec60..719389fa6136 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; #[derive(Deserialize, Debug, PartialEq, Eq)] #[serde(untagged)] -enum Message<'a> { +pub enum Message<'a> { #[serde(borrow)] Single(Template<'a>), Choice(Vec<Template<'a>>), @@ -123,6 +123,13 @@ static_cfg! { static ref MESSAGES: NestedMap<'static> = toml_file("messages.toml"); } +pub fn get<R: Rng + ?Sized>( + name: &'static str, + rng: &mut R, +) -> Option<&'static Template<'static>> { + MESSAGES.lookup(name).and_then(|msg| msg.resolve(rng)) +} + /// Look up and format a game message based on the given (dot-separated) name, /// with the given random generator used to select from choice-based messages pub fn message<'a, R: Rng + ?Sized>( @@ -130,7 +137,7 @@ pub fn message<'a, R: Rng + ?Sized>( rng: &mut R, params: &TemplateParams<'a>, ) -> String { - match MESSAGES.lookup(name).and_then(|msg| msg.resolve(rng)) { + match get(name, rng) { Some(msg) => msg.format(params).unwrap_or_else(|e| { error!("Error formatting template: {}", e); "Template Error".to_string() |