object tags
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use color::Rgba8;
|
||||
use std::collections::HashSet;
|
||||
use crate::glyph::Glyph;
|
||||
use crate::utils::ObjectId;
|
||||
|
||||
/// A scripted object placed on the board, loaded from a map file.
|
||||
///
|
||||
@@ -21,6 +23,11 @@ use crate::glyph::Glyph;
|
||||
/// `init()` and `tick(dt)` functions are called via [`GameState::run_init`] and
|
||||
/// [`GameState::tick`]. Other event hooks (touch, shoot, …) are future work.
|
||||
pub struct ObjectDef {
|
||||
/// Stable identity assigned by [`crate::board::Board::add_object`].
|
||||
/// `0` is the sentinel meaning "not yet inserted into a board".
|
||||
/// Real ids start at 1 and never change after assignment.
|
||||
/// Not serialized — the id is stamped on insert, not stored in map files.
|
||||
pub id: ObjectId,
|
||||
/// Column of this object on the board (0-indexed).
|
||||
pub x: usize,
|
||||
/// Row of this object on the board (0-indexed).
|
||||
@@ -40,6 +47,10 @@ pub struct ObjectDef {
|
||||
/// Name of the Rhai script in [`Board::scripts`] that drives this object.
|
||||
/// `None` means this object has no script yet.
|
||||
pub script_name: Option<String>,
|
||||
/// Open-ended string labels for this object. Serialized as a TOML array;
|
||||
/// not subject to any rate limit — mutations take effect immediately after
|
||||
/// the frame's action queue is drained.
|
||||
pub tags: HashSet<String>,
|
||||
}
|
||||
|
||||
impl ObjectDef {
|
||||
@@ -60,6 +71,7 @@ impl ObjectDef {
|
||||
/// round-trip correctly.
|
||||
pub fn new(x: usize, y: usize) -> Self {
|
||||
Self {
|
||||
id: 0,
|
||||
x,
|
||||
y,
|
||||
glyph: Self::default_glyph(),
|
||||
@@ -67,6 +79,7 @@ impl ObjectDef {
|
||||
opaque: true,
|
||||
pushable: false,
|
||||
script_name: None,
|
||||
tags: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user