2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* tile_set.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "tile_set.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String n = p_name;
|
|
|
|
int slash = n.find("/");
|
2017-03-05 15:44:50 +00:00
|
|
|
if (slash == -1)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-05 15:44:50 +00:00
|
|
|
int id = String::to_int(n.c_str(), slash);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tile_map.has(id))
|
|
|
|
create_tile(id);
|
2017-03-05 15:44:50 +00:00
|
|
|
String what = n.substr(slash + 1, n.length());
|
|
|
|
|
|
|
|
if (what == "name")
|
|
|
|
tile_set_name(id, p_value);
|
|
|
|
else if (what == "texture")
|
|
|
|
tile_set_texture(id, p_value);
|
2017-06-22 15:15:50 +00:00
|
|
|
else if (what == "normal_map")
|
|
|
|
tile_set_normal_map(id, p_value);
|
2017-03-05 15:44:50 +00:00
|
|
|
else if (what == "tex_offset")
|
|
|
|
tile_set_texture_offset(id, p_value);
|
|
|
|
else if (what == "material")
|
|
|
|
tile_set_material(id, p_value);
|
|
|
|
else if (what == "modulate")
|
|
|
|
tile_set_modulate(id, p_value);
|
|
|
|
else if (what == "region")
|
|
|
|
tile_set_region(id, p_value);
|
|
|
|
else if (what == "shape")
|
2017-06-25 18:47:30 +00:00
|
|
|
tile_set_shape(id, 0, p_value);
|
2017-07-01 16:02:04 +00:00
|
|
|
else if (what == "shape_offset")
|
|
|
|
tile_set_shape_offset(id, 0, p_value);
|
2017-06-25 18:47:30 +00:00
|
|
|
else if (what == "shape_one_way")
|
|
|
|
tile_set_shape_one_way(id, 0, p_value);
|
2017-03-05 15:44:50 +00:00
|
|
|
else if (what == "shapes")
|
|
|
|
_tile_set_shapes(id, p_value);
|
|
|
|
else if (what == "occluder")
|
|
|
|
tile_set_light_occluder(id, p_value);
|
|
|
|
else if (what == "occluder_offset")
|
|
|
|
tile_set_occluder_offset(id, p_value);
|
|
|
|
else if (what == "navigation")
|
|
|
|
tile_set_navigation_polygon(id, p_value);
|
|
|
|
else if (what == "navigation_offset")
|
|
|
|
tile_set_navigation_polygon_offset(id, p_value);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String n = p_name;
|
|
|
|
int slash = n.find("/");
|
2017-03-05 15:44:50 +00:00
|
|
|
if (slash == -1)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-05 15:44:50 +00:00
|
|
|
int id = String::to_int(n.c_str(), slash);
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(id), false);
|
|
|
|
|
|
|
|
String what = n.substr(slash + 1, n.length());
|
|
|
|
|
|
|
|
if (what == "name")
|
|
|
|
r_ret = tile_get_name(id);
|
|
|
|
else if (what == "texture")
|
|
|
|
r_ret = tile_get_texture(id);
|
2017-06-22 15:15:50 +00:00
|
|
|
else if (what == "normal_map")
|
|
|
|
r_ret = tile_get_normal_map(id);
|
2017-03-05 15:44:50 +00:00
|
|
|
else if (what == "tex_offset")
|
|
|
|
r_ret = tile_get_texture_offset(id);
|
|
|
|
else if (what == "material")
|
|
|
|
r_ret = tile_get_material(id);
|
|
|
|
else if (what == "modulate")
|
|
|
|
r_ret = tile_get_modulate(id);
|
|
|
|
else if (what == "region")
|
|
|
|
r_ret = tile_get_region(id);
|
|
|
|
else if (what == "shape")
|
2017-06-25 18:47:30 +00:00
|
|
|
r_ret = tile_get_shape(id, 0);
|
2017-07-01 16:02:04 +00:00
|
|
|
else if (what == "shape_offset")
|
|
|
|
r_ret = tile_get_shape_offset(id, 0);
|
2017-06-25 18:47:30 +00:00
|
|
|
else if (what == "shape_one_way")
|
|
|
|
r_ret = tile_get_shape_one_way(id, 0);
|
2017-03-05 15:44:50 +00:00
|
|
|
else if (what == "shapes")
|
|
|
|
r_ret = _tile_get_shapes(id);
|
|
|
|
else if (what == "occluder")
|
|
|
|
r_ret = tile_get_light_occluder(id);
|
|
|
|
else if (what == "occluder_offset")
|
|
|
|
r_ret = tile_get_occluder_offset(id);
|
|
|
|
else if (what == "navigation")
|
|
|
|
r_ret = tile_get_navigation_polygon(id);
|
|
|
|
else if (what == "navigation_offset")
|
|
|
|
r_ret = tile_get_navigation_polygon_offset(id);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int id = E->key();
|
2017-03-05 15:44:50 +00:00
|
|
|
String pre = itos(id) + "/";
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, pre + "name"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
|
2017-06-22 15:15:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "tex_offset"));
|
2017-04-07 02:36:37 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial"));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::COLOR, pre + "modulate"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::RECT2, pre + "region"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "occluder_offset"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "navigation_offset"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "navigation", PROPERTY_HINT_RESOURCE_TYPE, "NavigationPolygon"));
|
2017-07-01 16:02:04 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_EDITOR));
|
2017-06-25 18:47:30 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
|
2017-03-05 15:44:50 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::create_tile(int p_id) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(tile_map.has(p_id));
|
2017-06-25 18:47:30 +00:00
|
|
|
tile_map[p_id] = TileData();
|
2014-02-10 01:10:30 +00:00
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_texture(int p_id, const Ref<Texture> &p_texture) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].texture = p_texture;
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture> TileSet::tile_get_texture(int p_id) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Texture>());
|
2014-02-10 01:10:30 +00:00
|
|
|
return tile_map[p_id].texture;
|
|
|
|
}
|
|
|
|
|
2017-06-22 15:15:50 +00:00
|
|
|
void TileSet::tile_set_normal_map(int p_id, const Ref<Texture> &p_normal_map) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
|
|
|
tile_map[p_id].normal_map = p_normal_map;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture> TileSet::tile_get_normal_map(int p_id) const {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Texture>());
|
|
|
|
return tile_map[p_id].normal_map;
|
|
|
|
}
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void TileSet::tile_set_material(int p_id, const Ref<ShaderMaterial> &p_material) {
|
2015-03-09 05:34:56 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].material = p_material;
|
2015-03-09 05:34:56 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
Ref<ShaderMaterial> TileSet::tile_get_material(int p_id) const {
|
2015-03-09 05:34:56 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<ShaderMaterial>());
|
2015-03-09 05:34:56 +00:00
|
|
|
return tile_map[p_id].material;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_modulate(int p_id, const Color &p_modulate) {
|
2016-11-30 13:33:39 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].modulate = p_modulate;
|
2016-11-30 13:33:39 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Color TileSet::tile_get_modulate(int p_id) const {
|
2016-11-30 13:33:39 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Color(1, 1, 1));
|
2016-11-30 13:33:39 +00:00
|
|
|
return tile_map[p_id].modulate;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_texture_offset(int p_id, const Vector2 &p_offset) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].offset = p_offset;
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2014-02-19 14:57:14 +00:00
|
|
|
Vector2 TileSet::tile_get_texture_offset(int p_id) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
|
2014-02-10 01:10:30 +00:00
|
|
|
return tile_map[p_id].offset;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_region(int p_id, const Rect2 &p_region) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].region = p_region;
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 TileSet::tile_get_region(int p_id) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Rect2());
|
2014-02-10 01:10:30 +00:00
|
|
|
return tile_map[p_id].region;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_name(int p_id, const String &p_name) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].name = p_name;
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
String TileSet::tile_get_name(int p_id) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), String());
|
2014-02-10 01:10:30 +00:00
|
|
|
return tile_map[p_id].name;
|
|
|
|
}
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
void TileSet::tile_clear_shapes(int p_id) {
|
|
|
|
tile_map[p_id].shapes_data.clear();
|
|
|
|
}
|
|
|
|
|
2017-07-01 16:02:04 +00:00
|
|
|
void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Vector2 &p_offset, bool p_one_way) {
|
2017-06-25 18:47:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
|
|
|
|
|
|
|
ShapeData new_data = ShapeData();
|
|
|
|
new_data.shape = p_shape;
|
2017-07-01 16:02:04 +00:00
|
|
|
new_data.shape_offset = p_offset;
|
2017-06-25 18:47:30 +00:00
|
|
|
new_data.one_way_collision = p_one_way;
|
|
|
|
|
|
|
|
tile_map[p_id].shapes_data.push_back(new_data);
|
|
|
|
};
|
|
|
|
int TileSet::tile_get_shape_count(int p_id) const {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
|
|
|
|
|
|
|
|
return tile_map[p_id].shapes_data.size();
|
|
|
|
};
|
|
|
|
|
|
|
|
void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-06-25 18:47:30 +00:00
|
|
|
if (tile_map[p_id].shapes_data.size() <= p_shape_id)
|
|
|
|
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
|
|
|
|
tile_map[p_id].shapes_data[p_shape_id].shape = p_shape;
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Shape2D>());
|
2017-06-25 18:47:30 +00:00
|
|
|
if (tile_map[p_id].shapes_data.size() > p_shape_id)
|
|
|
|
return tile_map[p_id].shapes_data[p_shape_id].shape;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return Ref<Shape2D>();
|
|
|
|
}
|
|
|
|
|
2017-07-01 16:02:04 +00:00
|
|
|
void TileSet::tile_set_shape_offset(int p_id, int p_shape_id, const Vector2 &p_offset) {
|
2017-06-25 18:47:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
|
|
|
if (tile_map[p_id].shapes_data.size() <= p_shape_id)
|
|
|
|
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
|
2017-07-01 16:02:04 +00:00
|
|
|
tile_map[p_id].shapes_data[p_shape_id].shape_offset = p_offset;
|
2017-06-25 18:47:30 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-07-01 16:02:04 +00:00
|
|
|
Vector2 TileSet::tile_get_shape_offset(int p_id, int p_shape_id) const {
|
2017-06-25 18:47:30 +00:00
|
|
|
|
2017-07-01 16:02:04 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
|
2017-06-25 18:47:30 +00:00
|
|
|
if (tile_map[p_id].shapes_data.size() > p_shape_id)
|
2017-07-01 16:02:04 +00:00
|
|
|
return tile_map[p_id].shapes_data[p_shape_id].shape_offset;
|
2017-06-25 18:47:30 +00:00
|
|
|
|
2017-07-01 16:02:04 +00:00
|
|
|
return Vector2();
|
2017-06-25 18:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_way) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
|
|
|
if (tile_map[p_id].shapes_data.size() <= p_shape_id)
|
|
|
|
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
|
|
|
|
tile_map[p_id].shapes_data[p_shape_id].one_way_collision = p_one_way;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), false);
|
|
|
|
if (tile_map[p_id].shapes_data.size() > p_shape_id)
|
|
|
|
return tile_map[p_id].shapes_data[p_shape_id].one_way_collision;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder) {
|
2015-03-09 05:34:56 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].occluder = p_light_occluder;
|
2015-03-09 05:34:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<OccluderPolygon2D> TileSet::tile_get_light_occluder(int p_id) const {
|
2015-03-09 05:34:56 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<OccluderPolygon2D>());
|
2015-03-09 05:34:56 +00:00
|
|
|
return tile_map[p_id].occluder;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset) {
|
2015-03-09 05:34:56 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].navigation_polygon_offset = p_offset;
|
2015-03-09 05:34:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 TileSet::tile_get_navigation_polygon_offset(int p_id) const {
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
|
2015-03-09 05:34:56 +00:00
|
|
|
return tile_map[p_id].navigation_polygon_offset;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon) {
|
2015-03-09 05:34:56 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].navigation_polygon = p_navigation_polygon;
|
2015-03-09 05:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<NavigationPolygon> TileSet::tile_get_navigation_polygon(int p_id) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<NavigationPolygon>());
|
2015-03-09 05:34:56 +00:00
|
|
|
return tile_map[p_id].navigation_polygon;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::tile_set_occluder_offset(int p_id, const Vector2 &p_offset) {
|
2015-03-09 05:34:56 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-03-05 15:44:50 +00:00
|
|
|
tile_map[p_id].occluder_offset = p_offset;
|
2015-03-09 05:34:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 TileSet::tile_get_occluder_offset(int p_id) const {
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
|
2015-03-09 05:34:56 +00:00
|
|
|
return tile_map[p_id].occluder_offset;
|
|
|
|
}
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
void TileSet::tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-06-25 18:47:30 +00:00
|
|
|
tile_map[p_id].shapes_data = p_shapes;
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
Vector<TileSet::ShapeData> TileSet::tile_get_shapes(int p_id) const {
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Vector<ShapeData>());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
return tile_map[p_id].shapes_data;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-06-25 18:47:30 +00:00
|
|
|
Vector<ShapeData> shapes_data;
|
2017-07-01 16:02:04 +00:00
|
|
|
Vector2 default_offset = tile_get_shape_offset(p_id, 0);
|
2017-06-25 18:47:30 +00:00
|
|
|
bool default_one_way = tile_get_shape_one_way(p_id, 0);
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < p_shapes.size(); i++) {
|
2017-06-25 18:47:30 +00:00
|
|
|
ShapeData s = ShapeData();
|
|
|
|
|
|
|
|
if (p_shapes[i].get_type() == Variant::OBJECT) {
|
|
|
|
Ref<Shape2D> shape = p_shapes[i];
|
|
|
|
if (shape.is_null()) continue;
|
|
|
|
|
|
|
|
s.shape = shape;
|
2017-07-01 16:02:04 +00:00
|
|
|
s.shape_offset = default_offset;
|
2017-06-25 18:47:30 +00:00
|
|
|
s.one_way_collision = default_one_way;
|
|
|
|
} else if (p_shapes[i].get_type() == Variant::DICTIONARY) {
|
|
|
|
Dictionary d = p_shapes[i];
|
|
|
|
|
|
|
|
if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT)
|
|
|
|
s.shape = d["shape"];
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
2017-07-01 16:02:04 +00:00
|
|
|
if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2)
|
|
|
|
s.shape_offset = d["shape_offset"];
|
2017-06-25 18:47:30 +00:00
|
|
|
else
|
2017-07-01 16:02:04 +00:00
|
|
|
s.shape_offset = default_offset;
|
2017-06-25 18:47:30 +00:00
|
|
|
|
|
|
|
if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL)
|
|
|
|
s.one_way_collision = d["one_way"];
|
|
|
|
else
|
|
|
|
s.one_way_collision = default_one_way;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ERR_EXPLAIN("Expected an array of objects or dictionaries for tile_set_shapes");
|
|
|
|
ERR_CONTINUE(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
shapes_data.push_back(s);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
tile_map[p_id].shapes_data = shapes_data;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Array TileSet::_tile_get_shapes(int p_id) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Array());
|
2014-02-10 01:10:30 +00:00
|
|
|
Array arr;
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
Vector<ShapeData> data = tile_map[p_id].shapes_data;
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
Dictionary shape_data;
|
|
|
|
shape_data["shape"] = data[i].shape;
|
2017-07-01 16:02:04 +00:00
|
|
|
shape_data["shape_offset"] = data[i].shape_offset;
|
2017-06-25 18:47:30 +00:00
|
|
|
shape_data["one_way"] = data[i].one_way_collision;
|
|
|
|
arr.push_back(shape_data);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Array TileSet::_get_tiles_ids() const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-18 09:49:34 +00:00
|
|
|
Array arr;
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2016-03-08 23:00:52 +00:00
|
|
|
arr.push_back(E->key());
|
2014-02-18 09:49:34 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-18 09:49:34 +00:00
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void TileSet::get_tile_list(List<int> *p_tiles) const {
|
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
p_tiles->push_back(E->key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TileSet::has_tile(int p_id) const {
|
|
|
|
|
|
|
|
return tile_map.has(p_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::remove_tile(int p_id) {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
|
|
|
tile_map.erase(p_id);
|
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TileSet::get_last_unused_tile_id() const {
|
|
|
|
|
|
|
|
if (tile_map.size())
|
2017-03-05 15:44:50 +00:00
|
|
|
return tile_map.back()->key() + 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int TileSet::find_tile_by_name(const String &p_name) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-25 18:47:30 +00:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_name == E->get().name)
|
2014-02-10 01:10:30 +00:00
|
|
|
return E->key();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::clear() {
|
|
|
|
|
|
|
|
tile_map.clear();
|
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("create_tile", "id"), &TileSet::create_tile);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_name", "id", "name"), &TileSet::tile_set_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_name", "id"), &TileSet::tile_get_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_texture", "id", "texture:Texture"), &TileSet::tile_set_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_texture:Texture", "id"), &TileSet::tile_get_texture);
|
2017-06-22 15:15:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_normal_map", "id", "normal_map:Texture"), &TileSet::tile_set_normal_map);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_normal_map:Texture", "id"), &TileSet::tile_get_normal_map);
|
2017-04-07 02:36:37 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_material", "id", "material:ShaderMaterial"), &TileSet::tile_set_material);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_material:ShaderMaterial", "id"), &TileSet::tile_get_material);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_texture_offset", "id", "texture_offset"), &TileSet::tile_set_texture_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_texture_offset", "id"), &TileSet::tile_get_texture_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_region", "id", "region"), &TileSet::tile_set_region);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_region", "id"), &TileSet::tile_get_region);
|
2017-06-25 18:47:30 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_shape", "id", "shape_id", "shape:Shape2D"), &TileSet::tile_set_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape:Shape2D", "id", "shape_id"), &TileSet::tile_get_shape);
|
2017-07-01 16:02:04 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_shape_offset", "id", "shape_id", "shape_offset"), &TileSet::tile_set_shape_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape_offset", "id", "shape_id"), &TileSet::tile_get_shape_offset);
|
2017-06-25 18:47:30 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_shape_one_way", "id", "shape_id", "one_way"), &TileSet::tile_set_shape_one_way);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape_one_way", "id", "shape_id"), &TileSet::tile_get_shape_one_way);
|
2017-07-01 16:02:04 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_add_shape", "id", "shape:Shape2D", "shape_offset", "one_way"), &TileSet::tile_add_shape, DEFVAL(false));
|
2017-06-25 18:47:30 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape_count", "id"), &TileSet::tile_get_shape_count);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_shapes", "id", "shapes"), &TileSet::_tile_set_shapes);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shapes", "id"), &TileSet::_tile_get_shapes);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_navigation_polygon", "id", "navigation_polygon:NavigationPolygon"), &TileSet::tile_set_navigation_polygon);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_navigation_polygon:NavigationPolygon", "id"), &TileSet::tile_get_navigation_polygon);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_navigation_polygon_offset", "id", "navigation_polygon_offset"), &TileSet::tile_set_navigation_polygon_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_navigation_polygon_offset", "id"), &TileSet::tile_get_navigation_polygon_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_light_occluder", "id", "light_occluder:OccluderPolygon2D"), &TileSet::tile_set_light_occluder);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_light_occluder:OccluderPolygon2D", "id"), &TileSet::tile_get_light_occluder);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_occluder_offset", "id", "occluder_offset"), &TileSet::tile_set_occluder_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_occluder_offset", "id"), &TileSet::tile_get_occluder_offset);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_tile", "id"), &TileSet::remove_tile);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &TileSet::clear);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_last_unused_tile_id"), &TileSet::get_last_unused_tile_id);
|
|
|
|
ClassDB::bind_method(D_METHOD("find_tile_by_name", "name"), &TileSet::find_tile_by_name);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tiles_ids", "name"), &TileSet::_get_tiles_ids);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TileSet::TileSet() {
|
|
|
|
}
|