Limit event_name to the actual list of valid event names
This commit is contained in:
parent
91f3eecaf6
commit
b301eaa476
|
@ -9,6 +9,7 @@ use crate::models::world::scenes::{Exit, Prop, Scene, Stage};
|
|||
use crate::models::Insertable;
|
||||
use gbnf::prelude::limit::{GbnfLimitedComplex, GbnfLimitedPrimitive};
|
||||
use itertools::Itertools;
|
||||
use std::sync::OnceLock;
|
||||
use strum::VariantNames;
|
||||
use tabled::settings::Style;
|
||||
use tabled::{Table, Tabled};
|
||||
|
@ -19,6 +20,16 @@ const ITEM: &'static str = "item";
|
|||
const PROP: &'static str = "prop";
|
||||
const NO_KEY: &'static str = "n/a";
|
||||
|
||||
fn valid_event_names() -> &'static Vec<String> {
|
||||
static CELL: OnceLock<Vec<String>> = OnceLock::new();
|
||||
CELL.get_or_init(|| {
|
||||
CommandEvent::VARIANTS
|
||||
.into_iter()
|
||||
.map(|e| e.to_string())
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Tabled)]
|
||||
struct EntityTableRow<'a> {
|
||||
name: &'a str,
|
||||
|
@ -249,6 +260,7 @@ fn execution_gbnf_limit<'a>(stage: &'a Stage) -> RawCommandExecutionGbnfLimit {
|
|||
applies_to.push("self".to_string());
|
||||
|
||||
let event_limit = RawCommandEventGbnfLimit {
|
||||
event_name: GbnfLimitedPrimitive::new(valid_event_names().to_owned()),
|
||||
applies_to: GbnfLimitedPrimitive::new(applies_to),
|
||||
parameter: GbnfLimitedPrimitive::new(all_uuids),
|
||||
};
|
||||
|
|
|
@ -79,9 +79,12 @@ impl RawCommandExecution {
|
|||
#[derive(Debug, Serialize, Deserialize, Clone, Gbnf)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct RawCommandEvent {
|
||||
#[gbnf_limit_primitive]
|
||||
pub event_name: String,
|
||||
|
||||
#[gbnf_limit_primitive]
|
||||
pub applies_to: String,
|
||||
|
||||
#[gbnf_limit_primitive]
|
||||
pub parameter: String,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue