This repository has been archived on 2022-06-29. You can view files and clone it, but cannot push or open issues or pull requests.
urtrator/context/context_object.go
pztrn e2a9298f85 One more huge refactoring and quick connect widget working.
Refactored the way URTrator working with profiles - now everything
that could be taken from internal cache will be taken from cache.
The very same as with servers.

Moved all callbacks from callbacks to events, so we achieve full
asynchronity here and can launch anything in goroutines :).

Moved MainWindow-related game launching functions into another
file (mainwindow_launch.go).

Made quick connect widget working. Note, that even if you're on
Favorites and trying to connect to one of favorited servers but
with quick connect - you still have to choose right profile
near Launch button!

Maybe something else I forget.
2016-10-08 19:57:33 +05:00

109 lines
2.6 KiB
Go

// URTator - Urban Terror server browser and game launcher, written in
// Go.
//
// Copyright (c) 2016, Stanslav N. a.k.a pztrn (or p0z1tr0n)
// All rights reserved.
//
// Licensed under Terms and Conditions of GNU General Public License
// version 3 or any higher.
// ToDo: put full text of license here.
package context
import (
// stdlib
"errors"
"fmt"
// local
"github.com/pztrn/urtrator/cache"
"github.com/pztrn/urtrator/colorizer"
"github.com/pztrn/urtrator/configuration"
"github.com/pztrn/urtrator/database"
"github.com/pztrn/urtrator/eventer"
"github.com/pztrn/urtrator/launcher"
"github.com/pztrn/urtrator/requester"
// Github
"github.com/mattn/go-gtk/gtk"
)
type Context struct {
// Caching.
Cache *cache.Cache
// Colors parser and prettifier.
Colorizer *colorizer.Colorizer
// Configuration.
Cfg *configuration.Config
// Database.
Database *database.Database
// Eventer.
Eventer *eventer.Eventer
// Game launcher.
Launcher *launcher.Launcher
// Requester, which requests server's information.
Requester *requester.Requester
}
func (ctx *Context) Close() error {
fmt.Println("Closing URTrator...")
launched := ctx.Launcher.CheckForLaunchedUrbanTerror()
if launched != nil {
return errors.New("Urban Terror is launched!")
}
ctx.Cache.FlushProfiles(map[string]string{})
ctx.Cache.FlushServers(map[string]string{})
ctx.Database.Close()
// At last, close main window.
gtk.MainQuit()
return nil
}
func (ctx *Context) initializeCache() {
ctx.Cache = cache.New(ctx.Database, ctx.Eventer)
ctx.Cache.Initialize()
}
func (ctx *Context) initializeColorizer() {
ctx.Colorizer = colorizer.New()
ctx.Colorizer.Initialize()
}
func (ctx *Context) initializeConfig() {
ctx.Cfg = configuration.New()
ctx.Cfg.Initialize()
}
func (ctx *Context) initializeDatabase() {
ctx.Database = database.New(ctx.Cfg)
ctx.Database.Initialize(ctx.Cfg)
ctx.Database.Migrate()
}
func (ctx *Context) initializeEventer() {
ctx.Eventer = eventer.New()
ctx.Eventer.Initialize()
}
func (ctx *Context) initializeLauncher() {
ctx.Launcher = launcher.New()
ctx.Launcher.Initialize()
}
func (ctx *Context) initializeRequester() {
ctx.Requester = requester.New(ctx.Cache, ctx.Eventer)
ctx.Requester.Initialize()
}
func (ctx *Context) Initialize() {
fmt.Println("Initializing application context...")
ctx.initializeColorizer()
ctx.initializeConfig()
ctx.initializeDatabase()
ctx.initializeEventer()
ctx.initializeCache()
ctx.initializeLauncher()
ctx.initializeRequester()
}