diff options
Diffstat (limited to 'Map/Presentation')
20 files changed, 64 insertions, 65 deletions
diff --git a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift index 83d5009..5983745 100644 --- a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift +++ b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift @@ -20,7 +20,7 @@ struct EvolutionPicker: View { @State var isHovered = false @Binding var selectedEvolution: StageType - + var body: some View { Button( diff --git a/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift b/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift index 72a572a..6d2f6c4 100644 --- a/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift +++ b/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift @@ -20,7 +20,7 @@ struct GlassEvolutionPicker: View { @State var isShowingMenu = false @Binding var selectedEvolution: StageType - + var body: some View { Button( diff --git a/Map/Presentation/Base Components/MapRender/MapBackground.swift b/Map/Presentation/Base Components/MapRender/MapBackground.swift index 710d549..d1e48d8 100644 --- a/Map/Presentation/Base Components/MapRender/MapBackground.swift +++ b/Map/Presentation/Base Components/MapRender/MapBackground.swift @@ -20,7 +20,7 @@ struct MapBackground: View { let mapSize: CGSize let stages: [Double] - + var body: some View { ZStack(alignment: .topLeading) { PatternView( diff --git a/Map/Presentation/Base Components/MapRender/MapGroup.swift b/Map/Presentation/Base Components/MapRender/MapGroup.swift index ca5e954..ccec52f 100644 --- a/Map/Presentation/Base Components/MapRender/MapGroup.swift +++ b/Map/Presentation/Base Components/MapRender/MapGroup.swift @@ -91,6 +91,6 @@ struct MapGroup: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark) ], color: .red) } diff --git a/Map/Presentation/Base Components/MapRender/MapGroups.swift b/Map/Presentation/Base Components/MapRender/MapGroups.swift index 149ea65..8676f1a 100644 --- a/Map/Presentation/Base Components/MapRender/MapGroups.swift +++ b/Map/Presentation/Base Components/MapRender/MapGroups.swift @@ -40,7 +40,7 @@ struct MapGroups: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark) ] ]) } diff --git a/Map/Presentation/Base Components/MapRender/MapIntertias.swift b/Map/Presentation/Base Components/MapRender/MapIntertias.swift index 91ec6f9..9e013c6 100644 --- a/Map/Presentation/Base Components/MapRender/MapIntertias.swift +++ b/Map/Presentation/Base Components/MapRender/MapIntertias.swift @@ -50,6 +50,6 @@ struct MapIntertias: View { mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0), inertias: [ Inertia(id: 0, position: CGPoint(x: 50.0, y: 50.0)), - Inertia(id: 1, position: CGPoint(x: 10.0, y: 20.0)), + Inertia(id: 1, position: CGPoint(x: 10.0, y: 20.0)) ]) } diff --git a/Map/Presentation/Base Components/MapRender/MapMask.swift b/Map/Presentation/Base Components/MapRender/MapMask.swift index c4ba055..05070bf 100644 --- a/Map/Presentation/Base Components/MapRender/MapMask.swift +++ b/Map/Presentation/Base Components/MapRender/MapMask.swift @@ -65,7 +65,7 @@ struct MapMask: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark) ], labelPositions: [:]) } diff --git a/Map/Presentation/Base Components/MapRender/MapVertices.swift b/Map/Presentation/Base Components/MapRender/MapVertices.swift index a3558fa..0ab7fab 100644 --- a/Map/Presentation/Base Components/MapRender/MapVertices.swift +++ b/Map/Presentation/Base Components/MapRender/MapVertices.swift @@ -23,7 +23,7 @@ struct MapVertices: View { let padding = CGFloat(5.0) @State private var offset = CGSize.zero - @State private var draggingVertex: Vertex? = nil + @State private var draggingVertex: Vertex? var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in } @@ -156,7 +156,7 @@ struct MapVertices: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark) ], labelPositions: [:]) } diff --git a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift index eeccec3..69ebfc0 100644 --- a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift +++ b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift @@ -49,7 +49,7 @@ class HoverView: NSView { box.topAnchor.constraint(equalTo: topAnchor), box.leadingAnchor.constraint(equalTo: leadingAnchor), box.trailingAnchor.constraint(equalTo: trailingAnchor), - box.bottomAnchor.constraint(equalTo: bottomAnchor), + box.bottomAnchor.constraint(equalTo: bottomAnchor) ]) let label = NSTextField(labelWithString: message) @@ -89,7 +89,7 @@ class HoverView: NSView { button.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 8), button.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8), - heightAnchor.constraint(equalToConstant: 32), + heightAnchor.constraint(equalToConstant: 32) ]) } diff --git a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift index 99fa684..2850c57 100644 --- a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift +++ b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift @@ -13,12 +13,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see https://map.tranquil.systems. import Cocoa -import SwiftUI -import WmapParser import SwiftTreeSitter import SwiftTreeSitterLayer +import SwiftUI import TreeSitterWmap - +import WmapParser class MapTextEditorController: NSViewController { @@ -63,7 +62,7 @@ class MapTextEditorController: NSViewController { self.highlightRanges = highlightRanges self.selectedRange = selectedRange super.init(nibName: nil, bundle: nil) - + if let wmapConfiguration = try? LanguageConfiguration(tree_sitter_wmap(), name: "wmap") { let languageConfiguration = LanguageLayer.Configuration(languageProvider: { name in switch name { @@ -71,7 +70,8 @@ class MapTextEditorController: NSViewController { default: return nil } }) - self.rootLayer = try? LanguageLayer(languageConfig: wmapConfiguration, configuration: languageConfiguration) + self.rootLayer = try? LanguageLayer( + languageConfig: wmapConfiguration, configuration: languageConfiguration) } } @@ -83,7 +83,7 @@ class MapTextEditorController: NSViewController { override func loadView() { let scrollView = NSTextView.scrollableTextView() let textView = scrollView.documentView as! NSTextView - + scrollView.translatesAutoresizingMaskIntoConstraints = false textView.backgroundColor = .Theme.UI.background @@ -105,14 +105,16 @@ class MapTextEditorController: NSViewController { textView.textContainer?.containerSize = NSSize( width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) // Allow text view to grow horizontally - textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) + textView.maxSize = NSSize( + width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) // Enable horizontal scrollbar when soft wrap is disabled scrollView.hasHorizontalScroller = true scrollView.horizontalScrollElasticity = .none } else { textView.textContainer?.widthTracksTextView = true // Reset max size for wrapping - textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) + textView.maxSize = NSSize( + width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) // Hide horizontal scrollbar when soft wrap is enabled scrollView.hasHorizontalScroller = false scrollView.horizontalScrollElasticity = .automatic @@ -291,7 +293,7 @@ class MapTextEditorController: NSViewController { NSLayoutConstraint.activate([ hoverView.leadingAnchor.constraint(equalTo: textView.leadingAnchor, constant: hoverX), - hoverView.topAnchor.constraint(equalTo: textView.topAnchor, constant: hoverY), + hoverView.topAnchor.constraint(equalTo: textView.topAnchor, constant: hoverY) ]) self.hoverView = hoverView @@ -356,7 +358,8 @@ class MapTextEditorController: NSViewController { } private func applyTreeSitterHighlighting(textStorage: NSTextStorage, range: NSRange) { - guard let highlights = try? rootLayer?.highlights(in: range, provider: text.predicateTextProvider) + guard + let highlights = try? rootLayer?.highlights(in: range, provider: text.predicateTextProvider) else { return } for highlight in highlights { @@ -367,11 +370,12 @@ class MapTextEditorController: NSViewController { // Check for missing components if UserDefaults.standard.bool(forKey: "useSmartEditor"), - let parsedMap, - highlight.name == "variable.component_label" { + let parsedMap, + highlight.name == "variable.component_label" { // Extract the component label text from the range - let componentText = (textStorage.string as NSString).substring(with: highlight.range).trimmingCharacters(in: .whitespacesAndNewlines) + let componentText = (textStorage.string as NSString).substring(with: highlight.range) + .trimmingCharacters(in: .whitespacesAndNewlines) // Check if this component exists in the parsed map let componentExists = parsedMap.components.contains(where: { @@ -408,8 +412,7 @@ extension MapTextEditorController: NSTextViewDelegate { } } - func textView(_ view: NSTextView, shouldChangeTextIn: NSRange, replacementString: String?) -> Bool - { + func textView(_ view: NSTextView, shouldChangeTextIn: NSRange, replacementString: String?) -> Bool { let range = Range(shouldChangeTextIn, in: view.string) let target = view.string[range!] @@ -458,7 +461,7 @@ extension MapTextEditorController: NSTextStorageDelegate { } private func colorizeText(textStorage: NSTextStorage) { - let range = NSMakeRange(0, textStorage.length) + let range = NSRange(location: 0, length: textStorage.length) colorizeTextRange(textStorage: textStorage, range: range) } diff --git a/Map/Presentation/Commands/MapCommands.swift b/Map/Presentation/Commands/MapCommands.swift index b992a42..c485023 100644 --- a/Map/Presentation/Commands/MapCommands.swift +++ b/Map/Presentation/Commands/MapCommands.swift @@ -58,7 +58,7 @@ struct MapCommands: Commands { Button("commands.file.export") { if let selectedEvolution, let document { if let image = document.exportAsImage(withEvolution: selectedEvolution) { - + // Capture image data to avoid sendability issues with NSImage guard let tiffData = image.tiffRepresentation else { return } @@ -155,7 +155,7 @@ struct MapCommands: Commands { savePanel.begin { result in if result == .OK { let bitmapImage = NSBitmapImageRep(data: tiffData) - + Task { @MainActor in guard let url = savePanel.url else { return } let selectedFormat = formats[accessoryController.formatPopup.indexOfSelectedItem] diff --git a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift index ba525ad..e2e5004 100644 --- a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift +++ b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift @@ -64,7 +64,7 @@ struct MapRenderView: View { Line(start: CGPoint(x: 0, y: 0), end: CGPoint(x: 0, y: mapSize.height)), Line( start: CGPoint(x: 0, y: mapSize.height), - end: CGPoint(x: mapSize.width, y: mapSize.height)), + end: CGPoint(x: mapSize.width, y: mapSize.height)) ] for vertex in parsed.vertices { @@ -113,7 +113,8 @@ struct MapRenderView: View { Group { MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: renderableMap.stages) MapEdges( - mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: renderableMap.edges) + mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: renderableMap.edges + ) MapOpportunities( mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, opportunities: renderableMap.opportunities) @@ -131,9 +132,10 @@ struct MapRenderView: View { .drawingGroup() .opacity(0.1) } else { - MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: renderableMap.groups).drawingGroup( - opaque: true - ).opacity(0.1) + MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: renderableMap.groups) + .drawingGroup( + opaque: true + ).opacity(0.1) } MapNotes( mapSize: mapSize, lineWidth: lineWidth, notes: renderableMap.notes) diff --git a/Map/Presentation/MapEditor.swift b/Map/Presentation/MapEditor.swift index 892c803..c323882 100644 --- a/Map/Presentation/MapEditor.swift +++ b/Map/Presentation/MapEditor.swift @@ -123,7 +123,7 @@ struct MapEditor: View { } .background(Color.Theme.UI.background) .cornerRadius(5.0) - GeometryReader { geometry in + GeometryReader { _ in ScrollView([.horizontal, .vertical], showsIndicators: false) { MapRenderView( parsedMap: parsedMap, evolution: $selectedEvolution, @@ -142,20 +142,20 @@ struct MapEditor: View { .padding(.bottom, Dimensions.MapEditor.additionalPadding) } .background(Color.Theme.UI.background) - .gesture( - MagnificationGesture() - .onChanged { value in - let delta = value / lastZoom - lastZoom = value - zoom = min(max(zoom * delta, zoomRange.lowerBound), zoomRange.upperBound) - } - .onEnded { _ in - lastZoom = 1.0 - } - ) + .gesture( + MagnificationGesture() + .onChanged { value in + let delta = value / lastZoom + lastZoom = value + zoom = min(max(zoom * delta, zoomRange.lowerBound), zoomRange.upperBound) + } + .onEnded { _ in + lastZoom = 1.0 + } + ) } } - + if #unavailable(macOS 26) { Divider() HStack { @@ -249,8 +249,7 @@ struct MapEditor: View { for (index, line) in lines.enumerated() { if let regex = try? NSRegularExpression(pattern: vertexPattern, options: [.caseInsensitive]), - let match = regex.firstMatch(in: line, range: NSRange(line.startIndex..., in: line)) - { + let match = regex.firstMatch(in: line, range: NSRange(line.startIndex..., in: line)) { let nameRange = Range(match.range(at: 1), in: line)! let name = String(line[nameRange]).trimmingCharacters(in: .whitespaces) diff --git a/Map/Presentation/Preferences/GeneralPreferencesView.swift b/Map/Presentation/Preferences/GeneralPreferencesView.swift index 31e54c2..406bee2 100644 --- a/Map/Presentation/Preferences/GeneralPreferencesView.swift +++ b/Map/Presentation/Preferences/GeneralPreferencesView.swift @@ -174,7 +174,7 @@ struct GeneralPreferencesView: View { private func handleExportResult(_ result: Result<URL, Error>) { switch result { - case .success(_): + case .success: // Export successful if exportShouldReset { // Reset preferences if this was an export-and-reset operation diff --git a/Map/Presentation/PreferencesWindow.swift b/Map/Presentation/PreferencesWindow.swift index 3a50119..0865524 100644 --- a/Map/Presentation/PreferencesWindow.swift +++ b/Map/Presentation/PreferencesWindow.swift @@ -102,7 +102,7 @@ struct PreferencesWindow: View { } } } - + private func clipShape() -> AnyShape { if #available(macOS 26.0, *) { AnyShape(RoundedRectangle(cornerRadius: Dimensions.Preferences.Toolbar.glassRadius)) @@ -112,7 +112,6 @@ struct PreferencesWindow: View { } } - #Preview { PreferencesWindow() } diff --git a/Map/Presentation/Theme/Color+theme.swift b/Map/Presentation/Theme/Color+theme.swift index dcc84cb..541bbb6 100644 --- a/Map/Presentation/Theme/Color+theme.swift +++ b/Map/Presentation/Theme/Color+theme.swift @@ -51,7 +51,7 @@ extension Color { Color.Theme.jasperRed, Color.Theme.lightPorcelainGreen, Color.Theme.naplesYellow, - Color.Theme.hermosaPink, + Color.Theme.hermosaPink ] } } diff --git a/Map/Presentation/Theme/Dimensions.swift b/Map/Presentation/Theme/Dimensions.swift index b7c1faf..40ca73d 100644 --- a/Map/Presentation/Theme/Dimensions.swift +++ b/Map/Presentation/Theme/Dimensions.swift @@ -71,9 +71,9 @@ struct Dimensions { struct EvolutionPicker { static var radius: CGFloat { if #available(macOS 26, *) { - return 12.0 + return 12.0 } else { - return 4.0 + return 4.0 } } static let controlSize = 8.0 @@ -89,7 +89,7 @@ struct Dimensions { } } } - + struct Preferences { struct Window { diff --git a/Map/Presentation/Theme/Font+theme.swift b/Map/Presentation/Theme/Font+theme.swift index bb1d8f6..d560d77 100644 --- a/Map/Presentation/Theme/Font+theme.swift +++ b/Map/Presentation/Theme/Font+theme.swift @@ -43,8 +43,7 @@ extension Font { static var note: Font { if UserDefaults.standard.bool(forKey: "useCustomFont"), let customFontName = UserDefaults.standard.string(forKey: "customFontName"), - !customFontName.isEmpty - { + !customFontName.isEmpty { return Font.custom(customFontName, size: Dimensions.FontSize.Map.note).weight(.regular) } return Font.libertinus(size: Dimensions.FontSize.Map.note).weight(.regular) @@ -53,8 +52,7 @@ extension Font { static var axisLabel: Font { if UserDefaults.standard.bool(forKey: "useCustomFont"), let customFontName = UserDefaults.standard.string(forKey: "customFontName"), - !customFontName.isEmpty - { + !customFontName.isEmpty { return Font.custom(customFontName, size: Dimensions.FontSize.Map.axisLabel).weight( .regular) } @@ -64,8 +62,7 @@ extension Font { static var vertexLabel: Font { if UserDefaults.standard.bool(forKey: "useCustomFont"), let customFontName = UserDefaults.standard.string(forKey: "customFontName"), - !customFontName.isEmpty - { + !customFontName.isEmpty { return Font.custom(customFontName, size: Dimensions.FontSize.Map.vertexLabel).weight( .regular) } diff --git a/Map/Presentation/Theme/NSColor+theme.swift b/Map/Presentation/Theme/NSColor+theme.swift index 21db412..5f349a3 100644 --- a/Map/Presentation/Theme/NSColor+theme.swift +++ b/Map/Presentation/Theme/NSColor+theme.swift @@ -29,7 +29,7 @@ extension NSColor { .withAlphaComponent( 0.3) static let error = (NSColor(named: "Jasper Red") ?? .textColor) - + static func colorForSyntax(_ captureName: String) -> NSColor { switch captureName { case ("variable.component_label"): diff --git a/Map/Presentation/Theme/NSFont+theme.swift b/Map/Presentation/Theme/NSFont+theme.swift index 712cc1d..77927a6 100644 --- a/Map/Presentation/Theme/NSFont+theme.swift +++ b/Map/Presentation/Theme/NSFont+theme.swift @@ -31,8 +31,7 @@ extension NSFont { @MainActor static var regular: NSFont { if UserDefaults.standard.bool(forKey: "useCustomEditorFont"), let customEditorFontName = UserDefaults.standard.string(forKey: "customEditorFontName"), - !customEditorFontName.isEmpty - { + !customEditorFontName.isEmpty { return NSFontManager.shared.font( withFamily: customEditorFontName, traits: NSFontTraitMask(), |