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

@ -60,7 +60,8 @@ func main() {
var logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).Level(logLevels[config.Verbosity])
// set up context
mainCtx := appctx.NewClientContext(config, &logger)
appctx.NewClientContext(config, &logger)
mainCtx := appctx.ClientState
//set up main window
mw := mainwindow.Init(mainCtx)
@ -72,9 +73,9 @@ func main() {
go decodeInput(mainCtx, mw.GetLayer("base"))
//fixme set up (load / generate) level - move to game / enter or title / exit
//level, rooms := _default.DefaultGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1))
level, rooms := mapgens.DefaultGen(gamemap.NewLevel("test", 1))
//level, rooms := mapgens.DelaunayMstGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1))
level, rooms := mapgens.DelaunayMstExtGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1))
//level, rooms := mapgens.DelaunayMstExtGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1))
//level, rooms := mapgens.DelaunayPureGen(mainCtx, gamemap.NewLevel(mainCtx, "test", 1))
State.Level = level
@ -85,7 +86,7 @@ func main() {
//set up controller
controller := ecs.NewController(mainCtx)
controller := ecs.NewController()
controller.MapComponentClass(ecs.CoordsComponent, types.Coords{})
controller.MapComponentClass(ecs.AppearanceComponent, types.Appearance{})
@ -105,9 +106,9 @@ func main() {
bp := items.Backpack{MaxMass:100, MaxBulk:100}
//Set up Screen Manager
screenMgr := types.NewScreenManager(mainCtx)
screenMgr := types.NewScreenManager()
screenMgr.AddScreen("title", screens.NewTitleScreen(mw, screenMgr))
screenMgr.AddScreen("game", screens.NewGameScreen(mainCtx, mw, &State, vp, controller, screenMgr))
screenMgr.AddScreen("game", screens.NewGameScreen(mw, &State, vp, controller, screenMgr))
screenMgr.AddScreen("help", screens.NewMenuScreen(
mw,
screenMgr,
@ -126,7 +127,7 @@ func main() {
"i - inventory",
"? - this screen",
"Ctrl+q - exit",
"f or F - fire or throw weapon",
"f or F - fire weapon or throw item",
"z or Z - cast a spell",
"p - pray",
"Ctrl+p - message log",
@ -183,7 +184,7 @@ func main() {
},
})
controller.AddComponent(potion, rooms[0].Center) //implicit Coords
controller.AddComponent(potion, items.Carried{Mass:5, Bulk:3})
controller.AddComponent(potion, items.Carried{Mass:5, Bulk:3}) //fixme generate from blueprint!
controller.AddComponent(potion, items.Usable{})
controller.AddComponent(potion, items.Consumable{})
controller.AddComponent(potion, ecs.Named{Name:"first potion"})
@ -222,7 +223,7 @@ func main() {
// f()
// break
case <-State.Exit:
appctx.Logger(mainCtx).Warn().Msg("quitting NOW")
appctx.Logger().Warn().Msg("quitting NOW")
exit = true
break
// не оставляйте default в бесконечном select {} - сожрет всё CPU
@ -233,7 +234,7 @@ func main() {
}
}
appctx.Logger(mainCtx).Info().Msg("pre-shutdown sequence")
appctx.Logger().Info().Msg("pre-shutdown sequence")
}
func setupLayers(mainwindow *mainwindow.MainWindow) {
@ -253,9 +254,9 @@ func decodeInput(ctx context.Context, baseLayer *mainwindow.Layer) {
continue
}
if keycode == blt.TK_CLOSE && !waitForWCspam {
appctx.Logger(ctx).Warn().Msg("exiting on window close...")
appctx.Logger().Warn().Msg("exiting on window close...")
State.Exit <- struct{}{}
appctx.Logger(ctx).Warn().Msg("...done")
appctx.Logger().Warn().Msg("...done")
return
}
var pressed = ""
@ -279,9 +280,9 @@ func decodeInput(ctx context.Context, baseLayer *mainwindow.Layer) {
case "Ctrl+q":
//fallthrough
//case "Escape":
appctx.Logger(ctx).Info().Msg("exiting on quit command...")
appctx.Logger().Info().Msg("exiting on quit command...")
State.Exit <- struct{}{}
appctx.Logger(ctx).Info().Msg("...done")
appctx.Logger().Info().Msg("...done")
exit = true
return
default: