loader revisited

This commit is contained in:
Ilia Denisov
2026-03-16 19:52:02 +02:00
committed by GitHub
parent e6c6970947
commit 3f1776aa5f
30 changed files with 1581 additions and 527 deletions
+49 -10
View File
@@ -4,6 +4,7 @@ import (
"image"
"sync"
"galaxy/client/updater"
"galaxy/client/world"
"galaxy/connector"
mc "galaxy/model/client"
@@ -67,6 +68,17 @@ type client struct {
viewportH int
hits []world.Hit
fullStorage storage.Storage
fullConnector connector.Connector
updater *updater.Manager
backgroundStop chan struct{}
backgroundOnce sync.Once
onConnectionFn func(bool)
onConnectionErrFn func(error)
onStorageErrFn func(error)
onServiceErrFn func(error)
}
func NewClient(s storage.UIStorage, conn connector.UIConnector, app fyne.App) (mc.Client, error) {
@@ -82,6 +94,16 @@ func NewClient(s storage.UIStorage, conn connector.UIConnector, app fyne.App) (m
},
lastCanvasScale: 1.0,
hits: make([]world.Hit, 5),
backgroundStop: make(chan struct{}),
}
if fullStorage, ok := s.(storage.Storage); ok {
e.fullStorage = fullStorage
}
if fullConnector, ok := conn.(connector.Connector); ok {
e.fullConnector = fullConnector
}
if e.fullStorage != nil && e.fullConnector != nil {
e.updater = updater.NewManager(e.fullStorage, e.fullConnector)
}
e.loadReportFunc = e.loadReport
@@ -128,10 +150,6 @@ func (e *client) setReport(r report.Report) {
e.loadWorld(w)
}
func (e *client) handlerError(err error) {
}
func (e *client) BuildUI(w fyne.Window) {
mapCanvas := newInteractiveRaster(e, e.raster, e.onRasterWidgetLayout, e.onScrolled, e.onDragged, e.onDradEnd, e.onTapped)
mapCanvas.SetMinSize(fyne.NewSize(292, 292))
@@ -201,19 +219,40 @@ func (e *client) loadWorld(w *world.World) {
func (e *client) Run() error {
e.BuildUI(e.window)
e.window.SetMaster()
e.window.ShowAndRun()
e.startBackground()
e.RequestRefresh()
e.window.ShowAndRun()
e.stopBackground()
return nil
}
func (e *client) Shutdown() { e.window.Close() }
func (e *client) Shutdown() {
e.stopBackground()
e.window.Close()
}
func (e *client) Version() string { return version }
func (e *client) OnConnection(bool) {}
func (e *client) OnConnection(isGood bool) {
if e.onConnectionFn != nil {
e.onConnectionFn(isGood)
}
}
func (e *client) OnConnectionError(error) {}
func (e *client) OnConnectionError(err error) {
if e.onConnectionErrFn != nil {
e.onConnectionErrFn(err)
}
}
func (e *client) OnStorageError(error) {}
func (e *client) OnStorageError(err error) {
if e.onStorageErrFn != nil {
e.onStorageErrFn(err)
}
}
func (e *client) OnServiceError(error) {}
func (e *client) OnServiceError(err error) {
if e.onServiceErrFn != nil {
e.onServiceErrFn(err)
}
}