feat: westworldwithmessaging. add entitymanager, telegram, messagehandlers, delayedmessages, expand baseentity
This commit is contained in:
1 parent
0e7482e04c
commit
129dd5d8b8
18 files changed
+505
-19
No files matched your search
@@ -1,4 +1,4 @@
|
||||
package westworldwithwoman
|
||||
package westworldwithmessaging
|
||||
|
||||
// StateMachine is the Go version of the C++ class template:
|
||||
//
|
||||
@@ -129,3 +129,25 @@ func (sm *StateMachine[T]) PreviousState() State[T] {
|
||||
func (sm *StateMachine[T]) IsInState(st State[T]) bool {
|
||||
return sm.currentState == st
|
||||
}
|
||||
|
||||
// HandleMessage is the Go version of StateMachine::HandleMessage. A
|
||||
// telegram is offered to the current state first; if that state
|
||||
// doesn't have code in place to deal with this particular message
|
||||
// (OnMessage returns false), it's offered to the global state
|
||||
// instead. The C++ version was marked const - same as Update, Go has
|
||||
// no equivalent keyword and doesn't need one.
|
||||
func (sm *StateMachine[T]) HandleMessage(msg Telegram) bool {
|
||||
// first see if the current state is valid and that it can handle
|
||||
// the message
|
||||
if sm.currentState != nil && sm.currentState.OnMessage(sm.owner, msg) {
|
||||
return true
|
||||
}
|
||||
|
||||
// if not, and if a global state has been implemented, send
|
||||
// the message to the global state
|
||||
if sm.globalState != nil && sm.globalState.OnMessage(sm.owner, msg) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user