pub trait Prototypical: Asset + Sized {
    type Id: Clone + Debug + Eq + Hash + Send + Sync + ToString;
    type Child: PrototypicalChild<Self>;

    // Required methods
    fn id(&self) -> &Self::Id;
    fn path(&self) -> &ProtoPath;
    fn schematics(&self) -> &Schematics;
    fn schematics_mut(&mut self) -> &mut Schematics;
    fn templates(&self) -> Option<&Templates>;
    fn templates_mut(&mut self) -> Option<&mut Templates>;
    fn dependencies(&self) -> &Dependencies;
    fn dependencies_mut(&mut self) -> &mut Dependencies;
    fn children(&self) -> Option<&Children<Self>>;
    fn children_mut(&mut self) -> Option<&mut Children<Self>>;

    // Provided method
    fn requires_entity(&self) -> bool { ... }
}
Expand description

The trait used to define a prototype.

Prototypes are containers for Schematics that can be spawned in at runtime. They may also inherit from other prototypes (where the inherited prototypes are known as Templates) and contain a hierarchy of Children.

Required Associated Types§

source

type Id: Clone + Debug + Eq + Hash + Send + Sync + ToString

The type used to identify this prototype.

This can be used to control how a prototype is accessed. For example, if we wanted to split prototypes into “packages”, then we could require a package identifier along with the prototype name in order to access the prototype:

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct MyProtoId {
  package: String,
  name: String,
}

impl Display for MyProtoId {
  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
    write!(f, "{}::{}", self.package, self.name)
  }
}
source

type Child: PrototypicalChild<Self>

The type of the child this prototype uses.

This is used to configure how a child is processed.

Required Methods§

source

fn id(&self) -> &Self::Id

The ID of this prototype.

source

fn path(&self) -> &ProtoPath

The path to this prototype’s asset file.

source

fn schematics(&self) -> &Schematics

An immutable reference to the collection of Schematics contained in this prototype.

source

fn schematics_mut(&mut self) -> &mut Schematics

A mutable reference to the collection of Schematics contained in this prototype.

source

fn templates(&self) -> Option<&Templates>

An immutable reference to the collection of Templates inherited by this prototype, if any.

source

fn templates_mut(&mut self) -> Option<&mut Templates>

A mutable reference to the collection of Templates inherited by this prototype, if any.

source

fn dependencies(&self) -> &Dependencies

An immutable reference to the collection of Dependencies used by this prototype.

source

fn dependencies_mut(&mut self) -> &mut Dependencies

A mutable reference to the collection of Dependencies used by this prototype.

source

fn children(&self) -> Option<&Children<Self>>

An immutable reference to the collection of Children contained in this prototype, if any.

source

fn children_mut(&mut self) -> Option<&mut Children<Self>>

A mutable reference to the collection of Children contained in this prototype, if any.

Provided Methods§

source

fn requires_entity(&self) -> bool

Whether or not this prototype requires an entity to be spawned.

Defaults to true.

Implementors§