Skip to content

Commit

Permalink
Merge pull request #171 from TheMoonThatRises/chore/fix-swiftlint
Browse files Browse the repository at this point in the history
Fix swiftlint warnings
  • Loading branch information
Depal1 authored Sep 25, 2024
2 parents ae53436 + c996174 commit 8af7308
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 169 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/SwiftLint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: SwiftLint

on:
# Run on PR and push to every branch
pull_request:
push:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: SwiftLint
uses: norio-nomura/[email protected]
with:
args: --strict
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ identifier_name:

type_name:
allowed_symbols: ['_']

disabled_rules:
- todo
12 changes: 7 additions & 5 deletions AKPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ class AKPlugin: NSObject, Plugin {
}

private var modifierFlag: UInt = 0
func setupKeyboard(keyboard: @escaping(UInt16, Bool, Bool, Bool) -> Bool,
swapMode: @escaping() -> Bool) {

// swiftlint:disable:next function_body_length
func setupKeyboard(keyboard: @escaping (UInt16, Bool, Bool, Bool) -> Bool,
swapMode: @escaping () -> Bool) {
func checkCmd(modifier: NSEvent.ModifierFlags) -> Bool {
if modifier.contains(.command) {
self.cmdPressed = true
Expand Down Expand Up @@ -122,7 +124,7 @@ class AKPlugin: NSObject, Plugin {
})
}

func setupMouseMoved(_ mouseMoved: @escaping(CGFloat, CGFloat) -> Bool) {
func setupMouseMoved(_ mouseMoved: @escaping (CGFloat, CGFloat) -> Bool) {
let mask: NSEvent.EventTypeMask = [.leftMouseDragged, .otherMouseDragged, .rightMouseDragged]
NSEvent.addLocalMonitorForEvents(matching: mask, handler: { event in
let consumed = mouseMoved(event.deltaX, event.deltaY)
Expand All @@ -138,7 +140,7 @@ class AKPlugin: NSObject, Plugin {
})
}

func setupMouseButton(left: Bool, right: Bool, _ consumed: @escaping(Int, Bool) -> Bool) {
func setupMouseButton(left: Bool, right: Bool, _ consumed: @escaping (Int, Bool) -> Bool) {
let downType: NSEvent.EventTypeMask = left ? .leftMouseDown : right ? .rightMouseDown : .otherMouseDown
let upType: NSEvent.EventTypeMask = left ? .leftMouseUp : right ? .rightMouseUp : .otherMouseUp
NSEvent.addLocalMonitorForEvents(matching: downType, handler: { event in
Expand All @@ -159,7 +161,7 @@ class AKPlugin: NSObject, Plugin {
})
}

func setupScrollWheel(_ onMoved: @escaping(CGFloat, CGFloat) -> Bool) {
func setupScrollWheel(_ onMoved: @escaping (CGFloat, CGFloat) -> Bool) {
NSEvent.addLocalMonitorForEvents(matching: NSEvent.EventTypeMask.scrollWheel, handler: { event in
var deltaX = event.scrollingDeltaX, deltaY = event.scrollingDeltaY
if !event.hasPreciseScrollingDeltas {
Expand Down
4 changes: 4 additions & 0 deletions PlayTools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
B1271729288284BE0025112B /* DiscordActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1271728288284BE0025112B /* DiscordActivity.swift */; };
B1E8CF8A28BBE2AB004340D3 /* Keymapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1E8CF8928BBE2AB004340D3 /* Keymapping.swift */; };
B46C02C72C634AB5007637AB /* BatteryLevel.m in Sources */ = {isa = PBXBuildFile; fileRef = B46C02C62C634AB5007637AB /* BatteryLevel.m */; };
B66E65002C936EA100E48FD0 /* PlayedAppleDBConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = B66E64FF2C936E9800E48FD0 /* PlayedAppleDBConstants.swift */; };
B6D774FF2ACFC3D900C0D9D8 /* SwordRPC in Frameworks */ = {isa = PBXBuildFile; productRef = B6D774FE2ACFC3D900C0D9D8 /* SwordRPC */; };
EEB248592B81D074000C230A /* PlayedAppleDB.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB248582B81D074000C230A /* PlayedAppleDB.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -181,6 +182,7 @@
B1E8CF8928BBE2AB004340D3 /* Keymapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Keymapping.swift; sourceTree = "<group>"; };
B46C02C62C634AB5007637AB /* BatteryLevel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BatteryLevel.m; sourceTree = "<group>"; };
B46C02C82C634C60007637AB /* BatteryLevel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BatteryLevel.h; sourceTree = "<group>"; };
B66E64FF2C936E9800E48FD0 /* PlayedAppleDBConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayedAppleDBConstants.swift; sourceTree = "<group>"; };
EEB248582B81D074000C230A /* PlayedAppleDB.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayedAppleDB.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -530,6 +532,7 @@
ABCECEE729750BB100746595 /* MysticRunes */ = {
isa = PBXGroup;
children = (
B66E64FF2C936E9800E48FD0 /* PlayedAppleDBConstants.swift */,
ABCECEE529750BA600746595 /* PlayedApple.swift */,
EEB248582B81D074000C230A /* PlayedAppleDB.swift */,
AB7DA47429B85BFB0034ACB2 /* PlayShadow.m */,
Expand Down Expand Up @@ -733,6 +736,7 @@
9562D1532AB484FD002C329D /* EventAdapter.swift in Sources */,
AA7197A2287A481500623C15 /* CircleMenu.swift in Sources */,
954389CE2B39F26600B063BB /* ElementView.swift in Sources */,
B66E65002C936EA100E48FD0 /* PlayedAppleDBConstants.swift in Sources */,
9562D15A2AB4FBBB002C329D /* TransparentKeyboardEventAdapter.swift in Sources */,
AA71978B287A480D00623C15 /* MenuController.swift in Sources */,
9562D1732AB52416002C329D /* EditorKeyboardEventAdapter.swift in Sources */,
Expand Down
16 changes: 9 additions & 7 deletions PlayTools/Controls/ActionDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,19 @@ public class ActionDispatcher {
}

/**
Lift off (release) touch points of actions that moves freely under control of the user. (e.g. camera control action)
Would be called during every mode switching where `invalidateActions` is not called.
In such scenario button-type actions are not released, because users may continue using them across different modes.
Lift off (release) touch points of actions that moves freely under control of the
user. (e.g. camera control action) Would be called during every mode switching
where `invalidateActions` is not called. In such scenario button-type
actions are not released, because users may continue using them across different modes.
(e.g. holding W while unhiding cursor to click something)

But non-button-type actions (e.g. camera control action, fake mouse action) are unlikely used across modes.
If they're not released, they would interfere with and ruin the game's camera control (becomes random zoom in zoom out)
But non-button-type actions (e.g. camera control action, fake mouse action) are unlikely
used across modes. If they're not released, they would interfere with and ruin the game's
camera control (becomes random zoom in zoom out)
*/
static public func invalidateNonButtonActions() {
for action in actions
where !(action as? ButtonAction != nil || action is JoystickAction){
for action in actions
where !(action is ButtonAction || action is JoystickAction) {
action.invalidate()
}
}
Expand Down
3 changes: 2 additions & 1 deletion PlayTools/Controls/Backend/Action/PlayAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// PlayTools
//

// swiftlint:disable file_length
import Foundation

protocol Action {
Expand Down Expand Up @@ -332,7 +333,7 @@ class SwipeAction: Action {
var location: CGPoint = CGPoint.zero
private var id: Int?
let timer = DispatchSource.makeTimerSource(flags: [], queue: PlayInput.touchQueue)
private let actionName: String, keyName: String;
private let actionName: String, keyName: String
init(actionName: String, keyName: String) {
self.actionName = actionName
self.keyName = keyName
Expand Down
13 changes: 4 additions & 9 deletions PlayTools/Controls/Frontend/EventAdapter/EventAdapters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ public class EventAdapters {

static func keyboard(controlMode: ControlModeLiteral) -> KeyboardEventAdapter {
switch controlMode {
case .OFF: fallthrough
case .TEXT_INPUT:
case .OFF, .TEXT_INPUT:
return TransparentKeyboardEventAdapter()
case .CAMERA_ROTATE: fallthrough
case .ARBITRARY_CLICK:
case .CAMERA_ROTATE, .ARBITRARY_CLICK:
return TouchscreenKeyboardEventAdapter()
case .EDITOR:
return EditorKeyboardEventAdapter()
Expand All @@ -26,8 +24,7 @@ public class EventAdapters {

static func mouse(controlMode: ControlModeLiteral) -> MouseEventAdapter {
switch controlMode {
case .OFF: fallthrough
case .TEXT_INPUT:
case .OFF, .TEXT_INPUT:
return TransparentMouseEventAdapter()
case .CAMERA_ROTATE:
return CameraControlMouseEventAdapter()
Expand All @@ -42,9 +39,7 @@ public class EventAdapters {
switch controlMode {
case .OFF:
return TransparentControllerEventAdapter()
case .TEXT_INPUT: fallthrough
case .CAMERA_ROTATE: fallthrough
case .ARBITRARY_CLICK:
case .TEXT_INPUT, .CAMERA_ROTATE, .ARBITRARY_CLICK:
return TouchscreenControllerEventAdapter()
case .EDITOR:
return EditorControllerEventAdapter()
Expand Down
2 changes: 1 addition & 1 deletion PlayTools/Controls/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var keymapping = [
NSLocalizedString("menu.keymapping.rotateDisplay", tableName: "Playtools",
value: "Rotate display area", comment: ""),
NSLocalizedString("menu.keymapping.toggleDebug", tableName: "Playtools",
value: "Toggle Debug Overlay", comment: ""),
value: "Toggle Debug Overlay", comment: "")
]
var keymappingSelectors = [#selector(UIApplication.switchEditorMode(_:)),
#selector(UIApplication.removeElement(_:)),
Expand Down
6 changes: 3 additions & 3 deletions PlayTools/Editor/Controllers/EditorController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class EditorController {

public func setKey(_ name: String) {
if editorMode {
if name != "Mouse" || focusedControl as? MouseAreaModel != nil
|| focusedControl as? JoystickModel != nil
|| focusedControl as? DraggableButtonModel != nil {
if name != "Mouse" || focusedControl is MouseAreaModel
|| focusedControl is JoystickModel
|| focusedControl is DraggableButtonModel {
focusedControl?.setKey(name: name)
}
}
Expand Down
21 changes: 12 additions & 9 deletions PlayTools/Editor/Views/CircleMenu/CircleMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// swiftlint:disable type_body_length
// swiftlint:disable file_length
// swiftlint:disable line_length

import UIKit

Expand All @@ -46,7 +44,8 @@ func customize<Type>(_ value: Type, block: (_ object: Type) -> Void) -> Type {
Tells the delegate the circle menu is about to draw a button for a particular index.

- parameter circleMenu: The circle menu object informing the delegate of this impending event.
- parameter button: A circle menu button object that circle menu is going to use when drawing the row. Don't change button.tag
- parameter button: A circle menu button object that circle menu is going to use
when drawing the row. Don't change button.tag
- parameter atIndex: An button index.
*/
@objc optional func circleMenu(_ circleMenu: CircleMenu, willDisplay button: UIButton, atIndex: Int)
Expand Down Expand Up @@ -86,6 +85,7 @@ func customize<Type>(_ value: Type, block: (_ object: Type) -> Void) -> Type {

// MARK: CircleMenu

// swiftlint:disable type_body_length
/// A Button object with pop ups buttons
open class CircleMenu: UIButton {

Expand Down Expand Up @@ -126,7 +126,8 @@ open class CircleMenu: UIButton {
/**
Initializes and returns a circle menu object.

- parameter frame: A rectangle specifying the initial location and size of the circle menu in its superview’€™s coordinates.
- parameter frame: A rectangle specifying the initial location and size of the circle menu in
its superview’€™s coordinates.
- parameter normalIcon: The image to use for the specified normal state.
- parameter selectedIcon: The image to use for the specified selected state.
- parameter buttonsCount: The number of buttons.
Expand Down Expand Up @@ -428,9 +429,9 @@ open class CircleMenu: UIButton {
transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 5,
options: UIView.AnimationOptions.curveLinear,
animations: { () -> Void in
self.transform = CGAffineTransform(scaleX: 1, y: 1)
},
animations: {
self.transform = CGAffineTransform(scaleX: 1, y: 1)
},
completion: completion)
}

Expand Down Expand Up @@ -492,15 +493,15 @@ open class CircleMenu: UIButton {
fileprivate func hideCenterButton(duration: Double, delay: Double = 0) {
UIView.animate(withDuration: TimeInterval(duration), delay: TimeInterval(delay),
options: UIView.AnimationOptions.curveEaseOut,
animations: { () -> Void in
animations: {
self.transform = CGAffineTransform(scaleX: 0.001, y: 0.001)
}, completion: nil)
}

fileprivate func showCenterButton(duration: Float, delay: Double) {
UIView.animate(withDuration: TimeInterval(duration), delay: TimeInterval(delay), usingSpringWithDamping: 0.78,
initialSpringVelocity: 0, options: UIView.AnimationOptions.curveLinear,
animations: { () -> Void in
animations: {
self.transform = CGAffineTransform(scaleX: 1, y: 1)
self.alpha = 1
},
Expand Down Expand Up @@ -539,6 +540,8 @@ open class CircleMenu: UIButton {
}
}

// swiftlint:enable type_body_length

// MARK: extension

internal extension Float {
Expand Down
12 changes: 6 additions & 6 deletions PlayTools/Editor/Views/CircleMenu/CircleMenuButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal class CircleMenuButton: UIButton {
withDuration: duration,
delay: delay,
options: UIView.AnimationOptions(),
animations: { () -> Void in
animations: {
container.layer.transform = rotateTransform
},
completion: nil)
Expand Down Expand Up @@ -149,11 +149,11 @@ internal extension CircleMenuButton {
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0,
options: UIView.AnimationOptions.curveLinear,
animations: { () -> Void in
animations: {
self.container?.superview?.layoutIfNeeded()
self.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
self.alpha = 1
}, completion: { (_) -> Void in
}, completion: { _ in
})
}

Expand All @@ -167,10 +167,10 @@ internal extension CircleMenuButton {
withDuration: duration,
delay: delay,
options: UIView.AnimationOptions.curveEaseIn,
animations: { () -> Void in
animations: {
self.container?.superview?.layoutIfNeeded()
self.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
}, completion: { (_) -> Void in
}, completion: { _ in
self.alpha = 0

if self.container != nil {
Expand All @@ -191,7 +191,7 @@ internal extension CircleMenuButton {
withDuration: duration,
delay: delay,
options: UIView.AnimationOptions.curveEaseIn,
animations: { () -> Void in
animations: {
self.container?.superview?.layoutIfNeeded()
},
completion: nil)
Expand Down
4 changes: 2 additions & 2 deletions PlayTools/Editor/Views/CircleMenu/CircleMenuLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ internal class CircleMenuLoader: UIView {
withDuration: CFTimeInterval(duration),
delay: delay,
options: UIView.AnimationOptions.curveEaseIn,
animations: { () -> Void in
animations: {
self.alpha = 0
},
completion: { (_) -> Void in
completion: { _ in
self.removeFromSuperview()
completion()
})
Expand Down
Loading

0 comments on commit 8af7308

Please sign in to comment.