http connector first impl

This commit is contained in:
Ilia Denisov
2026-03-12 23:45:06 +02:00
committed by GitHub
parent f985370089
commit 9adadc3bbf
13 changed files with 962 additions and 41 deletions
+8 -1
View File
@@ -9,6 +9,7 @@ import (
"galaxy/connector"
mc "galaxy/model/client"
"galaxy/model/report"
"galaxy/storage"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
@@ -17,7 +18,10 @@ import (
"fyne.io/fyne/v2/widget"
)
const version = "1.0.0"
type client struct {
s storage.UIStorage
conn connector.UIConnector
app fyne.App
window fyne.Window
@@ -66,8 +70,9 @@ type client struct {
hits []world.Hit
}
func NewClient(ctx context.Context, conn connector.UIConnector, app fyne.App, settings mc.Settings) (mc.Client, error) {
func NewClient(ctx context.Context, s storage.UIStorage, conn connector.UIConnector, app fyne.App) (mc.Client, error) {
e := &client{
s: s,
conn: conn,
app: app,
window: app.NewWindow("Galaxy Plus"),
@@ -206,3 +211,5 @@ func (e *client) Shutdown() {
}
func (e *client) OnConnection(bool) {}
func (e *client) Version() string { return version }
+1 -5
View File
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"galaxy/client"
mc "galaxy/model/client"
"os"
"os/signal"
@@ -26,14 +25,11 @@ func main() {
}
}()
app := app.New()
settings := mc.Settings{
StoragePath: ".",
}
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
c, err := client.NewClient(ctx, nil, app, settings)
c, err := client.NewClient(ctx, nil, nil, app)
if err != nil {
return
}
-42
View File
@@ -1,42 +0,0 @@
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))
}