import State from '../state'
import keys from '../../cgt/inputs/keyboard'
import font from '../font'
import create_tact from '../../cgt/utils/tact'
import config from '../../config'

export default class ReadyState extends State {
    init(img) {
        this.img = img
        this.showText = false

        this.font = font.get()

        this.tact = create_tact(500)

        keys.map(config.keybindings().keyboard)
    }

    draw(ctx) {
        ctx.drawImage(this.img, 0, 0)
        if (this.showText) {
            this.font.draw(ctx, 'Press START', 80, 70)
        }
    }

    update() {
        if (this.tact()) {
            this.showText = !this.showText
        }

        if (keys.get('START')) {
            this.emit('start')
        }
    }
}
