mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-14 10:17:20 +01:00
Add property for voxel structures.
This commit is contained in:
parent
d985610574
commit
06d3b0ae32
@ -176,8 +176,6 @@ Ref<VoxelStructure> VoxelWorld::get_voxel_structure(const int index) const {
|
||||
return _voxel_structures.get(index);
|
||||
}
|
||||
void VoxelWorld::add_voxel_structure(const Ref<VoxelStructure> &structure) {
|
||||
ERR_FAIL_COND(!structure.is_valid());
|
||||
|
||||
_voxel_structures.push_back(structure);
|
||||
}
|
||||
void VoxelWorld::remove_voxel_structure(const Ref<VoxelStructure> &structure) {
|
||||
@ -210,6 +208,27 @@ void VoxelWorld::add_voxel_structure_at_position(Ref<VoxelStructure> structure,
|
||||
add_voxel_structure(structure);
|
||||
}
|
||||
|
||||
Vector<Variant> VoxelWorld::get_voxel_structures() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _voxel_structures.size(); i++) {
|
||||
#if VERSION_MAJOR < 4
|
||||
r.push_back(_voxel_structures[i].get_ref_ptr());
|
||||
#else
|
||||
r.push_back(_voxel_structures[i]);
|
||||
#endif
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void VoxelWorld::set_voxel_structures(const Vector<Variant> &structures) {
|
||||
clear_voxel_structures();
|
||||
|
||||
for (int i = 0; i < structures.size(); ++i) {
|
||||
Ref<VoxelLight> structure = Ref<VoxelLight>(structures[i]);
|
||||
|
||||
add_voxel_structure(structure);
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelWorld::add_chunk(Ref<VoxelChunk> chunk, const int x, const int y, const int z) {
|
||||
ERR_FAIL_COND(!chunk.is_valid());
|
||||
|
||||
@ -796,6 +815,10 @@ void VoxelWorld::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_voxel_structure_count"), &VoxelWorld::get_voxel_structure_count);
|
||||
ClassDB::bind_method(D_METHOD("add_voxel_structure_at_position", "structure", "world_position"), &VoxelWorld::add_voxel_structure_at_position);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_voxel_structures"), &VoxelWorld::get_voxel_structures);
|
||||
ClassDB::bind_method(D_METHOD("set_voxel_structures"), &VoxelWorld::set_voxel_structures);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_structures", PROPERTY_HINT_NONE, "17/17:VoxelStructure", PROPERTY_USAGE_DEFAULT, "VoxelStructure"), "set_voxel_structures", "get_voxel_structures");
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_chunk_added", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_chunk", "chunk", "x", "y", "z"), &VoxelWorld::add_chunk);
|
||||
|
@ -118,6 +118,9 @@ public:
|
||||
int get_voxel_structure_count() const;
|
||||
void add_voxel_structure_at_position(Ref<VoxelStructure> structure, const Vector3 &world_position);
|
||||
|
||||
Vector<Variant> get_voxel_structures();
|
||||
void set_voxel_structures(const Vector<Variant> &structures);
|
||||
|
||||
//Chunks
|
||||
void add_chunk(Ref<VoxelChunk> chunk, const int x, const int y, const int z);
|
||||
bool has_chunk(const int x, const int y, const int z) const;
|
||||
|
Loading…
Reference in New Issue
Block a user