mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 03:21:49 +00:00
implement player entity
This commit is contained in:
parent
49aa64a033
commit
487ba84517
8 changed files with 24 additions and 12 deletions
|
|
@ -66,6 +66,7 @@ entityid_t Entities::spawn(
|
|||
dynamic::Map_sptr saved,
|
||||
entityid_t uid)
|
||||
{
|
||||
std::cout << "spawn entity " << def.name << std::endl;
|
||||
auto rig = level->content->getRig(def.rigName);
|
||||
if (rig == nullptr) {
|
||||
throw std::runtime_error("rig "+def.rigName+" not found");
|
||||
|
|
@ -108,8 +109,10 @@ entityid_t Entities::spawn(
|
|||
componentName, entity_funcs_set {}, nullptr);
|
||||
scripting.components.emplace_back(std::move(component));
|
||||
}
|
||||
std::cout << "on_entity_spawn" << std::endl;
|
||||
scripting::on_entity_spawn(
|
||||
def, id, scripting.components, std::move(args), std::move(saved));
|
||||
std::cout << "done" << std::endl;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,10 @@ Player::~Player() {
|
|||
|
||||
void Player::updateEntity() {
|
||||
if (eid == 0) {
|
||||
// spawn entity
|
||||
auto& def = level->content->entities.require("base:player");
|
||||
eid = level->entities->spawn(def, Transform {
|
||||
getPosition(), glm::vec3(1.0f), glm::mat3(1.0f), {}, true
|
||||
});
|
||||
} else if (auto entity = level->entities->get(eid)) {
|
||||
position = entity->getTransform().pos;
|
||||
} else {
|
||||
|
|
@ -264,11 +267,12 @@ void Player::deserialize(dynamic::Map *src) {
|
|||
src->flag("flight", flight);
|
||||
src->flag("noclip", noclip);
|
||||
setChosenSlot(src->get("chosen-slot", getChosenSlot()));
|
||||
src->num("enitity", eid);
|
||||
src->num("entity", eid);
|
||||
|
||||
if (auto invmap = src->map("inventory")) {
|
||||
getInventory()->deserialize(invmap.get());
|
||||
}
|
||||
std::cout << "Player::DESERIALIZE " << eid << std::endl;
|
||||
}
|
||||
|
||||
void Player::convert(dynamic::Map* data, const ContentLUT* lut) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue