| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/resource.h" |
| 34 |
#include "core/object/object.h" |
| 35 |
#include "core/templates/local_vector.h" |
| 36 |
#include "core/templates/rb_set.h" |
| 37 |
#include "scene/2d/light_occluder_2d.h" |
| 38 |
#include "scene/main/canvas_item.h" |
| 39 |
#include "scene/resources/image_texture.h" |
| 40 |
#include "scene/resources/packed_scene.h" |
| 41 |
#include "scene/resources/physics_material.h" |
| 42 |
|
| 43 |
#ifndef PHYSICS_2D_DISABLED |
| 44 |
#include "scene/resources/2d/convex_polygon_shape_2d.h" |
| 45 |
#endif |
| 46 |
|
| 47 |
#ifndef NAVIGATION_2D_DISABLED |
| 48 |
#include "scene/resources/2d/navigation_polygon.h" |
| 49 |
#endif |
| 50 |
|
| 51 |
#ifndef DISABLE_DEPRECATED |
| 52 |
#include "scene/resources/shader.h" |
| 53 |
#endif |
| 54 |
|
| 55 |
class TileMap; |
| 56 |
class TileSetSource; |
| 57 |
class TileSetAtlasSource; |
| 58 |
class TileData; |
| 59 |
|
| 60 |
union TileMapCell { |
| 61 |
struct { |
| 62 |
int16_t source_id; |
| 63 |
int16_t coord_x; |
| 64 |
int16_t coord_y; |
| 65 |
int16_t alternative_tile; |
| 66 |
}; |
| 67 |
|
| 68 |
uint64_t _u64t; |
| 69 |
|
| 70 |
static uint32_t hash(const TileMapCell &p_hash) { |
| 71 |
return hash_one_uint64(p_hash._u64t); |
| 72 |
} |
| 73 |
|
| 74 |
TileMapCell(int p_source_id = -1, Vector2i p_atlas_coords = Vector2i(-1, -1), int p_alternative_tile = -1) { |
| 75 |
source_id = p_source_id; |
| 76 |
set_atlas_coords(p_atlas_coords); |
| 77 |
alternative_tile = p_alternative_tile; |
| 78 |
} |
| 79 |
|
| 80 |
Vector2i get_atlas_coords() const { |
| 81 |
return Vector2i(coord_x, coord_y); |
| 82 |
} |
| 83 |
|
| 84 |
void set_atlas_coords(const Vector2i &r_coords) { |
| 85 |
coord_x = r_coords.x; |
| 86 |
coord_y = r_coords.y; |
| 87 |
} |
| 88 |
|
| 89 |
bool operator<(const TileMapCell &p_other) const { |
| 90 |
if (source_id == p_other.source_id) { |
| 91 |
if (coord_x == p_other.coord_x) { |
| 92 |
if (coord_y == p_other.coord_y) { |
| 93 |
return alternative_tile < p_other.alternative_tile; |
| 94 |
} else { |
| 95 |
return coord_y < p_other.coord_y; |
| 96 |
} |
| 97 |
} else { |
| 98 |
return coord_x < p_other.coord_x; |
| 99 |
} |
| 100 |
} else { |
| 101 |
return source_id < p_other.source_id; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
bool operator!=(const TileMapCell &p_other) const { |
| 106 |
return !(source_id == p_other.source_id && coord_x == p_other.coord_x && coord_y == p_other.coord_y && alternative_tile == p_other.alternative_tile); |
| 107 |
} |
| 108 |
bool operator==(const TileMapCell &p_other) const { |
| 109 |
return source_id == p_other.source_id && coord_x == p_other.coord_x && coord_y == p_other.coord_y && alternative_tile == p_other.alternative_tile; |
| 110 |
} |
| 111 |
}; |
| 112 |
|
| 113 |
class TileMapPattern : public Resource { |
| 114 |
GDCLASS(TileMapPattern, Resource); |
| 115 |
|
| 116 |
Size2i size; |
| 117 |
HashMap<Vector2i, TileMapCell> pattern; |
| 118 |
|
| 119 |
void _set_tile_data(const Vector<int> &p_data); |
| 120 |
Vector<int> _get_tile_data() const; |
| 121 |
|
| 122 |
protected: |
| 123 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 124 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 125 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 126 |
|
| 127 |
static void _bind_methods(); |
| 128 |
|
| 129 |
public: |
| 130 |
void set_cell(const Vector2i &p_coords, int p_source_id, const Vector2i p_atlas_coords, int p_alternative_tile = 0); |
| 131 |
bool has_cell(const Vector2i &p_coords) const; |
| 132 |
void remove_cell(const Vector2i &p_coords, bool p_update_size = true); |
| 133 |
int get_cell_source_id(const Vector2i &p_coords) const; |
| 134 |
Vector2i get_cell_atlas_coords(const Vector2i &p_coords) const; |
| 135 |
int get_cell_alternative_tile(const Vector2i &p_coords) const; |
| 136 |
|
| 137 |
const HashMap<Vector2i, TileMapCell> &get_pattern() const { return pattern; } |
| 138 |
TypedArray<Vector2i> get_used_cells() const; |
| 139 |
|
| 140 |
Size2i get_size() const; |
| 141 |
void set_size(const Size2i &p_size); |
| 142 |
bool is_empty() const; |
| 143 |
|
| 144 |
void clear(); |
| 145 |
}; |
| 146 |
|
| 147 |
class TileSet : public Resource { |
| 148 |
GDCLASS(TileSet, Resource); |
| 149 |
|
| 150 |
#ifndef DISABLE_DEPRECATED |
| 151 |
private: |
| 152 |
struct CompatibilityShapeData { |
| 153 |
Vector2i autotile_coords; |
| 154 |
bool one_way = false; |
| 155 |
float one_way_margin = 0.0f; |
| 156 |
#ifndef PHYSICS_2D_DISABLED |
| 157 |
Ref<Shape2D> shape; |
| 158 |
#endif |
| 159 |
Transform2D transform; |
| 160 |
}; |
| 161 |
|
| 162 |
struct CompatibilityTileData { |
| 163 |
String name; |
| 164 |
Ref<Texture2D> texture; |
| 165 |
Vector2 tex_offset; |
| 166 |
Ref<Material> material; |
| 167 |
Rect2 region; |
| 168 |
int tile_mode = 0; |
| 169 |
Color modulate = Color(1, 1, 1); |
| 170 |
|
| 171 |
|
| 172 |
int autotile_bitmask_mode = 0; |
| 173 |
Vector2 autotile_icon_coordinate; |
| 174 |
Size2i autotile_tile_size = Size2i(16, 16); |
| 175 |
|
| 176 |
int autotile_spacing = 0; |
| 177 |
HashMap<Vector2i, int> autotile_bitmask_flags; |
| 178 |
HashMap<Vector2i, Ref<OccluderPolygon2D>> autotile_occluder_map; |
| 179 |
#ifndef NAVIGATION_2D_DISABLED |
| 180 |
HashMap<Vector2i, Ref<NavigationPolygon>> autotile_navpoly_map; |
| 181 |
#endif |
| 182 |
HashMap<Vector2i, int> autotile_priority_map; |
| 183 |
HashMap<Vector2i, int> autotile_z_index_map; |
| 184 |
|
| 185 |
Vector<CompatibilityShapeData> shapes; |
| 186 |
Ref<OccluderPolygon2D> occluder; |
| 187 |
Vector2 occluder_offset; |
| 188 |
#ifndef NAVIGATION_2D_DISABLED |
| 189 |
Ref<NavigationPolygon> navigation; |
| 190 |
#endif |
| 191 |
Vector2 navigation_offset; |
| 192 |
int z_index = 0; |
| 193 |
}; |
| 194 |
|
| 195 |
enum CompatibilityTileMode { |
| 196 |
COMPATIBILITY_TILE_MODE_SINGLE_TILE = 0, |
| 197 |
COMPATIBILITY_TILE_MODE_AUTO_TILE, |
| 198 |
COMPATIBILITY_TILE_MODE_ATLAS_TILE, |
| 199 |
}; |
| 200 |
|
| 201 |
HashMap<int, CompatibilityTileData *> compatibility_data; |
| 202 |
HashMap<int, int> compatibility_tilemap_mapping_tile_modes; |
| 203 |
HashMap<int, RBMap<Array, Array>> compatibility_tilemap_mapping; |
| 204 |
HashMap<Vector2i, int> compatibility_size_count; |
| 205 |
|
| 206 |
void _compatibility_conversion(); |
| 207 |
|
| 208 |
public: |
| 209 |
|
| 210 |
Array compatibility_tilemap_map(int p_tile_id, Vector2i p_coords, bool p_flip_h, bool p_flip_v, bool p_transpose); |
| 211 |
#endif |
| 212 |
|
| 213 |
public: |
| 214 |
static const int INVALID_SOURCE; |
| 215 |
|
| 216 |
enum CellNeighbor { |
| 217 |
CELL_NEIGHBOR_RIGHT_SIDE = 0, |
| 218 |
CELL_NEIGHBOR_RIGHT_CORNER, |
| 219 |
CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE, |
| 220 |
CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER, |
| 221 |
CELL_NEIGHBOR_BOTTOM_SIDE, |
| 222 |
CELL_NEIGHBOR_BOTTOM_CORNER, |
| 223 |
CELL_NEIGHBOR_BOTTOM_LEFT_SIDE, |
| 224 |
CELL_NEIGHBOR_BOTTOM_LEFT_CORNER, |
| 225 |
CELL_NEIGHBOR_LEFT_SIDE, |
| 226 |
CELL_NEIGHBOR_LEFT_CORNER, |
| 227 |
CELL_NEIGHBOR_TOP_LEFT_SIDE, |
| 228 |
CELL_NEIGHBOR_TOP_LEFT_CORNER, |
| 229 |
CELL_NEIGHBOR_TOP_SIDE, |
| 230 |
CELL_NEIGHBOR_TOP_CORNER, |
| 231 |
CELL_NEIGHBOR_TOP_RIGHT_SIDE, |
| 232 |
CELL_NEIGHBOR_TOP_RIGHT_CORNER, |
| 233 |
CELL_NEIGHBOR_MAX, |
| 234 |
}; |
| 235 |
|
| 236 |
static const char *CELL_NEIGHBOR_ENUM_TO_TEXT[]; |
| 237 |
|
| 238 |
enum TerrainMode { |
| 239 |
TERRAIN_MODE_MATCH_CORNERS_AND_SIDES = 0, |
| 240 |
TERRAIN_MODE_MATCH_CORNERS, |
| 241 |
TERRAIN_MODE_MATCH_SIDES, |
| 242 |
}; |
| 243 |
|
| 244 |
enum TileShape { |
| 245 |
TILE_SHAPE_SQUARE, |
| 246 |
TILE_SHAPE_ISOMETRIC, |
| 247 |
TILE_SHAPE_HALF_OFFSET_SQUARE, |
| 248 |
TILE_SHAPE_HEXAGON, |
| 249 |
}; |
| 250 |
|
| 251 |
enum TileLayout { |
| 252 |
TILE_LAYOUT_STACKED, |
| 253 |
TILE_LAYOUT_STACKED_OFFSET, |
| 254 |
TILE_LAYOUT_STAIRS_RIGHT, |
| 255 |
TILE_LAYOUT_STAIRS_DOWN, |
| 256 |
TILE_LAYOUT_DIAMOND_RIGHT, |
| 257 |
TILE_LAYOUT_DIAMOND_DOWN, |
| 258 |
}; |
| 259 |
|
| 260 |
enum TileOffsetAxis { |
| 261 |
TILE_OFFSET_AXIS_HORIZONTAL, |
| 262 |
TILE_OFFSET_AXIS_VERTICAL, |
| 263 |
}; |
| 264 |
|
| 265 |
struct PackedSceneSource { |
| 266 |
Ref<PackedScene> scene; |
| 267 |
Vector2 offset; |
| 268 |
}; |
| 269 |
|
| 270 |
class TerrainsPattern { |
| 271 |
bool valid = false; |
| 272 |
int terrain = -1; |
| 273 |
int bits[TileSet::CELL_NEIGHBOR_MAX] = {}; |
| 274 |
bool is_valid_bit[TileSet::CELL_NEIGHBOR_MAX] = {}; |
| 275 |
|
| 276 |
int not_empty_terrains_count = 0; |
| 277 |
|
| 278 |
public: |
| 279 |
bool is_valid() const; |
| 280 |
bool is_erase_pattern() const; |
| 281 |
|
| 282 |
bool operator<(const TerrainsPattern &p_terrains_pattern) const; |
| 283 |
bool operator==(const TerrainsPattern &p_terrains_pattern) const; |
| 284 |
bool operator!=(const TerrainsPattern &p_terrains_pattern) const { |
| 285 |
return !operator==(p_terrains_pattern); |
| 286 |
} |
| 287 |
|
| 288 |
void set_terrain(int p_terrain); |
| 289 |
int get_terrain() const; |
| 290 |
|
| 291 |
void set_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit, int p_terrain); |
| 292 |
int get_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const; |
| 293 |
|
| 294 |
void from_array(Array p_terrains); |
| 295 |
Array as_array() const; |
| 296 |
|
| 297 |
TerrainsPattern(const TileSet *p_tile_set, int p_terrain_set); |
| 298 |
TerrainsPattern() {} |
| 299 |
}; |
| 300 |
|
| 301 |
protected: |
| 302 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 303 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 304 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 305 |
void _validate_property(PropertyInfo &p_property) const; |
| 306 |
|
| 307 |
#ifdef TOOLS_ENABLED |
| 308 |
virtual uint32_t hash_edited_version_for_preview() const override { return 0; } |
| 309 |
#endif |
| 310 |
|
| 311 |
private: |
| 312 |
|
| 313 |
|
| 314 |
TileShape tile_shape = TILE_SHAPE_SQUARE; |
| 315 |
TileLayout tile_layout = TILE_LAYOUT_STACKED; |
| 316 |
TileOffsetAxis tile_offset_axis = TILE_OFFSET_AXIS_HORIZONTAL; |
| 317 |
Size2i tile_size = Size2i(16, 16); |
| 318 |
|
| 319 |
|
| 320 |
bool uv_clipping = false; |
| 321 |
struct OcclusionLayer { |
| 322 |
uint32_t light_mask = 1; |
| 323 |
bool sdf_collision = false; |
| 324 |
}; |
| 325 |
Vector<OcclusionLayer> occlusion_layers; |
| 326 |
|
| 327 |
Ref<ArrayMesh> tile_lines_mesh; |
| 328 |
Ref<ArrayMesh> tile_filled_mesh; |
| 329 |
mutable bool tile_meshes_dirty = true; |
| 330 |
|
| 331 |
#ifndef PHYSICS_2D_DISABLED |
| 332 |
|
| 333 |
struct PhysicsLayer { |
| 334 |
uint32_t collision_layer = 1; |
| 335 |
uint32_t collision_mask = 1; |
| 336 |
real_t collision_priority = 1.0; |
| 337 |
Ref<PhysicsMaterial> physics_material; |
| 338 |
}; |
| 339 |
Vector<PhysicsLayer> physics_layers; |
| 340 |
#endif |
| 341 |
|
| 342 |
|
| 343 |
struct Terrain { |
| 344 |
String name; |
| 345 |
Color color; |
| 346 |
}; |
| 347 |
struct TerrainSet { |
| 348 |
TerrainMode mode = TERRAIN_MODE_MATCH_CORNERS_AND_SIDES; |
| 349 |
Vector<Terrain> terrains; |
| 350 |
}; |
| 351 |
Vector<TerrainSet> terrain_sets; |
| 352 |
|
| 353 |
HashMap<TerrainMode, Ref<ArrayMesh>> terrain_meshes; |
| 354 |
HashMap<TerrainMode, HashMap<CellNeighbor, Ref<ArrayMesh>>> terrain_peering_bits_meshes; |
| 355 |
bool terrain_bits_meshes_dirty = true; |
| 356 |
|
| 357 |
LocalVector<RBMap<TileSet::TerrainsPattern, RBSet<TileMapCell>>> per_terrain_pattern_tiles; |
| 358 |
bool terrains_cache_dirty = true; |
| 359 |
void _update_terrains_cache(); |
| 360 |
|
| 361 |
|
| 362 |
struct NavigationLayer { |
| 363 |
uint32_t layers = 1; |
| 364 |
}; |
| 365 |
Vector<NavigationLayer> navigation_layers; |
| 366 |
|
| 367 |
|
| 368 |
struct CustomDataLayer { |
| 369 |
String name; |
| 370 |
Variant::Type type = Variant::NIL; |
| 371 |
}; |
| 372 |
Vector<CustomDataLayer> custom_data_layers; |
| 373 |
HashMap<String, int> custom_data_layers_by_name; |
| 374 |
|
| 375 |
|
| 376 |
HashMap<int, Ref<TileSetSource>> sources; |
| 377 |
Vector<int> source_ids; |
| 378 |
int next_source_id = 0; |
| 379 |
|
| 380 |
|
| 381 |
LocalVector<Ref<TileMapPattern>> patterns; |
| 382 |
|
| 383 |
void _compute_next_source_id(); |
| 384 |
void _source_changed(); |
| 385 |
|
| 386 |
|
| 387 |
RBMap<int, int> source_level_proxies; |
| 388 |
RBMap<Array, Array> coords_level_proxies; |
| 389 |
RBMap<Array, Array> alternative_level_proxies; |
| 390 |
|
| 391 |
|
| 392 |
Vector<Point2> _get_square_terrain_polygon(Vector2i p_size); |
| 393 |
Vector<Point2> _get_square_corner_or_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); |
| 394 |
Vector<Point2> _get_square_corner_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); |
| 395 |
Vector<Point2> _get_square_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); |
| 396 |
|
| 397 |
Vector<Point2> _get_isometric_terrain_polygon(Vector2i p_size); |
| 398 |
Vector<Point2> _get_isometric_corner_or_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); |
| 399 |
Vector<Point2> _get_isometric_corner_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); |
| 400 |
Vector<Point2> _get_isometric_side_terrain_peering_bit_polygon(Vector2i p_size, TileSet::CellNeighbor p_bit); |
| 401 |
|
| 402 |
Vector<Point2> _get_half_offset_terrain_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis); |
| 403 |
Vector<Point2> _get_half_offset_corner_or_side_terrain_peering_bit_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis, TileSet::CellNeighbor p_bit); |
| 404 |
Vector<Point2> _get_half_offset_corner_terrain_peering_bit_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis, TileSet::CellNeighbor p_bit); |
| 405 |
Vector<Point2> _get_half_offset_side_terrain_peering_bit_polygon(Vector2i p_size, float p_overlap, TileSet::TileOffsetAxis p_offset_axis, TileSet::CellNeighbor p_bit); |
| 406 |
|
| 407 |
protected: |
| 408 |
static void _bind_methods(); |
| 409 |
|
| 410 |
public: |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
void set_tile_shape(TileShape p_shape); |
| 415 |
TileShape get_tile_shape() const; |
| 416 |
void set_tile_layout(TileLayout p_layout); |
| 417 |
TileLayout get_tile_layout() const; |
| 418 |
void set_tile_offset_axis(TileOffsetAxis p_alignment); |
| 419 |
TileOffsetAxis get_tile_offset_axis() const; |
| 420 |
void set_tile_size(Size2i p_size); |
| 421 |
Size2i get_tile_size() const; |
| 422 |
|
| 423 |
|
| 424 |
int get_next_source_id() const; |
| 425 |
int get_source_count() const; |
| 426 |
int get_source_id(int p_index) const; |
| 427 |
int add_source(Ref<TileSetSource> p_tile_set_source, int p_source_id_override = -1); |
| 428 |
void set_source_id(int p_source_id, int p_new_id); |
| 429 |
void remove_source(int p_source_id); |
| 430 |
void remove_source_ptr(TileSetSource *p_tile_set_source); |
| 431 |
bool has_source(int p_source_id) const; |
| 432 |
Ref<TileSetSource> get_source(int p_source_id) const; |
| 433 |
|
| 434 |
|
| 435 |
void set_uv_clipping(bool p_uv_clipping); |
| 436 |
bool is_uv_clipping() const; |
| 437 |
|
| 438 |
int get_occlusion_layers_count() const; |
| 439 |
void add_occlusion_layer(int p_index = -1); |
| 440 |
void move_occlusion_layer(int p_from_index, int p_to_pos); |
| 441 |
void remove_occlusion_layer(int p_index); |
| 442 |
void set_occlusion_layer_light_mask(int p_layer_index, int p_light_mask); |
| 443 |
int get_occlusion_layer_light_mask(int p_layer_index) const; |
| 444 |
void set_occlusion_layer_sdf_collision(int p_layer_index, bool p_sdf_collision); |
| 445 |
bool get_occlusion_layer_sdf_collision(int p_layer_index) const; |
| 446 |
|
| 447 |
#ifndef PHYSICS_2D_DISABLED |
| 448 |
|
| 449 |
int get_physics_layers_count() const; |
| 450 |
void add_physics_layer(int p_index = -1); |
| 451 |
void move_physics_layer(int p_from_index, int p_to_pos); |
| 452 |
void remove_physics_layer(int p_index); |
| 453 |
void set_physics_layer_collision_layer(int p_layer_index, uint32_t p_layer); |
| 454 |
uint32_t get_physics_layer_collision_layer(int p_layer_index) const; |
| 455 |
void set_physics_layer_collision_mask(int p_layer_index, uint32_t p_mask); |
| 456 |
uint32_t get_physics_layer_collision_mask(int p_layer_index) const; |
| 457 |
void set_physics_layer_collision_priority(int p_layer_index, real_t p_priority); |
| 458 |
real_t get_physics_layer_collision_priority(int p_layer_index) const; |
| 459 |
void set_physics_layer_physics_material(int p_layer_index, Ref<PhysicsMaterial> p_physics_material); |
| 460 |
Ref<PhysicsMaterial> get_physics_layer_physics_material(int p_layer_index) const; |
| 461 |
#endif |
| 462 |
|
| 463 |
|
| 464 |
int get_terrain_sets_count() const; |
| 465 |
void add_terrain_set(int p_index = -1); |
| 466 |
void move_terrain_set(int p_from_index, int p_to_pos); |
| 467 |
void remove_terrain_set(int p_index); |
| 468 |
void set_terrain_set_mode(int p_terrain_set, TerrainMode p_terrain_mode); |
| 469 |
TerrainMode get_terrain_set_mode(int p_terrain_set) const; |
| 470 |
|
| 471 |
|
| 472 |
int get_terrains_count(int p_terrain_set) const; |
| 473 |
void add_terrain(int p_terrain_set, int p_index = -1); |
| 474 |
void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos); |
| 475 |
void remove_terrain(int p_terrain_set, int p_index); |
| 476 |
void set_terrain_name(int p_terrain_set, int p_terrain_index, String p_name); |
| 477 |
String get_terrain_name(int p_terrain_set, int p_terrain_index) const; |
| 478 |
void set_terrain_color(int p_terrain_set, int p_terrain_index, Color p_color); |
| 479 |
Color get_terrain_color(int p_terrain_set, int p_terrain_index) const; |
| 480 |
bool is_valid_terrain_peering_bit_for_mode(TileSet::TerrainMode p_terrain_mode, TileSet::CellNeighbor p_peering_bit) const; |
| 481 |
bool is_valid_terrain_peering_bit(int p_terrain_set, TileSet::CellNeighbor p_peering_bit) const; |
| 482 |
|
| 483 |
#ifndef NAVIGATION_2D_DISABLED |
| 484 |
|
| 485 |
int get_navigation_layers_count() const; |
| 486 |
void add_navigation_layer(int p_index = -1); |
| 487 |
void move_navigation_layer(int p_from_index, int p_to_pos); |
| 488 |
void remove_navigation_layer(int p_index); |
| 489 |
void set_navigation_layer_layers(int p_layer_index, uint32_t p_layers); |
| 490 |
uint32_t get_navigation_layer_layers(int p_layer_index) const; |
| 491 |
void set_navigation_layer_layer_value(int p_layer_index, int p_layer_number, bool p_value); |
| 492 |
bool get_navigation_layer_layer_value(int p_layer_index, int p_layer_number) const; |
| 493 |
#endif |
| 494 |
|
| 495 |
|
| 496 |
int get_custom_data_layers_count() const; |
| 497 |
void add_custom_data_layer(int p_index = -1); |
| 498 |
void move_custom_data_layer(int p_from_index, int p_to_pos); |
| 499 |
void remove_custom_data_layer(int p_index); |
| 500 |
int get_custom_data_layer_by_name(String p_value) const; |
| 501 |
void set_custom_data_layer_name(int p_layer_id, String p_value); |
| 502 |
bool has_custom_data_layer_by_name(const String &p_value) const; |
| 503 |
String get_custom_data_layer_name(int p_layer_id) const; |
| 504 |
void set_custom_data_layer_type(int p_layer_id, Variant::Type p_value); |
| 505 |
Variant::Type get_custom_data_layer_type(int p_layer_id) const; |
| 506 |
|
| 507 |
|
| 508 |
void set_source_level_tile_proxy(int p_source_from, int p_source_to); |
| 509 |
int get_source_level_tile_proxy(int p_source_from); |
| 510 |
bool has_source_level_tile_proxy(int p_source_from); |
| 511 |
void remove_source_level_tile_proxy(int p_source_from); |
| 512 |
|
| 513 |
void set_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_source_to, Vector2i p_coords_to); |
| 514 |
Array get_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from); |
| 515 |
bool has_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from); |
| 516 |
void remove_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from); |
| 517 |
|
| 518 |
void set_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from, int p_source_to, Vector2i p_coords_to, int p_alternative_to); |
| 519 |
Array get_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from); |
| 520 |
bool has_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from); |
| 521 |
void remove_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from); |
| 522 |
|
| 523 |
Array get_source_level_tile_proxies() const; |
| 524 |
Array get_coords_level_tile_proxies() const; |
| 525 |
Array get_alternative_level_tile_proxies() const; |
| 526 |
|
| 527 |
Array map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) const; |
| 528 |
|
| 529 |
void cleanup_invalid_tile_proxies(); |
| 530 |
void clear_tile_proxies(); |
| 531 |
|
| 532 |
|
| 533 |
int add_pattern(Ref<TileMapPattern> p_pattern, int p_index = -1); |
| 534 |
Ref<TileMapPattern> get_pattern(int p_index); |
| 535 |
void remove_pattern(int p_index); |
| 536 |
int get_patterns_count(); |
| 537 |
|
| 538 |
|
| 539 |
RBSet<TerrainsPattern> get_terrains_pattern_set(int p_terrain_set); |
| 540 |
RBSet<TileMapCell> get_tiles_for_terrains_pattern(int p_terrain_set, TerrainsPattern p_terrain_tile_pattern); |
| 541 |
TileMapCell get_random_tile_from_terrains_pattern(int p_terrain_set, TerrainsPattern p_terrain_tile_pattern); |
| 542 |
|
| 543 |
|
| 544 |
Vector<Vector2> get_tile_shape_polygon() const; |
| 545 |
void draw_tile_shape(CanvasItem *p_canvas_item, Transform2D p_transform, Color p_color, bool p_filled = false, Ref<Texture2D> p_texture = Ref<Texture2D>()) const; |
| 546 |
|
| 547 |
|
| 548 |
Vector2 map_to_local(const Vector2i &p_pos) const; |
| 549 |
Vector2i local_to_map(const Vector2 &p_pos) const; |
| 550 |
bool is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const; |
| 551 |
Vector2i get_neighbor_cell(const Vector2i &p_coords, TileSet::CellNeighbor p_cell_neighbor) const; |
| 552 |
TypedArray<Vector2i> get_surrounding_cells(const Vector2i &p_coords) const; |
| 553 |
Vector2i map_pattern(const Vector2i &p_position_in_tilemap, const Vector2i &p_coords_in_pattern, Ref<TileMapPattern> p_pattern) const; |
| 554 |
void draw_cells_outline(CanvasItem *p_canvas_item, const RBSet<Vector2i> &p_cells, Color p_color, Transform2D p_transform = Transform2D()) const; |
| 555 |
|
| 556 |
Vector<Point2> get_terrain_polygon(int p_terrain_set); |
| 557 |
Vector<Point2> get_terrain_peering_bit_polygon(int p_terrain_set, TileSet::CellNeighbor p_bit); |
| 558 |
void draw_terrains(CanvasItem *p_canvas_item, Transform2D p_transform, const TileData *p_tile_data); |
| 559 |
Vector<Vector<Ref<Texture2D>>> generate_terrains_icons(Size2i p_size); |
| 560 |
|
| 561 |
|
| 562 |
virtual void reset_state() override; |
| 563 |
|
| 564 |
|
| 565 |
static Vector2i transform_coords_layout(const Vector2i &p_coords, TileSet::TileOffsetAxis p_offset_axis, TileSet::TileLayout p_from_layout, TileSet::TileLayout p_to_layout); |
| 566 |
|
| 567 |
TileSet(); |
| 568 |
~TileSet(); |
| 569 |
}; |
| 570 |
|
| 571 |
class TileSetSource : public Resource { |
| 572 |
GDCLASS(TileSetSource, Resource); |
| 573 |
|
| 574 |
protected: |
| 575 |
const TileSet *tile_set = nullptr; |
| 576 |
|
| 577 |
static void _bind_methods(); |
| 578 |
|
| 579 |
public: |
| 580 |
static const Vector2i INVALID_ATLAS_COORDS; |
| 581 |
static const int INVALID_TILE_ALTERNATIVE; |
| 582 |
|
| 583 |
|
| 584 |
virtual void set_tile_set(const TileSet *p_tile_set); |
| 585 |
TileSet *get_tile_set() const; |
| 586 |
virtual void notify_tile_data_properties_should_change() {} |
| 587 |
virtual void add_occlusion_layer(int p_index) {} |
| 588 |
virtual void move_occlusion_layer(int p_from_index, int p_to_pos) {} |
| 589 |
virtual void remove_occlusion_layer(int p_index) {} |
| 590 |
virtual void add_physics_layer(int p_index) {} |
| 591 |
virtual void move_physics_layer(int p_from_index, int p_to_pos) {} |
| 592 |
virtual void remove_physics_layer(int p_index) {} |
| 593 |
virtual void add_terrain_set(int p_index) {} |
| 594 |
virtual void move_terrain_set(int p_from_index, int p_to_pos) {} |
| 595 |
virtual void remove_terrain_set(int p_index) {} |
| 596 |
virtual void add_terrain(int p_terrain_set, int p_index) {} |
| 597 |
virtual void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos) {} |
| 598 |
virtual void remove_terrain(int p_terrain_set, int p_index) {} |
| 599 |
virtual void add_navigation_layer(int p_index) {} |
| 600 |
virtual void move_navigation_layer(int p_from_index, int p_to_pos) {} |
| 601 |
virtual void remove_navigation_layer(int p_index) {} |
| 602 |
virtual void add_custom_data_layer(int p_index) {} |
| 603 |
virtual void move_custom_data_layer(int p_from_index, int p_to_pos) {} |
| 604 |
virtual void remove_custom_data_layer(int p_index) {} |
| 605 |
virtual void reset_state() override; |
| 606 |
|
| 607 |
|
| 608 |
virtual int get_tiles_count() const = 0; |
| 609 |
virtual Vector2i get_tile_id(int tile_index) const = 0; |
| 610 |
virtual bool has_tile(Vector2i p_atlas_coords) const = 0; |
| 611 |
|
| 612 |
|
| 613 |
virtual int get_alternative_tiles_count(const Vector2i p_atlas_coords) const = 0; |
| 614 |
virtual int get_alternative_tile_id(const Vector2i p_atlas_coords, int p_index) const = 0; |
| 615 |
virtual bool has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const = 0; |
| 616 |
}; |
| 617 |
|
| 618 |
class TileSetAtlasSource : public TileSetSource { |
| 619 |
GDCLASS(TileSetAtlasSource, TileSetSource); |
| 620 |
|
| 621 |
public: |
| 622 |
enum TileAnimationMode { |
| 623 |
TILE_ANIMATION_MODE_DEFAULT, |
| 624 |
TILE_ANIMATION_MODE_RANDOM_START_TIMES, |
| 625 |
TILE_ANIMATION_MODE_MAX, |
| 626 |
}; |
| 627 |
|
| 628 |
enum TransformBits { |
| 629 |
TRANSFORM_FLIP_H = 1 << 12, |
| 630 |
TRANSFORM_FLIP_V = 1 << 13, |
| 631 |
TRANSFORM_TRANSPOSE = 1 << 14, |
| 632 |
}; |
| 633 |
|
| 634 |
static const int16_t UNTRANSFORM_MASK = ~(TileSetAtlasSource::TRANSFORM_FLIP_H + TileSetAtlasSource::TRANSFORM_FLIP_V + TileSetAtlasSource::TRANSFORM_TRANSPOSE); |
| 635 |
|
| 636 |
private: |
| 637 |
struct TileAlternativesData { |
| 638 |
Vector2i size_in_atlas = Vector2i(1, 1); |
| 639 |
Vector2i texture_offset; |
| 640 |
|
| 641 |
|
| 642 |
int animation_columns = 0; |
| 643 |
Vector2i animation_separation; |
| 644 |
real_t animation_speed = 1.0; |
| 645 |
TileSetAtlasSource::TileAnimationMode animation_mode = TILE_ANIMATION_MODE_DEFAULT; |
| 646 |
LocalVector<real_t> animation_frames_durations; |
| 647 |
|
| 648 |
|
| 649 |
HashMap<int, TileData *> alternatives; |
| 650 |
Vector<int> alternatives_ids; |
| 651 |
int next_alternative_id = 1; |
| 652 |
}; |
| 653 |
|
| 654 |
bool initializing = true; |
| 655 |
|
| 656 |
Ref<Texture2D> texture; |
| 657 |
Vector2i margins; |
| 658 |
Vector2i separation; |
| 659 |
Size2i texture_region_size = Size2i(16, 16); |
| 660 |
|
| 661 |
HashMap<Vector2i, TileAlternativesData> tiles; |
| 662 |
Vector<Vector2i> tiles_ids; |
| 663 |
HashMap<Vector2i, Vector2i> _coords_mapping_cache; |
| 664 |
|
| 665 |
TileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile); |
| 666 |
const TileData *_get_atlas_tile_data(Vector2i p_atlas_coords, int p_alternative_tile) const; |
| 667 |
|
| 668 |
void _compute_next_alternative_id(const Vector2i p_atlas_coords); |
| 669 |
|
| 670 |
void _clear_coords_mapping_cache(Vector2i p_atlas_coords); |
| 671 |
void _create_coords_mapping_cache(Vector2i p_atlas_coords); |
| 672 |
|
| 673 |
bool use_texture_padding = true; |
| 674 |
Ref<CanvasTexture> padded_texture; |
| 675 |
bool padded_texture_needs_update = false; |
| 676 |
void _queue_update_padded_texture(); |
| 677 |
Ref<ImageTexture> _create_padded_image_texture(const Ref<Texture2D> &p_source); |
| 678 |
void _update_padded_texture(); |
| 679 |
void _try_emit_changed(); |
| 680 |
|
| 681 |
protected: |
| 682 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 683 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 684 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 685 |
|
| 686 |
void _notification(int p_notification); |
| 687 |
static void _bind_methods(); |
| 688 |
|
| 689 |
public: |
| 690 |
|
| 691 |
virtual void set_tile_set(const TileSet *p_tile_set) override; |
| 692 |
const TileSet *get_tile_set() const; |
| 693 |
virtual void notify_tile_data_properties_should_change() override; |
| 694 |
virtual void add_occlusion_layer(int p_index) override; |
| 695 |
virtual void move_occlusion_layer(int p_from_index, int p_to_pos) override; |
| 696 |
virtual void remove_occlusion_layer(int p_index) override; |
| 697 |
#ifndef PHYSICS_2D_DISABLED |
| 698 |
virtual void add_physics_layer(int p_index) override; |
| 699 |
virtual void move_physics_layer(int p_from_index, int p_to_pos) override; |
| 700 |
virtual void remove_physics_layer(int p_index) override; |
| 701 |
#endif |
| 702 |
virtual void add_terrain_set(int p_index) override; |
| 703 |
virtual void move_terrain_set(int p_from_index, int p_to_pos) override; |
| 704 |
virtual void remove_terrain_set(int p_index) override; |
| 705 |
virtual void add_terrain(int p_terrain_set, int p_index) override; |
| 706 |
virtual void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos) override; |
| 707 |
virtual void remove_terrain(int p_terrain_set, int p_index) override; |
| 708 |
#ifndef NAVIGATION_2D_DISABLED |
| 709 |
virtual void add_navigation_layer(int p_index) override; |
| 710 |
virtual void move_navigation_layer(int p_from_index, int p_to_pos) override; |
| 711 |
virtual void remove_navigation_layer(int p_index) override; |
| 712 |
#endif |
| 713 |
virtual void add_custom_data_layer(int p_index) override; |
| 714 |
virtual void move_custom_data_layer(int p_from_index, int p_to_pos) override; |
| 715 |
virtual void remove_custom_data_layer(int p_index) override; |
| 716 |
virtual void reset_state() override; |
| 717 |
|
| 718 |
|
| 719 |
void set_texture(Ref<Texture2D> p_texture); |
| 720 |
Ref<Texture2D> get_texture() const; |
| 721 |
void set_margins(Vector2i p_margins); |
| 722 |
Vector2i get_margins() const; |
| 723 |
void set_separation(Vector2i p_separation); |
| 724 |
Vector2i get_separation() const; |
| 725 |
void set_texture_region_size(Vector2i p_tile_size); |
| 726 |
Vector2i get_texture_region_size() const; |
| 727 |
|
| 728 |
|
| 729 |
void set_use_texture_padding(bool p_use_padding); |
| 730 |
bool get_use_texture_padding() const; |
| 731 |
|
| 732 |
|
| 733 |
void create_tile(const Vector2i p_atlas_coords, const Vector2i p_size = Vector2i(1, 1)); |
| 734 |
void remove_tile(Vector2i p_atlas_coords); |
| 735 |
virtual bool has_tile(Vector2i p_atlas_coords) const override; |
| 736 |
void move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_new_atlas_coords = INVALID_ATLAS_COORDS, Vector2i p_new_size = Vector2i(-1, -1)); |
| 737 |
Vector2i get_tile_size_in_atlas(Vector2i p_atlas_coords) const; |
| 738 |
|
| 739 |
virtual int get_tiles_count() const override; |
| 740 |
virtual Vector2i get_tile_id(int p_index) const override; |
| 741 |
|
| 742 |
bool has_room_for_tile(Vector2i p_atlas_coords, Vector2i p_size, int p_animation_columns, Vector2i p_animation_separation, int p_frames_count, Vector2i p_ignored_tile = INVALID_ATLAS_COORDS) const; |
| 743 |
PackedVector2Array get_tiles_to_be_removed_on_change(Ref<Texture2D> p_texture, Vector2i p_margins, Vector2i p_separation, Vector2i p_texture_region_size); |
| 744 |
Vector2i get_tile_at_coords(Vector2i p_atlas_coords) const; |
| 745 |
|
| 746 |
bool has_tiles_outside_texture() const; |
| 747 |
Vector<Vector2i> get_tiles_outside_texture() const; |
| 748 |
void clear_tiles_outside_texture(); |
| 749 |
|
| 750 |
|
| 751 |
void set_tile_animation_columns(const Vector2i p_atlas_coords, int p_frame_columns); |
| 752 |
int get_tile_animation_columns(const Vector2i p_atlas_coords) const; |
| 753 |
void set_tile_animation_separation(const Vector2i p_atlas_coords, const Vector2i p_separation); |
| 754 |
Vector2i get_tile_animation_separation(const Vector2i p_atlas_coords) const; |
| 755 |
void set_tile_animation_speed(const Vector2i p_atlas_coords, real_t p_speed); |
| 756 |
real_t get_tile_animation_speed(const Vector2i p_atlas_coords) const; |
| 757 |
void set_tile_animation_mode(const Vector2i p_atlas_coords, const TileSetAtlasSource::TileAnimationMode p_mode); |
| 758 |
TileSetAtlasSource::TileAnimationMode get_tile_animation_mode(const Vector2i p_atlas_coords) const; |
| 759 |
void set_tile_animation_frames_count(const Vector2i p_atlas_coords, int p_frames_count); |
| 760 |
int get_tile_animation_frames_count(const Vector2i p_atlas_coords) const; |
| 761 |
void set_tile_animation_frame_duration(const Vector2i p_atlas_coords, int p_frame_index, real_t p_duration); |
| 762 |
real_t get_tile_animation_frame_duration(const Vector2i p_atlas_coords, int p_frame_index) const; |
| 763 |
real_t get_tile_animation_total_duration(const Vector2i p_atlas_coords) const; |
| 764 |
|
| 765 |
|
| 766 |
int create_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_id_override = -1); |
| 767 |
void remove_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile); |
| 768 |
void set_alternative_tile_id(const Vector2i p_atlas_coords, int p_alternative_tile, int p_new_id); |
| 769 |
virtual bool has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const override; |
| 770 |
int get_next_alternative_tile_id(const Vector2i p_atlas_coords) const; |
| 771 |
|
| 772 |
virtual int get_alternative_tiles_count(const Vector2i p_atlas_coords) const override; |
| 773 |
virtual int get_alternative_tile_id(const Vector2i p_atlas_coords, int p_index) const override; |
| 774 |
|
| 775 |
|
| 776 |
TileData *get_tile_data(const Vector2i p_atlas_coords, int p_alternative_tile) const; |
| 777 |
|
| 778 |
|
| 779 |
Vector2i get_atlas_grid_size() const; |
| 780 |
Rect2i get_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const; |
| 781 |
bool is_position_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Vector2 p_position) const; |
| 782 |
bool is_rect_in_tile_texture_region(const Vector2i p_atlas_coords, int p_alternative_tile, Rect2 p_rect) const; |
| 783 |
|
| 784 |
static int alternative_no_transform(int p_alternative_id); |
| 785 |
|
| 786 |
|
| 787 |
Ref<Texture2D> get_runtime_texture() const; |
| 788 |
Rect2i get_runtime_tile_texture_region(Vector2i p_atlas_coords, int p_frame = 0) const; |
| 789 |
|
| 790 |
~TileSetAtlasSource(); |
| 791 |
}; |
| 792 |
|
| 793 |
class TileSetScenesCollectionSource : public TileSetSource { |
| 794 |
GDCLASS(TileSetScenesCollectionSource, TileSetSource); |
| 795 |
|
| 796 |
private: |
| 797 |
struct SceneData { |
| 798 |
Ref<PackedScene> scene; |
| 799 |
bool display_placeholder = false; |
| 800 |
}; |
| 801 |
Vector<int> scenes_ids; |
| 802 |
HashMap<int, SceneData> scenes; |
| 803 |
int next_scene_id = 1; |
| 804 |
|
| 805 |
bool initializing = true; |
| 806 |
|
| 807 |
void _compute_next_alternative_id(); |
| 808 |
void _try_emit_changed(); |
| 809 |
|
| 810 |
protected: |
| 811 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 812 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 813 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 814 |
|
| 815 |
void _notification(int p_notification); |
| 816 |
static void _bind_methods(); |
| 817 |
|
| 818 |
public: |
| 819 |
|
| 820 |
int get_tiles_count() const override; |
| 821 |
Vector2i get_tile_id(int p_tile_index) const override; |
| 822 |
bool has_tile(Vector2i p_atlas_coords) const override; |
| 823 |
|
| 824 |
|
| 825 |
int get_alternative_tiles_count(const Vector2i p_atlas_coords) const override; |
| 826 |
int get_alternative_tile_id(const Vector2i p_atlas_coords, int p_index) const override; |
| 827 |
bool has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const override; |
| 828 |
|
| 829 |
|
| 830 |
int get_scene_tiles_count() { return get_alternative_tiles_count(Vector2i()); } |
| 831 |
int get_scene_tile_id(int p_index) { return get_alternative_tile_id(Vector2i(), p_index); } |
| 832 |
bool has_scene_tile_id(int p_id) { return has_alternative_tile(Vector2i(), p_id); } |
| 833 |
int create_scene_tile(Ref<PackedScene> p_packed_scene = Ref<PackedScene>(), int p_id_override = -1); |
| 834 |
void set_scene_tile_id(int p_id, int p_new_id); |
| 835 |
void set_scene_tile_scene(int p_id, Ref<PackedScene> p_packed_scene); |
| 836 |
Ref<PackedScene> get_scene_tile_scene(int p_id) const; |
| 837 |
void set_scene_tile_display_placeholder(int p_id, bool p_packed_scene); |
| 838 |
bool get_scene_tile_display_placeholder(int p_id) const; |
| 839 |
void remove_scene_tile(int p_id); |
| 840 |
int get_next_scene_tile_id() const; |
| 841 |
}; |
| 842 |
|
| 843 |
class TileData : public Object { |
| 844 |
GDCLASS(TileData, Object); |
| 845 |
|
| 846 |
private: |
| 847 |
const TileSet *tile_set = nullptr; |
| 848 |
bool allow_transform = true; |
| 849 |
|
| 850 |
|
| 851 |
bool flip_h = false; |
| 852 |
bool flip_v = false; |
| 853 |
bool transpose = false; |
| 854 |
Vector2i texture_origin; |
| 855 |
Ref<Material> material; |
| 856 |
Color modulate = Color(1.0, 1.0, 1.0, 1.0); |
| 857 |
int z_index = 0; |
| 858 |
int y_sort_origin = 0; |
| 859 |
struct OcclusionLayerTileData { |
| 860 |
struct PolygonOccluderTileData { |
| 861 |
Ref<OccluderPolygon2D> occluder_polygon; |
| 862 |
mutable HashMap<int, Ref<OccluderPolygon2D>> transformed_polygon_occluders; |
| 863 |
}; |
| 864 |
Vector<PolygonOccluderTileData> polygons; |
| 865 |
}; |
| 866 |
Vector<OcclusionLayerTileData> occluders; |
| 867 |
|
| 868 |
#ifndef PHYSICS_2D_DISABLED |
| 869 |
|
| 870 |
struct PhysicsLayerTileData { |
| 871 |
struct PolygonShapeTileData { |
| 872 |
LocalVector<Vector2> polygon; |
| 873 |
LocalVector<Ref<ConvexPolygonShape2D>> shapes; |
| 874 |
mutable HashMap<int, LocalVector<Ref<ConvexPolygonShape2D>>> transformed_shapes; |
| 875 |
bool one_way = false; |
| 876 |
float one_way_margin = 1.0; |
| 877 |
}; |
| 878 |
|
| 879 |
Vector2 linear_velocity; |
| 880 |
double angular_velocity = 0.0; |
| 881 |
Vector<PolygonShapeTileData> polygons; |
| 882 |
}; |
| 883 |
Vector<PhysicsLayerTileData> physics; |
| 884 |
|
| 885 |
#endif |
| 886 |
|
| 887 |
|
| 888 |
int terrain_set = -1; |
| 889 |
int terrain = -1; |
| 890 |
int terrain_peering_bits[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; |
| 891 |
|
| 892 |
#ifndef NAVIGATION_2D_DISABLED |
| 893 |
|
| 894 |
struct NavigationLayerTileData { |
| 895 |
Ref<NavigationPolygon> navigation_polygon; |
| 896 |
mutable HashMap<int, Ref<NavigationPolygon>> transformed_navigation_polygon; |
| 897 |
}; |
| 898 |
Vector<NavigationLayerTileData> navigation; |
| 899 |
#endif |
| 900 |
|
| 901 |
|
| 902 |
double probability = 1.0; |
| 903 |
|
| 904 |
|
| 905 |
Vector<Variant> custom_data; |
| 906 |
|
| 907 |
protected: |
| 908 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 909 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 910 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 911 |
static void _bind_methods(); |
| 912 |
|
| 913 |
#ifndef DISABLE_DEPRECATED |
| 914 |
#ifndef NAVIGATION_2D_DISABLED |
| 915 |
Ref<NavigationPolygon> _get_navigation_polygon_bind_compat_84660(int p_layer_id) const; |
| 916 |
#endif |
| 917 |
Ref<OccluderPolygon2D> _get_occluder_bind_compat_84660(int p_layer_id) const; |
| 918 |
|
| 919 |
static void _bind_compatibility_methods(); |
| 920 |
#endif |
| 921 |
|
| 922 |
public: |
| 923 |
|
| 924 |
void set_tile_set(const TileSet *p_tile_set); |
| 925 |
void notify_tile_data_properties_should_change(); |
| 926 |
void add_occlusion_layer(int p_index); |
| 927 |
void move_occlusion_layer(int p_from_index, int p_to_pos); |
| 928 |
void remove_occlusion_layer(int p_index); |
| 929 |
#ifndef PHYSICS_2D_DISABLED |
| 930 |
void add_physics_layer(int p_index); |
| 931 |
void move_physics_layer(int p_from_index, int p_to_pos); |
| 932 |
void remove_physics_layer(int p_index); |
| 933 |
#endif |
| 934 |
void add_terrain_set(int p_index); |
| 935 |
void move_terrain_set(int p_from_index, int p_to_pos); |
| 936 |
void remove_terrain_set(int p_index); |
| 937 |
void add_terrain(int p_terrain_set, int p_index); |
| 938 |
void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos); |
| 939 |
void remove_terrain(int p_terrain_set, int p_index); |
| 940 |
void add_navigation_layer(int p_index); |
| 941 |
void move_navigation_layer(int p_from_index, int p_to_pos); |
| 942 |
void remove_navigation_layer(int p_index); |
| 943 |
void add_custom_data_layer(int p_index); |
| 944 |
void move_custom_data_layer(int p_from_index, int p_to_pos); |
| 945 |
void remove_custom_data_layer(int p_index); |
| 946 |
void set_allow_transform(bool p_allow_transform); |
| 947 |
bool is_allowing_transform() const; |
| 948 |
|
| 949 |
|
| 950 |
TileData *duplicate(); |
| 951 |
|
| 952 |
|
| 953 |
void set_flip_h(bool p_flip_h); |
| 954 |
bool get_flip_h() const; |
| 955 |
void set_flip_v(bool p_flip_v); |
| 956 |
bool get_flip_v() const; |
| 957 |
void set_transpose(bool p_transpose); |
| 958 |
bool get_transpose() const; |
| 959 |
|
| 960 |
void set_texture_origin(Vector2i p_texture_origin); |
| 961 |
Vector2i get_texture_origin() const; |
| 962 |
void set_material(Ref<Material> p_material); |
| 963 |
Ref<Material> get_material() const; |
| 964 |
void set_modulate(Color p_modulate); |
| 965 |
Color get_modulate() const; |
| 966 |
void set_z_index(int p_z_index); |
| 967 |
int get_z_index() const; |
| 968 |
void set_y_sort_origin(int p_y_sort_origin); |
| 969 |
int get_y_sort_origin() const; |
| 970 |
|
| 971 |
#ifndef DISABLE_DEPRECATED |
| 972 |
void set_occluder(int p_layer_id, Ref<OccluderPolygon2D> p_occluder_polygon); |
| 973 |
Ref<OccluderPolygon2D> get_occluder(int p_layer_id, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const; |
| 974 |
#endif |
| 975 |
|
| 976 |
void set_occluder_polygons_count(int p_layer_id, int p_polygons_count); |
| 977 |
int get_occluder_polygons_count(int p_layer_id) const; |
| 978 |
void add_occluder_polygon(int p_layer_id); |
| 979 |
void remove_occluder_polygon(int p_layer_id, int p_polygon_index); |
| 980 |
void set_occluder_polygon(int p_layer_id, int p_polygon_index, const Ref<OccluderPolygon2D> &p_occluder_polygon); |
| 981 |
Ref<OccluderPolygon2D> get_occluder_polygon(int p_layer_id, int p_polygon_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const; |
| 982 |
|
| 983 |
#ifndef PHYSICS_2D_DISABLED |
| 984 |
|
| 985 |
void set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity); |
| 986 |
Vector2 get_constant_linear_velocity(int p_layer_id) const; |
| 987 |
void set_constant_angular_velocity(int p_layer_id, real_t p_velocity); |
| 988 |
real_t get_constant_angular_velocity(int p_layer_id) const; |
| 989 |
void set_collision_polygons_count(int p_layer_id, int p_shapes_count); |
| 990 |
int get_collision_polygons_count(int p_layer_id) const; |
| 991 |
void add_collision_polygon(int p_layer_id); |
| 992 |
void remove_collision_polygon(int p_layer_id, int p_polygon_index); |
| 993 |
void set_collision_polygon_points(int p_layer_id, int p_polygon_index, Vector<Vector2> p_polygon); |
| 994 |
Vector<Vector2> get_collision_polygon_points(int p_layer_id, int p_polygon_index) const; |
| 995 |
void set_collision_polygon_one_way(int p_layer_id, int p_polygon_index, bool p_one_way); |
| 996 |
bool is_collision_polygon_one_way(int p_layer_id, int p_polygon_index) const; |
| 997 |
void set_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index, float p_one_way_margin); |
| 998 |
float get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const; |
| 999 |
int get_collision_polygon_shapes_count(int p_layer_id, int p_polygon_index) const; |
| 1000 |
Ref<ConvexPolygonShape2D> get_collision_polygon_shape(int p_layer_id, int p_polygon_index, int shape_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const; |
| 1001 |
#endif |
| 1002 |
|
| 1003 |
|
| 1004 |
void set_terrain_set(int p_terrain_id); |
| 1005 |
int get_terrain_set() const; |
| 1006 |
void set_terrain(int p_terrain_id); |
| 1007 |
int get_terrain() const; |
| 1008 |
void set_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit, int p_terrain_id); |
| 1009 |
int get_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const; |
| 1010 |
bool is_valid_terrain_peering_bit(TileSet::CellNeighbor p_peering_bit) const; |
| 1011 |
|
| 1012 |
TileSet::TerrainsPattern get_terrains_pattern() const; |
| 1013 |
|
| 1014 |
#ifndef NAVIGATION_2D_DISABLED |
| 1015 |
|
| 1016 |
void set_navigation_polygon(int p_layer_id, Ref<NavigationPolygon> p_navigation_polygon); |
| 1017 |
Ref<NavigationPolygon> get_navigation_polygon(int p_layer_id, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const; |
| 1018 |
#endif |
| 1019 |
|
| 1020 |
|
| 1021 |
void set_probability(float p_probability); |
| 1022 |
float get_probability() const; |
| 1023 |
|
| 1024 |
|
| 1025 |
void set_custom_data(String p_layer_name, Variant p_value); |
| 1026 |
Variant get_custom_data(String p_layer_name) const; |
| 1027 |
bool has_custom_data(const String &p_layer_name) const; |
| 1028 |
void set_custom_data_by_layer_id(int p_layer_id, Variant p_value); |
| 1029 |
Variant get_custom_data_by_layer_id(int p_layer_id) const; |
| 1030 |
|
| 1031 |
|
| 1032 |
static PackedVector2Array get_transformed_vertices(const PackedVector2Array &p_vertices, bool p_flip_h, bool p_flip_v, bool p_transpose, bool p_preserve_winding_order = false); |
| 1033 |
}; |
| 1034 |
|
| 1035 |
VARIANT_ENUM_CAST(TileSet::CellNeighbor); |
| 1036 |
VARIANT_ENUM_CAST(TileSet::TerrainMode); |
| 1037 |
VARIANT_ENUM_CAST(TileSet::TileShape); |
| 1038 |
VARIANT_ENUM_CAST(TileSet::TileLayout); |
| 1039 |
VARIANT_ENUM_CAST(TileSet::TileOffsetAxis); |
| 1040 |
|
| 1041 |
VARIANT_ENUM_CAST(TileSetAtlasSource::TileAnimationMode); |