Skip to content

Commit

Permalink
Minor code changes in response to swiftlint warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysm94 committed Apr 10, 2018
1 parent a627c2b commit 6992502
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 47 deletions.
2 changes: 1 addition & 1 deletion PokemonKit/Sources/Ability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct Ability: Codable {
}

extension Ability: Equatable {
public static func ==(lhs: Ability, rhs: Ability) -> Bool {
public static func == (lhs: Ability, rhs: Ability) -> Bool {
return lhs.name == rhs.name
}
}
2 changes: 1 addition & 1 deletion PokemonKit/Sources/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum Action: Codable, Equatable {
case attack, switchTo, forceSwitch, recharge, run
}

// MARK:- Codable
// MARK: - Codable
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

Expand Down
2 changes: 1 addition & 1 deletion PokemonKit/Sources/Attack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extension Attack: Equatable, Hashable {
return self.name.hashValue
}

public static func ==(lhs: Attack, rhs: Attack) -> Bool {
public static func == (lhs: Attack, rhs: Attack) -> Bool {
return lhs.name == rhs.name &&
lhs.power == rhs.power &&
lhs.basePP == rhs.basePP &&
Expand Down
31 changes: 18 additions & 13 deletions PokemonKit/Sources/BattleEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class BattleEngine: NSObject, GKGameModel {
if
let lookahead = turns.first,
case let .attack(attack) = lookahead.action,
case .multiHitMove(_,_)? = attack.bonusEffect
case .multiHitMove(_, _)? = attack.bonusEffect
{
multiHitMoveRunning = true
}
Expand All @@ -142,7 +142,6 @@ public class BattleEngine: NSObject, GKGameModel {
case var .attack(attack):
var attacker: Pokemon
var defender: Pokemon


if turn.player.playerId == playerOne.playerId {
attacker = playerOne.activePokemon
Expand Down Expand Up @@ -172,13 +171,13 @@ public class BattleEngine: NSObject, GKGameModel {
lastDamage = 0

// Skips doing damage if this is the first half of a multi-turn move, but still queues the relevant .useAttack
if case .multiTurnMove(_,_)? = attack.bonusEffect {
if case .multiTurnMove(_, _)? = attack.bonusEffect {
view?.queue(action: .useAttack(attacker: attacker, defender: defender, attack: attack))
return
}

// Skips doing damage if this is the first instance of a multi-hit move
if case .multiHitMove(_,_)? = attack.bonusEffect {
if case .multiHitMove(_, _)? = attack.bonusEffect {
return
}

Expand Down Expand Up @@ -287,10 +286,17 @@ public class BattleEngine: NSObject, GKGameModel {
}
}

let shouldAttack = [confusionCheck(), sleepCheck(), paralysisCheck(), protectedCheck(), hitCheck()].reduce(true) { $0 && $1 }
let shouldAttack = [
confusionCheck(),
sleepCheck(),
paralysisCheck(),
protectedCheck(),
hitCheck()
].reduce(true) { $0 && $1 }

func successfulDamage() {
// If the condition for a multi-turn move is matched, use it immediately (e.g. in the case of Solar Beam, if the weather is sunny)
// If the condition for a multi-turn move is matched, use it immediately
// (e.g. in the case of Solar Beam, if the weather is sunny)
if case .multiTurnMove(let condition, _)? = attack.bonusEffect, condition(self) {
attack = attack.withoutBonusEffect()
}
Expand Down Expand Up @@ -429,7 +435,6 @@ public class BattleEngine: NSObject, GKGameModel {
view?.queue(action: .clear)
}


/// Initialiser for the Battle Engine
///
/// - Parameters:
Expand Down Expand Up @@ -558,7 +563,7 @@ public class BattleEngine: NSObject, GKGameModel {

if !turns.isEmpty {
switch turn.action {
case .attack(_), .switchTo(_):
case .attack, .switchTo:
removeTurns(belongingTo: turn.player)
turns.append(turn)
default:
Expand Down Expand Up @@ -590,7 +595,7 @@ public class BattleEngine: NSObject, GKGameModel {
private func removeTurns(belongingTo player: Player) {
turns = turns.filter { turn in
switch turn.action {
case .attack(_), .switchTo(_):
case .attack, .switchTo:
return turn.player != player
default:
return true
Expand All @@ -614,7 +619,7 @@ public class BattleEngine: NSObject, GKGameModel {
case running, completed, awaitingSwitch
}

// MARK:- GameplayKit Methods
// MARK: - GameplayKit Methods

public var players: [GKGameModelPlayer]? {
return [playerOne, playerTwo]
Expand Down Expand Up @@ -705,7 +710,7 @@ public class BattleEngine: NSObject, GKGameModel {
score -= 30
case .mustRecharge:
score -= 20
case .preparingTo(_):
case .preparingTo:
score -= 20
}
}
Expand Down Expand Up @@ -786,7 +791,7 @@ public class BattleEngine: NSObject, GKGameModel {
return copy
}

public static func ==(lhs: BattleEngine, rhs: BattleEngine) -> Bool {
public static func == (lhs: BattleEngine, rhs: BattleEngine) -> Bool {
let value =
lhs.playerOne == rhs.playerOne &&
lhs.playerTwo == rhs.playerTwo &&
Expand All @@ -803,7 +808,7 @@ public class BattleEngine: NSObject, GKGameModel {
return value
}

public static func !=(lhs: BattleEngine, rhs: BattleEngine) -> Bool {
public static func != (lhs: BattleEngine, rhs: BattleEngine) -> Bool {
return !(lhs == rhs)
}

Expand Down
14 changes: 6 additions & 8 deletions PokemonKit/Sources/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,48 +58,46 @@ public class Player: NSObject, Codable, GKGameModelPlayer {
}

extension Player {
public static func ==(lhs: Player, rhs: Player) -> Bool {
public static func == (lhs: Player, rhs: Player) -> Bool {
return lhs.name == rhs.name &&
lhs.playerId == rhs.playerId &&
lhs.team == rhs.team &&
lhs.activePokemon == rhs.activePokemon
}

public static func !=(lhs: Player, rhs: Player) -> Bool {
public static func != (lhs: Player, rhs: Player) -> Bool {
return !(lhs == rhs)
}

public static func ==(lhs: Player, rhs: GKGameModelPlayer) -> Bool {
public static func == (lhs: Player, rhs: GKGameModelPlayer) -> Bool {
if let right = rhs as? Player {
return lhs == right
} else {
return false
}
}

public static func ==(lhs: GKGameModelPlayer, rhs: Player) -> Bool {
public static func == (lhs: GKGameModelPlayer, rhs: Player) -> Bool {
if let left = lhs as? Player {
return left == rhs
} else {
return false
}
}

public static func !=(lhs: Player, rhs: GKGameModelPlayer) -> Bool {
public static func != (lhs: Player, rhs: GKGameModelPlayer) -> Bool {
if let right = rhs as? Player {
return lhs != right
} else {
return false
}
}

public static func !=(lhs: GKGameModelPlayer, rhs: Player) -> Bool {
public static func != (lhs: GKGameModelPlayer, rhs: Player) -> Bool {
if let left = lhs as? Player {
return left != rhs
} else {
return false
}
}
}


1 change: 0 additions & 1 deletion PokemonKit/Sources/Pokedex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ public class Pokedex {

let languageID = Expression<Int>("local_language_id")


let query = """
select p.id, p.identifier, ps.name,
(select tn.name from type_names as tn
Expand Down
4 changes: 1 addition & 3 deletions PokemonKit/Sources/Pokemon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ extension Pokemon: CustomStringConvertible {
}

extension Pokemon: Equatable {
public static func ==(lhs: Pokemon, rhs: Pokemon) -> Bool {
public static func == (lhs: Pokemon, rhs: Pokemon) -> Bool {
return
lhs.species == rhs.species &&
lhs._nickname == rhs._nickname &&
Expand All @@ -263,5 +263,3 @@ extension Pokemon: Equatable {
lhs._currentHP == rhs._currentHP
}
}


2 changes: 1 addition & 1 deletion PokemonKit/Sources/Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class Random {
}

func copy() -> Random {
let copyRandomSource = self.randomSource.copy() as! GKRandomSource
guard let copyRandomSource = self.randomSource.copy() as? GKRandomSource else { fatalError() }

return Random(source: copyRandomSource)
}
Expand Down
9 changes: 7 additions & 2 deletions PokemonKit/Sources/Stats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ public struct Stats: Codable {
}

extension Stats: Equatable {
public static func ==(lhs: Stats, rhs: Stats) -> Bool {
return lhs.hp == rhs.hp && lhs.atk == rhs.atk && lhs.spAtk == rhs.spAtk && lhs.spDef == rhs.spDef && lhs.spd == rhs.spd
public static func == (lhs: Stats, rhs: Stats) -> Bool {
return
lhs.hp == rhs.hp &&
lhs.atk == rhs.atk &&
lhs.spAtk == rhs.spAtk &&
lhs.spDef == rhs.spDef &&
lhs.spd == rhs.spd
}
}
8 changes: 4 additions & 4 deletions PokemonKit/Sources/Turn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Turn: NSObject, Codable, GKGameModelUpdate {

var playerSpeed: Int {
switch action {
case .attack(_):
case .attack:
if player.activePokemon.status == .paralysed {
return player.activePokemon.baseStats.spd / 2
} else {
Expand All @@ -35,9 +35,9 @@ public class Turn: NSObject, Codable, GKGameModelUpdate {
switch action {
case let .attack(attack):
return attack.priority
case .switchTo(_):
case .switchTo:
return 6
case .forceSwitch(_):
case .forceSwitch:
return 7
case .run:
return 7
Expand All @@ -58,7 +58,7 @@ public class Turn: NSObject, Codable, GKGameModelUpdate {
}

extension Turn {
public static func ==(lhs: Turn, rhs: Turn) -> Bool {
public static func == (lhs: Turn, rhs: Turn) -> Bool {
return lhs.playerSpeed == rhs.playerSpeed &&
lhs.priority == rhs.priority &&
lhs.action == rhs.action
Expand Down
6 changes: 3 additions & 3 deletions PokemonKit/Sources/VolatileStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public enum VolatileStatus: Codable, Equatable, Hashable {

public func turn() -> VolatileStatus {
switch self {
case .confused(let c):
return .confused(c - 1)
case .confused(let counter):
return .confused(counter - 1)
default:
return self
}
}

// MARK:- Codable implementation
// MARK: - Codable implementation
enum CodingKeys: CodingKey {
case base, counter, attack
}
Expand Down
2 changes: 1 addition & 1 deletion PokemonKit/Sources/Weather.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public enum Weather: CustomStringConvertible {
return true
case (.extremelyHarshSunlight, .water):
return true
case(_,_):
case(_, _):
return false
}
}
Expand Down
12 changes: 4 additions & 8 deletions PokemonKit/Tests/Sources/PokemonKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ class PokemonKitTests: XCTestCase {
print(String(data: encodedTeamData, encoding: .utf8)!)
decodedTeamData = try JSONDecoder().decode([Pokemon].self, from: encodedTeamData)
} catch let error {
print(error)
XCTFail()
XCTFail(error.localizedDescription)
}
XCTAssertEqual(team, decodedTeamData)


}

func testActivePokemon() {
Expand Down Expand Up @@ -296,7 +293,6 @@ class PokemonKitTests: XCTestCase {
XCTAssertEqual(effectiveness, Type.Effectiveness.notEffective)
}


/// Checks that Solar Beam applies the correct volatile status to the Pokémon that uses it, and does no damage on the first turn
func testSolarBeamFirstTurn() {
let solarBeam = Pokedex.default.attacks["Solar Beam"]!
Expand Down Expand Up @@ -487,7 +483,7 @@ class PokemonKitTests: XCTestCase {
XCTAssertNotEqual(rhys.playerId, joe.playerId)
}

// MARK:- GKMinmaxStrategist tests
// MARK: - GKMinmaxStrategist tests

func testAICanMakeTurn() {
joe.activePokemon.attacks.append(Pokedex.default.attacks["Hyper Beam"]!)
Expand Down Expand Up @@ -548,7 +544,7 @@ class PokemonKitTests: XCTestCase {
XCTAssertTrue(engine.turns.count == 0)
}

// MARK:- Test Copy Constructors
// MARK: - Test Copy Constructors

func testPokemonCopyConstructor() {
bulbasaur.volatileStatus.insert(.flinch)
Expand All @@ -568,7 +564,7 @@ class PokemonKitTests: XCTestCase {
XCTAssertNotEqual(bulbasaur, bulbasaurCopy)
}

// MARK:- Weather Tests
// MARK: - Weather Tests
func testFireMoveInSunlight() {
engine.weather = .harshSunlight

Expand Down

0 comments on commit 6992502

Please sign in to comment.