Skip to content

Commit

Permalink
Added missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrlabs committed Aug 28, 2024
1 parent f53c840 commit 87024b2
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 94 deletions.
12 changes: 6 additions & 6 deletions lorien/BrushStroke/BrushStroke.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ func remove_all_points() -> void:
# -------------------------------------------------------------------------------------------------
func enable_collider(enable: bool) -> void:
# Remove current collider
var collider = get_node_or_null(COLLIDER_NODE_NAME)
if collider != null:
remove_child(collider)
collider.queue_free()
var body: StaticBody2D = get_node_or_null(COLLIDER_NODE_NAME)
if body != null:
remove_child(body)
body.queue_free()

# Create new collider
if enable:
var body := StaticBody2D.new()
body = StaticBody2D.new()
body.name = COLLIDER_NODE_NAME
var idx := 0
while idx < points.size()-1:
Expand Down Expand Up @@ -120,7 +120,7 @@ func refresh() -> void:
var top_left := MAX_VECTOR2
var bottom_right := MIN_VECTOR2
var curve_step: float = 1.0 / pressures.size()
for point in points:
for point: Vector2 in points:
# Add the point
_line2d.add_point(point)
var pressure: float = pressures[p_idx]
Expand Down
2 changes: 1 addition & 1 deletion lorien/BrushStroke/BrushStrokeOptimizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func optimize(s: BrushStroke) -> void:
filtered_pressures.append(s.pressures.front())

var previous_angle := 0.0
for i in range(1, s.points.size()):
for i: int in range(1, s.points.size()):
var prev_point := s.points[i-1]
var point := s.points[i]
var pressure = s.pressures[i]
Expand Down
6 changes: 3 additions & 3 deletions lorien/InfiniteCanvas/PanZoomCamera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func _do_pan(pan: Vector2) -> void:

# -------------------------------------------------------------------------------------------------
func _do_zoom_scroll(step: int) -> void:
var new_zoom = _to_nearest_zoom_step(_current_zoom_level) * pow(ZOOM_INCREMENT, step)
var new_zoom := _to_nearest_zoom_step(_current_zoom_level) * pow(ZOOM_INCREMENT, step)
_zoom_canvas(new_zoom, get_local_mouse_position())

# -------------------------------------------------------------------------------------------------
Expand All @@ -86,8 +86,8 @@ func _zoom_canvas(target_zoom: float, anchor: Vector2) -> void:
return

# Pan canvas to keep content fixed under the cursor
var zoom_center = anchor - offset
var ratio = _current_zoom_level / target_zoom - 1.0
var zoom_center := anchor - offset
var ratio := _current_zoom_level / target_zoom - 1.0
offset -= zoom_center * ratio

_current_zoom_level = target_zoom
Expand Down
4 changes: 2 additions & 2 deletions lorien/InfiniteCanvas/Tools/BrushTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func _process(delta: float) -> void:
Settings.GENERAL_PRESSURE_SENSITIVITY, Config.DEFAULT_PRESSURE_SENSITIVITY
)

var point_pressure = pressure_curve.sample(_current_pressure) * sensitivity
var point_pressure := pressure_curve.sample(_current_pressure) * sensitivity
if _first_point:
point_pressure *= 1.4
_first_point = false
Expand All @@ -72,7 +72,7 @@ func _is_stroke_a_dot() -> bool:
return true

if stroke.points.size() == 2:
var dist: float = stroke.points[0].distance_to(stroke.points[1])
var dist := stroke.points[0].distance_to(stroke.points[1])
if dist <= DOT_MAX_DISTANCE_THRESHOLD:
return true

Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/CanvasTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func add_subdivided_line(from: Vector2, to: Vector2, pressure: float) -> void:
if do_subdiv:
var subdiv_length := dist * SUBDIVISION_PERCENT
var subdiv_count := int(dist / subdiv_length)
for i in subdiv_count:
for i: int in subdiv_count:
var point: Vector2 = from + dir*subdiv_length*i
add_stroke_point(point, pressure)

Expand Down
11 changes: 6 additions & 5 deletions lorien/InfiniteCanvas/Tools/CircleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const STEP_STATIC := 4
var _start_position_top_left: Vector2

# -------------------------------------------------------------------------------------------------
var sin_arr : Array
var cos_arr : Array
var sin_arr : Array[float]
var cos_arr : Array[float]

# -------------------------------------------------------------------------------------------------
func _init():
sin_arr.resize(360)
cos_arr.resize(360)
for i in 360:
for i: int in 360:
sin_arr[i] = sin(deg_to_rad(i))
cos_arr[i] = cos(deg_to_rad(i))

Expand Down Expand Up @@ -58,7 +59,7 @@ func _make_ellipse(pressure: float, step: int, should_draw_circle: bool) -> void
r2 = r1

var dir := (_cursor.global_position -_start_position_top_left);
var center : Vector2
var center: Vector2

if dir.x >= 0 && dir.y >= 0:
center = _start_position_top_left + Vector2(r1, r2)
Expand All @@ -69,7 +70,7 @@ func _make_ellipse(pressure: float, step: int, should_draw_circle: bool) -> void
else:
center = _start_position_top_left + Vector2(r1, -r2)

for i in range(0, 360, step):
for i: int in range(0, 360, step):
var point := Vector2(
center.x + r1 * sin_arr[i],
center.y + r2 * cos_arr[i]
Expand Down
16 changes: 8 additions & 8 deletions lorien/InfiniteCanvas/Tools/EraserTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func _stroke_intersects_circle(stroke: BrushStroke, circle_position: Vector2) ->

# Check every segment of the brush stroke for an intersection with the curser
var eraser_brush_radius := float(_cursor._brush_size) * 0.5
for i in stroke.points.size() - 1:
var pressure: float = float(stroke.pressures[i] + stroke.pressures[i+1]) / 2.0
var segment_radius: float = (pressure / float(BrushStroke.MAX_PRESSURE_VALUE)) * float(stroke.size) * 0.5
var radius: float = segment_radius + eraser_brush_radius
var start = stroke.position + stroke.points[i]
var end = stroke.position + stroke.points[i+1]
for i: int in stroke.points.size() - 1:
var pressure := float(stroke.pressures[i] + stroke.pressures[i+1]) / 2.0
var segment_radius := (pressure / float(BrushStroke.MAX_PRESSURE_VALUE)) * float(stroke.size) * 0.5
var radius := segment_radius + eraser_brush_radius
var start := stroke.position + stroke.points[i]
var end := stroke.position + stroke.points[i+1]
if Geometry2D.segment_intersects_circle(start, end, circle_position, radius*OVERLAP_THRESHOLD) >= 0:
return true
return false

# -------------------------------------------------------------------------------------------------
func _remove_stroke(brush_position: Vector2) -> void:
for stroke in _canvas.get_strokes_in_camera_frustrum():
for stroke: BrushStroke in _canvas.get_strokes_in_camera_frustrum():
if !_removed_strokes.has(stroke) && _stroke_intersects_circle(stroke, brush_position):
_removed_strokes.append(stroke)

Expand All @@ -59,7 +59,7 @@ func _add_undoredo_action_for_erased_strokes() -> void:
var project: Project = ProjectManager.get_active_project()
if _removed_strokes.size():
project.undo_redo.create_action("Erase Stroke")
for stroke in _removed_strokes:
for stroke: BrushStroke in _removed_strokes:
_removed_strokes.erase(stroke)
project.undo_redo.add_do_method(Callable(_canvas, "_do_delete_stroke").bind(stroke))
project.undo_redo.add_undo_method(Callable(_canvas, "_undo_delete_stroke").bind(stroke))
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/LineTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func tool_event(event: InputEvent) -> void:

# -------------------------------------------------------------------------------------------------
func _add_point_at_mouse_pos(pressure: float) -> Vector2:
var brush_position: Vector2 = _cursor.global_position
var brush_position := _cursor.global_position
pressure = pressure_curve.sample(pressure)
add_stroke_point(brush_position, pressure)
return brush_position
Expand Down
28 changes: 14 additions & 14 deletions lorien/InfiniteCanvas/Tools/SelectionTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func tool_event(event: InputEvent) -> void:
# ------------------------------------------------------------------------------------------------
func compute_selection(start_pos: Vector2, end_pos: Vector2) -> void:
var selection_rect : Rect2 = Utils.calculate_rect(start_pos, end_pos)
for stroke in _canvas.get_strokes_in_camera_frustrum():
for stroke: BrushStroke in _canvas.get_strokes_in_camera_frustrum():
var bounding_box: Rect2 = _bounding_box_cache[stroke]
if selection_rect.intersects(bounding_box):
for point in stroke.points:
for point: Vector2 in stroke.points:
var abs_point: Vector2 = stroke.position + point
if selection_rect.has_point(abs_point):
_set_stroke_selected(stroke)
Expand All @@ -139,7 +139,7 @@ func _paste_strokes(strokes: Array) -> void:
var top_left := Vector2(MAX_FLOAT, MAX_FLOAT)
var bottom_right := Vector2(MIN_FLOAT, MIN_FLOAT)

for stroke in strokes:
for stroke: BrushStroke in strokes:
top_left.x = min(top_left.x, stroke.top_left_pos.x + stroke.position.x)
top_left.y = min(top_left.y, stroke.top_left_pos.y + stroke.position.y)
bottom_right.x = max(bottom_right.x, stroke.bottom_right_pos.x + stroke.position.x)
Expand All @@ -148,7 +148,7 @@ func _paste_strokes(strokes: Array) -> void:

# Duplicate the strokes
var duplicates := []
for stroke in strokes:
for stroke: BrushStroke in strokes:
var dup := _duplicate_stroke(stroke, offset)
dup.add_to_group(GROUP_SELECTED_STROKES)
dup.modulate = Config.DEFAULT_SELECTION_COLOR
Expand All @@ -164,13 +164,13 @@ func _duplicate_stroke(stroke: BrushStroke, offset: Vector2) -> BrushStroke:
dup.size = stroke.size
dup.color = stroke.color
dup.pressures = stroke.pressures.duplicate()
for point in stroke.points:
for point: Vector2 in stroke.points:
dup.points.append(point + offset)
return dup

# ------------------------------------------------------------------------------------------------
func _modify_strokes_colors(strokes: Array[BrushStroke], color: Color) -> void:
for stroke in strokes:
for stroke: BrushStroke in strokes:
stroke.color = color

# ------------------------------------------------------------------------------------------------
Expand All @@ -192,34 +192,34 @@ func _set_stroke_selected(stroke: BrushStroke) -> void:
func _add_undoredo_action_for_moved_strokes() -> void:
var project: Project = ProjectManager.get_active_project()
project.undo_redo.create_action("Move Strokes")
for stroke in _stroke_positions_before_move.keys():
for stroke: BrushStroke in _stroke_positions_before_move.keys():
project.undo_redo.add_do_property(stroke, "global_position", stroke.global_position)
project.undo_redo.add_undo_property(stroke, "global_position", _stroke_positions_before_move[stroke])
project.undo_redo.commit_action()
project.dirty = true

# -------------------------------------------------------------------------------------------------
func _offset_selected_strokes(offset: Vector2) -> void:
for stroke in get_selected_strokes():
for stroke: BrushStroke in get_selected_strokes():
stroke.set_meta(META_OFFSET, stroke.position - offset)

# -------------------------------------------------------------------------------------------------
func _move_selected_strokes() -> void:
for stroke in get_selected_strokes():
for stroke: BrushStroke in get_selected_strokes():
stroke.global_position = stroke.get_meta(META_OFFSET) + _cursor.global_position

# ------------------------------------------------------------------------------------------------
func _commit_strokes_under_selection_rectangle() -> void:
for stroke in get_tree().get_nodes_in_group(GROUP_STROKES_IN_SELECTION_RECTANGLE):
for stroke: BrushStroke in get_tree().get_nodes_in_group(GROUP_STROKES_IN_SELECTION_RECTANGLE):
stroke.remove_from_group(GROUP_STROKES_IN_SELECTION_RECTANGLE)
stroke.add_to_group(GROUP_SELECTED_STROKES)

# ------------------------------------------------------------------------------------------------
func _deselect_marked_strokes() -> void:
for s in get_tree().get_nodes_in_group(GROUP_MARKED_FOR_DESELECTION):
s.remove_from_group(GROUP_MARKED_FOR_DESELECTION)
s.remove_from_group(GROUP_SELECTED_STROKES)
s.modulate = Color.WHITE
for stroke: BrushStroke in get_tree().get_nodes_in_group(GROUP_MARKED_FOR_DESELECTION):
stroke.remove_from_group(GROUP_MARKED_FOR_DESELECTION)
stroke.remove_from_group(GROUP_SELECTED_STROKES)
stroke.modulate = Color.WHITE

# ------------------------------------------------------------------------------------------------
func deselect_all_strokes() -> void:
Expand Down
6 changes: 3 additions & 3 deletions lorien/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func _ready():
_create_active_default_project()

# Open project passed as CLI argument
for arg in OS.get_cmdline_args():
for arg: String in OS.get_cmdline_args():
if Utils.is_valid_lorien_file(arg):
_on_open_project(arg)

Expand Down Expand Up @@ -184,7 +184,7 @@ func _toggle_player() -> void:
func _save_state() -> void:
# Open projects
var open_projects: Array[String]
for project in ProjectManager.get_open_projects():
for project: Project in ProjectManager.get_open_projects():
open_projects.append(project.filepath)
StatePersistence.set_value(StatePersistence.OPEN_PROJECTS, open_projects)

Expand Down Expand Up @@ -232,7 +232,7 @@ func _toggle_zen_mode() -> void:

# -------------------------------------------------------------------------------------------------
func _on_files_dropped(files: PackedStringArray) -> void:
for file in files:
for file: String in files:
if Utils.is_valid_lorien_file(file):
_on_open_project(file)

Expand Down
11 changes: 5 additions & 6 deletions lorien/Misc/I18nParser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class ParseResult:

# -------------------------------------------------------------------------------------------------
func load_files() -> ParseResult:
var result = ParseResult.new()
for f in _get_i18n_files():
var result := ParseResult.new()
for f: String in _get_i18n_files():
var file := FileAccess.open(f, FileAccess.READ)
if file != null:
var position := Translation.new()
Expand All @@ -46,8 +46,8 @@ func load_files() -> ParseResult:

var split_index := line.find(" ")
if split_index >= 0:
var key: String = line.substr(0, split_index)
var value: String = line.substr(split_index, line.length() - 1)
var key := line.substr(0, split_index)
var value := line.substr(split_index, line.length() - 1)

# Remove inline comments
var comment_index := value.find("#")
Expand All @@ -74,9 +74,8 @@ func _i18n_filter_shortcut_list(action_name: String) -> String:
return "INVALID_ACTION %s" % action_name

var keybindings := PackedStringArray()
for e in InputMap.action_get_events(action_name):
for e: InputEvent in InputMap.action_get_events(action_name):
if e is InputEventKey:
e = e as InputEventKey
keybindings.append(OS.get_keycode_string(e.get_keycode_with_modifiers()))

if len(keybindings) == 0:
Expand Down
4 changes: 2 additions & 2 deletions lorien/Misc/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func reload_locales():

# -------------------------------------------------------------------------------------------------
func _load_settings() -> int:
var err = _config_file.load(Config.CONFIG_PATH)
var err := _config_file.load(Config.CONFIG_PATH)
if err == ERR_FILE_NOT_FOUND:
pass
elif err != OK:
Expand All @@ -61,7 +61,7 @@ func _load_settings() -> int:

# -------------------------------------------------------------------------------------------------
func _save_settings() -> int:
var err = _config_file.save(Config.CONFIG_PATH)
var err := _config_file.save(Config.CONFIG_PATH)
if err == ERR_FILE_NOT_FOUND:
pass
elif err != OK:
Expand Down
4 changes: 2 additions & 2 deletions lorien/Misc/StatePersistence.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func _ready():

# -------------------------------------------------------------------------------------------------
func _load_state() -> int:
var err = _config_file.load(Config.STATE_PATH)
var err := _config_file.load(Config.STATE_PATH)
if err == ERR_FILE_NOT_FOUND:
pass
elif err != OK:
Expand All @@ -27,7 +27,7 @@ func _load_state() -> int:

# -------------------------------------------------------------------------------------------------
func _save_state() -> int:
var err = _config_file.save(Config.STATE_PATH)
var err := _config_file.save(Config.STATE_PATH)
if err == ERR_FILE_NOT_FOUND:
pass
elif err != OK:
Expand Down
6 changes: 3 additions & 3 deletions lorien/Misc/SvgExporter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func export_svg(strokes: Array[BrushStroke], background: Color, path: String) ->
# Calculate total canvas dimensions
var max_dim := BrushStroke.MIN_VECTOR2
var min_dim := BrushStroke.MAX_VECTOR2
for stroke in strokes:
for stroke: BrushStroke in strokes:
min_dim.x = min(min_dim.x, stroke.top_left_pos.x + stroke.global_position.x)
min_dim.y = min(min_dim.y, stroke.top_left_pos.y + stroke.global_position.y)
max_dim.x = max(max_dim.x, stroke.bottom_right_pos.x + stroke.global_position.x)
Expand All @@ -33,7 +33,7 @@ func export_svg(strokes: Array[BrushStroke], background: Color, path: String) ->
# Write svg to file
_svg_start(file, origin, size)
_svg_rect(file, origin, size, background)
for stroke in strokes:
for stroke: BrushStroke in strokes:
_svg_polyline(file, stroke)
_svg_end(file)

Expand Down Expand Up @@ -63,7 +63,7 @@ func _svg_polyline(file: FileAccess, stroke: BrushStroke) -> void:
file.store_string("<polyline points=\"")
var idx := 0
var point_count := stroke.points.size()
for point in stroke.points:
for point: Vector2 in stroke.points:
point += stroke.global_position
if idx < point_count-1:
file.store_string("%.1f %.1f," % [point.x, point.y])
Expand Down
Loading

2 comments on commit 87024b2

@SamTheBlow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mbrlabs, I was browsing this project again for fun and saw this commit. Did you know that there's a project setting to warn you of untyped declarations? In the project settings (with advanced settings enabled) it's in Debug -> GDScript -> Warnings -> "Untyped Declaration". It shows you everything that's still not statically typed, and because it's a project setting, other devs receive the warnings too. Hopefully you find this info useful!

@mbrlabs
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, no i didn't know that. I'm going to enable it next time. Thanks!

Please sign in to comment.