const Phaser = require('phaser'); const { TEXT } = require('./constants'); const ROW_WIDTH = 400; const ROW_HEIGHT = 200; const ROW_FILL = 0x888888; const TOP_MARGIN = 50; const ROW_MARGIN = 50; const TEXT_MARGIN = 24; const xPos = i => 0; const yPos = i => (i * ROW_HEIGHT + ROW_MARGIN) + TOP_MARGIN; class CrypRow extends Phaser.GameObjects.Group { constructor(list, cryps) { super(list); cryps.forEach((cryp, i) => { const X_ORIGIN = xPos(i); const Y_ORIGIN = yPos(i); const row = list.add.rectangle(X_ORIGIN, Y_ORIGIN, ROW_WIDTH, ROW_HEIGHT, ROW_FILL * Math.random()) .setInteractive() .setOrigin(0); row.cryp = cryp; this.add(row); this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 0), cryp.name, TEXT.HEADER)); this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 1), cryp.stamina.base, TEXT.NORMAL)); }); return true; } } module.exports = CrypRow;