make context great again
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package gamemap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
|
||||
"lab.zaar.be/thefish/alchemyst-go/engine/types"
|
||||
"lab.zaar.be/thefish/alchemyst-go/util/appctx"
|
||||
@ -13,7 +14,7 @@ var mapHeight = 90
|
||||
|
||||
type Level struct {
|
||||
types.Rect
|
||||
ctx appctx.ClientCtx
|
||||
ctx context.Context
|
||||
Name string
|
||||
Branch string
|
||||
Depth int
|
||||
@ -53,17 +54,26 @@ func (l *Level) SetTileByXY (x,y int, tile *Tile) {
|
||||
l.Tiles[y*l.W+x] = tile
|
||||
}
|
||||
|
||||
//only replaces tile if original is not passable
|
||||
func (l *Level) MakePassByXY (x,y int, tile *Tile) {
|
||||
t := l.Tiles[y*l.W+x]
|
||||
if t.BlocksPass {
|
||||
l.Tiles[y*l.W+x] = tile
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (l *Level) Put (x, y int, tileFunc interface{}) {
|
||||
tile := tileFunc.(func() *Tile)()
|
||||
if tile == nil {
|
||||
l.ctx.Logger().Fatal().Msgf("Got non-tile type to put into level: %v", tile)
|
||||
appctx.Logger(l.ctx).Fatal().Msgf("Got non-tile type to put into level: %v", tile)
|
||||
}
|
||||
if l.InBounds(types.Coords{x, y}) {
|
||||
l.Tiles[y*l.W+x] = tile
|
||||
}
|
||||
}
|
||||
|
||||
func NewLevel(ctx appctx.ClientCtx, branch string, depth int) *Level {
|
||||
func NewLevel(ctx context.Context, branch string, depth int) *Level {
|
||||
l := &Level{
|
||||
ctx: ctx,
|
||||
Name: branch + string(depth),
|
||||
@ -72,7 +82,7 @@ func NewLevel(ctx appctx.ClientCtx, branch string, depth int) *Level {
|
||||
}
|
||||
|
||||
l.Tiles = make([]*Tile, l.W*l.H)
|
||||
ctx.Logger().Debug().Msgf("Generating level of branch %s depth %d", branch, depth)
|
||||
appctx.Logger(ctx).Debug().Msgf("Generating level of branch %s depth %d", branch, depth)
|
||||
return l
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user