Uproot GuiVertex, GuiMesh, GuiEntity, use generic entities.

* Add update method to GUIComponent
* Cursory 'model' GUIType support.
* Fix zeus:default/entity/bee.venus
master
Nicole Collings 2020-02-11 16:54:20 -08:00
parent 41719bc67d
commit 7ba58799e9
38 changed files with 297 additions and 348 deletions

View File

@ -9,15 +9,13 @@ out vec4 fragColor;
uniform sampler2D tex;
void main() {
vec4 color;
if (useTex > 0.5) {
color = texture(tex, colorData.xy) * vec4(colorBlend, colorData.w);
vec4 spec = texture(tex, colorData.xy) * vec4(colorBlend, colorData.w);
if (spec.a <= 0) discard;
fragColor = spec;
}
else {
color = colorData * vec4(colorBlend, 1);
if (colorData.a <= 0) discard;
fragColor = colorData * vec4(colorBlend, 1);
}
if (color.w == 0) discard;
fragColor = color;
}

View File

@ -4,16 +4,32 @@ layout (location = 0) in vec3 aPos;
layout (location = 1) in vec4 aColorData;
layout (location = 2) in vec3 aColorBlend;
layout (location = 3) in float aUseTex;
layout (location = 4) in vec3 aNormal;
layout (location = 5) in ivec4 aBoneIDs;
layout (location = 6) in vec4 aBoneWeights;
uniform mat4 model;
uniform mat4 ortho;
const int MAX_BONES = 100;
uniform mat4 uBones[MAX_BONES];
out vec4 colorData;
out vec3 colorBlend;
out float useTex;
void main() {
gl_Position = ortho * model * vec4(aPos, 1);
mat4 boneTransform = uBones[aBoneIDs[0]] * aBoneWeights[0];
boneTransform += uBones[aBoneIDs[1]] * aBoneWeights[1];
boneTransform += uBones[aBoneIDs[2]] * aBoneWeights[2];
boneTransform += uBones[aBoneIDs[3]] * aBoneWeights[3];
float totalWeight = aBoneWeights[0] + aBoneWeights[1] + aBoneWeights[2] + aBoneWeights[3];
boneTransform = (boneTransform * totalWeight) + (mat4(1.0) * (1 - totalWeight));
// normal = transpose(inverse(mat3(model))) * (boneTransform * vec4(normalize(aNormal), 0.0)).xyz;
gl_Position = ortho * model * boneTransform * vec4(aPos, 1);
colorData = aColorData;
colorBlend = aColorBlend;
useTex = aUseTex;

View File

@ -14,7 +14,7 @@ uniform sampler2D tex;
void main() {
if (useTex > 0.5) {
vec4 spec = texture(tex, colorData.xy) * vec4(colorBlend, 1);
vec4 spec = texture(tex, colorData.xy) * vec4(colorBlend, colorData.w);
if (spec.a < 0.1) discard;
gSpecular = spec;
}

View File

@ -169,12 +169,7 @@ set(ZEPHA_SRC
game/graph/meshtypes/ChunkVertex.h
game/graph/meshtypes/Mesh.cpp
game/graph/meshtypes/Mesh.h
game/graph/meshtypes/GuiMesh.cpp
game/graph/meshtypes/GuiMesh.h
game/graph/meshtypes/GuiVertex.h
game/hud/GuiEntity.cpp
game/hud/GuiEntity.h
util/Mat4Conv.h
util/Mat4Conv.h
game/entity/ModelBone.cpp
game/entity/ModelBone.h
game/entity/ModelAnimation.cpp

View File

@ -24,7 +24,7 @@ void BlockDef::createModel() {
unsigned int indOffset = 0;
std::vector<EntityVertex> entityVertices;
std::vector<GuiVertex> guiVertices;
// std::vector<GuiVertex> guiVertices;
std::vector<unsigned int> indices;
for (std::vector<MeshPart>& pArray : model.parts) {
@ -32,19 +32,19 @@ void BlockDef::createModel() {
for (const BlockModelVertex &vertex : p.vertices) {
entityVertices.push_back(EntityVertex {
vertex.pos - glm::vec3(0.5f),
{vertex.tex.x, vertex.tex.y, 0, 0},
{vertex.tex.x, vertex.tex.y, 0, 1},
{1, 1, 1},
true,
vertex.nml,
{}, {}
});
float brightness = 0.8 + (glm::abs(vertex.nml.z) * 0.2) + (vertex.nml.y * 0.4);
guiVertices.push_back(GuiVertex {
vertex.pos - glm::vec3(0.5f),
{vertex.tex.x, vertex.tex.y, 0, 1},
glm::vec3(brightness),
true
});
// float brightness = 0.8 + (glm::abs(vertex.nml.z) * 0.2) + (vertex.nml.y * 0.4);
// guiVertices.push_back(GuiVertex {
// vertex.pos - glm::vec3(0.5f),
// {vertex.tex.x, vertex.tex.y, 0, 1},
// glm::vec3(brightness),
// true
// });
}
for (unsigned int index : p.indices) {
@ -56,7 +56,8 @@ void BlockDef::createModel() {
}
entity->create(entityVertices, indices);
entityModel = std::make_shared<Model>();
entityModel->fromMesh(std::move(entity));
guiModel->create(guiVertices, indices);
// guiModel->create(guiVertices, indices);
}

View File

@ -11,7 +11,6 @@
#include "../ItemDef.h"
#include "../../lua/Callback.h"
#include "../../game/entity/Model.h"
#include "../../game/graph/meshtypes/GuiMesh.h"
class BlockDef : public ItemDef {
public:
@ -31,8 +30,7 @@ public:
std::vector<SelectionBox> sBoxes;
std::vector<SelectionBox> cBoxes;
std::shared_ptr<Model> entityModel = std::make_shared<Model>();
std::shared_ptr<GuiMesh> guiModel = std::make_shared<GuiMesh>();
std::shared_ptr<Model> entityModel {};
std::unordered_map<Callback, sol::function, Util::EnumClassHash> callbacks {};
};

View File

@ -106,15 +106,24 @@ float Entity::getRotateZ() {
}
void Entity::setScale(float scale) {
this->visualScale = glm::vec3(scale);
this->scale = glm::vec3(scale);
}
void Entity::interpScale(float scale) {
this->scale = glm::vec3(scale);
}
void Entity::setScale(glm::vec3 scale) {
this->visualScale = scale;
this->scale = scale;
}
void Entity::interpScale(float scale) {
void Entity::interpScale(glm::vec3 scale) {
this->scale = scale;
}
float Entity::getScale() {
glm::vec3 Entity::getScale() {
return scale;
}
@ -127,7 +136,7 @@ glm::mat4 Entity::getModelMatrix() {
model = glm::rotate(model, glm::radians(visualRotation.y), {0, 1, 0});
model = glm::rotate(model, glm::radians(visualRotation.z), {0, 0, 1});
model = glm::scale(model, glm::vec3(visualScale));
model = glm::scale(model, visualScale);
return model;
}
@ -155,4 +164,4 @@ void Entity::playRange(unsigned int start, unsigned int end, bool loop) {
void Entity::setPlaying(bool playing, unsigned int offset) {
animState.setPlaying(playing);
if (offset != UINT_MAX) animState.setFrame(offset + animState.getFrame());
}
}

View File

@ -44,7 +44,9 @@ public:
void interpScale(float scale);
void setScale(float scale);
float getScale();
void interpScale(glm::vec3 scale);
void setScale(glm::vec3 scale);
glm::vec3 getScale();
void setAnimations(const std::vector<AnimationSegment>& anims);
void playAnimation(const std::string& anim, bool loop);
@ -67,8 +69,8 @@ protected:
glm::vec3 rotation {};
glm::vec3 visualRotation {};
float scale = 1;
float visualScale = 1;
glm::vec3 scale {1, 1, 1};
glm::vec3 visualScale {1, 1, 1};
std::shared_ptr<Model> model = nullptr;
std::vector<glm::mat4> transforms {};

View File

@ -101,7 +101,7 @@ void Model::loadMeshAndBone(aiMesh *mesh, std::unique_ptr<EntityMesh>& target) {
vertex.useTex = true;
vertex.colorData = {
texture->uv.x + mesh->mTextureCoords[0][i].x * (texture->uv.z - texture->uv.x),
texture->uv.y + mesh->mTextureCoords[0][i].y * (texture->uv.w - texture->uv.y), 0, 0
texture->uv.y + mesh->mTextureCoords[0][i].y * (texture->uv.w - texture->uv.y), 0, 1 //Alpha
};
}
else vertex.colorData = {1, 1, 1, 1};

View File

@ -58,15 +58,15 @@ void WireframeEntity::createBox(glm::vec3 a, glm::vec3 b, float x, float y, floa
glm::vec3 c = color;
std::vector<EntityVertex> myVerts {
/*0*/ {{x - hw + a.x, y - hw + a.y, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*1*/ {{x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*2*/ {{x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*3*/ {{x - hw + a.x, y - hw + a.y, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*0*/ {{x - hw + a.x, y - hw + a.y, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
/*1*/ {{x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
/*2*/ {{x - hw + a.x + xSize + w, y - hw + a.y, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
/*3*/ {{x - hw + a.x, y - hw + a.y, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
/*4*/ {{x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*5*/ {{x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*6*/ {{x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*7*/ {{x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}},
/*4*/ {{x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
/*5*/ {{x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z }, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
/*6*/ {{x - hw + a.x + xSize + w, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
/*7*/ {{x - hw + a.x, y - hw + a.y + ySize + w, z - hw + a.z + zSize + w}, {c.x, c.y, c.z, 1}, {1, 1, 1}, false, {0, 1, 0}, {}, {}},
};
std::vector<unsigned int> myInds {

View File

@ -31,6 +31,7 @@ Renderer::Renderer(glm::ivec2 win) :
gu.matrix = camera.getOrthographicMatrix();
gu.ortho = guiShader.get("ortho");
gu.model = guiShader.get("model");
gu.bones = guiShader.get("uBones");
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -95,7 +96,7 @@ void Renderer::beginChunkDeferredCalls() {
glClearBufferfv(GL_COLOR, 1, clearTransparent);
glClearBufferfv(GL_COLOR, 2, skyColor);
world.use();
setShader(world);
world.set(world.uniforms.proj, camera.getProjectionMatrix());
world.set(world.uniforms.view, camera.getViewMatrix());
world.set(world.uniforms.time, static_cast<float>(elapsedTime));
@ -105,7 +106,7 @@ void Renderer::beginChunkDeferredCalls() {
void Renderer::beginEntityDeferredCalls() {
currentModelUniform = entity.uniforms.model;
entity.use();
setShader(entity);
entity.set(entity.uniforms.proj, camera.getProjectionMatrix());
entity.set(entity.uniforms.view, camera.getViewMatrix());
}
@ -117,7 +118,7 @@ void Renderer::endDeferredCalls() {
glClearColor(clearColor.x, clearColor.y, clearColor.z, 0);
glClear(GL_COLOR_BUFFER_BIT);
ssao.use();
setShader(ssao);
ssao.set(ssao.uniforms.proj, camera.getProjectionMatrix());
ssao.set(ssao.uniforms.view, camera.getViewMatrix());
ssao.set(ssao.uniforms.kernelCount, ssao.kernelCount);
@ -141,7 +142,7 @@ void Renderer::endDeferredCalls() {
glBindFramebuffer(GL_FRAMEBUFFER, blur.fbo);
glClear(GL_COLOR_BUFFER_BIT);
blur.use();
setShader(blur);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, ssao.colorBuffer);
renderQuad();
@ -151,7 +152,7 @@ void Renderer::endDeferredCalls() {
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
lighting.use();
setShader(lighting);
lighting.set(lighting.uniforms.camPosition, camera.getPos());
glActiveTexture(GL_TEXTURE0);
@ -186,7 +187,7 @@ void Renderer::beginGUIDrawCalls() {
glDisable(GL_CULL_FACE);
glEnable(GL_BLEND);
guiShader.use();
setShader(guiShader);
guiShader.set(gu.ortho, gu.matrix);
}
@ -230,13 +231,18 @@ void Renderer::enableTexture(Texture *texture) {
}
}
void Renderer::setShader(Shader& s) {
s.use();
this->currentShader = &s;
}
void Renderer::setClearColor(unsigned char r, unsigned char g, unsigned char b) {
clearColor = {static_cast<float>(r)/255.f, static_cast<float>(g)/255.f, static_cast<float>(b)/255.f, 1};
}
void Renderer::setBones(std::vector<glm::mat4> &transforms) {
if (transforms.empty()) return;
entity.setArr(entity.uniforms.bones, static_cast<GLsizei>(transforms.size()), transforms.at(0));
currentShader->setArr((currentShader == &entity ? entity.uniforms.bones : gu.bones), static_cast<GLsizei>(transforms.size()), transforms.at(0));
}
void Renderer::toggleDepthTest(bool enable) {
@ -245,4 +251,4 @@ void Renderer::toggleDepthTest(bool enable) {
void Renderer::clearDepthBuffer() {
glClear(GL_DEPTH_BUFFER_BIT);
}
}

View File

@ -31,6 +31,8 @@ public:
void beginGUIDrawCalls();
void swapBuffers();
void setShader(Shader& s);
void setClearColor(unsigned char r, unsigned char g, unsigned char b);
void toggleDepthTest(bool enable);
void clearDepthBuffer();
@ -60,6 +62,8 @@ private:
Shader guiShader;
GuiUniforms gu;
Shader* currentShader;
GLint currentModelUniform;
double elapsedTime = 0;
};

View File

@ -7,14 +7,20 @@
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
struct EntityVertex {
glm::vec3 position;
glm::vec4 colorData;
glm::vec3 colorBlend;
float useTex;
glm::vec3 normal;
glm::ivec4 boneIDs;
glm::vec4 boneWeights;
class EntityVertex {
public:
EntityVertex() = default;
EntityVertex(glm::vec3 position, glm::vec4 colorData, glm::vec3 colorBlend, float useTex, glm::vec3 normal,
glm::ivec4 boneIDs, glm::vec4 boneWeights) : position(position), colorData(colorData),
colorBlend(colorBlend), useTex(useTex), normal(normal), boneIDs(boneIDs), boneWeights(boneWeights) {};
glm::vec3 position {};
glm::vec4 colorData {};
glm::vec3 colorBlend {};
float useTex = false;
glm::vec3 normal {};
glm::ivec4 boneIDs {};
glm::vec4 boneWeights {};
};
#define STRIDE_OFFSET_ENTITY(m) sizeof(struct EntityVertex), (void *)offsetof(struct EntityVertex, m)

View File

@ -1,29 +0,0 @@
//
// Created by aurailus on 24/08/19.
//
#include "GuiMesh.h"
GuiMesh::GuiMesh(const GuiMesh &o) {
throw "Copy constructor for GuiMesh is not supported! Throwing.";
}
void GuiMesh::create(const std::vector<GuiVertex>& vertices, const std::vector<unsigned int>& indices) {
if (vertices.size() == 0) return;
indCount = static_cast<GLsizei>(indices.size());
genArrays(static_cast<unsigned int>(vertices.size() * sizeof(GuiVertex)),
static_cast<unsigned int>(indices.size() * sizeof(unsigned int)),
&vertices.front(), &indices.front());
unsigned int idx = 0;
createVertexAttrib(idx++, 3, GL_FLOAT, STRIDE_OFFSET_GUI(position));
createVertexAttrib(idx++, 4, GL_FLOAT, STRIDE_OFFSET_GUI(colorData));
createVertexAttrib(idx++, 3, GL_FLOAT, STRIDE_OFFSET_GUI(colorBlend));
createVertexAttrib(idx , 1, GL_FLOAT, STRIDE_OFFSET_GUI(useTexture));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}

View File

@ -1,17 +0,0 @@
//
// Created by aurailus on 24/08/19.
//
#pragma once
#include <vector>
#include "Mesh.h"
#include "GuiVertex.h"
class GuiMesh : public Mesh {
public:
GuiMesh() = default;
GuiMesh(const GuiMesh& o);
void create(const std::vector<GuiVertex>& vertices, const std::vector<unsigned int>& indices);
~GuiMesh() = default;
};

View File

@ -1,24 +0,0 @@
//
// Created by aurailus on 24/08/19.
//
#pragma once
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
struct GuiVertex {
GuiVertex(glm::vec3 position, glm::vec4 colorData, glm::vec3 colorBlend, float useTexture) :
position(position),
colorData(colorData),
colorBlend(colorBlend),
useTexture(useTexture) {}
glm::vec3 position;
glm::vec4 colorData;
glm::vec3 colorBlend;
float useTexture;
};
#define STRIDE_OFFSET_GUI(m) sizeof(struct GuiVertex), (void *)offsetof(struct GuiVertex, m)

View File

@ -13,4 +13,6 @@ struct GuiUniforms {
GLint ortho;
GLint model;
GLint bones;
};

View File

@ -32,6 +32,7 @@ GameGui::GameGui(Inventory& inventory, InventoryList& hand, glm::vec2 bufferSize
void GameGui::update(double delta) {
Drawable::update(delta);
menuRoot->update(delta);
handList->setPos((renderer.window.getMousePos() - glm::ivec2(24)) / 3 * 3);

View File

@ -9,7 +9,7 @@ std::shared_ptr<GUIComponent> GameGuiBuilder::createComponent(SerializedGuiElem
auto comp = GuiBuilder::createComponent(data);
if (comp) return comp;
//Extra definitions
// Extra definitions
glm::vec2 pos {};

View File

@ -3,7 +3,6 @@
//
#include "GuiBuilder.h"
#include "components/compound/GUIImageButton.h"
GuiBuilder::GuiBuilder(LocalDefs& defs, std::shared_ptr<GUIContainer> root) :
defs(defs), root(root) {}
@ -269,8 +268,31 @@ std::shared_ptr<GUIComponent> GuiBuilder::createComponent(SerializedGuiElem& dat
return text;
}
else if (data.type == "model") {
glm::vec2 scale = {1, 1};
if (data.tokens.count("size")) {
auto tokens = splitValue(data.tokens["size"], 2);
scale = {stringToNum(tokens[0], PercentBehavior::DECIMAL),
stringToNum(tokens[1], PercentBehavior::DECIMAL)};
}
std::string modelStr = (data.tokens.count("model")) ? data.tokens["model"] : "";
auto m = std::make_shared<Model>();
m->fromSerialized(defs.models.models["zeus:default:bird"], {defs.textures["zeus:default:raven"]});
auto model = std::make_shared<GUIModel>(data.key);
model->create(scale, m);
model->setPos(pos);
model->setCallbacks(cbLeftClick, cbRightClick, cbHover);
return model;
}
// An unknown type was specified.
return nullptr;
}
float GuiBuilder::stringToNum(const std::string& input, PercentBehavior behavior = PercentBehavior::BUFF_WIDTH) {
if (input.find("px") != std::string::npos) {
return atof(input.substr(0, input.find("px")).c_str()) * SCALE_MODIFIER;

View File

@ -10,7 +10,9 @@
#include "../../def/LocalDefs.h"
#include "components/basic/GUIRect.h"
#include "components/basic/GUIText.h"
#include "components/basic/GUIModel.h"
#include "components/basic/GUIContainer.h"
#include "components/compound/GUIImageButton.h"
class GuiBuilder {
public:

View File

@ -1,81 +0,0 @@
//
// Created by aurailus on 25/11/18.
//
#include "GuiEntity.h"
GuiEntity::GuiEntity(std::shared_ptr<GuiMesh> mesh) {
setMesh(mesh);
}
void GuiEntity::setMesh(std::shared_ptr<GuiMesh> myMesh) {
cleanup();
this->mesh = myMesh;
}
void GuiEntity::draw(Renderer& renderer) {
if (visible) {
auto mm = getModelMatrix();
renderer.setModelMatrix(mm);
mesh->draw();
}
}
void GuiEntity::setPos(glm::vec2 position) {
this->position.x = position.x;
this->position.y = position.y;
}
glm::vec2 GuiEntity::getPos() {
return {position.x, position.y};
}
void GuiEntity::setDepth(float depth) {
position.z = depth;
}
float GuiEntity::getDepth() {
return position.z;
}
void GuiEntity::setRotation(glm::mat4 rotation){
this->rotation = rotation;
}
glm::mat4 GuiEntity::getRotation() {
return rotation;
}
void GuiEntity::setScale(float scale) {
setScale({scale, scale});
}
void GuiEntity::setScale(glm::vec2 scale) {
this->scale = {scale.x, scale.y, this->scale.z};
}
void GuiEntity::setScale(glm::vec3 scale) {
this->scale = scale;
}
glm::vec2 GuiEntity::getScale() {
return glm::vec2(scale.x, scale.y);
}
glm::vec3 GuiEntity::getScale3() {
return scale;
}
glm::mat4 GuiEntity::getModelMatrix() {
glm::mat4 model = glm::mat4(1.0);
model = glm::translate(model, position);
model = model * rotation;
model = glm::scale(model, scale);
return model;
}
void GuiEntity::cleanup() {
mesh = nullptr;
}

View File

@ -1,49 +0,0 @@
//
// Created by aurailus on 25/11/18.
//
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <memory>
#include "../graph/meshtypes/GuiMesh.h"
#include "../graph/drawable/Drawable.h"
class GuiEntity : public Drawable {
public:
GuiEntity() = default;
explicit GuiEntity(std::shared_ptr<GuiMesh> mesh);
void setMesh(std::shared_ptr<GuiMesh> mesh);
void draw(Renderer& renderer) override;
void setPos(glm::vec2 position);
glm::vec2 getPos();
void setDepth(float depth);
float getDepth();
void setRotation(glm::mat4 rotation);
glm::mat4 getRotation();
void setScale(float scale);
void setScale(glm::vec2 scale);
void setScale(glm::vec3 scale);
glm::vec2 getScale();
glm::vec3 getScale3();
glm::mat4 getModelMatrix();
void cleanup();
~GuiEntity() = default;
protected:
glm::vec3 position {};
glm::mat4 rotation {};
glm::vec3 scale {1, 1, 1};
private:
std::shared_ptr<GuiMesh> mesh = nullptr;
};

View File

@ -10,7 +10,7 @@ GUIComponent::GUIComponent(const std::string& key) :
void GUIComponent::setScale(glm::vec2 scale) {
this->scale = scale;
entity.setScale(scale);
entity.setScale({scale.x, scale.y, scale.x});
}
glm::vec2 GUIComponent::getScale() {
@ -28,11 +28,11 @@ glm::vec4 GUIComponent::getPadding() {
void GUIComponent::setPos(glm::ivec2 pos) {
this->pos = pos;
if (parent != nullptr) {
glm::vec2 parentPos = parent->entity.getPos();
glm::vec3 parentPos = parent->entity.getPos();
pos += glm::vec2 {parentPos.x, parentPos.y};
pos += glm::vec2 {parent->getPadding().w, parent->getPadding().x};
}
entity.setPos(pos);
entity.setPos({pos.x, pos.y, 0});
for (const auto& child : children) {
child->updatePos();
}
@ -87,11 +87,11 @@ void GUIComponent::setVisible(bool visible) {
void GUIComponent::updatePos() {
glm::vec2 realPos(pos);
if (parent != nullptr) {
glm::vec2 parentPos = parent->entity.getPos();
glm::vec3 parentPos = parent->entity.getPos();
realPos += glm::vec2 {parentPos.x, parentPos.y};
realPos += glm::vec2 {parent->getPadding().w, parent->getPadding().x};
}
entity.setPos(realPos);
entity.setPos({realPos.x, realPos.y, 0});
for (const auto& child : children) {
child->updatePos();
}
@ -119,6 +119,12 @@ bool GUIComponent::mouseActivity(glm::ivec2 pos) {
return isHovering;
}
void GUIComponent::update(double delta) {
for (const auto& child : children) {
child->update(delta);
}
}
bool GUIComponent::leftClickEvent(bool state, glm::ivec2 pos) {
clickEvent(true, state, pos);
}

View File

@ -7,7 +7,7 @@
#include <memory>
#include <list>
#include "../GuiEntity.h"
#include "../../entity/Entity.h"
class GUIComponent : public Drawable {
public:
@ -25,6 +25,8 @@ public:
virtual void setPos(glm::ivec2 pos);
virtual glm::ivec2 getPos();
virtual void update(double delta);
bool mouseActivity(glm::ivec2 pos);
bool leftClickEvent(bool state, glm::ivec2 pos);
bool rightClickEvent(bool state, glm::ivec2 pos);
@ -70,7 +72,7 @@ protected:
callback cbRightClick = nullptr;
callback cbHover = nullptr;
GuiEntity entity;
Entity entity;
private:
void updatePos();
};

View File

@ -12,7 +12,7 @@ void GUIGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <Atlas
this->scale = scale;
this->padding = padding;
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
this->length = length;
this->maxVal = maxValue;
@ -22,7 +22,7 @@ void GUIGraph::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr <Atlas
history = std::vector<float>(static_cast<unsigned long>(length));
entity.setMesh(std::make_shared<GuiMesh>());
entity.setModel(std::make_shared<Model>());
}
void GUIGraph::pushValue(float value) {
@ -55,7 +55,7 @@ void GUIGraph::setMax(float max) {
}
void GUIGraph::buildHistogramMesh() {
std::vector<GuiVertex> vertices {};
std::vector<EntityVertex> vertices {};
std::vector<unsigned int> indices {};
auto uv = texture->uv;
@ -72,11 +72,11 @@ void GUIGraph::buildHistogramMesh() {
float h = num / maxVal;
float sec = (float)std::round(9 - fmin(h, 1)*9) * 0.1f;
auto columnVerts = std::vector<GuiVertex> {
{{xOffset, -h, 0}, {uv.x + age * uv.z, uv.y + sec * uv.w, 0, 1}, {1, 1, 1}, true},
{{xOffset + 1,-h, 0}, {uv.x + (age+0.01f) * uv.z, uv.y + sec * uv.w, 0, 1}, {1, 1, 1}, true},
{{xOffset + 1, 0, 0}, {uv.x + (age+0.01f) * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 1}, {1, 1, 1}, true},
{{xOffset, 0, 0}, {uv.x + age * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 1}, {1, 1, 1}, true},
auto columnVerts = std::vector<EntityVertex> {
{{xOffset, -h, 0}, {uv.x + age * uv.z, uv.y + sec * uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{xOffset + 1,-h, 0}, {uv.x + (age+0.01f) * uv.z, uv.y + sec * uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{xOffset + 1, 0, 0}, {uv.x + (age+0.01f) * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{xOffset, 0, 0}, {uv.x + age * uv.z, uv.y + (sec+0.10f) * uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
};
vertices.insert(vertices.end(), columnVerts.begin(), columnVerts.end());
@ -92,7 +92,11 @@ void GUIGraph::buildHistogramMesh() {
indOffset += 4;
}
auto m = std::make_shared<GuiMesh>();
auto m = std::make_unique<EntityMesh>();
m->create(vertices, indices);
entity.setMesh(m);
auto model = std::make_shared<Model>();
model->fromMesh(std::move(m));
entity.setModel(model);
}

View File

@ -23,17 +23,15 @@ void GUIInventoryItem::create(glm::vec2 scale, unsigned short count, ItemDef& de
add(item);
}
else {
auto& model = static_cast<BlockDef&>(def).guiModel;
auto& model = static_cast<BlockDef&>(def).entityModel;
auto item = std::make_shared<GUIModel>("item");
item->create(scale * 10.5f, model);
item->setPos(glm::vec2{7.75, 7.75} * scale);
glm::mat4 rot;
rot = glm::rotate(rot, glm::radians(180.f), {1, 0, 0});
rot = glm::rotate(rot, glm::radians( 45.f), {0, 1, 0});
rot = glm::rotate(rot, glm::radians(-25.f), {1, 0, 1});
item->setRotation(rot);
item->setRotationX(180.f - 30.f);
item->setRotationY(45.f);
item->setRotationZ(0.f);
add(item);
}

View File

@ -6,11 +6,13 @@
GUIModel::GUIModel(const std::string &key) : GUIComponent(key) {}
void GUIModel::create(glm::vec2 scale, std::shared_ptr<GuiMesh> model) {
entity.setMesh(model);
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z, scale.x + padding.w + padding.y});
}
void GUIModel::create(glm::vec2 scale, std::shared_ptr<Model> model) {
entity.setModel(model);
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
setRotationX(180);
setRotationY(215);
}
void GUIModel::draw(Renderer &renderer) {
renderer.toggleDepthTest(true);
@ -19,6 +21,18 @@ void GUIModel::draw(Renderer &renderer) {
renderer.toggleDepthTest(false);
}
void GUIModel::setRotation(glm::mat4 rotation) {
entity.setRotation(rotation);
}
void GUIModel::setRotationX(float x) {
entity.setRotateX(x);
}
void GUIModel::setRotationY(float y) {
entity.setRotateY(y);
}
void GUIModel::setRotationZ(float z) {
entity.setRotateZ(z);
}
void GUIModel::update(double delta) {
entity.update(delta);
}

View File

@ -13,11 +13,12 @@ public:
GUIModel() = default;
GUIModel(const std::string& key);
void create(glm::vec2 scale, std::shared_ptr<GuiMesh> model);
void create(glm::vec2 scale, std::shared_ptr<Model> model);
void update(double delta) override;
void setRotation(glm::mat4 rotation);
void setRotationX(float x);
void setRotationY(float x);
void setRotationZ(float x);
void draw(Renderer& renderer) override;
std::shared_ptr<GuiMesh> model;
};

View File

@ -13,12 +13,17 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 color) {
this->scale = scale;
this->padding = padding;
auto mesh = std::make_shared<GuiMesh>();
mesh->create({{{0, 0, 0}, color, {1, 1, 1}, false}, {{0, 1, 0}, color, {1, 1, 1}, false},
{{1, 1, 0}, color, {1, 1, 1}, false}, {{1, 0, 0}, color, {1, 1, 1}, false}}, {0, 1, 2, 2, 3, 0});
auto mesh = std::make_unique<EntityMesh>();
mesh->create({{{0, 0, 0}, color, {1, 1, 1}, false, {}, {}, {}},
{{0, 1, 0}, color, {1, 1, 1}, false, {}, {}, {}},
{{1, 1, 0}, color, {1, 1, 1}, false, {}, {}, {}},
{{1, 0, 0}, color, {1, 1, 1}, false, {}, {}, {}}
}, {0, 1, 2, 2, 3, 0});
auto model = std::make_shared<Model>();
model->fromMesh(std::move(mesh));
entity.setMesh(mesh);
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
entity.setModel(model);
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
}
// Multiple Color Constructor
@ -28,12 +33,18 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 tl, glm::vec4
this->scale = scale;
this->padding = padding;
auto mesh = std::make_shared<GuiMesh>();
mesh->create({{{0, 0, 0}, tl, {1, 1, 1}, false}, {{0, 1, 0}, bl, {1, 1, 1}, false},
{{1, 1, 0}, br, {1, 1, 1}, false}, {{1, 0, 0}, tr, {1, 1, 1}, false}}, {0, 1, 2, 2, 3, 0});
auto mesh = std::make_unique<EntityMesh>();
mesh->create({
{{0, 0, 0}, tl, {1, 1, 1}, false, {}, {}, {}},
{{0, 1, 0}, bl, {1, 1, 1}, false, {}, {}, {}},
{{1, 1, 0}, br, {1, 1, 1}, false, {}, {}, {}},
{{1, 0, 0}, tr, {1, 1, 1}, false, {}, {}, {}}
}, {0, 1, 2, 2, 3, 0});
auto model = std::make_shared<Model>();
model->fromMesh(std::move(mesh));
entity.setMesh(mesh);
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
entity.setModel(model);
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
}
// Texture Constructor
@ -45,16 +56,18 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRe
this->texture = texture;
this->hitbox = scale + glm::vec2{padding.y + padding.w, padding.x + padding.z};
auto mesh = std::make_shared<GuiMesh>();
auto mesh = std::make_unique<EntityMesh>();
mesh->create({
{{0, 0, 0}, {this->texture->uv.x, this->texture->uv.y, 0, 1}, {1, 1, 1}, true},
{{0, 1, 0}, {this->texture->uv.x, this->texture->uv.w, 0, 1}, {1, 1, 1}, true},
{{1, 1, 0}, {this->texture->uv.z, this->texture->uv.w, 0, 1}, {1, 1, 1}, true},
{{1, 0, 0}, {this->texture->uv.z, this->texture->uv.y, 0, 1}, {1, 1, 1}, true}
{{0, 0, 0}, {this->texture->uv.x, this->texture->uv.y, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{0, 1, 0}, {this->texture->uv.x, this->texture->uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{1, 1, 0}, {this->texture->uv.z, this->texture->uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{1, 0, 0}, {this->texture->uv.z, this->texture->uv.y, 0, 1}, {1, 1, 1}, true, {}, {}, {}}
}, {0, 1, 2, 2, 3, 0});
auto model = std::make_shared<Model>();
model->fromMesh(std::move(mesh));
entity.setMesh(mesh);
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
entity.setModel(model);
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
}
// Texture Constructor
@ -65,14 +78,16 @@ void GUIRect::create(glm::vec2 scale, glm::vec4 padding, std::shared_ptr<AtlasRe
this->padding = padding;
this->texture = std::move(texture);
auto mesh = std::make_shared<GuiMesh>();
auto mesh = std::make_unique<EntityMesh>();
mesh->create({
{{0, 0, 0}, {this->texture->uv.x, this->texture->uv.y, 0, tint.w}, glm::vec3{tint}, true},
{{0, 1, 0}, {this->texture->uv.x, this->texture->uv.w, 0, tint.w}, glm::vec3{tint}, true},
{{1, 1, 0}, {this->texture->uv.z, this->texture->uv.w, 0, tint.w}, glm::vec3{tint}, true},
{{1, 0, 0}, {this->texture->uv.z, this->texture->uv.y, 0, tint.w}, glm::vec3{tint}, true}
{{0, 0, 0}, {this->texture->uv.x, this->texture->uv.y, 0, tint.w}, glm::vec3{tint}, true, {}, {}, {}},
{{0, 1, 0}, {this->texture->uv.x, this->texture->uv.w, 0, tint.w}, glm::vec3{tint}, true, {}, {}, {}},
{{1, 1, 0}, {this->texture->uv.z, this->texture->uv.w, 0, tint.w}, glm::vec3{tint}, true, {}, {}, {}},
{{1, 0, 0}, {this->texture->uv.z, this->texture->uv.y, 0, tint.w}, glm::vec3{tint}, true, {}, {}, {}}
}, {0, 1, 2, 2, 3, 0});
auto model = std::make_shared<Model>();
model->fromMesh(std::move(mesh));
entity.setMesh(mesh);
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
entity.setModel(model);
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
}

View File

@ -18,8 +18,7 @@ void GUIText::create(glm::vec2 scale, glm::vec4 padding, glm::vec4 bgcolor, glm:
this->bgcolor = bgcolor;
this->color = color;
entity.setScale(scale);
setScale(scale);
setText("");
}
@ -29,7 +28,7 @@ void GUIText::setText(std::string text) {
maxLineWidth = 0;
std::vector<GuiVertex> textVertices;
std::vector<EntityVertex> textVertices;
textVertices.reserve(text.length()*8 + 200);
std::vector<unsigned int> textIndices;
textIndices.reserve(text.length()*12 + 240);
@ -49,10 +48,10 @@ void GUIText::setText(std::string text) {
if (lineWidth > maxLineWidth) maxLineWidth = lineWidth;
if (bgcolor.w != 0) {
textVertices.emplace_back(glm::vec3 {-1, yOffset - 1, 0}, bgcolor, glm::vec3(1), 0.f);
textVertices.emplace_back(glm::vec3 {-1, yOffset + h + 1, 0}, bgcolor, glm::vec3(1), 0.f);
textVertices.emplace_back(glm::vec3 {lineWidth + 1, yOffset + h + 1, 0}, bgcolor, glm::vec3(1), 0.f);
textVertices.emplace_back(glm::vec3 {lineWidth + 1, yOffset - 1, 0}, bgcolor, glm::vec3(1), 0.f);
textVertices.emplace_back(glm::vec3 {-1, yOffset - 1, 0}, bgcolor, glm::vec3(1), 0.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textVertices.emplace_back(glm::vec3 {-1, yOffset + h + 1, 0}, bgcolor, glm::vec3(1), 0.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textVertices.emplace_back(glm::vec3 {lineWidth + 1, yOffset + h + 1, 0}, bgcolor, glm::vec3(1), 0.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textVertices.emplace_back(glm::vec3 {lineWidth + 1, yOffset - 1, 0}, bgcolor, glm::vec3(1), 0.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textIndices.emplace_back(indOffset);
textIndices.emplace_back(indOffset + 1);
@ -110,10 +109,10 @@ void GUIText::setText(std::string text) {
yOffset -= 1;
}
textVertices.emplace_back(glm::vec3 {xOffset, yOffset, 0}, glm::vec4 {charUVs.x, charUVs.y, 0, color.w}, c, 1.f);
textVertices.emplace_back(glm::vec3 {xOffset, yOffset + h, 0}, glm::vec4 {charUVs.x, charUVs.w, 0, color.w}, c, 1.f);
textVertices.emplace_back(glm::vec3 {xOffset + charWidth, yOffset + h, 0}, glm::vec4 {charUVs.z, charUVs.w, 0, color.w}, c, 1.f);
textVertices.emplace_back(glm::vec3 {xOffset + charWidth, yOffset, 0}, glm::vec4 {charUVs.z, charUVs.y, 0, color.w}, c, 1.f);
textVertices.emplace_back(glm::vec3 {xOffset, yOffset, 0}, glm::vec4 {charUVs.x, charUVs.y, 0, color.w}, c, 1.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textVertices.emplace_back(glm::vec3 {xOffset, yOffset + h, 0}, glm::vec4 {charUVs.x, charUVs.w, 0, color.w}, c, 1.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textVertices.emplace_back(glm::vec3 {xOffset + charWidth, yOffset + h, 0}, glm::vec4 {charUVs.z, charUVs.w, 0, color.w}, c, 1.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textVertices.emplace_back(glm::vec3 {xOffset + charWidth, yOffset, 0}, glm::vec4 {charUVs.z, charUVs.y, 0, color.w}, c, 1.f, glm::vec3 {}, glm::ivec4 {}, glm::vec4 {});
textIndices.emplace_back(indOffset);
textIndices.emplace_back(indOffset + 1);
@ -128,9 +127,13 @@ void GUIText::setText(std::string text) {
xOffset += charWidth;
}
auto m = std::make_shared<GuiMesh>();
auto m = std::make_unique<EntityMesh>();
m->create(textVertices, textIndices);
entity.setMesh(m);
auto model = std::make_shared<Model>();
model->fromMesh(std::move(m));
entity.setModel(model);
}
std::string GUIText::getText() {

View File

@ -26,15 +26,17 @@ void GUIImageButton::setHoverCallback(const callback& hoverCallback) {
void GUIImageButton::rebuild(bool hover) {
auto tex = (hover) ? (hoverTexture != nullptr) ? hoverTexture : texture : texture;
auto mesh = std::make_shared<GuiMesh>();
auto mesh = std::make_unique<EntityMesh>();
mesh->create({
{{0, 0, 0}, {tex->uv.x, tex->uv.y, 0, 1}, {1, 1, 1}, true},
{{0, 1, 0}, {tex->uv.x, tex->uv.w, 0, 1}, {1, 1, 1}, true},
{{1, 1, 0}, {tex->uv.z, tex->uv.w, 0, 1}, {1, 1, 1}, true},
{{1, 0, 0}, {tex->uv.z, tex->uv.y, 0, 1}, {1, 1, 1}, true}
{{0, 0, 0}, {tex->uv.x, tex->uv.y, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{0, 1, 0}, {tex->uv.x, tex->uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{1, 1, 0}, {tex->uv.z, tex->uv.w, 0, 1}, {1, 1, 1}, true, {}, {}, {}},
{{1, 0, 0}, {tex->uv.z, tex->uv.y, 0, 1}, {1, 1, 1}, true, {}, {}, {}}
}, {0, 1, 2, 2, 3, 0});
entity.setMesh(mesh);
entity.setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
auto model = std::make_shared<Model>();
model->fromMesh(std::move(mesh));
entity.setModel(model);
setScale({scale.x + padding.w + padding.y, scale.y + padding.x + padding.z});
}

View File

@ -78,7 +78,7 @@ void LocalLuaEntity::set_scale(float scale) {
}
float LocalLuaEntity::get_scale() {
return entity->getScale();
return entity->getScale().x; //TODO: Make this return a vector - maybe?
}
void LocalLuaEntity::set_display_type(const std::string &type, const std::string &arg, sol::optional<std::string> arg2) {

View File

@ -2,7 +2,10 @@
// Created by aurailus on 17/12/18.
//
#include "../ErrorFormatter.h"
#include "LocalLuaParser.h"
#include "../register/RegisterBlocks.h"
#include "../register/RegisterItems.h"
#include "../register/RegisterKeybinds.h"
@ -128,6 +131,39 @@ void LocalLuaParser::update(double delta, bool* keys) {
manager.update(keys);
}
sol::protected_function_result LocalLuaParser::errorCallback(lua_State*, sol::protected_function_result errPfr) {
sol::error err = errPfr;
std::string errString = err.what();
std::string::size_type slash = errString.find('/');
assert(slash != std::string::npos);
std::string modString = errString.substr(0, slash);
std::string::size_type lineNumStart = errString.find(':', slash);
assert(lineNumStart != std::string::npos);
std::string::size_type lineNumEnd = errString.find(':', lineNumStart + 1);
assert(lineNumEnd != std::string::npos);
std::string fileName = errString.substr(0, lineNumStart);
int lineNum = std::stoi(errString.substr(lineNumStart + 1, lineNumEnd - lineNumStart - 1));
for (auto& mod : mods) {
if (mod.config.name == modString) {
for (auto& file : mod.files) {
if (file.path == fileName) {
std::cout << std::endl << ErrorFormatter::formatError(fileName, lineNum, errString, file.file) << std::endl;
break;
}
}
break;
}
}
exit(1);
return errPfr;
}
sol::protected_function_result LocalLuaParser::DoFileSandboxed(std::string file) {
size_t modname_length = file.find('/');
std::string modname = file.substr(0, modname_length);
@ -142,11 +178,8 @@ sol::protected_function_result LocalLuaParser::DoFileSandboxed(std::string file)
env["_FILE"] = f.path;
env["_MODNAME"] = mod.config.name;
auto pfr = lua.safe_script(f.file, env, [&](lua_State*, sol::protected_function_result errPfr) {
sol::error err = errPfr;
std::cout << Log::err << file << " returned an error: " << err.what() << Log::endl;
return errPfr;
}, "@" + f.path, sol::load_mode::text);
auto pfr = lua.safe_script(f.file, env, std::bind(&LocalLuaParser::errorCallback, this,
std::placeholders::_1, std::placeholders::_2), "@" + f.path, sol::load_mode::text);
return pfr;
}

View File

@ -29,6 +29,7 @@ public:
std::vector<std::string> modsOrder;
private:
sol::protected_function_result DoFileSandboxed(std::string file);
sol::protected_function_result errorCallback(lua_State*, sol::protected_function_result errPfr);
double delta = 0;
LuaInputManager manager;

View File

@ -454,7 +454,8 @@ sol::protected_function_result ServerLuaParser::DoFileSandboxed(std::string file
env["_FILE"] = f.path;
env["_MODNAME"] = mod.config.name;
auto pfr = lua.safe_script(f.file, env, std::bind(&ServerLuaParser::errorCallback, this, std::placeholders::_1, std::placeholders::_2), "@" + f.path);
auto pfr = lua.safe_script(f.file, env, std::bind(&ServerLuaParser::errorCallback, this,
std::placeholders::_1, std::placeholders::_2), "@" + f.path, sol::load_mode::text);
return pfr;
}
}

View File

@ -10,7 +10,9 @@ zepha.register_entity("zeus:default:bee", {
self.object.anims:define({
fly = {1, 45}
}):set_anim("fly"):play()
})
self.object.anims:set_anim("fly"):play()
},
on_update = fn(self, delta) {
self.object.pos = v(

View File

@ -128,6 +128,11 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
slot_spacing: 2px 2px
end
end
model
size: 8px 8px
position: 100, 100
end
end
end
]], {