Limit event_name to the actual list of valid event names

This commit is contained in:
projectmoon 2024-03-27 12:12:44 +01:00
parent 91f3eecaf6
commit b301eaa476
2 changed files with 15 additions and 0 deletions

View File

@ -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),
};

View File

@ -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,
}