mtx images

This commit is contained in:
ntr 2019-09-22 18:45:30 +10:00
parent c4a291e890
commit 9bf700bd75

View File

@ -1,6 +1,10 @@
const { Component } = require('preact');
const preact = require('preact'); const preact = require('preact');
const { connect } = require('preact-redux'); const { connect } = require('preact-redux');
const idleAnimation = require('./anims/idle');
const wiggle = require('./anims/wiggle');
const addState = connect( const addState = connect(
function receiveState(state) { function receiveState(state) {
const { const {
@ -23,17 +27,70 @@ const addState = connect(
); );
function AccountBox(args) { class AccountAvatar extends Component {
const { constructor() {
account, super();
mtxActive, // 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
sendMtxAccountApply, // which is a count of how many resoluttions have passed
} = args; this.animations = [];
this.resetAnimations = this.resetAnimations.bind(this);
}
render() {
const { account, mtxActive } = this.props;
const imgStyle = account.img const imgStyle = account.img
? { 'background-image': `url(/imgs/${account.img}.svg)`, cursor: mtxActive ? 'pointer' : '' } ? { 'background-image': `url(/imgs/${account.img}.svg)`, cursor: mtxActive ? 'pointer' : '' }
: null; : null;
return (
<div
class="img avatar"
id={account.id}
onMouseDown={this.onClick.bind(this)}
style={imgStyle}>
</div>
);
}
onClick() {
if (this.props.mtxActive) {
return this.props.sendMtxAccountApply();
}
return this.animations.push(wiggle(this.props.account.id, this.idle));
}
componentDidMount() {
this.idle = idleAnimation(this.props.account.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();
}
// shouldComponentUpdate(newProps) {
// const { account } = newProps;
// if (account !== this.props.account) {
// return true;
// }
// return false;
// }
}
const StateAccountAvatar = addState(AccountAvatar);
function AccountBox(args) {
const {
account,
} = args;
// if (!isTop) { // if (!isTop) {
// return ( // return (
@ -45,20 +102,10 @@ function AccountBox(args) {
// ); // );
// } // }
const onClick = () => {
if (!mtxActive) return false;
return sendMtxAccountApply();
};
return ( return (
<div class='player-box bottom'> <div class='player-box bottom'>
<div class="msg">&nbsp;</div> <div class="msg">&nbsp;</div>
<div <StateAccountAvatar />
class="img avatar"
id={account.img}
onClick={onClick}
style={imgStyle}>
</div>
<div class="name">{account.name}</div> <div class="name">{account.name}</div>
<div class="score">0 MMR</div> <div class="score">0 MMR</div>
</div> </div>