Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonqiu212 committed Mar 13, 2024
1 parent 5788fdd commit adf2d7d
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 97 deletions.
17 changes: 8 additions & 9 deletions star-dash/star-dash/AppDelegate.swift
Expand Up @@ -10,27 +10,26 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
true
}

// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// If any sessions were discarded while the application was not running, this will be called shortly
// after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


}

12 changes: 7 additions & 5 deletions star-dash/star-dash/Constants/PhysicsConstants.swift
Expand Up @@ -15,15 +15,17 @@ struct PhysicsConstants {
static let obstacle: UInt32 = 0b01000
static let tool: UInt32 = 0b10000
}

struct CollisionMask {
static let playerCollisionMask = CollisionCategory.monster | CollisionCategory.collectible | CollisionCategory.obstacle | CollisionCategory.tool

static let playerCollisionMask = CollisionCategory.monster
| CollisionCategory.collectible | CollisionCategory.obstacle | CollisionCategory.tool

static let monsterCollisionMask = CollisionCategory.player | CollisionCategory.tool

static let collectibleCollisionMask = CollisionCategory.player

static let obstacleCollisionMask = CollisionCategory.player

static let toolCollisionMask = CollisionCategory.player | CollisionCategory.monster
}
}
6 changes: 3 additions & 3 deletions star-dash/star-dash/Entities/Components/Component.swift
Expand Up @@ -6,15 +6,15 @@
//

import Foundation

typealias ComponentId = UUID

class Component {
var entityId: EntityId
var id: ComponentId

init(id: ComponentId, entityId: EntityId) {
self.id = id
self.entityId = entityId

}

}
4 changes: 2 additions & 2 deletions star-dash/star-dash/Entities/Components/HealthComponent.swift
Expand Up @@ -9,12 +9,12 @@ import Foundation

class HealthComponent: Component {
var health: Int

init(id: ComponentId, entityId: EntityId, health: Int) {
self.health = health
super.init(id: id, entityId: entityId)
}

convenience init(entityId: EntityId, health: Int) {
self.init(id: UUID(), entityId: entityId, health: health)
}
Expand Down
13 changes: 8 additions & 5 deletions star-dash/star-dash/Entities/Components/PhysicsComponent.swift
Expand Up @@ -13,17 +13,20 @@ class PhysicsComponent: Component {
var force: CGVector
var collisionMask: UInt32
var affectedByGravity: Bool

init(id: ComponentId, entityId: EntityId, mass: CGFloat, velocity: CGVector, force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) {

init(id: ComponentId, entityId: EntityId, mass: CGFloat, velocity: CGVector,
force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) {
self.mass = mass
self.velocity = velocity
self.force = force
self.collisionMask = collisionMask
self.affectedByGravity = affectedByGravity
super.init(id: id, entityId: entityId)
}

convenience init(entityId: EntityId, mass: CGFloat, velocity: CGVector, force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) {
self.init(id: UUID(), entityId: entityId, mass: mass, velocity: velocity, force: force, collisionMask: collisionMask, affectedByGravity: affectedByGravity)

convenience init(entityId: EntityId, mass: CGFloat, velocity: CGVector,
force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) {
self.init(id: UUID(), entityId: entityId, mass: mass, velocity: velocity,
force: force, collisionMask: collisionMask, affectedByGravity: affectedByGravity)
}
}
10 changes: 4 additions & 6 deletions star-dash/star-dash/Entities/Components/PositionComponent.swift
Expand Up @@ -7,27 +7,25 @@

import Foundation


class PositionComponent: Component {
var position: CGPoint
var rotation: Float

init(id: UUID, entityId: UUID, position: CGPoint, rotation: Float) {
self.position = position
self.rotation = rotation
super.init(id: id, entityId: entityId)
}

convenience init(entityId: UUID, position: CGPoint, rotation: Float) {
self.init(id: UUID(), entityId: entityId, position: position, rotation: rotation)
}

func setPosition(position: CGPoint) {
self.position = position
}

func setRotation(rotation: Float) {
self.rotation = rotation
}

}
10 changes: 6 additions & 4 deletions star-dash/star-dash/Entities/Components/SpriteComponent.swift
Expand Up @@ -6,19 +6,21 @@
//

import Foundation

class SpriteComponent: Component {
// sprite could be single image or sprite set, could use enum to seperate, for sprite set will need to discuss how to rep animation
// TODO: sprite could be single image or sprite set, could use enum to seperate,
// for sprite set will need to discuss how to rep animation
var image: String
var size: CGSize

init(id: ComponentId, entityId: EntityId, image: String, size: CGSize) {
self.image = image
self.size = size
super.init(id: id, entityId: entityId)
}

convenience init(entityId: EntityId, image: String, size: CGSize) {
self.init(id: UUID(), entityId: entityId, image: image, size: size)
}

}
3 changes: 2 additions & 1 deletion star-dash/star-dash/Entities/Entity.swift
Expand Up @@ -6,10 +6,11 @@
//

import Foundation

typealias EntityId = UUID

protocol Entity {
var id: EntityId {get}

func setUpAndAdd(to: EntityManager)
}
9 changes: 6 additions & 3 deletions star-dash/star-dash/Entities/EntityManager.swift
Expand Up @@ -6,32 +6,35 @@
//

import Foundation

typealias ComponentSet = Set<ComponentId>
typealias ComponentMap = [ComponentId: Component]
typealias EntityMap = [EntityId: Entity]
typealias EntityComponentMap = [EntityId: ComponentSet]

class EntityManager {
var componentMap: ComponentMap
var entityMap: EntityMap
var entityComponentMap: EntityComponentMap

init(componentMap: ComponentMap, entityMap: EntityMap, entityComponentMap: EntityComponentMap) {
self.componentMap = componentMap
self.entityMap = entityMap
self.entityComponentMap = entityComponentMap
}

convenience init() {
self.init(componentMap: .init(), entityMap: .init(), entityComponentMap: .init())
}

func add(component: Component) {
guard self.componentMap[component.id] != nil else {
return
}
self.componentMap[component.id] = component
self.entityComponentMap[component.entityId]?.insert(component.id)
}

func add(entity: Entity) {
guard self.entityMap[entity.id] != nil else {
return
Expand Down
9 changes: 4 additions & 5 deletions star-dash/star-dash/Entities/GameEntities/Collectible.swift
Expand Up @@ -10,17 +10,16 @@ import Foundation
class Collectible: Entity {
let id: EntityId
private let position: CGPoint

init(id: EntityId, position: CGPoint) {
self.id = id
self.position = position
}

convenience init(position: CGPoint) {
self.init(id: UUID(), position: position)
}



func setUpAndAdd(to: EntityManager) {
let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero)
let physicsComponent = PhysicsComponent(
Expand All @@ -30,7 +29,7 @@ class Collectible: Entity {
force: .zero,
collisionMask: PhysicsConstants.CollisionMask.collectibleCollisionMask,
affectedByGravity: false)

to.add(entity: self)
to.add(component: positionComponent)
to.add(component: physicsComponent)
Expand Down
11 changes: 5 additions & 6 deletions star-dash/star-dash/Entities/GameEntities/Monster.swift
Expand Up @@ -6,20 +6,20 @@
//

import Foundation

class Monster: Entity {
let id: EntityId
private let position: CGPoint

init(id: EntityId, position: CGPoint) {
self.id = id
self.position = position
}

convenience init(position: CGPoint) {
self.init(id: UUID(), position: position)
}



func setUpAndAdd(to: EntityManager) {
let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero)
let healthComponent = HealthComponent(entityId: self.id, health: 100)
Expand All @@ -30,8 +30,7 @@ class Monster: Entity {
force: .zero,
collisionMask: PhysicsConstants.CollisionMask.monsterCollisionMask,
affectedByGravity: false)



to.add(entity: self)
to.add(component: positionComponent)
to.add(component: healthComponent)
Expand Down
9 changes: 4 additions & 5 deletions star-dash/star-dash/Entities/GameEntities/Obstacle.swift
Expand Up @@ -10,17 +10,16 @@ import Foundation
class Obstacle: Entity {
let id: EntityId
private let position: CGPoint

init(id: EntityId, position: CGPoint) {
self.id = id
self.position = position
}

convenience init(position: CGPoint) {
self.init(id: UUID(), position: position)
}



func setUpAndAdd(to: EntityManager) {
let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero)
let physicsComponent = PhysicsComponent(
Expand All @@ -30,7 +29,7 @@ class Obstacle: Entity {
force: .zero,
collisionMask: PhysicsConstants.CollisionMask.obstacleCollisionMask,
affectedByGravity: false)

to.add(entity: self)
to.add(component: positionComponent)
to.add(component: physicsComponent)
Expand Down
11 changes: 6 additions & 5 deletions star-dash/star-dash/Entities/GameEntities/Player.swift
Expand Up @@ -6,21 +6,22 @@
//

import Foundation

class Player: Entity {
let id: EntityId
private let position: CGPoint
private let playerSprite: PlayerSprite

init(id: EntityId, position: CGPoint, playerSprite: PlayerSprite) {
self.id = id
self.position = position
self.playerSprite = playerSprite
}

convenience init(position: CGPoint, playerSprite: PlayerSprite) {
self.init(id: UUID(), position: position, playerSprite: playerSprite)
}



func setUpAndAdd(to: EntityManager) {
let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero)
let healthComponent = HealthComponent(entityId: self.id, health: 100)
Expand All @@ -31,9 +32,9 @@ class Player: Entity {
force: .zero,
collisionMask: PhysicsConstants.CollisionMask.playerCollisionMask,
affectedByGravity: true)

let spriteComponent = SpriteComponent(entityId: self.id, image: "", size: .zero)

to.add(entity: self)
to.add(component: positionComponent)
to.add(component: healthComponent)
Expand Down
9 changes: 4 additions & 5 deletions star-dash/star-dash/Entities/GameEntities/Tool.swift
Expand Up @@ -10,17 +10,16 @@ import Foundation
class Tool: Entity {
let id: EntityId
private let position: CGPoint

init(id: EntityId, position: CGPoint) {
self.id = id
self.position = position
}

convenience init(position: CGPoint) {
self.init(id: UUID(), position: position)
}



func setUpAndAdd(to: EntityManager) {
let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero)
let physicsComponent = PhysicsComponent(
Expand All @@ -30,7 +29,7 @@ class Tool: Entity {
force: .zero,
collisionMask: PhysicsConstants.CollisionMask.toolCollisionMask,
affectedByGravity: false)

to.add(entity: self)
to.add(component: positionComponent)
to.add(component: physicsComponent)
Expand Down
1 change: 1 addition & 0 deletions star-dash/star-dash/Enums/PlayerSprite.swift
Expand Up @@ -6,6 +6,7 @@
//

import Foundation

enum PlayerSprite: String {
case RedNose = "red-nose"
}

0 comments on commit adf2d7d

Please sign in to comment.