Skip to content

Commit

Permalink
Added more missing types & enabled missing type warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrlabs committed Aug 29, 2024
1 parent 1f65640 commit a07a713
Show file tree
Hide file tree
Showing 34 changed files with 161 additions and 156 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- Setting to disable pressure sensitivity and always draw with a constant brush width
- Quit shortcut (CTRL+Q by default)
- Translations: Ukrainian, Arabic

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions lorien/BrushStroke/BrushStroke.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ var top_left_pos: Vector2
var bottom_right_pos: Vector2

# ------------------------------------------------------------------------------------------------
func _ready():
func _ready() -> void:
_line2d.width_curve = Curve.new()
_line2d.texture = BrushStrokeTexture.texture

_visibility_notifier.screen_entered.connect(func(): add_to_group(GROUP_ONSCREEN))
_visibility_notifier.screen_exited.connect(func(): remove_from_group(GROUP_ONSCREEN))
_visibility_notifier.screen_entered.connect(func() -> void: add_to_group(GROUP_ONSCREEN))
_visibility_notifier.screen_exited.connect(func() -> void: remove_from_group(GROUP_ONSCREEN))

var rounding_mode: int = Settings.get_rendering_value(
Settings.RENDERING_BRUSH_ROUNDING, Config.DEFAULT_BRUSH_ROUNDING
Expand Down
2 changes: 1 addition & 1 deletion lorien/BrushStroke/BrushStrokeOptimizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func optimize(s: BrushStroke) -> void:
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]
var pressure := s.pressures[i]

# Distance between 2 points must be greater than x
var distance := prev_point.distance_to(point)
Expand Down
8 changes: 4 additions & 4 deletions lorien/BrushStroke/BrushStrokeTexture.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func _ready() -> void:
# The texture must be square for mipmaps to work correctly. The texture's in-memory size is still
# pretty low (less than 200 KB), so this should not cause any performance problems.
var data := PackedByteArray()
for mipmap in [256, 128, 64, 32, 16, 8, 4, 2, 1]:
for y in mipmap:
for x in mipmap:
for mipmap: int in [256, 128, 64, 32, 16, 8, 4, 2, 1]:
for y: int in mipmap:
for x: int in mipmap:
# White. If you need a different color for the Line2D, change the `default_color` property.
data.push_back(255)

Expand All @@ -47,5 +47,5 @@ func _ready() -> void:
# Average of 0 and 255 (there is only one pixel).
data.push_back(128)

var image = Image.create_from_data(256, 256, true, Image.FORMAT_LA8, data)
var image := Image.create_from_data(256, 256, true, Image.FORMAT_LA8, data)
texture = ImageTexture.create_from_image(image)
4 changes: 2 additions & 2 deletions lorien/InfiniteCanvas/Cursor/BaseCursor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ var _pressure := 1.0
@onready var _camera: Camera2D = get_viewport().get_node("Camera2D")

# -------------------------------------------------------------------------------------------------
func _input(event):
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
update_position()

# -------------------------------------------------------------------------------------------------
func update_position():
func update_position() -> void:
global_position = _camera.get_global_mouse_position()

# -------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Cursor/BrushCursor/BrushCursor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class_name BrushCursor
extends BaseCursor

# -------------------------------------------------------------------------------------------------
func _draw():
func _draw() -> void:
var radius := _brush_size/2.0
draw_arc(Vector2.ZERO, radius*_pressure, 0, PI*2, 32, Color.BLACK, 0.5, true)
#draw_circle(Vector2.ZERO, radius*0.08, Color.BLACK)
Expand Down
22 changes: 12 additions & 10 deletions lorien/InfiniteCanvas/InfiniteCanvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ var _player: Player = null
var _player_enabled := false

# -------------------------------------------------------------------------------------------------
func _ready():
func _ready() -> void:
_optimizer = BrushStrokeOptimizer.new()
_brush_size = Settings.get_general_value(Settings.GENERAL_DEFAULT_BRUSH_SIZE, Config.DEFAULT_BRUSH_SIZE)
set_background_color(Settings.get_appearance_value(Settings.APPEARANCE_CANVAS_COLOR, Config.DEFAULT_CANVAS_COLOR))
_active_tool._on_brush_size_changed(_brush_size)
_active_tool.enabled = false

var constant_pressure = Settings.get_general_value(Settings.GENERAL_CONSTANT_PRESSURE, Config.DEFAULT_CONSTANT_PRESSURE)
var constant_pressure: bool = Settings.get_general_value(
Settings.GENERAL_CONSTANT_PRESSURE, Config.DEFAULT_CONSTANT_PRESSURE)

if constant_pressure:
_brush_tool.pressure_curve = _constant_pressure_curve
else:
Expand Down Expand Up @@ -141,15 +143,15 @@ func set_background_color(color: Color) -> void:
_grid.set_canvas_color(_background_color)

# -------------------------------------------------------------------------------------------------
func enable_player(enable: bool) -> void:
_player_enabled = enable
func enable_player(e: bool) -> void:
_player_enabled = e

# colliders
for stroke in _strokes_parent.get_children():
stroke.enable_collider(enable)
stroke.enable_collider(e)

# player
if enable:
if e:
_player = PLAYER.instantiate()
_player.reset(_active_tool.get_cursor().global_position)
_viewport.add_child(_player)
Expand Down Expand Up @@ -270,7 +272,7 @@ func end_stroke() -> void:
func add_strokes(strokes: Array) -> void:
_current_project.undo_redo.create_action("Add Strokes")
var point_count := 0
for stroke in strokes:
for stroke: BrushStroke in strokes:
point_count += stroke.points.size()
_current_project.undo_redo.add_undo_method(undo_last_stroke)
_current_project.undo_redo.add_undo_reference(stroke)
Expand Down Expand Up @@ -304,7 +306,7 @@ func use_project(project: Project) -> void:
# -------------------------------------------------------------------------------------------------
func undo_last_stroke() -> void:
if _current_stroke == null && !_current_project.strokes.is_empty():
var stroke = _strokes_parent.get_child(_strokes_parent.get_child_count() - 1)
var stroke: BrushStroke = _strokes_parent.get_child(_strokes_parent.get_child_count() - 1)
_strokes_parent.remove_child(stroke)
_current_project.remove_last_stroke()
info.point_count -= stroke.points.size()
Expand All @@ -323,7 +325,7 @@ func set_brush_color(color: Color) -> void:
_active_tool._on_brush_color_changed(_brush_color)

# -------------------------------------------------------------------------------------------------
func enable_constant_pressure(e: bool):
func enable_constant_pressure(e: bool) -> void:
if e:
_brush_tool.pressure_curve = _constant_pressure_curve
else:
Expand Down Expand Up @@ -353,7 +355,7 @@ func _delete_selected_strokes() -> void:
var strokes := _selection_tool.get_selected_strokes()
if !strokes.is_empty():
_current_project.undo_redo.create_action("Delete Selection")
for stroke in strokes:
for stroke: BrushStroke in strokes:
_current_project.undo_redo.add_do_method(_do_delete_stroke.bind(stroke))
_current_project.undo_redo.add_undo_reference(stroke)
_current_project.undo_redo.add_undo_method(_undo_delete_stroke.bind(stroke))
Expand Down
8 changes: 4 additions & 4 deletions lorien/InfiniteCanvas/InfiniteCanvasGrid.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var _grid_size := Config.DEFAULT_GRID_SIZE
var _grid_color: Color

# -------------------------------------------------------------------------------------------------
func _ready():
func _ready() -> void:
_grid_size = Settings.get_appearance_value(Settings.APPEARANCE_GRID_SIZE, Config.DEFAULT_GRID_SIZE)
_pattern = Settings.get_appearance_value(Settings.APPEARANCE_GRID_PATTERN, Config.DEFAULT_GRID_PATTERN)

Expand Down Expand Up @@ -47,8 +47,8 @@ func set_canvas_color(c: Color) -> void:
# -------------------------------------------------------------------------------------------------
func _draw() -> void:
var zoom := (Vector2.ONE / _camera.zoom).x
var size = Vector2(get_viewport().size.x, get_viewport().size.y) * zoom
var offset = _camera.offset
var size := Vector2(get_viewport().size.x, get_viewport().size.y) * zoom
var offset := _camera.offset
var grid_size := int(ceil((_grid_size * pow(zoom, 0.75))))

match _pattern:
Expand All @@ -57,7 +57,7 @@ func _draw() -> void:
var x_start := int(offset.x / grid_size) - 1
var x_end := int((size.x + offset.x) / grid_size) + 1
var y_start := int(offset.y / grid_size) - 1
var y_end = int((size.y + offset.y) / grid_size) + 1
var y_end := int((size.y + offset.y) / grid_size) + 1

for x in range(x_start, x_end):
for y in range(y_start, y_end):
Expand Down
8 changes: 4 additions & 4 deletions lorien/InfiniteCanvas/PanZoomCamera.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extends Camera2D

# -------------------------------------------------------------------------------------------------
signal zoom_changed(value)
signal position_changed(value)
signal zoom_changed(value: float)
signal position_changed(value: Vector2)

# -------------------------------------------------------------------------------------------------
const ZOOM_INCREMENT := 1.1
Expand Down Expand Up @@ -66,7 +66,7 @@ func tool_event(event: InputEvent) -> void:
# -------------------------------------------------------------------------------------------------
func _do_pan(pan: Vector2) -> void:
offset -= pan * (1.0 / _current_zoom_level)
emit_signal("position_changed", offset)
position_changed.emit(offset)

# -------------------------------------------------------------------------------------------------
func _do_zoom_scroll(step: int) -> void:
Expand All @@ -93,7 +93,7 @@ func _zoom_canvas(target_zoom: float, anchor: Vector2) -> void:
_current_zoom_level = target_zoom

zoom = Vector2(_current_zoom_level, _current_zoom_level)
emit_signal("zoom_changed", _current_zoom_level)
zoom_changed.emit(_current_zoom_level)

# -------------------------------------------------------------------------------------------------
func _to_nearest_zoom_step(zoom_level: float) -> float:
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/BrushTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func _is_stroke_a_dot() -> bool:
# -------------------------------------------------------------------------------------------------
func _draw_point() -> void:
var origin := _cursor.global_position
var pressure = 0.5
var pressure := 0.5
var offset := 1.5

add_stroke_point(origin, pressure)
Expand Down
4 changes: 2 additions & 2 deletions lorien/InfiniteCanvas/Tools/CanvasTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var enabled := false: get = get_enabled, set = set_enabled
var performing_stroke := false

# -------------------------------------------------------------------------------------------------
func _ready():
func _ready() -> void:
_cursor = get_node(cursor_path)
_canvas = get_parent()
set_enabled(false)
Expand All @@ -33,7 +33,7 @@ func _on_brush_size_changed(size: int) -> void:
_cursor.change_size(size)

# -------------------------------------------------------------------------------------------------
func get_cursor():
func get_cursor() -> BaseCursor:
return _cursor

# -------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/CircleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var sin_arr : Array[float]
var cos_arr : Array[float]

# -------------------------------------------------------------------------------------------------
func _init():
func _init() -> void:
sin_arr.resize(360)
cos_arr.resize(360)
for i: int in 360:
Expand Down
4 changes: 2 additions & 2 deletions lorien/InfiniteCanvas/Tools/EraserTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const BOUNDING_BOX_MARGIN := 20.0

# -------------------------------------------------------------------------------------------------
var _last_mouse_position: Vector2
var _removed_strokes := [] # BrushStroke -> Vector2
var _bounding_box_cache = {} # BrushStroke -> Rect2
var _removed_strokes: Array[BrushStroke]
var _bounding_box_cache := {} # BrushStroke -> Rect2

# -------------------------------------------------------------------------------------------------
func tool_event(event: InputEvent) -> void:
Expand Down
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/Tools/SelectionRectangle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func reset() -> void:
end_position = Vector2.ZERO

# -------------------------------------------------------------------------------------------------
func _draw():
func _draw() -> void:
if !(start_position - end_position).is_zero_approx():
material.set_shader_parameter("background_color", _canvas.get_background_color())
draw_rect(Rect2(start_position, end_position - start_position), FILL_COLOR)
Expand Down
10 changes: 5 additions & 5 deletions lorien/InfiniteCanvas/Tools/SelectionTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ enum State {
# -------------------------------------------------------------------------------------------------
@export var selection_rectangle_path: NodePath
var _selection_rectangle: SelectionRectangle
var _state = State.NONE
var _state := State.NONE
var _selecting_start_pos: Vector2 = Vector2.ZERO
var _selecting_end_pos: Vector2 = Vector2.ZERO
var _multi_selecting: bool
var _mouse_moved_during_pressed := false
var _stroke_positions_before_move := {} # BrushStroke -> Vector2
var _bounding_box_cache = {} # BrushStroke -> Rect2
var _bounding_box_cache := {} # BrushStroke -> Rect2

# ------------------------------------------------------------------------------------------------
func _ready():
func _ready() -> void:
super()
_selection_rectangle = get_node(selection_rectangle_path)
_cursor.mode = SelectionCursor.Mode.SELECT
Expand All @@ -46,7 +46,7 @@ func tool_event(event: InputEvent) -> void:
var strokes := get_selected_strokes()
if strokes.size() > 0:
Utils.remove_group_from_all_nodes(GROUP_COPIED_STROKES)
for stroke in strokes:
for stroke: BrushStroke in strokes:
stroke.add_to_group(GROUP_COPIED_STROKES)
print("Copied %d strokes" % strokes.size())

Expand Down Expand Up @@ -74,7 +74,7 @@ func tool_event(event: InputEvent) -> void:
_state = State.MOVING
_mouse_moved_during_pressed = false
_offset_selected_strokes(_cursor.global_position)
for s in get_selected_strokes():
for s: BrushStroke in get_selected_strokes():
_stroke_positions_before_move[s] = s.global_position
# LMB up - stop selection or movement
else:
Expand Down
25 changes: 12 additions & 13 deletions lorien/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _dirty_project_to_close: Project = null
var _player_enabled := false

# -------------------------------------------------------------------------------------------------
func _ready():
func _ready() -> void:
# Init stuff
randomize()
Engine.max_fps = Settings.get_rendering_value(Settings.RENDERING_FOREGROUND_FPS, Config.DEFAULT_FOREGROUND_FPS)
Expand Down Expand Up @@ -101,7 +101,7 @@ func _ready():
_apply_state()

# -------------------------------------------------------------------------------------------------
func _notification(what):
func _notification(what: int) -> void:
if NOTIFICATION_WM_CLOSE_REQUEST == what:
_quit()
elif NOTIFICATION_APPLICATION_FOCUS_IN == what:
Expand All @@ -116,12 +116,12 @@ func _notification(what):
_canvas.disable()

# -------------------------------------------------------------------------------------------------
func _exit_tree():
func _exit_tree() -> void:
_menubar.remove_all_tabs()
ProjectManager.remove_all_projects()

# -------------------------------------------------------------------------------------------------
func _process(delta):
func _process(delta: float) -> void:
_statusbar.set_stroke_count(_canvas.info.stroke_count)
_statusbar.set_point_count(_canvas.info.point_count)
_statusbar.set_pressure(_canvas.info.current_pressure)
Expand All @@ -135,7 +135,7 @@ func _process(delta):
_menubar.update_tab_title(active_project)

# -------------------------------------------------------------------------------------------------
func _unhandled_input(event):
func _unhandled_input(event: InputEvent) -> void:
if !is_dialog_open():
if Utils.event_pressed_bug_workaround("toggle_player", event):
_toggle_player()
Expand Down Expand Up @@ -209,9 +209,8 @@ func _apply_state() -> void:

# Open projects
var open_projects: Array = StatePersistence.get_value(StatePersistence.OPEN_PROJECTS, Array())
for path in open_projects:
if path is String:
_on_open_project(path)
for path: String in open_projects:
_on_open_project(path)

# Active project
var active_project_path: String = StatePersistence.get_value(StatePersistence.ACTIVE_PROJECT, "")
Expand Down Expand Up @@ -279,7 +278,7 @@ func _create_active_default_project() -> void:

# -------------------------------------------------------------------------------------------------
func _save_project(project: Project) -> void:
var meta_data = ProjectMetadata.make_dict(_canvas)
var meta_data := ProjectMetadata.make_dict(_canvas)
project.meta_data = meta_data
ProjectManager.save_project(project)
_menubar.update_tab_title(project)
Expand Down Expand Up @@ -323,7 +322,7 @@ func _close_project(project_id: int) -> void:
_make_project_active(new_project)

# -------------------------------------------------------------------------------------------------
func _toggle_fullscreen():
func _toggle_fullscreen() -> void:
match get_window().mode:
Window.MODE_EXCLUSIVE_FULLSCREEN, Window.MODE_FULLSCREEN:
get_window().mode = Window.MODE_WINDOWED
Expand Down Expand Up @@ -473,16 +472,16 @@ func _on_open_url(url: String) -> void:
_canvas.disable()

# -------------------------------------------------------------------------------------------------
func _on_InfiniteCanvas_mouse_entered():
func _on_InfiniteCanvas_mouse_entered() -> void:
if !is_dialog_open() && !_is_mouse_on_ui():
_canvas.enable()

# -------------------------------------------------------------------------------------------------
func _on_InfiniteCanvas_mouse_exited():
func _on_InfiniteCanvas_mouse_exited() -> void:
_canvas.disable()

# --------------------------------------------------------------------------------------------------
func _on_export_confirmed(path: String):
func _on_export_confirmed(path: String) -> void:
match path.get_extension():
"svg":
var project: Project = ProjectManager.get_active_project()
Expand Down
Loading

0 comments on commit a07a713

Please sign in to comment.