make BlockMaterial serializable
This commit is contained in:
parent
862ac496a8
commit
9e28b783fd
@ -186,11 +186,7 @@ void ContentUnitLoader<DefT>::loadUnit(
|
|||||||
void ContentLoader::loadBlockMaterial(
|
void ContentLoader::loadBlockMaterial(
|
||||||
BlockMaterial& def, const io::path& file
|
BlockMaterial& def, const io::path& file
|
||||||
) {
|
) {
|
||||||
auto root = io::read_json(file);
|
def.deserialize(io::read_json(file));
|
||||||
root.at("steps-sound").get(def.stepsSound);
|
|
||||||
root.at("place-sound").get(def.placeSound);
|
|
||||||
root.at("break-sound").get(def.breakSound);
|
|
||||||
root.at("hit-sound").get(def.hitSound);
|
|
||||||
if (def.hitSound.empty()) {
|
if (def.hitSound.empty()) {
|
||||||
def.hitSound = def.stepsSound;
|
def.hitSound = def.stepsSound;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -243,7 +243,7 @@ void scripting::on_content_load(Content* content) {
|
|||||||
const auto& materials = content->getBlockMaterials();
|
const auto& materials = content->getBlockMaterials();
|
||||||
lua::createtable(L, 0, materials.size());
|
lua::createtable(L, 0, materials.size());
|
||||||
for (const auto& [name, material] : materials) {
|
for (const auto& [name, material] : materials) {
|
||||||
lua::pushvalue(L, material->serialize());
|
lua::pushvalue(L, material->toTable());
|
||||||
lua::setfield(L, name);
|
lua::setfield(L, name);
|
||||||
}
|
}
|
||||||
lua::setfield(L, "materials");
|
lua::setfield(L, "materials");
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
#include "presets/ParticlesPreset.hpp"
|
#include "presets/ParticlesPreset.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
|
|
||||||
dv::value BlockMaterial::serialize() const {
|
dv::value BlockMaterial::toTable() const {
|
||||||
return dv::object({
|
return dv::object({
|
||||||
{"name", name},
|
{"name", name},
|
||||||
{"stepsSound", stepsSound},
|
{"stepsSound", stepsSound},
|
||||||
@ -18,6 +18,24 @@ dv::value BlockMaterial::serialize() const {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dv::value BlockMaterial::serialize() const {
|
||||||
|
return dv::object({
|
||||||
|
{"name", name},
|
||||||
|
{"steps-sound", stepsSound},
|
||||||
|
{"place-sound", placeSound},
|
||||||
|
{"break-sound", breakSound},
|
||||||
|
{"hit-sound", hitSound}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlockMaterial::deserialize(const dv::value& src) {
|
||||||
|
src.at("name").get(name);
|
||||||
|
src.at("steps-sound").get(stepsSound);
|
||||||
|
src.at("place-sound").get(placeSound);
|
||||||
|
src.at("break-sound").get(breakSound);
|
||||||
|
src.at("hit-sound").get(hitSound);
|
||||||
|
}
|
||||||
|
|
||||||
CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ)
|
CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ)
|
||||||
: axes({axisX, axisY, axisZ}) {
|
: axes({axisX, axisY, axisZ}) {
|
||||||
fix = glm::ivec3(0);
|
fix = glm::ivec3(0);
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include "maths/aabb.hpp"
|
#include "maths/aabb.hpp"
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "util/EnumMetadata.hpp"
|
#include "util/EnumMetadata.hpp"
|
||||||
|
#include "interfaces/Serializable.hpp"
|
||||||
|
|
||||||
struct ParticlesPreset;
|
struct ParticlesPreset;
|
||||||
|
|
||||||
@ -116,14 +117,16 @@ VC_ENUM_END
|
|||||||
using BoxModel = AABB;
|
using BoxModel = AABB;
|
||||||
|
|
||||||
/// @brief Common kit of block properties applied to groups of blocks
|
/// @brief Common kit of block properties applied to groups of blocks
|
||||||
struct BlockMaterial {
|
struct BlockMaterial : Serializable {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string stepsSound;
|
std::string stepsSound;
|
||||||
std::string placeSound;
|
std::string placeSound;
|
||||||
std::string breakSound;
|
std::string breakSound;
|
||||||
std::string hitSound;
|
std::string hitSound;
|
||||||
|
|
||||||
dv::value serialize() const;
|
dv::value toTable() const; // for compatibility
|
||||||
|
dv::value serialize() const override;
|
||||||
|
void deserialize(const dv::value& src) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Block properties definition
|
/// @brief Block properties definition
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user