builtin scripts

This commit is contained in:
2026-06-16 14:34:42 -05:00
parent 7608fc959f
commit 6464e47747
13 changed files with 317 additions and 119 deletions
+20 -1
View File
@@ -143,6 +143,7 @@ pub(crate) struct ObjectTemplate {
pub opaque: bool,
pub pushable: bool,
pub script_name: Option<String>,
pub builtin_script: Option<&'static str>,
pub tags: Vec<String>,
pub name: Option<String>,
}
@@ -212,6 +213,7 @@ fn resolve_entry(ch: char, e: &PaletteEntry, errors: &mut Vec<LogLine>) -> Resol
opaque: e.opaque.unwrap_or(true),
pushable: e.pushable.unwrap_or(false),
script_name: e.script_name.clone(),
builtin_script: None,
tags: e.tags.clone().unwrap_or_default(),
name: e.name.clone(),
}),
@@ -233,7 +235,24 @@ fn resolve_entry(ch: char, e: &PaletteEntry, errors: &mut Vec<LogLine>) -> Resol
"player" => Resolved::Player,
// Any other kind must be an archetype name.
other => match Archetype::try_from(other) {
Ok(a) => Resolved::Cell(glyph_with_default(a.default_glyph()), a),
// Script-backed archetypes (e.g. pushers) expand into an object carrying
// the embedded script plus a `BUILTIN_<archetype>` tag the script reads.
Ok(a) => match crate::builtin_scripts::archetype_script(a) {
Some(src) => {
let b = a.behavior();
Resolved::Object(ObjectTemplate {
glyph: glyph_with_default(a.default_glyph()),
solid: b.solid,
opaque: b.opaque,
pushable: false,
script_name: None,
builtin_script: Some(src),
tags: vec![crate::builtin_scripts::builtin_tag(a)],
name: None,
})
}
None => Resolved::Cell(glyph_with_default(a.default_glyph()), a),
},
Err(msg) => {
errors.push(LogLine::error(format!(
"palette '{ch}': {msg}; using error block"