add block.materials table
This commit is contained in:
@@ -160,6 +160,18 @@ void scripting::process_post_runnables() {
|
|||||||
void scripting::on_content_load(Content* content) {
|
void scripting::on_content_load(Content* content) {
|
||||||
scripting::content = content;
|
scripting::content = content;
|
||||||
scripting::indices = content->getIndices();
|
scripting::indices = content->getIndices();
|
||||||
|
|
||||||
|
auto L = lua::get_main_state();
|
||||||
|
if (lua::getglobal(L, "block")) {
|
||||||
|
const auto& materials = content->getBlockMaterials();
|
||||||
|
lua::createtable(L, 0, materials.size());
|
||||||
|
for (const auto& [name, material] : materials) {
|
||||||
|
lua::pushvalue(L, material->serialize());
|
||||||
|
lua::setfield(L, name);
|
||||||
|
}
|
||||||
|
lua::setfield(L, "materials");
|
||||||
|
lua::pop(L);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::on_world_load(LevelController* controller) {
|
void scripting::on_world_load(LevelController* controller) {
|
||||||
|
|||||||
@@ -8,6 +8,15 @@
|
|||||||
#include "presets/ParticlesPreset.hpp"
|
#include "presets/ParticlesPreset.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
|
|
||||||
|
dv::value BlockMaterial::serialize() const {
|
||||||
|
return dv::object({
|
||||||
|
{"name", name},
|
||||||
|
{"stepsSound", stepsSound},
|
||||||
|
{"placeSound", placeSound},
|
||||||
|
{"breakSound", breakSound}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
std::string to_string(BlockModel model) {
|
std::string to_string(BlockModel model) {
|
||||||
switch (model) {
|
switch (model) {
|
||||||
case BlockModel::none:
|
case BlockModel::none:
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ struct BlockMaterial {
|
|||||||
std::string stepsSound {""};
|
std::string stepsSound {""};
|
||||||
std::string placeSound {""};
|
std::string placeSound {""};
|
||||||
std::string breakSound {""};
|
std::string breakSound {""};
|
||||||
|
|
||||||
|
dv::value serialize() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Block properties definition
|
/// @brief Block properties definition
|
||||||
|
|||||||
Reference in New Issue
Block a user