add player.get_camera(playerid)
This commit is contained in:
parent
2b50e85cdc
commit
34ab3eb41c
@ -8,6 +8,7 @@
|
||||
#include "../../../items/Inventory.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
@ -186,6 +187,19 @@ static int l_set_entity(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_camera(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
if (player == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
auto found = std::find(
|
||||
level->cameras.begin(), level->cameras.end(), player->currentCamera);
|
||||
if (found == level->cameras.end()) {
|
||||
return 0;
|
||||
}
|
||||
return lua::pushinteger(L, found - level->cameras.end());
|
||||
}
|
||||
|
||||
static int l_set_camera(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
if (player == nullptr) {
|
||||
@ -215,6 +229,7 @@ const luaL_Reg playerlib [] = {
|
||||
{"get_spawnpoint", lua::wrap<l_get_spawnpoint>},
|
||||
{"get_entity", lua::wrap<l_get_entity>},
|
||||
{"set_entity", lua::wrap<l_set_entity>},
|
||||
{"get_camera", lua::wrap<l_get_camera>},
|
||||
{"set_camera", lua::wrap<l_set_camera>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -160,8 +160,6 @@ void Player::postUpdate() {
|
||||
|
||||
skeleton.visible = currentCamera != camera;
|
||||
|
||||
auto velocityMod = glm::length(hitbox.velocity);
|
||||
|
||||
size_t bodyIndex = skeleton.config->find("body")->getIndex();
|
||||
size_t headIndex = skeleton.config->find("head")->getIndex();
|
||||
|
||||
@ -271,7 +269,8 @@ std::unique_ptr<dynamic::Map> Player::serialize() const {
|
||||
root->put("chosen-slot", chosenSlot);
|
||||
root->put("entity", eid);
|
||||
root->put("inventory", inventory->serialize());
|
||||
auto found = std::find(level->cameras.begin(), level->cameras.end(), currentCamera);
|
||||
auto found = std::find(
|
||||
level->cameras.begin(), level->cameras.end(), currentCamera);
|
||||
if (found != level->cameras.end()) {
|
||||
root->put("camera", level->content->getIndices(
|
||||
ResourceType::CAMERA).getName(found - level->cameras.begin()));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user