diff --git a/scenes/tilemap/tilemap.gd b/scenes/tilemap/tilemap.gd index 15ef85c1..7227b74a 100644 --- a/scenes/tilemap/tilemap.gd +++ b/scenes/tilemap/tilemap.gd @@ -156,7 +156,7 @@ func on_data_received(coords: Dictionary) -> void: func _on_resize() -> void: - var center = $canvas.size / 2.0 + var center: Vector2 = $canvas.size / 2.0 $canvas/spr_mask.position = center $canvas/spr_mask.scale = $canvas.size / default_size @@ -165,7 +165,7 @@ func _on_resize() -> void: func add_mark_from_screen_pos(id: int, scr_xy: Vector2, mark: Node) -> bool: if _marks.has(id): return false - var wrld_pos = screen_to_world(_xyz, scr_xy) + var wrld_pos: Vector2 = screen_to_world(_xyz, scr_xy) _marks[id] = { 'position': wrld_pos, 'mark': mark, 'gap_size': 0.0 } add_child(mark) return true @@ -184,7 +184,7 @@ func delete_mark(id: int) -> bool: func add_mark_from_lon_lat(id: int, lon: float, lat: float, mark: Node, gap_size: float = 32) -> bool: if _marks.has(id): return false - var wrld_pos = lonlat_to_world(lon, lat) + var wrld_pos: Vector2 = lonlat_to_world(lon, lat) _marks[id] = {'position': wrld_pos, 'mark': mark, 'gap_size': gap_size} add_child(mark) queue_redraw() @@ -273,30 +273,30 @@ func set_zoom(zoom: float, pivot: Vector2) -> void: func _draw() -> void: # Рисование плиток - var z = min(max_zoom_level, _xyz.z) - var t1 = screen_to_tile(Vector2(0, 0), z) - var t2 = screen_to_tile($canvas.size, z) + Vector2(1, 1) + var z: float = min(max_zoom_level, _xyz.z) + var t1: = screen_to_tile(Vector2(0, 0), z) + var t2: = screen_to_tile($canvas.size, z) + Vector2(1, 1) is_out_border1 = true is_out_border2 = true for tx in range(t1.x, t2.x): for ty in range(t1.y, t2.y): _draw_tile(tx, ty, z) # Рисование отметок - var n = pow(2, z) - var dx = n * tile_width + var n: = pow(2, z) + var dx: = n * tile_width var c: Vector2 = $canvas.size / 2.0 - var r = c.length() + var r: float = c.length() visible_marks_count = 0 for dot in _marks.values(): - var scr_pos = world_to_screen(dot.position) + var scr_pos: Vector2 = world_to_screen(dot.position) scr_pos.x = posmod(scr_pos.x, dx) dot.mark.position = scr_pos dot.mark.visible = is_mark_visible(dot) dot.mark.visible = c.distance_to(scr_pos) < (r - dot.gap_size) visible_marks_count += int(dot.mark.visible) # Рисование границ - var p1 = $canvas.position - var p2 = $canvas.size / Vector2(1, 20) + var p1: Vector2 = $canvas.position + var p2: Vector2 = $canvas.size / Vector2(1, 20) if is_out_border1 and _dragging: draw_texture_rect(border1, Rect2(p1, p2), false, Color.WHITE, false) p1.y = p1.y + $canvas.size.y - p2.y @@ -455,74 +455,74 @@ func _draw_tile(tx: int, ty: int, z: float) -> void: ## convert lon/lat to world coords func lonlat_to_world(lon: float, lat: float) -> Vector2: - var x = lon / 180.0 - var latsin = sin(deg_to_rad(lat) * sign(lat)) - var y = (sign(lat) * (log((1.0 + latsin) / (1.0 - latsin)) / 2.0)) / PI + var x: = lon / 180.0 + var latsin: = sin(deg_to_rad(lat) * sign(lat)) + var y: float = (sign(lat) * (log((1.0 + latsin) / (1.0 - latsin)) / 2.0)) / PI return Vector2(x, y) ## convert lon/lat to screen coords func lonlat_to_screen(lon: float, lat: float) -> Vector2: - var w = lonlat_to_world(lon, lat) + var w: Vector2 = lonlat_to_world(lon, lat) return world_to_screen(w) ## convert lon/lat to tile coords func lonlat_to_tile(lon: float, lat: float, z: float) -> Vector2: - var w = lonlat_to_world(lon,lat) + var w: Vector2 = lonlat_to_world(lon,lat) return world_to_tile(w.x, w.y, z) ## convert world coords to lon/lat func world_to_lonlat(wx: float, wy: float) -> Vector2: - var lon = wx * 180.0 - var lat = rad_to_deg(atan(sinh(wy * PI))) + var lon: float = wx * 180.0 + var lat: float = rad_to_deg(atan(sinh(wy * PI))) return Vector2(lon, lat) ## convert screen coords to lon/lat func screen_to_lonlat(scr_xy: Vector2) -> Vector2: - var w = screen_to_world(_xyz, scr_xy) + var w: Vector2 = screen_to_world(_xyz, scr_xy) return world_to_lonlat(w.x, w.y) ## convert tile coords to lon/lat func tile_to_lonlat(tx: float, ty: float, tz: float) -> Vector2: - var w = tile_to_world(tx, ty, tz) + var w: Vector2 = tile_to_world(tx, ty, tz) return world_to_lonlat(w.x, w.y) ## convert screen coords to world coords func screen_to_world(xyz: Vector3, s: Vector2) -> Vector2: - var n = pow(2.0, xyz.z) - var span_w = n * tile_width - var span_h = n * tile_height - var px = s.x - $canvas.size.x / 2 + span_w / 2 - var py = s.y - $canvas.size.y / 2 + span_h / 2 - var xr = px / span_w - var yr = py / span_h - var x = (xr * 2.0 - 1.0) + xyz.x - var y = ((-yr * 2.0) + 1.0) + xyz.y + var n: float = pow(2.0, xyz.z) + var span_w: float = n * tile_width + var span_h: float = n * tile_height + var px: float = s.x - $canvas.size.x / 2 + span_w / 2 + var py: float = s.y - $canvas.size.y / 2 + span_h / 2 + var xr: float = px / span_w + var yr: float = py / span_h + var x: float = (xr * 2.0 - 1.0) + xyz.x + var y: float = ((-yr * 2.0) + 1.0) + xyz.y return Vector2(x, y) ## convert screen coords to tile coords func screen_to_tile(scr_xy: Vector2, z: float) -> Vector2: - var world = screen_to_world(_xyz, scr_xy) + var world: Vector2 = screen_to_world(_xyz, scr_xy) return world_to_tile(world.x, world.y, z) ## convert tile coords to screen coords func tile_to_screen(tx: float, ty: float, tz: float) -> Vector2: - var w = tile_to_world(tx, ty, tz) + var w: Vector2 = tile_to_world(tx, ty, tz) return world_to_screen(w) ## convert tile coords to world coords func tile_to_world(tx: float, ty: float, tz: float) -> Vector2: - var n = pow(2.0, floor(tz)) - var x = (tx / n) * 2.0 - 1.0 - var y = -((ty / n) * 2.0 - 1.0) + var n: float = pow(2.0, floor(tz)) + var x: float = (tx / n) * 2.0 - 1.0 + var y: float = -((ty / n) * 2.0 - 1.0) return Vector2(x, y) @@ -551,7 +551,7 @@ func xyz_to_idx(x: float, y: float, z: float) -> int: func get_tile(x: int, y: int, z: int) -> Tile: - var n = pow(2, z) + var n: float = pow(2, z) if x >= 0: x %= int(n) else: @@ -561,7 +561,7 @@ func get_tile(x: int, y: int, z: int) -> Tile: if z < 0 or y < 0 or y >= n: return null - var idx = xyz_to_idx(x, y, z) + var idx: int = xyz_to_idx(x, y, z) var req: = get_node_or_null(NodePath(TILE_REQUEST_NAME % idx)) if req: @@ -594,12 +594,12 @@ func get_tile(x: int, y: int, z: int) -> Tile: func lonlat_to_dms(lon: float, lat: float) -> String: - var pf = 'N' if lat >= 0 else 'S' + var pf: String = 'N' if lat >= 0 else 'S' lat = abs(lat) - var deg = floor(lat) - var minute = (lat - deg) * 60 - var second = (minute - floor(minute)) * 60 - var text = ('%02d' % deg) + ('%02d' % floor(minute)) + ('%02d' % floor(second)) + pf + ' ' + var deg: float = floor(lat) + var minute: float = (lat - deg) * 60 + var second: float = (minute - floor(minute)) * 60 + var text: String = ('%02d' % deg) + ('%02d' % floor(minute)) + ('%02d' % floor(second)) + pf + ' ' pf = 'E' if lon >= 0 else 'W' lon = abs(lon) @@ -679,7 +679,7 @@ func clear() -> void: func set_coordinates(lon: float, lat: float) -> void: var anim: Animation = $player.get_animation('goto') - var new_pos = lonlat_to_world(lon, lat) + var new_pos: Vector2 = lonlat_to_world(lon, lat) anim.track_insert_key(0, 0, _xyz.x) anim.track_insert_key(1, 0, _xyz.y) anim.track_insert_key(0, animation_time, new_pos.x)