Files
galaxy-game/client/storage.go
T
2026-03-12 19:45:46 +03:00

43 lines
2.1 KiB
Go

package client
import (
model "galaxy/model/client"
"galaxy/model/order"
"galaxy/model/report"
)
// Storage manages Client's data local storing and retrieval.
// It performs all I/O operations asynchronously to avoid UI main thread blocking.
type Storage interface {
// StateExists check if previously saved [model.State] exists on filesystem and returns result.
// I/O error may occur, it that case returned result will be false and error is non-nil.
StateExists() (bool, error)
// LoadState loads Client's [model.State] from filesystem data asynchronously.
// Passed callback func will accept non-nil error in case of I/O or decoding errors occuried,
// otherwise callback func accepts loaded [model.State].
LoadState(func(model.State, error))
// SaveState stores Client's state at the filesystem asynchronously.
// I/O or encoding error may occur, it that case callback func will be called with non-nil error.
SaveState(model.State, func(error))
// LoadReport 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].
LoadReport(model.GameID, uint, func(report.Report, error))
// PutReport stores given [report.Report] for a given [model.GameID] and turn number at the filesystem asynchronously.
// I/O or encoding error may occur, it that case callback func will be called with non-nil error.
PutReport(model.GameID, uint, report.Report, func(error))
// LoadOrder loads a [order.Order] 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 [order.Order].
LoadOrder(model.GameID, uint, func(order.Order, error))
// PutOrder stores given [order.Order] for a given [model.GameID] and turn number at the filesystem asynchronously.
// I/O or encoding error may occur, it that case callback func will be called with non-nil error.
PutOrder(model.GameID, uint, order.Order, func(error))
}