import Game from '../core/game'

class Logger {

    constructor (x = 90, y = 70) {
        this.lines = []

        this.x = x
        this.y = y
    }

    init () {
        Game.on('draw', ({ ctx }) => {

            // console.log(this.lines.join("\n"))

            ctx.font = '18px sans-serif'
            ctx.fillStyle = '#fff'
            this.lines.forEach((line, index) => {
                ctx.fillText(line, this.x, this.y + index * 50)
            })

            this.lines = []

        }, 100)

        Game.on('log', msg => {
            this.lines.push(msg)
        })
    }

}

export default new Logger
