fix: save being broken after a while

This commit is contained in:
Daniel Schmidt 2024-09-02 12:13:16 +02:00
parent 1604f876a8
commit efbc74077a

View File

@ -292,7 +292,12 @@ func (s *Session) ToSavedState() SavedState {
PointsPerRound: s.pointsPerRound,
Merchant: s.merchant,
EventHistory: s.eventHistory,
StateCheckpoints: s.stateCheckpoints,
StateCheckpoints: lo.Map(s.stateCheckpoints, func(item StateCheckpoint, index int) StateCheckpoint {
return StateCheckpoint{
Session: nil,
Events: item.Events,
}
}),
CtxData: s.ctxData,
LoadedMods: s.loadedMods,
}
@ -512,6 +517,14 @@ func (s *Session) SetEvent(id string) {
if _, ok := s.resources.Events[id]; ok {
s.eventHistory = append(s.eventHistory, id)
_, _ = s.resources.Events[id].OnEnter.Call(CreateContext("type_id", id))
} else {
s.log.Println("Event not found:", id)
s.currentEvent = ""
// If we can't find the event, we just go to the next state
if s.state == GameStateEvent {
s.SetGameState(GameStateRandom)
}
}
}