adds StateName generic to EntityStateMachine
This commit is contained in:
parent
08e20d1656
commit
81e18ba443
|
|
@ -166,8 +166,8 @@ public class StateComponentMapping {
|
||||||
|
|
||||||
// MARK: -
|
// MARK: -
|
||||||
|
|
||||||
public class EntityStateMachine {
|
public class EntityStateMachine<StateName: Hashable> {
|
||||||
private var states: [String: EntityState]
|
private var states: [StateName: EntityState]
|
||||||
|
|
||||||
private var currentState: EntityState?
|
private var currentState: EntityState?
|
||||||
|
|
||||||
|
|
@ -178,18 +178,18 @@ public class EntityStateMachine {
|
||||||
states = [:]
|
states = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult public func addState(name: String, state: EntityState) -> Self {
|
@discardableResult public func addState(name: StateName, state: EntityState) -> Self {
|
||||||
states[name] = state
|
states[name] = state
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
public func createState(name: String) -> EntityState {
|
public func createState(name: StateName) -> EntityState {
|
||||||
let state = EntityState()
|
let state = EntityState()
|
||||||
states[name] = state
|
states[name] = state
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
public func changeState(name: String) {
|
public func changeState(name: StateName) {
|
||||||
guard let newState = states[name] else {
|
guard let newState = states[name] else {
|
||||||
fatalError("Entity state '\(name)' doesn't exist")
|
fatalError("Entity state '\(name)' doesn't exist")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -223,9 +223,8 @@ class EntityStateTests: XCTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntityStateMachineTests: XCTestCase {
|
class EntityStateMachineTests: XCTestCase {
|
||||||
|
|
||||||
var nexus = Nexus()
|
var nexus = Nexus()
|
||||||
var fsm = EntityStateMachine(entity: .init(nexus: .init(), id: .invalid))
|
var fsm = EntityStateMachine<String>(entity: .init(nexus: .init(), id: .invalid))
|
||||||
var entity = Entity(nexus: .init(), id: .init(rawValue: 1))
|
var entity = Entity(nexus: .init(), id: .init(rawValue: 1))
|
||||||
|
|
||||||
override func setUp() {
|
override func setUp() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue