class Drawer { #tubeDrawObjects; #scale; constructor(_padding, _scale, _game) { this.#tubeDrawObjects = [] this.#scale = _scale; this.#initializeTubeDrawObjects(_game, _padding); this.#computeCanvasSize(_padding); } applySelectedEffect(index) { this.#tubeDrawObjects[index].y -= this.#scale; } removeSelectedEffect(index) { this.#tubeDrawObjects[index].y += this.#scale; } #initializeTubeDrawObjects(_game, _padding) { let _tubeX = _padding; let _tubeY = _padding + this.#scale; for (let tbIndex = 0; tbIndex < _game.tubesNumber(); tbIndex++) { let tubeDrawObject = new TubeDrawObject(_tubeX, _tubeY, _game.tubeAt(tbIndex), this.#scale); this.#tubeDrawObjects.push(tubeDrawObject); _tubeX += this.#scale + _padding; } } #computeCanvasSize(_padding) { let w = this.#tubeDrawObjects.reduce((res, value) => res + value.width + _padding, _padding); let h = this.#tubeDrawObjects[0].height + 2 * _padding + this.#scale; createCanvas(w, h); } draw() { clear(); background('orange'); this.#tubeDrawObjects.forEach(obj => obj.draw()); } getTubeIdAt(x, y) { for (let i = 0; i < this.#tubeDrawObjects.length; i++) { if (this.#tubeDrawObjects[i].inbounds(x, y)) return i; } return -1; } }