plasma-prp 0.1.0

Read, write, inspect, and manipulate Plasma engine PRP files used by Myst Online: Uru Live
Documentation
//! plModifier — base trait for scene object behaviors.
//!
//! Modifiers are attached to plSceneObjects and receive messages sent to
//! their target objects. They provide per-frame evaluation and message handling.
//!
//! C++ ref: pnModifier/plModifier.h/.cpp, plMsgForwarder.h/.cpp

use crate::core::uoid::Uoid;

/// Trait for all modifiers — objects that attach to scene objects and
/// respond to messages and per-frame updates.
///
/// Corresponds to plModifier in C++.
pub trait Modifier: Send + Sync {
    /// Get the class index of this modifier.
    fn class_index(&self) -> u16;

    /// Get the number of targets this modifier is attached to.
    fn num_targets(&self) -> usize;

    /// Add a target scene object.
    fn add_target(&mut self, target: Uoid);

    /// Remove a target scene object.
    fn remove_target(&mut self, target: &Uoid);

    /// Per-frame evaluation. Called each frame for active modifiers.
    /// Returns true if the modifier's state changed.
    fn eval(&mut self, secs: f64, del: f32, dirty: u32) -> bool;
}

/// Single-target modifier base — most modifiers only have one target.
/// Corresponds to plSingleModifier in C++.
#[derive(Debug, Clone, Default)]
pub struct SingleModifierData {
    pub target: Option<Uoid>,
}

impl SingleModifierData {
    pub fn new() -> Self {
        Self { target: None }
    }

    pub fn set_target(&mut self, target: Uoid) {
        self.target = Some(target);
    }

    pub fn clear_target(&mut self) {
        self.target = None;
    }
}

/// plMsgForwarder — forwards messages from one key to multiple receivers.
#[derive(Debug, Clone, Default)]
pub struct MsgForwarderData {
    pub forward_keys: Vec<Uoid>,
}

impl MsgForwarderData {
    pub fn new() -> Self {
        Self {
            forward_keys: Vec::new(),
        }
    }

    pub fn add_forward_key(&mut self, key: Uoid) {
        self.forward_keys.push(key);
    }
}