add 'entity.despawn' command
This commit is contained in:
parent
c9958c9718
commit
41a22938d6
@ -11,6 +11,10 @@ function setup_variables()
|
||||
if pentity ~= 0 then
|
||||
console.set('entity.id', pentity)
|
||||
end
|
||||
local sentity = player.get_selected_entity(pid)
|
||||
if sentity ~= nil then
|
||||
console.set('entity.selected', sentity)
|
||||
end
|
||||
end
|
||||
|
||||
function on_history_up()
|
||||
|
||||
@ -156,3 +156,16 @@ console.add_command(
|
||||
return "spawned new player entity #"..tostring(eid)
|
||||
end
|
||||
)
|
||||
|
||||
console.add_command(
|
||||
"entity.despawn entity:sel=$entity.selected",
|
||||
"Despawn entity",
|
||||
function (args, kwargs)
|
||||
local eid = args[1]
|
||||
local entity = entities.get(eid)
|
||||
if entity ~= nil then
|
||||
entity:despawn()
|
||||
return "despawned entity #"..tostring(eid)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
@ -105,10 +105,10 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
}
|
||||
}));
|
||||
panel->add(create_label([=]() {
|
||||
const auto& selection = player->selection;
|
||||
if (selection.entity == ENTITY_NONE) {
|
||||
auto eid = player->getSelectedEntity();
|
||||
if (eid == ENTITY_NONE) {
|
||||
return std::wstring {L"entity: -"};
|
||||
} else if (auto entity = level->entities->get(selection.entity)) {
|
||||
} else if (auto entity = level->entities->get(eid)) {
|
||||
return L"entity: "+util::str2wstr_utf8(entity->getDef().name)+
|
||||
L" uid: "+std::to_wstring(entity->getUID());
|
||||
} else {
|
||||
|
||||
@ -373,6 +373,12 @@ public:
|
||||
if (!arg->optional) {
|
||||
throw error("missing argument "+util::quote(arg->name));
|
||||
} else {
|
||||
if (auto string = std::get_if<std::string>(&arg->def)) {
|
||||
if ((*string)[0] == '$') {
|
||||
args->put((*interpreter)[string->substr(1)]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
args->put(arg->def);
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,6 +241,7 @@ void PlayerController::update(float delta, bool input, bool pause) {
|
||||
if (!pause) {
|
||||
if (input) {
|
||||
updateKeyboard();
|
||||
player->updateSelectedEntity();
|
||||
} else {
|
||||
resetKeyboard();
|
||||
}
|
||||
|
||||
@ -140,8 +140,8 @@ static int l_get_selected_block(lua::State* L) {
|
||||
|
||||
static int l_get_selected_entity(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
if (player->selection.entity) {
|
||||
return lua::pushinteger(L, player->selection.entity);
|
||||
if (auto eid = player->getSelectedEntity()) {
|
||||
return lua::pushinteger(L, eid);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -135,6 +135,10 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
||||
input.flight = false;
|
||||
}
|
||||
|
||||
void Player::updateSelectedEntity() {
|
||||
selectedEid = selection.entity;
|
||||
}
|
||||
|
||||
void Player::postUpdate() {
|
||||
auto entity = level->entities->get(eid);
|
||||
if (!entity.has_value()) {
|
||||
@ -225,6 +229,10 @@ void Player::setEntity(entityid_t eid) {
|
||||
this->eid = eid;
|
||||
}
|
||||
|
||||
entityid_t Player::getSelectedEntity() const {
|
||||
return selectedEid;
|
||||
}
|
||||
|
||||
std::shared_ptr<Inventory> Player::getInventory() const {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ class Player : public Object, public Serializable {
|
||||
bool flight = false;
|
||||
bool noclip = false;
|
||||
entityid_t eid;
|
||||
entityid_t selectedEid;
|
||||
public:
|
||||
std::shared_ptr<Camera> camera, spCamera, tpCamera;
|
||||
std::shared_ptr<Camera> currentCamera;
|
||||
@ -66,6 +67,7 @@ public:
|
||||
void teleport(glm::vec3 position);
|
||||
void updateEntity();
|
||||
void updateInput(PlayerInput& input, float delta);
|
||||
void updateSelectedEntity();
|
||||
void postUpdate();
|
||||
|
||||
void attemptToFindSpawnpoint();
|
||||
@ -83,6 +85,8 @@ public:
|
||||
|
||||
entityid_t getEntity() const;
|
||||
void setEntity(entityid_t eid);
|
||||
|
||||
entityid_t getSelectedEntity() const;
|
||||
|
||||
std::shared_ptr<Inventory> getInventory() const;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user