Merge branch 'main' into curl
This commit is contained in:
@@ -185,8 +185,16 @@ assetload::postfunc assetload::layout(
|
||||
return [=](auto assets) {
|
||||
try {
|
||||
auto cfg = std::dynamic_pointer_cast<LayoutCfg>(config);
|
||||
size_t pos = name.find(':');
|
||||
auto prefix = name.substr(0, pos);
|
||||
assets->store(
|
||||
UiDocument::read(cfg->env, name, file, "abs:" + file), name
|
||||
UiDocument::read(
|
||||
cfg->env,
|
||||
name,
|
||||
file,
|
||||
prefix + ":layouts/" + name.substr(pos + 1) + ".xml"
|
||||
),
|
||||
name
|
||||
);
|
||||
} catch (const parsing_error& err) {
|
||||
throw std::runtime_error(
|
||||
|
||||
@@ -191,6 +191,7 @@ void ContentLoader::loadBlock(
|
||||
Block& def, const std::string& name, const fs::path& file
|
||||
) {
|
||||
auto root = files::read_json(file);
|
||||
def.properties = root;
|
||||
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
@@ -360,6 +361,7 @@ void ContentLoader::loadItem(
|
||||
ItemDef& def, const std::string& name, const fs::path& file
|
||||
) {
|
||||
auto root = files::read_json(file);
|
||||
def.properties = root;
|
||||
|
||||
if (root.has("parent")) {
|
||||
const auto& parentName = root["parent"].asString();
|
||||
|
||||
@@ -366,6 +366,7 @@ void Engine::loadContent() {
|
||||
load_configs(pack.folder);
|
||||
}
|
||||
content = contentBuilder.build();
|
||||
interpreter->reset();
|
||||
scripting::on_content_load(content.get());
|
||||
|
||||
ContentLoader::loadScripts(*content);
|
||||
|
||||
@@ -25,7 +25,7 @@ GLTexture::GLTexture(const ubyte* data, uint width, uint height, ImageFormat ima
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 2);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -242,18 +242,34 @@ void ImageData::extrude(int x, int y, int w, int h) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fixing black transparent pixels for Mip-Mapping
|
||||
void ImageData::fixAlphaColor() {
|
||||
// Fixing black transparent pixels for Mip-Mapping
|
||||
for (uint ly = 0; ly < height-1; ly++) {
|
||||
for (uint lx = 0; lx < width-1; lx++) {
|
||||
if (data[((ly) * width + lx) * 4 + 3]) {
|
||||
for (int c = 0; c < 3; c++) {
|
||||
int val = data[((ly) + + lx) * 4 + c];
|
||||
if (data[((ly) * width + lx + 1) * 4 + 3] == 0)
|
||||
data[((ly) * width + lx + 1) * 4 + c] = val;
|
||||
if (data[((ly + 1) * width + lx) * 4 + 3] == 0)
|
||||
data[((ly + 1) * width + lx) * 4 + c] = val;
|
||||
}
|
||||
int samples = 0;
|
||||
int sums[3] {};
|
||||
for (uint ly = 0; ly < height; ly++) {
|
||||
for (uint lx = 0; lx < width; lx++) {
|
||||
if (data[(ly * width + lx) * 4 + 3] == 0) {
|
||||
continue;
|
||||
}
|
||||
samples++;
|
||||
for (int c = 0; c < 3; c++) {
|
||||
sums[c] += data[(ly * width + lx) * 4 + c];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (samples == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sums[i] /= samples;
|
||||
}
|
||||
for (uint ly = 0; ly < height; ly++) {
|
||||
for (uint lx = 0; lx < width; lx++) {
|
||||
if (data[(ly * width + lx) * 4 + 3] != 0) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
data[(ly * width + lx) * 4 + i] = sums[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
|
||||
glm::vec3(wrapper.position) + glm::vec3(0.5f),
|
||||
glm::vec3(1.01f),
|
||||
regions,
|
||||
glm::vec4(0),
|
||||
glm::vec4(1,1,1,0),
|
||||
false
|
||||
);
|
||||
break;
|
||||
@@ -66,7 +66,7 @@ void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
|
||||
glm::vec3(wrapper.position) + aabb.center(),
|
||||
size * glm::vec3(1.01f),
|
||||
regions,
|
||||
glm::vec4(0),
|
||||
glm::vec4(1,1,1,0),
|
||||
false
|
||||
);
|
||||
break;
|
||||
|
||||
@@ -196,8 +196,8 @@ void ChunksRenderer::drawChunks(
|
||||
shader.uniform1i("u_alphaClip", true);
|
||||
|
||||
// TODO: minimize draw calls number
|
||||
for (size_t i = 0; i < indices.size(); i++) {
|
||||
auto chunk = chunks.getChunks()[indices[i].index];
|
||||
for (int i = indices.size()-1; i >= 0; i--) {
|
||||
auto& chunk = chunks.getChunks()[indices[i].index];
|
||||
auto mesh = retrieveChunk(indices[i].index, camera, shader, culling);
|
||||
|
||||
if (mesh) {
|
||||
|
||||
@@ -114,7 +114,7 @@ model::Model ModelsGenerator::generate(
|
||||
} else if (blockDef.model == BlockModel::custom) {
|
||||
model = assets.require<model::Model>(blockDef.modelName);
|
||||
for (auto& mesh : model.meshes) {
|
||||
mesh.scale(glm::vec3(0.3f));
|
||||
mesh.scale(glm::vec3(0.2f));
|
||||
}
|
||||
return model;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ model::Model ModelsGenerator::generate(
|
||||
} default:
|
||||
break;
|
||||
}
|
||||
mesh.scale(glm::vec3(0.3f));
|
||||
mesh.scale(glm::vec3(0.2f));
|
||||
}
|
||||
configure_textures(model, blockDef, assets);
|
||||
return model;
|
||||
|
||||
@@ -247,12 +247,12 @@ void WorldRenderer::renderHands(
|
||||
|
||||
// prepare modified HUD camera
|
||||
Camera hudcam = camera;
|
||||
hudcam.far = 100.0f;
|
||||
hudcam.setFov(1.2f);
|
||||
hudcam.far = 10.0f;
|
||||
hudcam.setFov(0.9f);
|
||||
hudcam.position = {};
|
||||
|
||||
// configure model matrix
|
||||
const glm::vec3 itemOffset(0.08f, 0.035f, -0.1);
|
||||
const glm::vec3 itemOffset(0.06f, 0.035f, -0.1);
|
||||
|
||||
static glm::mat4 prevRotation(1.0f);
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ SlotView::SlotView(
|
||||
layout(std::move(layout))
|
||||
{
|
||||
setColor(glm::vec4(0, 0, 0, 0.2f));
|
||||
setTooltipDelay(0.05f);
|
||||
setTooltipDelay(0.0f);
|
||||
}
|
||||
|
||||
void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
@@ -135,7 +135,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
const int slotSize = InventoryView::SLOT_SIZE;
|
||||
|
||||
const ItemStack& stack = *bound;
|
||||
glm::vec4 tint(1.0f);
|
||||
glm::vec4 tint(1, 1, 1, isEnabled() ? 1 : 0.5f);
|
||||
glm::vec2 pos = calcPos();
|
||||
glm::vec4 color = getColor();
|
||||
|
||||
@@ -208,11 +208,73 @@ bool SlotView::isHighlighted() const {
|
||||
return highlighted;
|
||||
}
|
||||
|
||||
void SlotView::performLeftClick(ItemStack& stack, ItemStack& grabbed) {
|
||||
if (layout.taking && Events::pressed(keycode::LEFT_SHIFT)) {
|
||||
if (layout.shareFunc) {
|
||||
layout.shareFunc(layout.index, stack);
|
||||
}
|
||||
if (layout.updateFunc) {
|
||||
layout.updateFunc(layout.index, stack);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!layout.itemSource && stack.accepts(grabbed) && layout.placing) {
|
||||
stack.move(grabbed, content->getIndices());
|
||||
} else {
|
||||
if (layout.itemSource) {
|
||||
if (grabbed.isEmpty()) {
|
||||
grabbed.set(stack);
|
||||
} else {
|
||||
grabbed.clear();
|
||||
}
|
||||
} else if (grabbed.isEmpty()) {
|
||||
if (layout.taking) {
|
||||
std::swap(grabbed, stack);
|
||||
}
|
||||
} else if (layout.taking && layout.placing) {
|
||||
std::swap(grabbed, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SlotView::performRightClick(ItemStack& stack, ItemStack& grabbed) {
|
||||
if (layout.rightClick) {
|
||||
layout.rightClick(inventoryid, stack);
|
||||
if (layout.updateFunc) {
|
||||
layout.updateFunc(layout.index, stack);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (layout.itemSource)
|
||||
return;
|
||||
if (grabbed.isEmpty()) {
|
||||
if (!stack.isEmpty() && layout.taking) {
|
||||
grabbed.set(stack);
|
||||
int halfremain = stack.getCount() / 2;
|
||||
grabbed.setCount(stack.getCount() - halfremain);
|
||||
stack.setCount(halfremain);
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto& stackDef = content->getIndices()->items.require(stack.getItemId());
|
||||
if (!layout.placing) {
|
||||
return;
|
||||
}
|
||||
if (stack.isEmpty()) {
|
||||
stack.set(grabbed);
|
||||
stack.setCount(1);
|
||||
grabbed.setCount(grabbed.getCount() - 1);
|
||||
} else if (stack.accepts(grabbed) && stack.getCount() < stackDef.stackSize) {
|
||||
stack.setCount(stack.getCount() + 1);
|
||||
grabbed.setCount(grabbed.getCount() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void SlotView::clicked(gui::GUI* gui, mousecode button) {
|
||||
if (bound == nullptr)
|
||||
return;
|
||||
|
||||
auto exchangeSlot = std::dynamic_pointer_cast<SlotView>(gui->get(EXCHANGE_SLOT_NAME));
|
||||
auto exchangeSlot =
|
||||
std::dynamic_pointer_cast<SlotView>(gui->get(EXCHANGE_SLOT_NAME));
|
||||
if (exchangeSlot == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -220,57 +282,9 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) {
|
||||
ItemStack& stack = *bound;
|
||||
|
||||
if (button == mousecode::BUTTON_1) {
|
||||
if (Events::pressed(keycode::LEFT_SHIFT)) {
|
||||
if (layout.shareFunc) {
|
||||
layout.shareFunc(layout.index, stack);
|
||||
}
|
||||
if (layout.updateFunc) {
|
||||
layout.updateFunc(layout.index, stack);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!layout.itemSource && stack.accepts(grabbed)) {
|
||||
stack.move(grabbed, content->getIndices());
|
||||
} else {
|
||||
if (layout.itemSource) {
|
||||
if (grabbed.isEmpty()) {
|
||||
grabbed.set(stack);
|
||||
} else {
|
||||
grabbed.clear();
|
||||
}
|
||||
} else {
|
||||
std::swap(grabbed, stack);
|
||||
}
|
||||
}
|
||||
performLeftClick(stack, grabbed);
|
||||
} else if (button == mousecode::BUTTON_2) {
|
||||
if (layout.rightClick) {
|
||||
layout.rightClick(inventoryid, stack);
|
||||
if (layout.updateFunc) {
|
||||
layout.updateFunc(layout.index, stack);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (layout.itemSource)
|
||||
return;
|
||||
if (grabbed.isEmpty()) {
|
||||
if (!stack.isEmpty()) {
|
||||
grabbed.set(stack);
|
||||
int halfremain = stack.getCount() / 2;
|
||||
grabbed.setCount(stack.getCount() - halfremain);
|
||||
stack.setCount(halfremain);
|
||||
}
|
||||
} else {
|
||||
auto& stackDef =
|
||||
content->getIndices()->items.require(stack.getItemId());
|
||||
if (stack.isEmpty()) {
|
||||
stack.set(grabbed);
|
||||
stack.setCount(1);
|
||||
grabbed.setCount(grabbed.getCount() - 1);
|
||||
} else if (stack.accepts(grabbed) && stack.getCount() < stackDef.stackSize) {
|
||||
stack.setCount(stack.getCount() + 1);
|
||||
grabbed.setCount(grabbed.getCount() - 1);
|
||||
}
|
||||
}
|
||||
performRightClick(stack, grabbed);
|
||||
}
|
||||
if (layout.updateFunc) {
|
||||
layout.updateFunc(layout.index, stack);
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace gui {
|
||||
slotcallback rightClick;
|
||||
int padding = 0;
|
||||
|
||||
bool taking = true;
|
||||
bool placing = true;
|
||||
|
||||
SlotLayout(
|
||||
int index,
|
||||
glm::vec2 position,
|
||||
@@ -55,6 +58,9 @@ namespace gui {
|
||||
|
||||
std::wstring tooltip;
|
||||
itemid_t prevItem = 0;
|
||||
|
||||
void performLeftClick(ItemStack& stack, ItemStack& grabbed);
|
||||
void performRightClick(ItemStack& stack, ItemStack& grabbed);
|
||||
public:
|
||||
SlotView(SlotLayout layout);
|
||||
|
||||
|
||||
@@ -483,6 +483,8 @@ static slotcallback readSlotFunc(InventoryView* view, UiXmlReader& reader, xml::
|
||||
static void readSlot(InventoryView* view, UiXmlReader& reader, xml::xmlelement element) {
|
||||
int index = element->attr("index", "0").asInt();
|
||||
bool itemSource = element->attr("item-source", "false").asBool();
|
||||
bool taking = element->attr("taking", "true").asBool();
|
||||
bool placing = element->attr("placing", "true").asBool();
|
||||
SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr, nullptr);
|
||||
if (element->has("pos")) {
|
||||
layout.position = element->attr("pos").asVec2();
|
||||
@@ -496,6 +498,8 @@ static void readSlot(InventoryView* view, UiXmlReader& reader, xml::xmlelement e
|
||||
if (element->has("onrightclick")) {
|
||||
layout.rightClick = readSlotFunc(view, reader, element, "onrightclick");
|
||||
}
|
||||
layout.taking = taking;
|
||||
layout.placing = placing;
|
||||
auto slot = view->addSlot(layout);
|
||||
reader.readUINode(reader, element, *slot);
|
||||
view->add(slot);
|
||||
@@ -507,6 +511,8 @@ static void readSlotsGrid(InventoryView* view, UiXmlReader& reader, xml::xmlelem
|
||||
int cols = element->attr("cols", "0").asInt();
|
||||
int count = element->attr("count", "0").asInt();
|
||||
const int slotSize = InventoryView::SLOT_SIZE;
|
||||
bool taking = element->attr("taking", "true").asBool();
|
||||
bool placing = element->attr("placing", "true").asBool();
|
||||
int interval = element->attr("interval", "-1").asInt();
|
||||
if (interval < 0) {
|
||||
interval = InventoryView::SLOT_INTERVAL;
|
||||
@@ -537,6 +543,8 @@ static void readSlotsGrid(InventoryView* view, UiXmlReader& reader, xml::xmlelem
|
||||
layout.rightClick = readSlotFunc(view, reader, element, "onrightclick");
|
||||
}
|
||||
layout.padding = padding;
|
||||
layout.taking = taking;
|
||||
layout.placing = placing;
|
||||
|
||||
int idx = 0;
|
||||
for (int row = 0; row < rows; row++) {
|
||||
|
||||
@@ -37,6 +37,12 @@ void Inventory::move(
|
||||
ItemStack& item, const ContentIndices* indices, size_t begin, size_t end
|
||||
) {
|
||||
end = std::min(slots.size(), end);
|
||||
for (size_t i = begin; i < end && !item.isEmpty(); i++) {
|
||||
ItemStack& slot = slots[i];
|
||||
if (!slot.isEmpty() && slot.accepts(item)) {
|
||||
slot.move(item, indices);
|
||||
}
|
||||
}
|
||||
for (size_t i = begin; i < end && !item.isEmpty(); i++) {
|
||||
ItemStack& slot = slots[i];
|
||||
if (slot.accepts(item)) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "data/dv.hpp"
|
||||
#include "typedefs.hpp"
|
||||
|
||||
struct item_funcs_set {
|
||||
@@ -25,6 +26,8 @@ struct ItemDef {
|
||||
/// @brief Item name will shown in inventory
|
||||
std::string caption;
|
||||
|
||||
dv::value properties = nullptr;
|
||||
|
||||
itemcount_t stackSize = 64;
|
||||
bool generated = false;
|
||||
uint8_t emission[4] {0, 0, 0, 0};
|
||||
|
||||
@@ -125,6 +125,10 @@ namespace cmd {
|
||||
const std::unordered_map<std::string, Command>& getCommands() const {
|
||||
return commands;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
commands.clear();
|
||||
}
|
||||
};
|
||||
|
||||
class CommandsInterpreter {
|
||||
@@ -158,5 +162,10 @@ namespace cmd {
|
||||
CommandsRepository* getRepository() const {
|
||||
return repository.get();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
repository->clear();
|
||||
variables.clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ PlayerController::PlayerController(
|
||||
player(level->players->get(0)),
|
||||
camControl(player, settings.camera),
|
||||
blocksController(blocksController),
|
||||
playerTickClock(20, 3) {
|
||||
playerTickClock(60, 1) {
|
||||
}
|
||||
|
||||
void PlayerController::onFootstep(const Hitbox& hitbox) {
|
||||
@@ -509,8 +509,7 @@ void PlayerController::updateInteraction(float delta) {
|
||||
bool longInteraction = interactionTimer <= 0 || xkey;
|
||||
bool lclick = Events::jactive(BIND_PLAYER_DESTROY) ||
|
||||
(longInteraction && Events::active(BIND_PLAYER_DESTROY));
|
||||
bool lattack = Events::jactive(BIND_PLAYER_ATTACK) ||
|
||||
(longInteraction && Events::active(BIND_PLAYER_ATTACK));
|
||||
bool lattack = Events::jactive(BIND_PLAYER_ATTACK);
|
||||
bool rclick = Events::jactive(BIND_PLAYER_BUILD) ||
|
||||
(longInteraction && Events::active(BIND_PLAYER_BUILD));
|
||||
if (lclick || rclick) {
|
||||
|
||||
@@ -19,7 +19,7 @@ static fs::path resolve_path(const std::string& path) {
|
||||
|
||||
static fs::path resolve_path_soft(const std::string& path) {
|
||||
if (path.find(':') == std::string::npos) {
|
||||
return path;
|
||||
return fs::u8path("");
|
||||
}
|
||||
return engine->getPaths()->resolve(path, false);
|
||||
}
|
||||
|
||||
@@ -334,7 +334,9 @@ static int p_set_interval(UINode* node, lua::State* L) {
|
||||
static int p_get_content_offset(UINode* node, lua::State* L) {
|
||||
return lua::pushvec(L, node->getContentOffset());
|
||||
}
|
||||
|
||||
static int p_get_id(UINode* node, lua::State* L) {
|
||||
return lua::pushstring(L, node->getId());
|
||||
}
|
||||
static int p_get_color(UINode* node, lua::State* L) {
|
||||
return lua::pushcolor(L, node->getColor());
|
||||
}
|
||||
@@ -390,6 +392,7 @@ static int l_gui_getattr(lua::State* L) {
|
||||
std::string_view,
|
||||
std::function<int(UINode*, lua::State*)>>
|
||||
getters {
|
||||
{"id", p_get_id},
|
||||
{"color", p_get_color},
|
||||
{"hoverColor", p_get_hover_color},
|
||||
{"pressedColor", p_get_pressed_color},
|
||||
|
||||
@@ -156,12 +156,32 @@ static int l_inventory_move(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_inventory_move_range(lua::State* L) {
|
||||
auto invAid = lua::tointeger(L, 1);
|
||||
auto slotAid = lua::tointeger(L, 2);
|
||||
auto invA = get_inventory(invAid, 1);
|
||||
validate_slotid(slotAid, invA.get());
|
||||
|
||||
auto invBid = lua::tointeger(L, 3);
|
||||
auto slotBegin = lua::isnoneornil(L, 4) ? -1 : lua::tointeger(L, 4);
|
||||
auto slotEnd = lua::isnoneornil(L, 5) ? -1 : lua::tointeger(L, 5) + 1;
|
||||
auto invB = get_inventory(invBid, 3);
|
||||
auto& slot = invA->getSlot(slotAid);
|
||||
if (slotBegin == -1) {
|
||||
invB->move(slot, content->getIndices());
|
||||
} else {
|
||||
invB->move(slot, content->getIndices(), slotBegin, slotEnd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg inventorylib[] = {
|
||||
{"get", lua::wrap<l_inventory_get>},
|
||||
{"set", lua::wrap<l_inventory_set>},
|
||||
{"size", lua::wrap<l_inventory_size>},
|
||||
{"add", lua::wrap<l_inventory_add>},
|
||||
{"move", lua::wrap<l_inventory_move>},
|
||||
{"move_range", lua::wrap<l_inventory_move_range>},
|
||||
{"get_block", lua::wrap<l_inventory_get_block>},
|
||||
{"bind_block", lua::wrap<l_inventory_bind_block>},
|
||||
{"unbind_block", lua::wrap<l_inventory_unbind_block>},
|
||||
|
||||
@@ -68,7 +68,6 @@ void scripting::initialize(Engine* engine) {
|
||||
lua::initialize(*engine->getPaths());
|
||||
|
||||
load_script(fs::path("stdlib.lua"), true);
|
||||
load_script(fs::path("stdcmd.lua"), true);
|
||||
load_script(fs::path("classes.lua"), true);
|
||||
}
|
||||
|
||||
@@ -157,10 +156,26 @@ void scripting::process_post_runnables() {
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static int push_properties_tables(
|
||||
lua::State* L, const ContentUnitIndices<T>& indices
|
||||
) {
|
||||
const auto units = indices.getDefs();
|
||||
size_t size = indices.count();
|
||||
lua::createtable(L, size, 0);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
lua::pushvalue(L, units[i]->properties);
|
||||
lua::rawseti(L, i);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void scripting::on_content_load(Content* content) {
|
||||
scripting::content = content;
|
||||
scripting::indices = content->getIndices();
|
||||
|
||||
const auto& indices = *content->getIndices();
|
||||
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::getglobal(L, "block")) {
|
||||
const auto& materials = content->getBlockMaterials();
|
||||
@@ -170,8 +185,18 @@ void scripting::on_content_load(Content* content) {
|
||||
lua::setfield(L, name);
|
||||
}
|
||||
lua::setfield(L, "materials");
|
||||
|
||||
push_properties_tables(L, indices.blocks);
|
||||
lua::setfield(L, "properties");
|
||||
lua::pop(L);
|
||||
}
|
||||
if (lua::getglobal(L, "item")) {
|
||||
push_properties_tables(L, indices.blocks);
|
||||
lua::setfield(L, "properties");
|
||||
lua::pop(L);
|
||||
}
|
||||
load_script(fs::path("post_content.lua"), true);
|
||||
load_script(fs::path("stdcmd.lua"), true);
|
||||
}
|
||||
|
||||
void scripting::on_world_load(LevelController* controller) {
|
||||
|
||||
@@ -120,6 +120,8 @@ public:
|
||||
/// @brief Textures set applied to block sides
|
||||
std::array<std::string, 6> textureFaces; // -x,x, -y,y, -z,z
|
||||
|
||||
dv::value properties = nullptr;
|
||||
|
||||
/// @brief id of used BlockMaterial, may specify non-existing material
|
||||
std::string material = DEFAULT_MATERIAL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user