Added scroll()

This commit is contained in:
2026-06-10 01:42:33 -05:00
parent c2168b992d
commit f73c02437d
7 changed files with 375 additions and 43 deletions
+21
View File
@@ -29,6 +29,19 @@ use rhai::{Dynamic, ImmutableString, Module};
/// How long a move occupies an object before it can act again, in seconds.
pub(crate) const MOVE_COST: f64 = 0.25;
/// One line of content in a [`Action::Scroll`] overlay.
///
/// Each element of the array passed to the `scroll()` Rhai function becomes a
/// `ScrollLine`: a plain string becomes [`Text`](ScrollLine::Text); a two-element
/// array `[choice, display]` becomes a [`Choice`](ScrollLine::Choice).
pub enum ScrollLine {
/// Plain text, word-wrapped to the scroll window width.
Text(String),
/// A selectable option: `choice` is the event name sent back to the source
/// object via `send`, and `display` is the label shown to the player.
Choice { choice: String, display: String },
}
/// One deferred mutation emitted by a script, applied by [`crate::game::GameState`]
/// after it is promoted onto the board queue.
///
@@ -52,6 +65,9 @@ pub(crate) enum Action {
SetColor { fg: Option<Rgba8>, bg: Option<Rgba8> },
/// Call `fn_name` on `target` object, optionally passing `arg`.
Send { target: ObjectId, fn_name: String, arg: Option<ScriptArg> },
/// Open a scrollable text overlay. Pauses game ticks while shown; a choice
/// selection dispatches [`Send`](Action::Send) to the source object.
Scroll(Vec<ScrollLine>),
}
// ── Direction helpers ─────────────────────────────────────────────────────────
@@ -128,6 +144,10 @@ pub(crate) fn action_to_map(action: &Action) -> rhai::Map {
m.insert("arg".into(), dyn_arg);
}
}
// Scroll lines are not round-trippable via the queue map API; emit type only.
Action::Scroll(_) => {
ins_str(&mut m, "type", "Scroll");
}
}
m
}
@@ -202,6 +222,7 @@ impl TryFrom<rhai::Map> for Action {
};
Ok(Action::Send { target: target as ObjectId, fn_name, arg })
}
"Scroll" => Err("Scroll actions cannot be constructed from maps".to_string()),
other => Err(format!("unknown action type: '{other}'")),
}
}