2021-11-23 16:53:47 +01:00
|
|
|
/*
|
2022-02-21 17:09:00 +01:00
|
|
|
Copyright (c) 2019-2022 Péter Magyar
|
2021-11-23 16:53:47 +01:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2022-02-21 22:02:46 +01:00
|
|
|
#include "prop_2d_data_light.h"
|
2021-11-23 16:53:47 +01:00
|
|
|
|
2022-02-21 22:02:46 +01:00
|
|
|
#include "prop_2d_data.h"
|
2021-11-23 16:53:47 +01:00
|
|
|
|
|
|
|
#if VERSION_MAJOR < 4
|
|
|
|
#include "scene/3d/light.h"
|
|
|
|
#else
|
|
|
|
#include "scene/3d/light_3d.h"
|
|
|
|
#define OmniLight OmniLight3D
|
|
|
|
#define Light Light3D
|
|
|
|
#endif
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
Color Prop2DDataLight::get_light_color() const {
|
2021-11-23 16:53:47 +01:00
|
|
|
return _light_color;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataLight::set_light_color(const Color value) {
|
2021-11-23 16:53:47 +01:00
|
|
|
_light_color = value;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
int Prop2DDataLight::get_light_size() const {
|
2021-11-23 16:53:47 +01:00
|
|
|
return _light_size;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataLight::set_light_size(const int value) {
|
2021-11-23 16:53:47 +01:00
|
|
|
_light_size = value;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
bool Prop2DDataLight::_processor_handles(Node *node) {
|
2021-11-23 16:53:47 +01:00
|
|
|
OmniLight *i = Object::cast_to<OmniLight>(node);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2022-02-22 19:05:10 +01:00
|
|
|
void Prop2DDataLight::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
2021-11-23 16:53:47 +01:00
|
|
|
OmniLight *i = Object::cast_to<OmniLight>(node);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!i);
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
Ref<Prop2DDataLight> l;
|
2021-11-23 16:53:47 +01:00
|
|
|
l.instance();
|
|
|
|
l->set_light_color(i->get_color());
|
|
|
|
l->set_light_size(i->get_param(Light::PARAM_RANGE));
|
2022-02-22 19:05:10 +01:00
|
|
|
//l->set_transform(transform * i->get_transform());
|
2021-11-23 16:53:47 +01:00
|
|
|
prop_data->add_prop(l);
|
|
|
|
}
|
|
|
|
|
2022-02-22 19:05:10 +01:00
|
|
|
Node *Prop2DDataLight::_processor_get_node_for(const Transform2D &transform) {
|
2021-11-23 16:53:47 +01:00
|
|
|
OmniLight *i = memnew(OmniLight);
|
|
|
|
|
|
|
|
i->set_color(get_light_color());
|
|
|
|
i->set_param(Light::PARAM_RANGE, get_light_size());
|
2022-02-22 19:05:10 +01:00
|
|
|
//i->set_transform(get_transform());
|
2021-11-23 16:53:47 +01:00
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
Prop2DDataLight::Prop2DDataLight() {
|
2021-11-23 16:53:47 +01:00
|
|
|
_light_size = 0;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
Prop2DDataLight::~Prop2DDataLight() {
|
2021-11-23 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataLight::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("get_light_color"), &Prop2DDataLight::get_light_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_light_color", "value"), &Prop2DDataLight::set_light_color);
|
2021-11-23 16:53:47 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_light_color", "get_light_color");
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_light_size"), &Prop2DDataLight::get_light_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_light_size", "value"), &Prop2DDataLight::set_light_size);
|
2021-11-23 16:53:47 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size"), "set_light_size", "get_light_size");
|
|
|
|
}
|