tins2020/context.go

41 lines
727 B
Go
Raw Normal View History

2020-05-08 16:38:26 +00:00
package tins2020
import (
rice "github.com/GeertJohan/go.rice"
"github.com/veandco/go-sdl2/sdl"
)
type Context struct {
2020-05-09 05:48:02 +00:00
Renderer *sdl.Renderer
2020-05-08 16:38:26 +00:00
Fonts Fonts
Resources Resources
Textures Textures
Settings Settings
}
func NewContext(res *rice.Box) (*Context, error) {
ctx := &Context{}
err := ctx.Settings.Init()
if err != nil {
return nil, err
}
err = ctx.Resources.Open(res)
if err != nil {
return nil, err
}
return ctx, nil
}
func (c *Context) Init(renderer *sdl.Renderer) {
2020-05-09 05:48:02 +00:00
c.Renderer = renderer
2020-05-08 16:38:26 +00:00
c.Fonts.Init(c.Resources.Copy())
2020-05-09 05:48:02 +00:00
c.Textures.Init(renderer, c.Resources.Copy())
2020-05-08 16:38:26 +00:00
}
func (c *Context) Destroy() {
c.Fonts.Destroy()
c.Resources.Destroy()
c.Textures.Destroy()
c.Settings.Store()
}