fix logger

This commit is contained in:
2020-09-25 00:45:45 +03:00
parent d2b22f4760
commit 9f3eaafa3f
21 changed files with 115 additions and 79 deletions

View File

@ -1,7 +1,6 @@
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"
@ -14,7 +13,6 @@ var mapHeight = 90
type Level struct {
types.Rect
ctx context.Context
Name string
Branch string
Depth int
@ -66,23 +64,22 @@ func (l *Level) MakePassByXY (x,y int, tile *Tile) {
func (l *Level) Put (x, y int, tileFunc interface{}) {
tile := tileFunc.(func() *Tile)()
if tile == nil {
appctx.Logger(l.ctx).Fatal().Msgf("Got non-tile type to put into level: %v", tile)
appctx.Logger().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 context.Context, branch string, depth int) *Level {
func NewLevel(branch string, depth int) *Level {
l := &Level{
ctx: ctx,
Name: branch + string(depth),
Depth: depth,
Rect: types.NewRect(0,0, mapWidth, mapHeight),
}
l.Tiles = make([]*Tile, l.W*l.H)
appctx.Logger(ctx).Debug().Msgf("Generating level of branch %s depth %d", branch, depth)
appctx.Logger().Debug().Msgf("Generating level of branch %s depth %d", branch, depth)
return l
}

View File

@ -1,7 +1,6 @@
package mapgens
import (
"context"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/util"
@ -39,9 +38,9 @@ var fges = map[int]types.RectFill{
},
}
func GetRandomRoomList(ctx context.Context, rng *util.RNG, l *gamemap.Level, maxRooms, minRoomSize, maxRoomSize int, ) []gamemap.Room{
func GetRandomRoomList(rng *util.RNG, l *gamemap.Level, maxRooms, minRoomSize, maxRoomSize int, ) []gamemap.Room{
rooms := make([]gamemap.Room, 0)
pfLoader := gamemap.NewPrefabLoader(ctx)
pfLoader := gamemap.NewPrefabLoader()
pfRooms := pfLoader.PrefabRoomsList()
var fillage types.RectFill
@ -102,11 +101,12 @@ func GetRandomRoomList(ctx context.Context, rng *util.RNG, l *gamemap.Level, max
return rooms
}
func BlitToLevel (ctx context.Context, l *gamemap.Level, rooms[]gamemap.Room) {
//fixme overlapping rooms
func BlitToLevel (l *gamemap.Level, rooms[]gamemap.Room) {
for _, room := range rooms {
err := room.BlitToLevel(ctx, l)
err := room.BlitToLevel(l)
if err != nil {
appctx.Logger(ctx).Err(err)
appctx.Logger().Err(err)
}
}
}

View File

@ -3,10 +3,9 @@ package mapgens
import (
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/util"
"lab.zaar.be/thefish/alchemyst-go/util/appctx"
)
func DefaultGen(ctx appctx.ClientCtx,l *gamemap.Level) (*gamemap.Level, []gamemap.Room) {
func DefaultGen(l *gamemap.Level) (*gamemap.Level, []gamemap.Room) {
rng := util.NewRNG()
@ -17,9 +16,9 @@ func DefaultGen(ctx appctx.ClientCtx,l *gamemap.Level) (*gamemap.Level, []gamema
}
}
rooms := GetRandomRoomList(ctx, rng, l, maxrooms, minRoomSize, maxRoomSize)
rooms := GetRandomRoomList(rng, l, maxrooms, minRoomSize, maxRoomSize)
BlitToLevel(ctx, l, rooms)
BlitToLevel(l, rooms)
for idx, room := range rooms {
if idx > 0 {

View File

@ -18,10 +18,10 @@ func DelaunayMstGen(ctx context.Context, l *gamemap.Level) (*gamemap.Level, []ga
l.SetTileByXY(i, j, gamemap.NewWall())
}
}
rooms := GetRandomRoomList(ctx, rng, l, maxrooms, minRoomSize, maxRoomSize)
rooms := GetRandomRoomList(rng, l, maxrooms, minRoomSize, maxRoomSize)
BlitToLevel(ctx, l, rooms)
BlitToLevel(l, rooms)
centers := make([]types.Coords, 0)
for _, room := range rooms {

View File

@ -4,11 +4,10 @@ import (
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/util"
"lab.zaar.be/thefish/alchemyst-go/util/appctx"
"lab.zaar.be/thefish/alchemyst-go/util/delaunay"
)
func DelaunayMstExtGen(ctx appctx.ClientCtx, l *gamemap.Level) (*gamemap.Level, []gamemap.Room) {
func DelaunayMstExtGen(l *gamemap.Level) (*gamemap.Level, []gamemap.Room) {
rng := util.NewRNG()
@ -18,9 +17,9 @@ func DelaunayMstExtGen(ctx appctx.ClientCtx, l *gamemap.Level) (*gamemap.Level,
l.SetTileByXY(i, j, gamemap.NewWall())
}
}
rooms := GetRandomRoomList(ctx, rng, l, maxrooms, minRoomSize, maxRoomSize)
rooms := GetRandomRoomList(rng, l, maxrooms, minRoomSize, maxRoomSize)
BlitToLevel(ctx, l, rooms)
BlitToLevel(l, rooms)
centers := make([]types.Coords, 0)
for _, room := range rooms {

View File

@ -18,9 +18,9 @@ func DelaunayPureGen(ctx context.Context, l *gamemap.Level) (*gamemap.Level, []g
l.SetTileByXY(i, j, gamemap.NewWall())
}
}
rooms := GetRandomRoomList(ctx, rng, l, maxrooms, minRoomSize, maxRoomSize)
rooms := GetRandomRoomList(rng, l, maxrooms, minRoomSize, maxRoomSize)
BlitToLevel(ctx, l, rooms)
BlitToLevel(l, rooms)
centers := make([]types.Coords, 0)
for _, room := range rooms {

View File

@ -1,7 +1,6 @@
package gamemap
import (
"context"
"encoding/json"
"io/ioutil"
"lab.zaar.be/thefish/alchemyst-go/engine/items"
@ -42,12 +41,10 @@ func LoadPrefabFile(filename string) (*PrefabFile, error) {
return instance, nil
}
type PrefabLoader struct {
ctx context.Context
}
type PrefabLoader struct {}
func NewPrefabLoader(ctx context.Context) PrefabLoader {
return PrefabLoader{ctx: ctx}
func NewPrefabLoader() PrefabLoader {
return PrefabLoader{}
}
func (pfbl PrefabLoader) PrefabRoomsList() []Room {
@ -106,7 +103,7 @@ func (pfbl PrefabLoader) PrefabRoomsList() []Room {
} else {
f, ok = TileTypeMap[shortName]
if (!ok) {
appctx.Logger(pfbl.ctx).Warn().Msgf("Unknown tile: %s", shortName)
appctx.Logger().Warn().Msgf("Unknown tile: %s", shortName)
}
}
room.Geometry[i+ j*room.W] = f

View File

@ -1,7 +1,6 @@
package gamemap
import (
"context"
"errors"
"fmt"
"lab.zaar.be/thefish/alchemyst-go/engine/items"
@ -33,7 +32,7 @@ func (r *Room) Put (x, y int, tileFunc interface{}) {
}
}
func (room *Room) BlitToLevel(ctx context.Context, l *Level) error {
func (room *Room) BlitToLevel(l *Level) error {
//copy tiles like this:
//https://stackoverflow.com/questions/21011023/copy-pointer-values-a-b-in-golang
@ -51,7 +50,7 @@ func (room *Room) BlitToLevel(ctx context.Context, l *Level) error {
//check underlying tile
if underlyingTile == nil ||
underlyingTile.Name != "Wall" {
appctx.Logger(ctx).Warn().Msg("Invalid blit!")
appctx.Logger().Warn().Msg("Invalid blit!")
return invalidBlit
}
l.Put(mapCoords.X, mapCoords.Y, tileFunc)