import Game from '@/core/game'

import Walls from '@/classes/walls'
import ImageLoader from '@/core/imageloader'
import ScenesManager from '@/plugins/scenesmanager'
import Units from '@/classes/units'
import Rules from '@/classes/rules'

import map from '@/levels/de_shortdust'

export default class TestScene {
    constructor () {
    }

    init (manager) {
        Walls.init(map.walls)

        this.rules = new Rules()


        this.centerMap = () => {
            if (!this.bgImage) return
            const scale = Math.min(Game.width / this.bgImage.width, Game.height / this.bgImage.height) * 1
            // manager._left = -this.player.position[0]
            // manager._top = -this.player.position[1] // - 200

            // console.log(-manager._left, Game.width - this.bgImage.width)
            manager._zoom = scale
        }

        ImageLoader.load('map', map.image)

        this.units = new Units(map)
    }


    draw ({ ctx, dt }) {
        this.centerMap()
        ImageLoader.draw('map', ctx)
        this.units.draw({ ctx, dt })
    }


    drawTest (ctx) {
        ctx.beginPath()
        ctx.strokeStyle = 'rgba(255,255,255,.4)'

        this.walls.walls.forEach(wall => {

            let p1 = this.walls.findIntersect(this.player.position, wall[0])

            if (p1) {
                ctx.moveTo(this.player.position[0], this.player.position[1])
                ctx.lineTo(p1[0], p1[1])
            }

            p1 = this.walls.findIntersect(this.player.position, wall[1])
            if (p1) {
                ctx.moveTo(this.player.position[0], this.player.position[1])
                ctx.lineTo(p1[0], p1[1])
            }
        })

        ctx.stroke()
        ctx.closePath()
    }
}
