add entity trigger type parameter

This commit is contained in:
MihailRis 2024-07-02 23:54:38 +03:00
parent 5b154b57b3
commit 8add39e506
5 changed files with 15 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"hitbox": [0.2, 0.125, 0.2],
"triggers": [
[-0.2, -0.2, -0.2, 0.2, 0.2, 0.2]
["aabb", -0.2, -0.2, -0.2, 0.2, 0.2, 0.2]
]
}

View File

@ -304,7 +304,7 @@ function file.readlines(path)
end
stdcomp = require "core:internal/stdcomp"
entity.get = stdcomp.get_Entity
entities.get = stdcomp.get_Entity
-- Deprecated functions
block_index = block.index

View File

@ -12,6 +12,7 @@
#include "../logic/scripting/scripting.hpp"
#include "../typedefs.hpp"
#include "../util/listutil.hpp"
#include "../util/stringutil.hpp"
#include "../voxels/Block.hpp"
#include <iostream>
@ -317,10 +318,16 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
if (auto triggersarr = root->list("triggers")) {
for (size_t i = 0; i < triggersarr->size(); i++) {
if (auto triggerarr = triggersarr->list(i)) {
def.triggers.push_back({
{triggerarr->num(0), triggerarr->num(1), triggerarr->num(2)},
{triggerarr->num(3), triggerarr->num(4), triggerarr->num(5)}
});
auto triggerType = triggerarr->str(0);
if (triggerType == "aabb") {
def.boxTriggers.push_back({
{triggerarr->num(1), triggerarr->num(2), triggerarr->num(3)},
{triggerarr->num(4), triggerarr->num(5), triggerarr->num(6)}
});
} else {
logger.error() << name << ": trigger #" << i << " - unknown type "
<< util::quote(triggerType);
}
}
}
}

View File

@ -52,7 +52,7 @@ entityid_t Entities::spawn(
registry.emplace<Transform>(entity, pos, size, glm::mat3(1.0f));
auto& body = registry.emplace<Rigidbody>(
entity, true, Hitbox {pos, def.hitbox}, std::vector<Trigger>{});
for (auto& box : def.triggers) {
for (auto& box : def.boxTriggers) {
body.triggers.emplace_back(Trigger{
true,
id,

View File

@ -18,7 +18,7 @@ struct EntityDef {
std::string scriptName = name.substr(name.find(':')+1);
glm::vec3 hitbox {0.5f};
std::vector<AABB> triggers {};
std::vector<AABB> boxTriggers {};
std::string rigName = name.substr(name.find(":")+1);
struct {