-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from sp4ce-cowboy/feature/branch-systemsNew
Add Systems Component [with merge conflicts resolved]
- Loading branch information
Showing
21 changed files
with
277 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
TowerForge/TowerForge/LevelManager/Events/Implemented Events/RemoveEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
struct RemoveEvent: TFEvent { | ||
let timestamp: TimeInterval | ||
let entityId: UUID | ||
|
||
init(on entityId: UUID, at timestamp: TimeInterval) { | ||
self.timestamp = timestamp | ||
self.entityId = entityId | ||
} | ||
|
||
func execute(in target: any EventTarget) -> EventOutput? { | ||
guard let removeSystem = target.system(ofType: RemoveSystem.self) else { | ||
return nil | ||
} | ||
|
||
removeSystem.handleRemove(for: entityId) | ||
return EventOutput() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 25 additions & 7 deletions
32
TowerForge/TowerForge/LevelManager/Systems/HealthSystem.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
// | ||
// HealthSystem.swift | ||
// TowerForge | ||
// | ||
// Created by Zheng Ze on 16/3/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class HealthSystem: TFSystem { | ||
var isActive = false | ||
weak var entityManager: EntityManager? | ||
weak var eventManager: EventManager? | ||
|
||
init(entityManager: EntityManager, eventManager: EventManager) { | ||
self.entityManager = entityManager | ||
self.eventManager = eventManager | ||
} | ||
|
||
/// Modifies the health of the entity associated with the specified UUID according | ||
/// to the provided healthpoints amount. | ||
/// - Parameters: | ||
/// - entityId: UUID of the entity whose health component is to be modified | ||
/// - hp: Value of the required adjustment of health. Can be positive or negative. | ||
func modifyHealth(for entityId: UUID, with hp: CGFloat) -> Bool { | ||
/*guard isActive else { TODO: Implement boolean check | ||
return | ||
}*/ | ||
guard let currentEntity = entityManager?.entity(with: entityId), | ||
let healthComponent = currentEntity.component(ofType: HealthComponent.self) else { | ||
return false | ||
} | ||
|
||
healthComponent.adjustHealth(amount: hp) | ||
return healthComponent.isZero | ||
} | ||
} |
Oops, something went wrong.