forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.rs
More file actions
40 lines (36 loc) · 1.09 KB
/
Copy pathentity.rs
File metadata and controls
40 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use feather_base::Text;
use feather_common::chat::{ChatKind, ChatMessage};
use feather_ecs::Entity;
use feather_plugin_host_macros::host_function;
use crate::context::{PluginContext, PluginPtr};
#[host_function]
pub fn entity_exists(cx: &PluginContext, entity: u64) -> anyhow::Result<u32> {
Ok(cx.game_mut().ecs.entity(Entity::from_bits(entity)).is_ok()).map(|b| b as u32)
}
#[host_function]
pub fn entity_send_message(
cx: &PluginContext,
entity: u64,
message_ptr: PluginPtr<u8>,
message_len: u32,
) -> anyhow::Result<()> {
let message = cx.read_string(message_ptr, message_len)?;
let entity = Entity::from_bits(entity);
let _ = cx.game_mut().send_message(
entity,
ChatMessage::new(ChatKind::System, Text::from(message)),
);
Ok(())
}
#[host_function]
pub fn entity_send_title(
cx: &PluginContext,
entity: u64,
title_ptr: PluginPtr<u8>,
title_len: u32,
) -> anyhow::Result<()> {
let title = cx.read_bincode(title_ptr, title_len)?;
let entity = Entity::from_bits(entity);
cx.game_mut().send_title(entity, title);
Ok(())
}