Browse Source

Merge pull request #39976 from aaronfranke/tilemap-vec2i

Update TileMap to use Vector2i
Rémi Verschelde 4 years ago
parent
commit
a3dd18b12e
4 changed files with 11 additions and 5 deletions
  1. 4 1
      doc/classes/TileMap.xml
  2. 3 0
      doc/classes/TileSet.xml
  3. 3 3
      scene/2d/tile_map.cpp
  4. 1 1
      scene/2d/tile_map.h

+ 4 - 1
doc/classes/TileMap.xml

@@ -90,9 +90,10 @@
 		<method name="map_to_world" qualifiers="const">
 			<return type="Vector2">
 			</return>
-			<argument index="0" name="map_position" type="Vector2">
+			<argument index="0" name="map_position" type="Vector2i">
 			</argument>
 			<description>
+				Returns the local position corresponding to the given tilemap (grid-based) coordinates.
 			</description>
 		</method>
 		<method name="set_cell">
@@ -107,6 +108,7 @@
 			<argument index="3" name="alternative_tile" type="int" default="-1">
 			</argument>
 			<description>
+				Sets the tile index for the cell given by a Vector2i.
 			</description>
 		</method>
 		<method name="update_dirty_quadrants">
@@ -137,6 +139,7 @@
 	<signals>
 		<signal name="changed">
 			<description>
+				Emitted when the [TileSet] of this TileMap changes.
 			</description>
 		</signal>
 	</signals>

+ 3 - 0
doc/classes/TileSet.xml

@@ -298,12 +298,15 @@
 	</members>
 	<constants>
 		<constant name="TILE_SHAPE_SQUARE" value="0" enum="TileShape">
+			Orthogonal orientation mode.
 		</constant>
 		<constant name="TILE_SHAPE_ISOMETRIC" value="1" enum="TileShape">
+			Isometric orientation mode.
 		</constant>
 		<constant name="TILE_SHAPE_HALF_OFFSET_SQUARE" value="2" enum="TileShape">
 		</constant>
 		<constant name="TILE_SHAPE_HEXAGON" value="3" enum="TileShape">
+			Hexagon orientation mode.
 		</constant>
 		<constant name="TILE_LAYOUT_STACKED" value="0" enum="TileLayout">
 		</constant>

+ 3 - 3
scene/2d/tile_map.cpp

@@ -902,7 +902,7 @@ void TileMap::_get_property_list(List<PropertyInfo> *p_list) const {
 	p_list->push_back(p);
 }
 
-Vector2 TileMap::map_to_world(const Vector2 &p_pos) const {
+Vector2 TileMap::map_to_world(const Vector2i &p_pos) const {
 	// SHOULD RETURN THE CENTER OF THE TILE
 	ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2());
 
@@ -980,7 +980,7 @@ Vector2 TileMap::map_to_world(const Vector2 &p_pos) const {
 }
 
 Vector2i TileMap::world_to_map(const Vector2 &p_pos) const {
-	ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2());
+	ERR_FAIL_COND_V(!tile_set.is_valid(), Vector2i());
 
 	Vector2 ret = p_pos;
 	ret /= tile_set->get_tile_size();
@@ -1143,7 +1143,7 @@ Vector2i TileMap::world_to_map(const Vector2 &p_pos) const {
 	} else {
 		ret = (ret + Vector2(0.00005, 0.00005)).floor();
 	}
-	return ret;
+	return Vector2i(ret);
 }
 
 bool TileMap::is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const {

+ 1 - 1
scene/2d/tile_map.h

@@ -264,7 +264,7 @@ public:
 
 	void update_dirty_quadrants();
 
-	Vector2 map_to_world(const Vector2 &p_pos) const;
+	Vector2 map_to_world(const Vector2i &p_pos) const;
 	Vector2i world_to_map(const Vector2 &p_pos) const;
 
 	bool is_existing_neighbor(TileSet::CellNeighbor p_cell_neighbor) const;