Coder Social home page Coder Social logo

ytaras / component_group Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sunjay/component_group

0.0 2.0 0.0 63 KB

A Rust crate for working with a group of Components (in the Specs ECS)

Home Page: https://docs.rs/component_group

License: Mozilla Public License 2.0

Rust 100.00%

component_group's Introduction

component_group

Crates.io Docs.rs Build Status Say Thanks!

This crate defines the ComponentGroup trait. This trait is used to make managing a group of specs::Component instances easier. This is useful for when you have several components that are often created, read, and updated together. You can use this trait to easily move an entire group of components between instances of specs::World.

Instead of having you keep duplicate code in sync across your application, this trait groups all of that logic in one place so you can focus and minimize the changes you need to make every time you add a component to the group.

The ComponentGroup trait can be automatically derived if each component in the group implements the Clone trait. This removes any of the boilerplate you may have needed to write in order to implement the trait yourself.

See the documentation for more details about the motivations for creating this trait and how to use it.

// Don't forget to add the component_group crate to your Cargo.toml file!
use component_group::ComponentGroup;

use specs::{World, Component, VecStorage, HashMapStorage};
use specs_derive::Component;

// These components are just for demonstration purposes. You should swap them
// out for your own. Components need to be Clone to use the automatic derive.

#[derive(Debug, Clone, Component)]
#[storage(VecStorage)]
pub struct Position {x: i32, y: i32}

#[derive(Debug, Clone, Component)]
#[storage(VecStorage)]
pub struct Velocity {x: i32, y: i32}

#[derive(Debug, Clone, Component)]
#[storage(VecStorage)]
pub struct Health(u32);

#[derive(Debug, Clone, Component)]
#[storage(HashMapStorage)]
pub struct Animation {frame: usize}

// This is all of the code you need to write to define the group and its operations!
#[derive(ComponentGroup)]
struct PlayerComponents {
    position: Position,
    velocity: Velocity,
    health: Health,
    // This optional component is allowed to not be present
    animation: Option<Animation>,
}

// Now you can easily add all of these components to an entity, load them all
// from the world, or even update them all at once!

component_group's People

Contributors

sunjay avatar ytaras avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.