ui calculator

This commit is contained in:
Ilia Denisov
2026-03-30 19:38:24 +02:00
committed by GitHub
parent 17f366cd6b
commit a7793f5416
37 changed files with 2046 additions and 270 deletions
+23
View File
@@ -128,6 +128,15 @@ func (s *fsStorage) SaveStateAsync(state client.State, callback func(error)) {
}()
}
func (s *fsStorage) ReportExistsAsync(id client.GameID, turn uint, callback func(bool, error)) {
go func() {
exists, err := s.gameDataExistsSync(id, turn)
if callback != nil {
callback(exists, err)
}
}()
}
func (s *fsStorage) LoadReportAsync(id client.GameID, turn uint, callback func(report.Report, error)) {
go func() {
rep, err := s.loadReportSync(id, turn)
@@ -343,6 +352,20 @@ func (s *fsStorage) saveOrderSync(id client.GameID, turn uint, o order.Order) er
}))
}
func (s *fsStorage) gameDataExistsSync(id client.GameID, turn uint) (bool, error) {
absPath, err := s.resolvePath(gameTurnFilePath(id, turn))
if err != nil {
return false, classifyStorageError(err)
}
exists, err := s.fileExistsUnlocked(absPath)
if err != nil {
return false, classifyStorageError(err)
}
return exists, nil
}
func (s *fsStorage) loadGameDataSync(id client.GameID, turn uint) (client.GameData, error) {
absPath, err := s.resolvePath(gameTurnFilePath(id, turn))
if err != nil {
+5
View File
@@ -36,6 +36,11 @@ type UIStorage interface {
// I/O or encoding error may occur, it that case callback func will be called with non-nil error.
SaveStateAsync(client.State, func(error))
// ReportExistsAsync asynchronously checks whether given [model.GameID] and turn number exists in the Storage.
// Passed callback func will will accept non-nil error in case of I/O or decoding errors occuried,
// otherwise callback func accepts boolean result.
ReportExistsAsync(client.GameID, uint, func(bool, error))
// LoadReportAsync loads a [report.Report] for a given [model.GameID] and turn number from filesystem asynchronously.
// Passed callback func will will accept non-nil error in case of I/O or decoding errors occuried,
// otherwise callback func accepts loaded [report.Report].