feather icon indicating copy to clipboard operation
feather copied to clipboard

High-Level Entity Methods (WIP)

Open caelunshun opened this issue 5 years ago • 0 comments

This PR aims to create a framework for high-level entity methods like "get item in main hand," "deal damage," "send message," etc. These methods require access to multiple components, so they cannot be implemented as methods on a single component struct. The approach taken by this PR is to provide entity wrapper structs for each entity. These wrapper structs implement traits providing the high-level methods.

For example, the Player struct implements the SendMessage trait providing the send_message() method.

Entity wrappers can be used in queries in the same way components are used right now. For example, to send a message to all players using Quill:

use quill::entities::{Player, SendMessage};
for (_, player) in game.query::<Player>() {
    player.send_message("Hello world");
}

All marker components have been suffixed with Marker (e.g. PlayerMarker) to make them distinct from the new wrapper structs, and to indicate their purpose is secondary to that of wrapper structs.

I also intend to add wrappers for abstract entities like LivingEntity, which would implement the Damageable, HasInventory, etc. traits.

This PR is incomplete. I still need to figure out how we can provide entity wrappers in Feather internally as well as Quill without duplicating code. Also, I haven't actually implemented the traits yet.

This might act as an alternative to #388.

caelunshun avatar Mar 09 '21 04:03 caelunshun