const { Component } = require('preact'); const preact = require('preact'); const idleAnimation = require('./anims/idle'); const wiggle = require('./anims/wiggle'); class Img extends Component { constructor() { super(); // The animation ids are a check to ensure that animations are not repeated // When a new account animation is communicated with state it will have a corresponding Id // which is a count of how many resoluttions have passed this.animations = []; this.resetAnimations = this.resetAnimations.bind(this); } render() { const { id, img } = this.props; const imgStyle = img ? { 'background-image': `url(/imgs/${img}.svg)` } : null; return (
); } onClick() { if (this.props.mtxActive) { return this.props.sendMtxAccountApply(); } return this.animations.push(wiggle(this.props.id, this.idle)); } componentDidMount() { this.idle = idleAnimation(this.props.id); return this.animations.push(this.idle); } resetAnimations() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); } } componentWillUnmount() { this.resetAnimations(); } } function Scoreboard(args) { const { isPlayer, player, chat, } = args; const scoreText = () => { if (player.score === 'Zero' || player.score === 'Lose') return [, , ]; if (player.score === 'One') return [, , ]; if (player.score === 'Two') return [, , ]; if (player.score === 'Win') return [, , ]; return ''; }; const winner = player.score === 'Win'; const chatText = chat ? chat : player.draw_offered ? 'draw' : '\u00A0'; if (!isPlayer) { const nameClass = `name ${player.img ? 'subscriber' : ''}`; return (
{scoreText()}
{player.name}
{chatText}
); } const boxClass = `player-box bottom ${winner ? 'winner': player.ready ? 'ready' : ''}`; const nameClass = `name ${player.img ? 'subscriber' : ''}`; return (
{chatText}
{scoreText()}
{player.name}
); } module.exports = Scoreboard;