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_tiled_wall_2d.h"
|
2021-11-23 16:53:47 +01:00
|
|
|
|
2022-02-21 22:02:46 +01:00
|
|
|
#include "../tiled_wall/tiled_wall_2d.h"
|
|
|
|
#include "../tiled_wall/tiled_wall_2d_data.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
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
int Prop2DDataTiledWall2D::get_width() const {
|
2021-11-23 16:53:47 +01:00
|
|
|
return _width;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataTiledWall2D::set_width(const int value) {
|
2021-11-23 16:53:47 +01:00
|
|
|
_width = value;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
int Prop2DDataTiledWall2D::get_heigth() const {
|
2021-11-23 16:53:47 +01:00
|
|
|
return _height;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataTiledWall2D::set_heigth(const int value) {
|
2021-11-23 16:53:47 +01:00
|
|
|
_height = value;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
Ref<TiledWall2DData> Prop2DDataTiledWall2D::get_data() {
|
2021-11-23 16:53:47 +01:00
|
|
|
return _data;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataTiledWall2D::set_data(const Ref<TiledWall2DData> &data) {
|
2021-11-23 16:53:47 +01:00
|
|
|
_data = data;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
bool Prop2DDataTiledWall2D::get_collision() const {
|
2021-11-23 16:53:47 +01:00
|
|
|
return _collision;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataTiledWall2D::set_collision(const int value) {
|
2021-11-23 16:53:47 +01:00
|
|
|
_collision = value;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
bool Prop2DDataTiledWall2D::_processor_handles(Node *node) {
|
|
|
|
TiledWall2D *t = Object::cast_to<TiledWall2D>(node);
|
2021-11-23 16:53:47 +01:00
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2022-02-22 19:05:10 +01:00
|
|
|
void Prop2DDataTiledWall2D::_processor_process(Ref<Prop2DData> prop_data, Node *node, const Transform2D &transform) {
|
2022-02-21 22:12:25 +01:00
|
|
|
TiledWall2D *t = Object::cast_to<TiledWall2D>(node);
|
2021-11-23 16:53:47 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!t);
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
Ref<Prop2DDataTiledWall2D> tw;
|
2021-11-23 16:53:47 +01:00
|
|
|
tw.instance();
|
|
|
|
|
|
|
|
tw->set_width(t->get_width());
|
|
|
|
tw->set_heigth(t->get_heigth());
|
|
|
|
tw->set_data(t->get_data());
|
|
|
|
tw->set_collision(t->get_collision());
|
2022-02-22 19:05:10 +01:00
|
|
|
//tw->set_transform(transform * t->get_transform());
|
2021-11-23 16:53:47 +01:00
|
|
|
prop_data->add_prop(tw);
|
|
|
|
}
|
|
|
|
|
2022-02-22 19:05:10 +01:00
|
|
|
Node *Prop2DDataTiledWall2D::_processor_get_node_for(const Transform2D &transform) {
|
2022-02-21 22:12:25 +01:00
|
|
|
TiledWall2D *t = memnew(TiledWall2D);
|
2021-11-23 16:53:47 +01:00
|
|
|
|
|
|
|
t->set_width(get_width());
|
|
|
|
t->set_heigth(get_heigth());
|
|
|
|
t->set_collision(get_collision());
|
|
|
|
t->set_data(get_data());
|
2022-02-22 19:05:10 +01:00
|
|
|
//t->set_transform(get_transform());
|
2021-11-23 16:53:47 +01:00
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
Prop2DDataTiledWall2D::Prop2DDataTiledWall2D() {
|
2021-11-23 16:53:47 +01:00
|
|
|
_width = 1;
|
|
|
|
_height = 1;
|
|
|
|
_collision = true;
|
|
|
|
}
|
2022-02-21 22:12:25 +01:00
|
|
|
Prop2DDataTiledWall2D::~Prop2DDataTiledWall2D() {
|
2021-11-23 16:53:47 +01:00
|
|
|
_data.unref();
|
|
|
|
}
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
void Prop2DDataTiledWall2D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("get_width"), &Prop2DDataTiledWall2D::get_width);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_width", "value"), &Prop2DDataTiledWall2D::set_width);
|
2021-11-23 16:53:47 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "width"), "set_width", "get_width");
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_heigth"), &Prop2DDataTiledWall2D::get_heigth);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_heigth", "value"), &Prop2DDataTiledWall2D::set_heigth);
|
2021-11-23 16:53:47 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "heigth"), "set_heigth", "get_heigth");
|
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_data"), &Prop2DDataTiledWall2D::get_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_data", "value"), &Prop2DDataTiledWall2D::set_data);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "TiledWall2DData"), "set_data", "get_data");
|
2021-11-23 16:53:47 +01:00
|
|
|
|
2022-02-21 22:12:25 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_collision"), &Prop2DDataTiledWall2D::get_collision);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_collision", "value"), &Prop2DDataTiledWall2D::set_collision);
|
2021-11-23 16:53:47 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision"), "set_collision", "get_collision");
|
|
|
|
}
|