Fixing auto-skip in harvest and adding restart-game.

This commit is contained in:
2020-04-06 16:59:07 -07:00
parent f485f811ba
commit 38c2920b85
2 changed files with 47 additions and 32 deletions

View File

@@ -1111,38 +1111,46 @@ class Die extends React.Component {
return roll;
}
tick() {
this.acc += this.interval;
// update die face
if (this.ticks < this.maxTicks && this.acc >= this.trigger) {
this.ticks++;
this.acc = 0;
// update trigger for decay
if (this.props.decay) {
this.trigger = decay(this.props.ms, this.decayFactorPct,
this.maxTicks - this.ticks);
}
// we're finished, clear things, set final roll value
if (this.ticks >= this.maxTicks) {
clearInterval(this.timerId);
this.timerId = false;
this.setState({ num: this.props.num, finalFace: true });
if (this.props.showScreen) {
this.showScreenTimerId = setInterval(() => {
this.props.showScreen();
clearInterval(this.showScreenTimerId);
this.showScreenTimerId = false;
}, this.props.showScreenDelay);
tick = () => {
let finished = false;
return function() {
if (!finished) {
this.acc += this.interval;
// update die face
if (this.ticks < this.maxTicks && this.acc >= this.trigger) {
this.ticks++;
this.acc = 0;
// update trigger for decay
if (this.props.decay) {
this.trigger = decay(this.props.ms, this.decayFactorPct,
this.maxTicks - this.ticks);
}
// we're finished, clear things, set final roll value
if (this.ticks >= this.maxTicks) {
finished = true;
clearInterval(this.timerId);
this.timerId = false;
this.setState({ num: this.props.num, finalFace: true });
if (this.props.showScreen) {
this.showScreenTimerId = setInterval(() => {
this.props.showScreen();
clearInterval(this.showScreenTimerId);
this.showScreenTimerId = false;
}, this.props.showScreenDelay);
}
} else {
this.setState({ num: this.roll() });
}
}
} else {
this.setState({ num: this.roll() });
console.log('harvest die finished but still ticking');
}
}
}
componentDidMount() {
if (this.props.roll) {
this.timerId = setInterval(() => this.tick(), this.interval);
this.timerId = setInterval(this.tick().bind(this), this.interval);
}
}