diff --git a/Shared/UI/GameScene+GameController.swift b/Shared/UI/GameScene+GameController.swift index 4d4bc3f..ba82761 100644 --- a/Shared/UI/GameScene+GameController.swift +++ b/Shared/UI/GameScene+GameController.swift @@ -8,8 +8,7 @@ import Foundation import GameController -extension GameScene -{ +extension GameScene { @objc func didConnectController(_ notification: Notification) { let controller = notification.object as! GCController gameController = controller diff --git a/Shared/UI/GameScene.swift b/Shared/UI/GameScene.swift index a4cb380..abe9fa1 100644 --- a/Shared/UI/GameScene.swift +++ b/Shared/UI/GameScene.swift @@ -9,15 +9,13 @@ import Foundation import SpriteKit import GameController -protocol IRenderScreen -{ +protocol IRenderScreen { func renderScreen() } -class GameScene: SKScene,IRenderScreen { +class GameScene: SKScene, IRenderScreen { - func getFpsInfo()->String - { + func getFpsInfo() -> String { return nes.getFpsInfo() } @@ -34,8 +32,7 @@ class GameScene: SKScene,IRenderScreen { #endif } - func adjRenderCavansSize(_ oldSize: CGSize) - { + func adjRenderCavansSize(_ oldSize: CGSize) { let windowWidth = oldSize.width let windowHeight = oldSize.height diff --git a/iOS/GameViewController.swift b/iOS/GameViewController.swift index 9886215..2a2f357 100644 --- a/iOS/GameViewController.swift +++ b/iOS/GameViewController.swift @@ -22,7 +22,7 @@ class GameViewController: UIViewController { GCInputButtonB, GCInputButtonA, GCInputButtonX, - GCInputButtonY, + GCInputButtonY ] self.virtualController = GCVirtualController(configuration: config) @@ -32,86 +32,87 @@ class GameViewController: UIViewController { } } + if let dpad: GCControllerDirectionPad = self.virtualController.controller?.extendedGamepad?.dpad { - dpad.valueChangedHandler = { (dpad: GCControllerDirectionPad, xValue: Float, yValue: Float) in - if dpad.up.isPressed { - print("↑") - self.nes.pressU() - } - if !dpad.up.isPressed { - self.nes.pressU(false) - } - if dpad.down.isPressed { - print("↓") - self.nes.pressD() - } - if !dpad.down.isPressed { - print("↓") - self.nes.pressD(false) - } - if dpad.left.isPressed { - print("←") - self.nes.pressL() - } - if !dpad.left.isPressed { - print("←") - self.nes.pressL(false) - } - if dpad.right.isPressed { - self.nes.pressR() - } - if !dpad.right.isPressed { - self.nes.pressR(false) - } - } + dpad.valueChangedHandler = { (dpad: GCControllerDirectionPad, xValue: Float, yValue: Float) in + if dpad.up.isPressed { + print("↑") + self.nes.pressU() + } + if !dpad.up.isPressed { + self.nes.pressU(false) + } + if dpad.down.isPressed { + print("↓") + self.nes.pressD() + } + if !dpad.down.isPressed { + print("↓") + self.nes.pressD(false) + } + if dpad.left.isPressed { + print("←") + self.nes.pressL() + } + if !dpad.left.isPressed { + print("←") + self.nes.pressL(false) + } + if dpad.right.isPressed { + self.nes.pressR() + } + if !dpad.right.isPressed { + self.nes.pressR(false) } + } + } - if let buttonA: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonA { - buttonA.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in - if buttonA.isPressed { + if let buttonB: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonA { + buttonB.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in + if buttonB.isPressed { print("B") self.nes.pressB() } - if !buttonA.isPressed { + if !buttonB.isPressed { print("B") self.nes.pressB(false) } } } - if let buttonB: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonB { - buttonB.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in - if buttonB.isPressed { + if let buttonA: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonB { + buttonA.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in + if buttonA.isPressed { print("A") self.nes.pressA() } - if !buttonB.isPressed { + if !buttonA.isPressed { print("A") self.nes.pressA(false) } } } - if let buttonB: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonX { - buttonB.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in - if buttonB.isPressed { - print("Option") + if let buttonSelect: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonX { + buttonSelect.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in + if buttonSelect.isPressed { + print("Select") self.nes.pressSelect() } - if !buttonB.isPressed { - print("Option") + if !buttonSelect.isPressed { + print("Select") self.nes.pressSelect(false) } } } - if let buttonB: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonY { - buttonB.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in - if buttonB.isPressed { + if let buttonStart: GCControllerButtonInput = self.virtualController.controller?.extendedGamepad?.buttonY { + buttonStart.valueChangedHandler = { (button: GCControllerButtonInput, value: Float, pressed: Bool) in + if buttonStart.isPressed { print("Start") self.nes.pressStart() } - if !buttonB.isPressed { + if !buttonStart.isPressed { print("Start") self.nes.pressStart(false) } @@ -119,25 +120,24 @@ class GameViewController: UIViewController { } } - func updateConfig() - { + func updateConfig() { self.virtualController.updateConfiguration(forElement: GCInputButtonA, configuration: { _ in - let elementConfiguration: GCVirtualController.ElementConfiguration = GCVirtualController.ElementConfiguration() - - elementConfiguration.path = UIBezierPath() - - let bezierPath: UIBezierPath = UIBezierPath() - bezierPath.move(to: CGPoint(x: 0, y: 0)) - bezierPath.addLine(to: CGPoint(x: -10, y: -10)) - bezierPath.addLine(to: CGPoint(x: 10, y: -10)) - bezierPath.addLine(to: CGPoint(x: 10, y: 10)) - bezierPath.addLine(to: CGPoint(x: -10, y: 10)) - bezierPath.close() - - elementConfiguration.path?.append(bezierPath) + let elementConfiguration: GCVirtualController.ElementConfiguration = GCVirtualController.ElementConfiguration() + + elementConfiguration.path = UIBezierPath() + + let bezierPath: UIBezierPath = UIBezierPath() + bezierPath.move(to: CGPoint(x: 0, y: 0)) + bezierPath.addLine(to: CGPoint(x: -10, y: -10)) + bezierPath.addLine(to: CGPoint(x: 10, y: -10)) + bezierPath.addLine(to: CGPoint(x: 10, y: 10)) + bezierPath.addLine(to: CGPoint(x: -10, y: 10)) + bezierPath.close() + + elementConfiguration.path?.append(bezierPath) - return elementConfiguration - }) + return elementConfiguration + }) } override func viewWillDisappear(_ animated: Bool) { diff --git a/iOS/VirtualConteollerView.swift b/iOS/VirtualConteollerView.swift index 1a92c48..ed69276 100644 --- a/iOS/VirtualConteollerView.swift +++ b/iOS/VirtualConteollerView.swift @@ -10,8 +10,7 @@ import SwiftUI struct VirtualControllerView: UIViewControllerRepresentable { typealias UIViewControllerType = GameViewController - func makeUIViewController(context: Self.Context) -> GameViewController - { + func makeUIViewController(context: Self.Context) -> GameViewController { return GameViewController() }