2023-01-10 15:26:54 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* tile_set.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "tile_set.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/array.h"
|
2019-03-04 03:05:43 +01:00
|
|
|
#include "core/engine.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
String n = p_name;
|
|
|
|
int slash = n.find("/");
|
2021-05-05 12:44:11 +02:00
|
|
|
if (slash == -1) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
int id = String::to_int(n.c_str(), slash);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (!tile_map.has(id)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
create_tile(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
String what = n.substr(slash + 1, n.length());
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (what == "name") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_name(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "texture") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_texture(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "normal_map") {
|
2017-06-22 17:15:50 +02:00
|
|
|
tile_set_normal_map(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "tex_offset") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_texture_offset(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "material") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_material(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "modulate") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_modulate(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "region") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_region(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "tile_mode") {
|
2018-02-17 12:08:44 +01:00
|
|
|
tile_set_tile_mode(id, (TileMode)((int)p_value));
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "is_autotile") {
|
2018-08-25 03:56:03 +02:00
|
|
|
// backward compatibility for Godot 3.0.x
|
|
|
|
// autotile used to be a bool, it's now an enum
|
|
|
|
bool is_autotile = p_value;
|
2021-05-05 12:44:11 +02:00
|
|
|
if (is_autotile) {
|
2018-08-25 03:56:03 +02:00
|
|
|
tile_set_tile_mode(id, AUTO_TILE);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2018-08-25 03:56:03 +02:00
|
|
|
} else if (what.left(9) == "autotile/") {
|
2017-10-22 03:42:23 +02:00
|
|
|
what = what.right(9);
|
2021-05-05 12:44:11 +02:00
|
|
|
if (what == "bitmask_mode") {
|
2017-10-22 03:42:23 +02:00
|
|
|
autotile_set_bitmask_mode(id, (BitmaskMode)((int)p_value));
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "icon_coordinate") {
|
2017-10-22 03:42:23 +02:00
|
|
|
autotile_set_icon_coordinate(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "tile_size") {
|
2017-10-22 03:42:23 +02:00
|
|
|
autotile_set_size(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "spacing") {
|
2017-10-22 03:42:23 +02:00
|
|
|
autotile_set_spacing(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "bitmask_flags") {
|
2017-10-22 03:42:23 +02:00
|
|
|
tile_map[id].autotile_data.flags.clear();
|
|
|
|
if (p_value.is_array()) {
|
|
|
|
Array p = p_value;
|
|
|
|
Vector2 last_coord;
|
|
|
|
while (p.size() > 0) {
|
|
|
|
if (p[0].get_type() == Variant::VECTOR2) {
|
|
|
|
last_coord = p[0];
|
|
|
|
} else if (p[0].get_type() == Variant::INT) {
|
|
|
|
autotile_set_bitmask(id, last_coord, p[0]);
|
|
|
|
}
|
|
|
|
p.pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (what == "occluder_map") {
|
2017-12-08 20:38:36 +01:00
|
|
|
tile_map[id].autotile_data.occluder_map.clear();
|
2017-10-22 03:42:23 +02:00
|
|
|
Array p = p_value;
|
|
|
|
Vector2 last_coord;
|
|
|
|
while (p.size() > 0) {
|
|
|
|
if (p[0].get_type() == Variant::VECTOR2) {
|
|
|
|
last_coord = p[0];
|
|
|
|
} else if (p[0].get_type() == Variant::OBJECT) {
|
|
|
|
autotile_set_light_occluder(id, p[0], last_coord);
|
|
|
|
}
|
|
|
|
p.pop_front();
|
|
|
|
}
|
|
|
|
} else if (what == "navpoly_map") {
|
|
|
|
tile_map[id].autotile_data.navpoly_map.clear();
|
|
|
|
Array p = p_value;
|
|
|
|
Vector2 last_coord;
|
|
|
|
while (p.size() > 0) {
|
|
|
|
if (p[0].get_type() == Variant::VECTOR2) {
|
|
|
|
last_coord = p[0];
|
|
|
|
} else if (p[0].get_type() == Variant::OBJECT) {
|
|
|
|
autotile_set_navigation_polygon(id, p[0], last_coord);
|
|
|
|
}
|
|
|
|
p.pop_front();
|
|
|
|
}
|
|
|
|
} else if (what == "priority_map") {
|
|
|
|
tile_map[id].autotile_data.priority_map.clear();
|
|
|
|
Array p = p_value;
|
|
|
|
Vector3 val;
|
|
|
|
Vector2 v;
|
|
|
|
int priority;
|
|
|
|
while (p.size() > 0) {
|
|
|
|
val = p[0];
|
|
|
|
if (val.z > 1) {
|
|
|
|
v.x = val.x;
|
|
|
|
v.y = val.y;
|
|
|
|
priority = (int)val.z;
|
|
|
|
tile_map[id].autotile_data.priority_map[v] = priority;
|
|
|
|
}
|
|
|
|
p.pop_front();
|
|
|
|
}
|
2018-07-02 15:39:39 +02:00
|
|
|
} else if (what == "z_index_map") {
|
|
|
|
tile_map[id].autotile_data.z_index_map.clear();
|
|
|
|
Array p = p_value;
|
|
|
|
Vector3 val;
|
|
|
|
Vector2 v;
|
|
|
|
int z_index;
|
|
|
|
while (p.size() > 0) {
|
|
|
|
val = p[0];
|
2018-12-08 01:00:54 +01:00
|
|
|
if (val.z != 0) {
|
2018-07-02 15:39:39 +02:00
|
|
|
v.x = val.x;
|
|
|
|
v.y = val.y;
|
|
|
|
z_index = (int)val.z;
|
|
|
|
tile_map[id].autotile_data.z_index_map[v] = z_index;
|
|
|
|
}
|
|
|
|
p.pop_front();
|
|
|
|
}
|
2023-01-17 03:10:09 +01:00
|
|
|
} else if (what == "fallback_mode") {
|
|
|
|
autotile_set_fallback_mode(id, (FallbackMode)((int)p_value));
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape") {
|
2019-11-08 17:57:51 +01:00
|
|
|
if (tile_get_shape_count(id) > 0) {
|
|
|
|
for (int i = 0; i < tile_get_shape_count(id); i++) {
|
|
|
|
tile_set_shape(id, i, p_value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tile_set_shape(id, 0, p_value);
|
|
|
|
}
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_offset") {
|
2019-11-08 17:57:51 +01:00
|
|
|
if (tile_get_shape_count(id) > 0) {
|
|
|
|
for (int i = 0; i < tile_get_shape_count(id); i++) {
|
|
|
|
tile_set_shape_offset(id, i, p_value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tile_set_shape_offset(id, 0, p_value);
|
|
|
|
}
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_transform") {
|
2019-11-08 17:57:51 +01:00
|
|
|
if (tile_get_shape_count(id) > 0) {
|
|
|
|
for (int i = 0; i < tile_get_shape_count(id); i++) {
|
|
|
|
tile_set_shape_transform(id, i, p_value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tile_set_shape_transform(id, 0, p_value);
|
|
|
|
}
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_one_way") {
|
2019-11-08 17:57:51 +01:00
|
|
|
if (tile_get_shape_count(id) > 0) {
|
|
|
|
for (int i = 0; i < tile_get_shape_count(id); i++) {
|
|
|
|
tile_set_shape_one_way(id, i, p_value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tile_set_shape_one_way(id, 0, p_value);
|
|
|
|
}
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_one_way_margin") {
|
2019-11-08 17:57:51 +01:00
|
|
|
if (tile_get_shape_count(id) > 0) {
|
|
|
|
for (int i = 0; i < tile_get_shape_count(id); i++) {
|
|
|
|
tile_set_shape_one_way_margin(id, i, p_value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tile_set_shape_one_way_margin(id, 0, p_value);
|
|
|
|
}
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shapes") {
|
2017-03-05 16:44:50 +01:00
|
|
|
_tile_set_shapes(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "occluder") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_light_occluder(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "occluder_offset") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_occluder_offset(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "navigation") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_navigation_polygon(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "navigation_offset") {
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_set_navigation_polygon_offset(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "z_index") {
|
2018-02-17 11:58:07 +01:00
|
|
|
tile_set_z_index(id, p_value);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
String n = p_name;
|
|
|
|
int slash = n.find("/");
|
2021-05-05 12:44:11 +02:00
|
|
|
if (slash == -1) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01: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());
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (what == "name") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_name(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "texture") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_texture(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "normal_map") {
|
2017-06-22 17:15:50 +02:00
|
|
|
r_ret = tile_get_normal_map(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "tex_offset") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_texture_offset(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "material") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_material(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "modulate") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_modulate(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "region") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_region(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "tile_mode") {
|
2018-02-17 12:08:44 +01:00
|
|
|
r_ret = tile_get_tile_mode(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what.left(9) == "autotile/") {
|
2017-10-22 03:42:23 +02:00
|
|
|
what = what.right(9);
|
2021-05-05 12:44:11 +02:00
|
|
|
if (what == "bitmask_mode") {
|
2017-10-22 03:42:23 +02:00
|
|
|
r_ret = autotile_get_bitmask_mode(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "icon_coordinate") {
|
2017-10-22 03:42:23 +02:00
|
|
|
r_ret = autotile_get_icon_coordinate(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "tile_size") {
|
2017-10-22 03:42:23 +02:00
|
|
|
r_ret = autotile_get_size(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "spacing") {
|
2017-10-22 03:42:23 +02:00
|
|
|
r_ret = autotile_get_spacing(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "bitmask_flags") {
|
2017-10-22 03:42:23 +02:00
|
|
|
Array p;
|
2019-03-31 19:28:42 +02:00
|
|
|
for (Map<Vector2, uint32_t>::Element *E = tile_map[id].autotile_data.flags.front(); E; E = E->next()) {
|
2017-10-22 03:42:23 +02:00
|
|
|
p.push_back(E->key());
|
|
|
|
p.push_back(E->value());
|
|
|
|
}
|
|
|
|
r_ret = p;
|
|
|
|
} else if (what == "occluder_map") {
|
|
|
|
Array p;
|
2021-05-04 14:20:36 +02:00
|
|
|
for (Map<Vector2, Ref<OccluderPolygon2D>>::Element *E = tile_map[id].autotile_data.occluder_map.front(); E; E = E->next()) {
|
2017-10-22 03:42:23 +02:00
|
|
|
p.push_back(E->key());
|
|
|
|
p.push_back(E->value());
|
|
|
|
}
|
|
|
|
r_ret = p;
|
|
|
|
} else if (what == "navpoly_map") {
|
|
|
|
Array p;
|
2021-05-04 14:20:36 +02:00
|
|
|
for (Map<Vector2, Ref<NavigationPolygon>>::Element *E = tile_map[id].autotile_data.navpoly_map.front(); E; E = E->next()) {
|
2017-10-22 03:42:23 +02:00
|
|
|
p.push_back(E->key());
|
|
|
|
p.push_back(E->value());
|
|
|
|
}
|
|
|
|
r_ret = p;
|
|
|
|
} else if (what == "priority_map") {
|
|
|
|
Array p;
|
|
|
|
Vector3 v;
|
|
|
|
for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.priority_map.front(); E; E = E->next()) {
|
|
|
|
if (E->value() > 1) {
|
2018-01-18 21:37:17 +01:00
|
|
|
//Don't save default value
|
2017-10-22 03:42:23 +02:00
|
|
|
v.x = E->key().x;
|
|
|
|
v.y = E->key().y;
|
|
|
|
v.z = E->value();
|
|
|
|
p.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_ret = p;
|
2018-07-02 15:39:39 +02:00
|
|
|
} else if (what == "z_index_map") {
|
|
|
|
Array p;
|
|
|
|
Vector3 v;
|
|
|
|
for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.z_index_map.front(); E; E = E->next()) {
|
|
|
|
if (E->value() != 0) {
|
|
|
|
//Don't save default value
|
|
|
|
v.x = E->key().x;
|
|
|
|
v.y = E->key().y;
|
|
|
|
v.z = E->value();
|
|
|
|
p.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_ret = p;
|
2023-01-17 03:10:09 +01:00
|
|
|
} else if (what == "fallback_mode") {
|
|
|
|
r_ret = autotile_get_fallback_mode(id);
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape") {
|
2017-06-25 20:47:30 +02:00
|
|
|
r_ret = tile_get_shape(id, 0);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_offset") {
|
2017-11-13 08:42:49 +01:00
|
|
|
r_ret = tile_get_shape_offset(id, 0);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_transform") {
|
2017-07-01 19:56:51 +02:00
|
|
|
r_ret = tile_get_shape_transform(id, 0);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_one_way") {
|
2017-06-25 20:47:30 +02:00
|
|
|
r_ret = tile_get_shape_one_way(id, 0);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shape_one_way_margin") {
|
2019-01-18 18:15:05 +01:00
|
|
|
r_ret = tile_get_shape_one_way_margin(id, 0);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "shapes") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = _tile_get_shapes(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "occluder") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_light_occluder(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "occluder_offset") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_occluder_offset(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "navigation") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_navigation_polygon(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "navigation_offset") {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_ret = tile_get_navigation_polygon_offset(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (what == "z_index") {
|
2018-02-17 11:58:07 +01:00
|
|
|
r_ret = tile_get_z_index(id);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
|
2017-06-25 20:47:30 +02:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
int id = E->key();
|
2017-03-05 16:44:50 +01:00
|
|
|
String pre = itos(id) + "/";
|
2020-02-04 20:09:59 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, pre + "name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "tex_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::COLOR, pre + "modulate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::RECT2, pre + "region", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, pre + "tile_mode", PROPERTY_HINT_ENUM, "SINGLE_TILE,AUTO_TILE,ATLAS_TILE", PROPERTY_USAGE_NOEDITOR));
|
2018-02-17 12:08:44 +01:00
|
|
|
if (tile_get_tile_mode(id) == AUTO_TILE) {
|
2018-05-17 05:39:43 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/bitmask_mode", PROPERTY_HINT_ENUM, "2X2,3X3 (minimal),3X3", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2018-02-17 12:08:44 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/bitmask_flags", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2018-01-11 23:35:12 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/spacing", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2018-07-02 15:39:39 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/z_index_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2023-01-17 03:10:09 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/fallback_mode", PROPERTY_HINT_ENUM, "Auto,Icon", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2018-07-29 23:54:12 +02:00
|
|
|
} else if (tile_get_tile_mode(id) == ATLAS_TILE) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/spacing", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2018-12-23 14:06:53 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2018-12-17 13:03:50 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/z_index_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
2020-02-04 20:09:59 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "occluder_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "navigation_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "navigation", PROPERTY_HINT_RESOURCE_TYPE, "NavigationPolygon", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, pre + "shape_one_way_margin", PROPERTY_HINT_RANGE, "0,128,0.01", PROPERTY_USAGE_NOEDITOR));
|
2017-03-05 16:44:50 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
2020-02-04 20:09:59 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, pre + "z_index", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1", PROPERTY_USAGE_NOEDITOR));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::create_tile(int p_id) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(tile_map.has(p_id), vformat("The TileSet already has a tile with ID '%d'.", p_id));
|
2017-06-25 20:47:30 +02:00
|
|
|
tile_map[p_id] = TileData();
|
2017-10-22 03:42:23 +02:00
|
|
|
tile_map[p_id].autotile_data = AutotileData();
|
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::autotile_set_bitmask_mode(int p_id, BitmaskMode p_mode) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
tile_map[p_id].autotile_data.bitmask_mode = p_mode;
|
2014-02-10 02:10:30 +01:00
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-10-22 03:42:23 +02:00
|
|
|
TileSet::BitmaskMode TileSet::autotile_get_bitmask_mode(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), BITMASK_2X2, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
return tile_map[p_id].autotile_data.bitmask_mode;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_texture(int p_id, const Ref<Texture> &p_texture) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].texture = p_texture;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
2018-01-10 23:45:14 +01:00
|
|
|
_change_notify("texture");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture> TileSet::tile_get_texture(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<Texture>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2014-02-10 02:10:30 +01:00
|
|
|
return tile_map[p_id].texture;
|
|
|
|
}
|
|
|
|
|
2017-06-22 17:15:50 +02:00
|
|
|
void TileSet::tile_set_normal_map(int p_id, const Ref<Texture> &p_normal_map) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-06-22 17:15:50 +02:00
|
|
|
tile_map[p_id].normal_map = p_normal_map;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture> TileSet::tile_get_normal_map(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<Texture>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-06-22 17:15:50 +02:00
|
|
|
return tile_map[p_id].normal_map;
|
|
|
|
}
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
void TileSet::tile_set_material(int p_id, const Ref<ShaderMaterial> &p_material) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].material = p_material;
|
2015-03-09 06:34:56 +01:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
Ref<ShaderMaterial> TileSet::tile_get_material(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<ShaderMaterial>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2015-03-09 06:34:56 +01:00
|
|
|
return tile_map[p_id].material;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_modulate(int p_id, const Color &p_modulate) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].modulate = p_modulate;
|
2016-11-30 14:33:39 +01:00
|
|
|
emit_changed();
|
2018-03-11 15:59:50 +01:00
|
|
|
_change_notify("modulate");
|
2016-11-30 14:33:39 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Color TileSet::tile_get_modulate(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Color(1, 1, 1), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2016-11-30 14:33:39 +01:00
|
|
|
return tile_map[p_id].modulate;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_texture_offset(int p_id, const Vector2 &p_offset) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].offset = p_offset;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
Vector2 TileSet::tile_get_texture_offset(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Vector2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2014-02-10 02:10:30 +01:00
|
|
|
return tile_map[p_id].offset;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_region(int p_id, const Rect2 &p_region) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].region = p_region;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
2018-02-17 12:08:44 +01:00
|
|
|
_change_notify("region");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Rect2 TileSet::tile_get_region(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Rect2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2014-02-10 02:10:30 +01:00
|
|
|
return tile_map[p_id].region;
|
|
|
|
}
|
|
|
|
|
2018-02-17 12:08:44 +01:00
|
|
|
void TileSet::tile_set_tile_mode(int p_id, TileMode p_tile_mode) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-02-17 12:08:44 +01:00
|
|
|
tile_map[p_id].tile_mode = p_tile_mode;
|
2017-10-22 03:42:23 +02:00
|
|
|
emit_changed();
|
2018-02-17 12:08:44 +01:00
|
|
|
_change_notify("tile_mode");
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
2018-02-17 12:08:44 +01:00
|
|
|
TileSet::TileMode TileSet::tile_get_tile_mode(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), SINGLE_TILE, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-02-17 12:08:44 +01:00
|
|
|
return tile_map[p_id].tile_mode;
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
2022-04-30 14:05:57 +02:00
|
|
|
void TileSet::autotile_set_icon_coordinate(int p_id, const Vector2 &p_coord) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2022-04-30 14:05:57 +02:00
|
|
|
tile_map[p_id].autotile_data.icon_coord = p_coord;
|
2017-10-22 03:42:23 +02:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 TileSet::autotile_get_icon_coordinate(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Vector2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
return tile_map[p_id].autotile_data.icon_coord;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::autotile_set_spacing(int p_id, int p_spacing) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
ERR_FAIL_COND(p_spacing < 0);
|
|
|
|
tile_map[p_id].autotile_data.spacing = p_spacing;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TileSet::autotile_get_spacing(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), 0, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
return tile_map[p_id].autotile_data.spacing;
|
|
|
|
}
|
|
|
|
|
2022-04-30 14:05:57 +02:00
|
|
|
void TileSet::autotile_set_size(int p_id, const Size2 &p_size) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
ERR_FAIL_COND(p_size.x <= 0 || p_size.y <= 0);
|
|
|
|
tile_map[p_id].autotile_data.size = p_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size2 TileSet::autotile_get_size(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Size2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
return tile_map[p_id].autotile_data.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::autotile_clear_bitmask_map(int p_id) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
tile_map[p_id].autotile_data.flags.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::autotile_set_subtile_priority(int p_id, const Vector2 &p_coord, int p_priority) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
ERR_FAIL_COND(p_priority <= 0);
|
|
|
|
tile_map[p_id].autotile_data.priority_map[p_coord] = p_priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), 1, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
if (tile_map[p_id].autotile_data.priority_map.has(p_coord)) {
|
|
|
|
return tile_map[p_id].autotile_data.priority_map[p_coord];
|
|
|
|
}
|
|
|
|
//When not custom priority set return the default value
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-19 17:20:49 +01:00
|
|
|
const Map<Vector2, int> &TileSet::autotile_get_priority_map(int p_id) const {
|
|
|
|
static Map<Vector2, int> dummy;
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), dummy, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-12-19 17:20:49 +01:00
|
|
|
return tile_map[p_id].autotile_data.priority_map;
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:39:39 +02:00
|
|
|
void TileSet::autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-07-02 15:39:39 +02:00
|
|
|
tile_map[p_id].autotile_data.z_index_map[p_coord] = p_z_index;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TileSet::autotile_get_z_index(int p_id, const Vector2 &p_coord) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), 1, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-07-02 15:39:39 +02:00
|
|
|
if (tile_map[p_id].autotile_data.z_index_map.has(p_coord)) {
|
|
|
|
return tile_map[p_id].autotile_data.z_index_map[p_coord];
|
|
|
|
}
|
|
|
|
//When not custom z index set return the default value
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-19 17:20:49 +01:00
|
|
|
const Map<Vector2, int> &TileSet::autotile_get_z_index_map(int p_id) const {
|
2017-10-22 03:42:23 +02:00
|
|
|
static Map<Vector2, int> dummy;
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), dummy, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-12-19 17:20:49 +01:00
|
|
|
return tile_map[p_id].autotile_data.z_index_map;
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
2023-01-17 03:10:09 +01:00
|
|
|
void TileSet::autotile_set_fallback_mode(int p_id, FallbackMode p_mode) {
|
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
|
|
|
tile_map[p_id].autotile_data.fallback_mode = p_mode;
|
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
TileSet::FallbackMode TileSet::autotile_get_fallback_mode(int p_id) const {
|
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), FALLBACK_AUTO, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
|
|
|
return tile_map[p_id].autotile_data.fallback_mode;
|
|
|
|
}
|
|
|
|
|
2022-04-30 14:05:57 +02:00
|
|
|
void TileSet::autotile_set_bitmask(int p_id, const Vector2 &p_coord, uint32_t p_flag) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
if (p_flag == 0) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (tile_map[p_id].autotile_data.flags.has(p_coord)) {
|
2017-10-22 03:42:23 +02:00
|
|
|
tile_map[p_id].autotile_data.flags.erase(p_coord);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-10-22 03:42:23 +02:00
|
|
|
} else {
|
|
|
|
tile_map[p_id].autotile_data.flags[p_coord] = p_flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 14:05:57 +02:00
|
|
|
uint32_t TileSet::autotile_get_bitmask(int p_id, const Vector2 &p_coord) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), 0, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
if (!tile_map[p_id].autotile_data.flags.has(p_coord)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return tile_map[p_id].autotile_data.flags[p_coord];
|
|
|
|
}
|
|
|
|
|
2019-03-31 19:28:42 +02:00
|
|
|
const Map<Vector2, uint32_t> &TileSet::autotile_get_bitmask_map(int p_id) {
|
|
|
|
static Map<Vector2, uint32_t> dummy;
|
|
|
|
static Map<Vector2, uint32_t> dummy_atlas;
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), dummy, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-07-29 23:54:12 +02:00
|
|
|
if (tile_get_tile_mode(p_id) == ATLAS_TILE) {
|
2019-03-31 19:28:42 +02:00
|
|
|
dummy_atlas = Map<Vector2, uint32_t>();
|
2018-07-29 23:54:12 +02:00
|
|
|
Rect2 region = tile_get_region(p_id);
|
|
|
|
Size2 size = autotile_get_size(p_id);
|
|
|
|
float spacing = autotile_get_spacing(p_id);
|
|
|
|
for (int x = 0; x < (region.size.x / (size.x + spacing)); x++) {
|
|
|
|
for (int y = 0; y < (region.size.y / (size.y + spacing)); y++) {
|
|
|
|
dummy_atlas.insert(Vector2(x, y), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dummy_atlas;
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2018-07-29 23:54:12 +02:00
|
|
|
return tile_map[p_id].autotile_data.flags;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
2023-01-17 03:10:09 +01:00
|
|
|
List<Vector2> TileSet::_autotile_get_subtile_candidates_for_bitmask(int p_id, uint16_t p_bitmask) const {
|
2017-10-22 03:42:23 +02:00
|
|
|
List<Vector2> coords;
|
2019-03-31 19:28:42 +02:00
|
|
|
uint32_t mask;
|
|
|
|
uint16_t mask_;
|
|
|
|
uint16_t mask_ignore;
|
|
|
|
for (Map<Vector2, uint32_t>::Element *E = tile_map[p_id].autotile_data.flags.front(); E; E = E->next()) {
|
2017-10-22 03:42:23 +02:00
|
|
|
mask = E->get();
|
|
|
|
if (tile_map[p_id].autotile_data.bitmask_mode == BITMASK_2X2) {
|
2019-03-31 19:28:42 +02:00
|
|
|
mask |= (BIND_IGNORE_TOP | BIND_IGNORE_LEFT | BIND_IGNORE_CENTER | BIND_IGNORE_RIGHT | BIND_IGNORE_BOTTOM);
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
2019-03-31 19:28:42 +02:00
|
|
|
|
|
|
|
mask_ = mask & 0xFFFF;
|
|
|
|
mask_ignore = mask >> 16;
|
|
|
|
|
|
|
|
if (((mask_ & (~mask_ignore)) == (p_bitmask & (~mask_ignore))) && (((~mask_) | mask_ignore) == ((~p_bitmask) | mask_ignore))) {
|
2019-04-07 13:09:38 +02:00
|
|
|
coords.push_back(E->key());
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 03:10:09 +01:00
|
|
|
return coords;
|
|
|
|
}
|
|
|
|
|
2023-06-10 05:20:41 +02:00
|
|
|
uint32_t TileSet::_count_bitmask_bits(uint32_t p_bitmask) {
|
2023-01-17 03:10:09 +01:00
|
|
|
uint32_t ret = 0;
|
|
|
|
|
|
|
|
for (uint32_t i = 1; i <= 256; i <<= 1) {
|
2023-06-10 05:20:41 +02:00
|
|
|
if (p_bitmask & i) {
|
2023-01-17 03:10:09 +01:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2023-06-10 05:20:41 +02:00
|
|
|
uint32_t TileSet::_score_bitmask_difference(uint32_t p_bitmask, uint32_t p_ref_bitmask) {
|
|
|
|
// Low value means less difference, high value means more difference.
|
2023-01-17 03:10:09 +01:00
|
|
|
uint32_t ret = 0;
|
|
|
|
|
2023-06-10 05:20:41 +02:00
|
|
|
p_bitmask ^= p_ref_bitmask;
|
|
|
|
// Add one to the score for each non-matching bit.
|
2023-01-17 03:10:09 +01:00
|
|
|
for (uint32_t i = 1; i <= 256; i <<= 1) {
|
2023-06-10 05:20:41 +02:00
|
|
|
if (p_bitmask & i) {
|
2023-01-17 03:10:09 +01:00
|
|
|
ret += 1;
|
2023-06-10 05:20:41 +02:00
|
|
|
// Make axial edge mismatches cost four times as much.
|
2023-01-17 03:10:09 +01:00
|
|
|
if (i & (TileSet::BIND_TOP | TileSet::BIND_LEFT | TileSet::BIND_RIGHT | TileSet::BIND_BOTTOM)) {
|
|
|
|
ret += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-10 05:20:41 +02:00
|
|
|
p_bitmask ^= p_ref_bitmask;
|
|
|
|
// Artificially reduce difference for all-filled and all-but-center-empty bitmasks.
|
2023-01-17 03:10:09 +01:00
|
|
|
// (511 is the non-IGNORE bitmasks all or'd together; 0x1FF)
|
2023-06-10 05:20:41 +02:00
|
|
|
if (ret > 0 && (p_bitmask == 511 || p_bitmask == TileSet::BIND_CENTER)) {
|
2023-01-17 03:10:09 +01:00
|
|
|
ret -= 1;
|
|
|
|
}
|
2023-06-10 05:20:41 +02:00
|
|
|
// Artificially increase difference for non-symmetric bitmasks if testing against all-filled or all-but-center-empty bitmask.
|
|
|
|
// This fixes some edge cases for certain common incomplete tilesheet layouts.
|
|
|
|
// (We only care about the truthiness of the bit tests, not their exact value, hence the bool casts.)
|
|
|
|
if ((p_ref_bitmask == 511 || p_ref_bitmask == TileSet::BIND_CENTER) &&
|
|
|
|
(bool(p_bitmask & TileSet::BIND_LEFT) != bool(p_bitmask & TileSet::BIND_RIGHT) ||
|
|
|
|
bool(p_bitmask & TileSet::BIND_TOP) != bool(p_bitmask & TileSet::BIND_BOTTOM) ||
|
|
|
|
bool(p_bitmask & TileSet::BIND_TOPRIGHT) != bool(p_bitmask & TileSet::BIND_BOTTOMLEFT) ||
|
|
|
|
bool(p_bitmask & TileSet::BIND_TOPLEFT) != bool(p_bitmask & TileSet::BIND_BOTTOMRIGHT))) {
|
2023-01-17 03:10:09 +01:00
|
|
|
ret += 16;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node, const Vector2 &p_tile_location) {
|
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Vector2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
|
|
|
// First try to forward selection to script
|
|
|
|
if (p_tilemap_node->get_class_name() == "TileMap") {
|
|
|
|
if (get_script_instance() != nullptr) {
|
|
|
|
if (get_script_instance()->has_method("_forward_subtile_selection")) {
|
|
|
|
Variant ret = get_script_instance()->call("_forward_subtile_selection", p_id, p_bitmask, p_tilemap_node, p_tile_location);
|
|
|
|
if (ret.get_type() == Variant::VECTOR2) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 05:20:41 +02:00
|
|
|
// If we found no forward-selected tile, look for a matching tile.
|
2023-01-17 03:10:09 +01:00
|
|
|
List<Vector2> coords = _autotile_get_subtile_candidates_for_bitmask(p_id, p_bitmask);
|
|
|
|
|
2023-06-10 05:20:41 +02:00
|
|
|
// If we didn't find anything, and auto fallback is enabled, try falling back to a tile with a similar bitmask instead of the default tile.
|
2023-01-17 03:10:09 +01:00
|
|
|
if (tile_map[p_id].autotile_data.fallback_mode == FALLBACK_AUTO && coords.size() == 0) {
|
2023-06-10 05:20:41 +02:00
|
|
|
uint32_t best_match_cost = 100000; // Main point of comparison, general difference between bitmasks.
|
|
|
|
uint32_t best_match_bitcount = 0; // Bit count, as a tie breaker.
|
2023-01-17 03:10:09 +01:00
|
|
|
uint16_t best_match_bitmask = 0;
|
|
|
|
|
|
|
|
for (Map<Vector2, uint32_t>::Element *E = tile_map[p_id].autotile_data.flags.front(); E; E = E->next()) {
|
|
|
|
uint32_t mask = E->get();
|
|
|
|
if (tile_map[p_id].autotile_data.bitmask_mode == BITMASK_2X2) {
|
|
|
|
mask |= (BIND_IGNORE_TOP | BIND_IGNORE_LEFT | BIND_IGNORE_CENTER | BIND_IGNORE_RIGHT | BIND_IGNORE_BOTTOM);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t mask_ignore = mask >> 16;
|
|
|
|
uint16_t mask_low = mask & 0xFFFF;
|
|
|
|
mask_low &= ~mask_ignore;
|
|
|
|
mask_low |= p_bitmask & mask_ignore;
|
|
|
|
|
2023-06-10 05:20:41 +02:00
|
|
|
// Always skip bitmasks with no center bit, or that have already been matched as the best.
|
2023-01-17 03:10:09 +01:00
|
|
|
if ((mask_low & BIND_CENTER) == 0 || mask_low == best_match_bitmask) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t cost = _score_bitmask_difference(mask_low, p_bitmask);
|
2023-06-10 05:20:41 +02:00
|
|
|
// To break ties, pick the bitmask with more set bits.
|
|
|
|
uint32_t bitcount = _count_bitmask_bits(mask_low);
|
2023-01-17 03:10:09 +01:00
|
|
|
|
2023-06-10 05:20:41 +02:00
|
|
|
// If more similar, confirm match.
|
2023-01-17 03:10:09 +01:00
|
|
|
if (cost < best_match_cost || (cost == best_match_cost && bitcount > best_match_bitcount)) {
|
|
|
|
best_match_cost = cost;
|
|
|
|
best_match_bitcount = bitcount;
|
|
|
|
best_match_bitmask = mask_low;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
coords = _autotile_get_subtile_candidates_for_bitmask(p_id, best_match_bitmask);
|
|
|
|
}
|
2019-03-31 19:28:42 +02:00
|
|
|
|
2017-10-22 03:42:23 +02:00
|
|
|
if (coords.size() == 0) {
|
|
|
|
return autotile_get_icon_coordinate(p_id);
|
|
|
|
} else {
|
2023-01-17 03:10:09 +01:00
|
|
|
List<uint32_t> priorities;
|
|
|
|
uint32_t priority_sum = 0;
|
|
|
|
for (List<Vector2>::Element *E = coords.front(); E; E = E->next()) {
|
|
|
|
uint32_t priority = autotile_get_subtile_priority(p_id, E->get());
|
|
|
|
priority_sum += priority;
|
|
|
|
priorities.push_back(priority);
|
|
|
|
}
|
|
|
|
|
2019-04-07 13:09:38 +02:00
|
|
|
uint32_t picked_value = Math::rand() % priority_sum;
|
|
|
|
uint32_t upper_bound;
|
|
|
|
uint32_t lower_bound = 0;
|
|
|
|
Vector2 result = coords.front()->get();
|
|
|
|
List<Vector2>::Element *coords_E = coords.front();
|
|
|
|
List<uint32_t>::Element *priorities_E = priorities.front();
|
|
|
|
while (priorities_E) {
|
|
|
|
upper_bound = lower_bound + priorities_E->get();
|
|
|
|
if (lower_bound <= picked_value && picked_value < upper_bound) {
|
|
|
|
result = coords_E->get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lower_bound = upper_bound;
|
|
|
|
priorities_E = priorities_E->next();
|
|
|
|
coords_E = coords_E->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-23 14:06:53 +01:00
|
|
|
Vector2 TileSet::atlastile_get_subtile_by_priority(int p_id, const Node *p_tilemap_node, const Vector2 &p_tile_location) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Vector2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-12-23 14:06:53 +01:00
|
|
|
//First try to forward selection to script
|
2021-05-04 16:00:45 +02:00
|
|
|
if (get_script_instance() != nullptr) {
|
2018-12-23 14:06:53 +01:00
|
|
|
if (get_script_instance()->has_method("_forward_atlas_subtile_selection")) {
|
|
|
|
Variant ret = get_script_instance()->call("_forward_atlas_subtile_selection", p_id, p_tilemap_node, p_tile_location);
|
|
|
|
if (ret.get_type() == Variant::VECTOR2) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 14:05:59 +02:00
|
|
|
const Vector2 spacing(autotile_get_spacing(p_id), autotile_get_spacing(p_id));
|
|
|
|
const Vector2 coord = tile_get_region(p_id).size / (autotile_get_size(p_id) + spacing);
|
2018-12-23 14:06:53 +01:00
|
|
|
|
|
|
|
List<Vector2> coords;
|
|
|
|
for (int x = 0; x < coord.x; x++) {
|
|
|
|
for (int y = 0; y < coord.y; y++) {
|
|
|
|
for (int i = 0; i < autotile_get_subtile_priority(p_id, Vector2(x, y)); i++) {
|
|
|
|
coords.push_back(Vector2(x, y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (coords.size() == 0) {
|
|
|
|
return autotile_get_icon_coordinate(p_id);
|
|
|
|
} else {
|
|
|
|
return coords[Math::random(0, (int)coords.size())];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_name(int p_id, const String &p_name) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].name = p_name;
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
2018-02-17 12:08:44 +01:00
|
|
|
_change_notify("name");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String TileSet::tile_get_name(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), String(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2014-02-10 02:10:30 +01:00
|
|
|
return tile_map[p_id].name;
|
|
|
|
}
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
void TileSet::tile_clear_shapes(int p_id) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-06-25 20:47:30 +02:00
|
|
|
tile_map[p_id].shapes_data.clear();
|
|
|
|
}
|
|
|
|
|
2017-10-22 03:42:23 +02:00
|
|
|
void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way, const Vector2 &p_autotile_coord) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-06-25 20:47:30 +02:00
|
|
|
|
|
|
|
ShapeData new_data = ShapeData();
|
|
|
|
new_data.shape = p_shape;
|
2017-07-01 19:56:51 +02:00
|
|
|
new_data.shape_transform = p_transform;
|
2017-06-25 20:47:30 +02:00
|
|
|
new_data.one_way_collision = p_one_way;
|
2017-10-22 03:42:23 +02:00
|
|
|
new_data.autotile_coord = p_autotile_coord;
|
2017-06-25 20:47:30 +02:00
|
|
|
|
|
|
|
tile_map[p_id].shapes_data.push_back(new_data);
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
int TileSet::tile_get_shape_count(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), 0, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-06-25 20:47:30 +02:00
|
|
|
return tile_map[p_id].shapes_data.size();
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
2017-06-25 20:47:30 +02:00
|
|
|
|
|
|
|
void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-06-21 11:34:32 +02:00
|
|
|
ERR_FAIL_COND(p_shape_id < 0);
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
|
2017-06-25 20:47:30 +02:00
|
|
|
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2018-07-25 03:11:03 +02:00
|
|
|
tile_map[p_id].shapes_data.write[p_shape_id].shape = p_shape;
|
2019-03-04 03:05:43 +01:00
|
|
|
_decompose_convex_shape(p_shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<Shape2D>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-07-03 17:18:36 +02:00
|
|
|
ERR_FAIL_COND_V(p_shape_id < 0, Ref<Shape2D>());
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id < tile_map[p_id].shapes_data.size()) {
|
2019-06-23 13:56:44 +02:00
|
|
|
return tile_map[p_id].shapes_data[p_shape_id].shape;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-06-23 13:56:44 +02:00
|
|
|
return Ref<Shape2D>();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-01 19:56:51 +02:00
|
|
|
void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_offset) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-07-03 17:18:36 +02:00
|
|
|
ERR_FAIL_COND(p_shape_id < 0);
|
2019-06-21 11:34:32 +02:00
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
|
2017-06-25 20:47:30 +02:00
|
|
|
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2018-07-25 03:11:03 +02:00
|
|
|
tile_map[p_id].shapes_data.write[p_shape_id].shape_transform = p_offset;
|
2017-06-25 20:47:30 +02:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-07-01 19:56:51 +02:00
|
|
|
Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Transform2D(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-07-03 17:18:36 +02:00
|
|
|
ERR_FAIL_COND_V(p_shape_id < 0, Transform2D());
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id < tile_map[p_id].shapes_data.size()) {
|
2019-06-23 13:56:44 +02:00
|
|
|
return tile_map[p_id].shapes_data[p_shape_id].shape_transform;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-06-25 20:47:30 +02:00
|
|
|
|
2019-06-23 13:56:44 +02:00
|
|
|
return Transform2D();
|
2017-06-25 20:47:30 +02:00
|
|
|
}
|
|
|
|
|
2017-11-13 08:42:49 +01:00
|
|
|
void TileSet::tile_set_shape_offset(int p_id, int p_shape_id, const Vector2 &p_offset) {
|
|
|
|
Transform2D transform = tile_get_shape_transform(p_id, p_shape_id);
|
|
|
|
transform.set_origin(p_offset);
|
|
|
|
tile_set_shape_transform(p_id, p_shape_id, transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 TileSet::tile_get_shape_offset(int p_id, int p_shape_id) const {
|
|
|
|
return tile_get_shape_transform(p_id, p_shape_id).get_origin();
|
|
|
|
}
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_way) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-06-21 11:34:32 +02:00
|
|
|
ERR_FAIL_COND(p_shape_id < 0);
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
|
2017-06-25 20:47:30 +02:00
|
|
|
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2018-07-25 03:11:03 +02:00
|
|
|
tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision = p_one_way;
|
2017-06-25 20:47:30 +02:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), false, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-07-03 17:18:36 +02:00
|
|
|
ERR_FAIL_COND_V(p_shape_id < 0, false);
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id < tile_map[p_id].shapes_data.size()) {
|
2019-06-23 13:56:44 +02:00
|
|
|
return tile_map[p_id].shapes_data[p_shape_id].one_way_collision;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-06-25 20:47:30 +02:00
|
|
|
|
2019-06-23 13:56:44 +02:00
|
|
|
return false;
|
2017-06-25 20:47:30 +02:00
|
|
|
}
|
|
|
|
|
2019-01-18 18:15:05 +01:00
|
|
|
void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_margin) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-06-21 11:34:32 +02:00
|
|
|
ERR_FAIL_COND(p_shape_id < 0);
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
|
2019-01-18 18:15:05 +01:00
|
|
|
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2019-01-18 18:15:05 +01:00
|
|
|
tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision_margin = p_margin;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
float TileSet::tile_get_shape_one_way_margin(int p_id, int p_shape_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), 0, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-07-03 17:18:36 +02:00
|
|
|
ERR_FAIL_COND_V(p_shape_id < 0, 0);
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_shape_id < tile_map[p_id].shapes_data.size()) {
|
2019-06-23 13:56:44 +02:00
|
|
|
return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2019-01-18 18:15:05 +01:00
|
|
|
|
2019-06-23 13:56:44 +02:00
|
|
|
return 0;
|
2019-01-18 18:15:05 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].occluder = p_light_occluder;
|
2015-03-09 06:34:56 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<OccluderPolygon2D> TileSet::tile_get_light_occluder(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<OccluderPolygon2D>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2015-03-09 06:34:56 +01:00
|
|
|
return tile_map[p_id].occluder;
|
|
|
|
}
|
|
|
|
|
2017-10-22 03:42:23 +02:00
|
|
|
void TileSet::autotile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder, const Vector2 &p_coord) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
if (p_light_occluder.is_null()) {
|
2017-12-08 20:38:36 +01:00
|
|
|
if (tile_map[p_id].autotile_data.occluder_map.has(p_coord)) {
|
|
|
|
tile_map[p_id].autotile_data.occluder_map.erase(p_coord);
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-12-08 20:38:36 +01:00
|
|
|
tile_map[p_id].autotile_data.occluder_map[p_coord] = p_light_occluder;
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<OccluderPolygon2D> TileSet::autotile_get_light_occluder(int p_id, const Vector2 &p_coord) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<OccluderPolygon2D>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2019-06-21 11:34:32 +02:00
|
|
|
|
2017-12-08 20:38:36 +01:00
|
|
|
if (!tile_map[p_id].autotile_data.occluder_map.has(p_coord)) {
|
2017-10-22 03:42:23 +02:00
|
|
|
return Ref<OccluderPolygon2D>();
|
|
|
|
} else {
|
2017-12-08 20:38:36 +01:00
|
|
|
return tile_map[p_id].autotile_data.occluder_map[p_coord];
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].navigation_polygon_offset = p_offset;
|
2015-03-09 06:34:56 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 TileSet::tile_get_navigation_polygon_offset(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Vector2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2015-03-09 06:34:56 +01:00
|
|
|
return tile_map[p_id].navigation_polygon_offset;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].navigation_polygon = p_navigation_polygon;
|
2015-03-09 06:34:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<NavigationPolygon> TileSet::tile_get_navigation_polygon(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<NavigationPolygon>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2015-03-09 06:34:56 +01:00
|
|
|
return tile_map[p_id].navigation_polygon;
|
|
|
|
}
|
|
|
|
|
2021-05-04 14:20:36 +02:00
|
|
|
const Map<Vector2, Ref<OccluderPolygon2D>> &TileSet::autotile_get_light_oclusion_map(int p_id) const {
|
|
|
|
static Map<Vector2, Ref<OccluderPolygon2D>> dummy;
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), dummy, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-12-08 20:38:36 +01:00
|
|
|
return tile_map[p_id].autotile_data.occluder_map;
|
2017-10-22 03:42:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::autotile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon, const Vector2 &p_coord) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
if (p_navigation_polygon.is_null()) {
|
|
|
|
if (tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) {
|
|
|
|
tile_map[p_id].autotile_data.navpoly_map.erase(p_coord);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tile_map[p_id].autotile_data.navpoly_map[p_coord] = p_navigation_polygon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<NavigationPolygon> TileSet::autotile_get_navigation_polygon(int p_id, const Vector2 &p_coord) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Ref<NavigationPolygon>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
if (!tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) {
|
|
|
|
return Ref<NavigationPolygon>();
|
|
|
|
} else {
|
|
|
|
return tile_map[p_id].autotile_data.navpoly_map[p_coord];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 14:20:36 +02:00
|
|
|
const Map<Vector2, Ref<NavigationPolygon>> &TileSet::autotile_get_navigation_map(int p_id) const {
|
|
|
|
static Map<Vector2, Ref<NavigationPolygon>> dummy;
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), dummy, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-10-22 03:42:23 +02:00
|
|
|
return tile_map[p_id].autotile_data.navpoly_map;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::tile_set_occluder_offset(int p_id, const Vector2 &p_offset) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-03-05 16:44:50 +01:00
|
|
|
tile_map[p_id].occluder_offset = p_offset;
|
2015-03-09 06:34:56 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector2 TileSet::tile_get_occluder_offset(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Vector2(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2015-03-09 06:34:56 +01:00
|
|
|
return tile_map[p_id].occluder_offset;
|
|
|
|
}
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
void TileSet::tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2017-06-25 20:47:30 +02:00
|
|
|
tile_map[p_id].shapes_data = p_shapes;
|
2019-03-04 03:05:43 +01:00
|
|
|
for (int i = 0; i < p_shapes.size(); i++) {
|
|
|
|
_decompose_convex_shape(p_shapes[i].shape);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
Vector<TileSet::ShapeData> TileSet::tile_get_shapes(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), Vector<ShapeData>(), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
return tile_map[p_id].shapes_data;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-02-17 11:58:07 +01:00
|
|
|
int TileSet::tile_get_z_index(int p_id) const {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tile_map.has(p_id), 0, vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-02-17 11:58:07 +01:00
|
|
|
return tile_map[p_id].z_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::tile_set_z_index(int p_id, int p_z_index) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2018-02-17 11:58:07 +01:00
|
|
|
tile_map[p_id].z_index = p_z_index;
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!tile_map.has(p_id));
|
2017-06-25 20:47:30 +02:00
|
|
|
Vector<ShapeData> shapes_data;
|
2017-07-01 19:56:51 +02:00
|
|
|
Transform2D default_transform = tile_get_shape_transform(p_id, 0);
|
2017-06-25 20:47:30 +02:00
|
|
|
bool default_one_way = tile_get_shape_one_way(p_id, 0);
|
2017-10-22 03:42:23 +02:00
|
|
|
Vector2 default_autotile_coord = Vector2();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_shapes.size(); i++) {
|
2017-06-25 20:47:30 +02:00
|
|
|
ShapeData s = ShapeData();
|
|
|
|
|
|
|
|
if (p_shapes[i].get_type() == Variant::OBJECT) {
|
|
|
|
Ref<Shape2D> shape = p_shapes[i];
|
2021-05-05 12:44:11 +02:00
|
|
|
if (shape.is_null()) {
|
2021-05-04 14:28:27 +02:00
|
|
|
continue;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-06-25 20:47:30 +02:00
|
|
|
|
|
|
|
s.shape = shape;
|
2017-07-01 19:56:51 +02:00
|
|
|
s.shape_transform = default_transform;
|
2017-06-25 20:47:30 +02:00
|
|
|
s.one_way_collision = default_one_way;
|
2017-10-22 03:42:23 +02:00
|
|
|
s.autotile_coord = default_autotile_coord;
|
2017-06-25 20:47:30 +02:00
|
|
|
} else if (p_shapes[i].get_type() == Variant::DICTIONARY) {
|
|
|
|
Dictionary d = p_shapes[i];
|
|
|
|
|
2019-03-04 03:05:43 +01:00
|
|
|
if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT) {
|
2017-06-25 20:47:30 +02:00
|
|
|
s.shape = d["shape"];
|
2019-03-04 03:05:43 +01:00
|
|
|
_decompose_convex_shape(s.shape);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2017-06-25 20:47:30 +02:00
|
|
|
continue;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-06-25 20:47:30 +02:00
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D) {
|
2017-07-01 19:56:51 +02:00
|
|
|
s.shape_transform = d["shape_transform"];
|
2021-05-05 12:44:11 +02:00
|
|
|
} else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2) {
|
2017-07-01 19:56:51 +02:00
|
|
|
s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2017-07-01 19:56:51 +02:00
|
|
|
s.shape_transform = default_transform;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-06-25 20:47:30 +02:00
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL) {
|
2017-06-25 20:47:30 +02:00
|
|
|
s.one_way_collision = d["one_way"];
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2017-06-25 20:47:30 +02:00
|
|
|
s.one_way_collision = default_one_way;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-06-25 20:47:30 +02:00
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (d.has("one_way_margin") && d["one_way_margin"].is_num()) {
|
2019-01-18 18:15:05 +01:00
|
|
|
s.one_way_collision_margin = d["one_way_margin"];
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2019-01-22 14:14:43 +01:00
|
|
|
s.one_way_collision_margin = 1.0;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2019-01-18 18:15:05 +01:00
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2) {
|
2017-10-22 03:42:23 +02:00
|
|
|
s.autotile_coord = d["autotile_coord"];
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2017-10-22 03:42:23 +02:00
|
|
|
s.autotile_coord = default_autotile_coord;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-10-22 03:42:23 +02:00
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
} else {
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_CONTINUE_MSG(true, "Expected an array of objects or dictionaries for tile_set_shapes.");
|
2017-06-25 20:47:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
shapes_data.push_back(s);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
tile_map[p_id].shapes_data = shapes_data;
|
2020-01-23 15:48:38 +01:00
|
|
|
emit_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Array TileSet::_tile_get_shapes(int p_id) const {
|
|
|
|
ERR_FAIL_COND_V(!tile_map.has(p_id), Array());
|
2014-02-10 02:10:30 +01:00
|
|
|
Array arr;
|
|
|
|
|
2017-06-25 20:47:30 +02: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 19:56:51 +02:00
|
|
|
shape_data["shape_transform"] = data[i].shape_transform;
|
2017-06-25 20:47:30 +02:00
|
|
|
shape_data["one_way"] = data[i].one_way_collision;
|
2019-01-18 18:15:05 +01:00
|
|
|
shape_data["one_way_margin"] = data[i].one_way_collision_margin;
|
2017-10-22 03:42:23 +02:00
|
|
|
shape_data["autotile_coord"] = data[i].autotile_coord;
|
2017-06-25 20:47:30 +02:00
|
|
|
arr.push_back(shape_data);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Array TileSet::_get_tiles_ids() const {
|
2014-02-18 10:49:34 +01:00
|
|
|
Array arr;
|
|
|
|
|
2017-06-25 20:47:30 +02:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
arr.push_back(E->key());
|
2014-02-18 10:49:34 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-18 10:49:34 +01:00
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2019-03-04 03:05:43 +01:00
|
|
|
void TileSet::_decompose_convex_shape(Ref<Shape2D> p_shape) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2019-03-04 03:05:43 +01:00
|
|
|
return;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2019-03-04 03:05:43 +01:00
|
|
|
Ref<ConvexPolygonShape2D> convex = p_shape;
|
2021-05-05 12:44:11 +02:00
|
|
|
if (!convex.is_valid()) {
|
2019-03-04 03:05:43 +01:00
|
|
|
return;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2021-05-04 14:20:36 +02:00
|
|
|
Vector<Vector<Vector2>> decomp = Geometry::decompose_polygon_in_convex(convex->get_points());
|
2019-03-04 03:05:43 +01:00
|
|
|
if (decomp.size() > 1) {
|
|
|
|
Array sub_shapes;
|
|
|
|
for (int i = 0; i < decomp.size(); i++) {
|
|
|
|
Ref<ConvexPolygonShape2D> _convex = memnew(ConvexPolygonShape2D);
|
|
|
|
_convex->set_points(decomp[i]);
|
|
|
|
sub_shapes.append(_convex);
|
|
|
|
}
|
|
|
|
convex->set_meta("decomposed", sub_shapes);
|
|
|
|
} else {
|
|
|
|
convex->set_meta("decomposed", Variant());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TileSet::get_tile_list(List<int> *p_tiles) const {
|
2017-06-25 20:47:30 +02:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
p_tiles->push_back(E->key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TileSet::has_tile(int p_id) const {
|
|
|
|
return tile_map.has(p_id);
|
|
|
|
}
|
|
|
|
|
2017-10-22 03:42:23 +02:00
|
|
|
bool TileSet::is_tile_bound(int p_drawn_id, int p_neighbor_id) {
|
|
|
|
if (p_drawn_id == p_neighbor_id) {
|
|
|
|
return true;
|
2021-05-04 16:00:45 +02:00
|
|
|
} else if (get_script_instance() != nullptr) {
|
2017-10-22 03:42:23 +02:00
|
|
|
if (get_script_instance()->has_method("_is_tile_bound")) {
|
|
|
|
Variant ret = get_script_instance()->call("_is_tile_bound", p_drawn_id, p_neighbor_id);
|
|
|
|
if (ret.get_type() == Variant::BOOL) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TileSet::remove_tile(int p_id) {
|
2021-05-09 16:56:52 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tile_map.has(p_id), vformat("The TileSet doesn't have a tile with ID '%d'.", p_id));
|
2014-02-10 02:10:30 +01:00
|
|
|
tile_map.erase(p_id);
|
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TileSet::get_last_unused_tile_id() const {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (tile_map.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return tile_map.back()->key() + 1;
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
return 0;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int TileSet::find_tile_by_name(const String &p_name) const {
|
2017-06-25 20:47:30 +02:00
|
|
|
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_name == E->get().name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return E->key();
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::clear() {
|
|
|
|
tile_map.clear();
|
|
|
|
_change_notify("");
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileSet::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("create_tile", "id"), &TileSet::create_tile);
|
2018-12-19 17:20:49 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("autotile_clear_bitmask_map", "id"), &TileSet::autotile_clear_bitmask_map);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_icon_coordinate", "id", "coord"), &TileSet::autotile_set_icon_coordinate);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_icon_coordinate", "id"), &TileSet::autotile_get_icon_coordinate);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_subtile_priority", "id", "coord", "priority"), &TileSet::autotile_set_subtile_priority);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_subtile_priority", "id", "coord"), &TileSet::autotile_get_subtile_priority);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_z_index", "id", "coord", "z_index"), &TileSet::autotile_set_z_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_z_index", "id", "coord"), &TileSet::autotile_get_z_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_light_occluder", "id", "light_occluder", "coord"), &TileSet::autotile_set_light_occluder);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_light_occluder", "id", "coord"), &TileSet::autotile_get_light_occluder);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_navigation_polygon", "id", "navigation_polygon", "coord"), &TileSet::autotile_set_navigation_polygon);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_navigation_polygon", "id", "coord"), &TileSet::autotile_get_navigation_polygon);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_bitmask", "id", "bitmask", "flag"), &TileSet::autotile_set_bitmask);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_bitmask", "id", "coord"), &TileSet::autotile_get_bitmask);
|
2017-12-25 15:19:56 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_bitmask_mode", "id", "mode"), &TileSet::autotile_set_bitmask_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_bitmask_mode", "id"), &TileSet::autotile_get_bitmask_mode);
|
2018-12-19 17:20:49 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_spacing", "id", "spacing"), &TileSet::autotile_set_spacing);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_spacing", "id"), &TileSet::autotile_get_spacing);
|
2018-08-30 20:56:38 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_size", "id", "size"), &TileSet::autotile_set_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_size", "id"), &TileSet::autotile_get_size);
|
2023-01-17 03:10:09 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("autotile_set_fallback_mode", "id", "mode"), &TileSet::autotile_set_fallback_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("autotile_get_fallback_mode", "id"), &TileSet::autotile_get_fallback_mode);
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_texture", "id", "texture"), &TileSet::tile_set_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_texture", "id"), &TileSet::tile_get_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_normal_map", "id", "normal_map"), &TileSet::tile_set_normal_map);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_normal_map", "id"), &TileSet::tile_get_normal_map);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_material", "id", "material"), &TileSet::tile_set_material);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_material", "id"), &TileSet::tile_get_material);
|
2018-07-23 23:32:20 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_modulate", "id", "color"), &TileSet::tile_set_modulate);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_modulate", "id"), &TileSet::tile_get_modulate);
|
2017-03-05 16:44:50 +01: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-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_shape", "id", "shape_id", "shape"), &TileSet::tile_set_shape);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape", "id", "shape_id"), &TileSet::tile_get_shape);
|
2018-08-27 11:09:11 +02: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-07-01 19:56:51 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_shape_transform", "id", "shape_id", "shape_transform"), &TileSet::tile_set_shape_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape_transform", "id", "shape_id"), &TileSet::tile_get_shape_transform);
|
2017-06-25 20:47:30 +02: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);
|
2019-01-18 18:15:05 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_shape_one_way_margin", "id", "shape_id", "one_way"), &TileSet::tile_set_shape_one_way_margin);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape_one_way_margin", "id", "shape_id"), &TileSet::tile_get_shape_one_way_margin);
|
2017-11-24 05:43:15 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_add_shape", "id", "shape", "shape_transform", "one_way", "autotile_coord"), &TileSet::tile_add_shape, DEFVAL(false), DEFVAL(Vector2()));
|
2017-06-25 20:47:30 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_shape_count", "id"), &TileSet::tile_get_shape_count);
|
2017-03-05 16:44:50 +01: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);
|
2018-04-08 22:54:02 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_tile_mode", "id", "tilemode"), &TileSet::tile_set_tile_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_tile_mode", "id"), &TileSet::tile_get_tile_mode);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_navigation_polygon", "id", "navigation_polygon"), &TileSet::tile_set_navigation_polygon);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_navigation_polygon", "id"), &TileSet::tile_get_navigation_polygon);
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_light_occluder", "id", "light_occluder"), &TileSet::tile_set_light_occluder);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_light_occluder", "id"), &TileSet::tile_get_light_occluder);
|
2017-03-05 16:44:50 +01:00
|
|
|
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);
|
2018-02-17 11:58:07 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("tile_set_z_index", "id", "z_index"), &TileSet::tile_set_z_index);
|
|
|
|
ClassDB::bind_method(D_METHOD("tile_get_z_index", "id"), &TileSet::tile_get_z_index);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
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-08-09 13:54:55 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tiles_ids"), &TileSet::_get_tiles_ids);
|
2017-10-22 03:42:23 +02:00
|
|
|
|
2017-12-10 15:10:54 +01:00
|
|
|
BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_tile_bound", PropertyInfo(Variant::INT, "drawn_id"), PropertyInfo(Variant::INT, "neighbor_id")));
|
|
|
|
BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_forward_subtile_selection", PropertyInfo(Variant::INT, "autotile_id"), PropertyInfo(Variant::INT, "bitmask"), PropertyInfo(Variant::OBJECT, "tilemap", PROPERTY_HINT_NONE, "TileMap"), PropertyInfo(Variant::VECTOR2, "tile_location")));
|
2018-12-23 14:06:53 +01:00
|
|
|
BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_forward_atlas_subtile_selection", PropertyInfo(Variant::INT, "atlastile_id"), PropertyInfo(Variant::OBJECT, "tilemap", PROPERTY_HINT_NONE, "TileMap"), PropertyInfo(Variant::VECTOR2, "tile_location")));
|
2017-10-22 03:42:23 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(BITMASK_2X2);
|
2018-05-17 05:39:43 +02:00
|
|
|
BIND_ENUM_CONSTANT(BITMASK_3X3_MINIMAL);
|
2017-10-22 03:42:23 +02:00
|
|
|
BIND_ENUM_CONSTANT(BITMASK_3X3);
|
|
|
|
|
2023-01-17 03:10:09 +01:00
|
|
|
BIND_ENUM_CONSTANT(FALLBACK_AUTO);
|
|
|
|
BIND_ENUM_CONSTANT(FALLBACK_ICON);
|
|
|
|
|
2017-10-22 03:42:23 +02:00
|
|
|
BIND_ENUM_CONSTANT(BIND_TOPLEFT);
|
|
|
|
BIND_ENUM_CONSTANT(BIND_TOP);
|
|
|
|
BIND_ENUM_CONSTANT(BIND_TOPRIGHT);
|
|
|
|
BIND_ENUM_CONSTANT(BIND_LEFT);
|
2020-01-27 15:07:32 +01:00
|
|
|
BIND_ENUM_CONSTANT(BIND_CENTER);
|
2017-10-22 03:42:23 +02:00
|
|
|
BIND_ENUM_CONSTANT(BIND_RIGHT);
|
|
|
|
BIND_ENUM_CONSTANT(BIND_BOTTOMLEFT);
|
|
|
|
BIND_ENUM_CONSTANT(BIND_BOTTOM);
|
|
|
|
BIND_ENUM_CONSTANT(BIND_BOTTOMRIGHT);
|
2018-04-08 22:54:02 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(SINGLE_TILE);
|
|
|
|
BIND_ENUM_CONSTANT(AUTO_TILE);
|
2018-07-29 23:54:12 +02:00
|
|
|
BIND_ENUM_CONSTANT(ATLAS_TILE);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TileSet::TileSet() {
|
|
|
|
}
|