client io architecture
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"galaxy/model/order"
|
||||
"galaxy/model/report"
|
||||
)
|
||||
|
||||
type Client interface {
|
||||
// Run initializes necessary UI layout an settings, and activates client's main window.
|
||||
// This is a blocking operation until client's main window is closed.
|
||||
Run() error
|
||||
|
||||
// Shutdown closes client's main window and performing all necessary data persistence.
|
||||
Shutdown()
|
||||
|
||||
// OnConnection receives an event when connection with client's server may be established (true) or connectivity lost (false).
|
||||
OnConnection(bool)
|
||||
}
|
||||
|
||||
type GameID string
|
||||
|
||||
func (i GameID) String() string {
|
||||
return string(i)
|
||||
}
|
||||
|
||||
type State struct {
|
||||
// TODO: store user login key
|
||||
GameState []GameState `json:"gameState"`
|
||||
ActiveGameID GameID `json:"activeGameId"`
|
||||
}
|
||||
|
||||
type GameState struct {
|
||||
ID GameID `json:"id"`
|
||||
LastTurn uint `json:"lastTurn"`
|
||||
ActiveTurn uint `json:"activeTurn"`
|
||||
}
|
||||
|
||||
type GameData struct {
|
||||
Turn uint `json:"turn"`
|
||||
Report report.Report `json:"report"`
|
||||
Order *order.Order `json:"order,omitempty"`
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
// TODO: use fyne.Storage for initializing and storing data
|
||||
StoragePath string
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import (
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
Commands []DecodableCommand `json:"cmd"`
|
||||
// TODO: check with already stored order, if any, and generate an error, if newer order exists
|
||||
UpdatedAt int `json:"updatedAt"`
|
||||
Commands []DecodableCommand `json:"cmd"`
|
||||
}
|
||||
|
||||
func (o Order) MarshalBinary() (data []byte, err error) {
|
||||
|
||||
@@ -14,6 +14,10 @@ func F(v float64) Float {
|
||||
return Float(u.Fixed3(v))
|
||||
}
|
||||
|
||||
func (f Float) F() float64 {
|
||||
return float64(f)
|
||||
}
|
||||
|
||||
type Report struct {
|
||||
Version uint `json:"version"`
|
||||
Turn uint `json:"turn"`
|
||||
|
||||
Reference in New Issue
Block a user