Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make orb selection instant per OMSI request #1123

Merged
1 commit merged into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions packages/2019-disaster-game/src/components/atoms/Orb.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const defaultState = {
hasAnimated: false
};

const pressSuccessDuration = 1;
const pressSuccessDuration = 0.5;

export default class Orb extends PureComponent {
constructor(props) {
Expand Down Expand Up @@ -75,21 +75,16 @@ export default class Orb extends PureComponent {
}

incrementGauge = () => {
const timer = setTimeout(() => {
const { isActive } = this.state;
if (isActive) {
this.setState({ isComplete: true });
clearTimeout(timer);
} else {
this.setState({ isActive: false });
clearTimeout(timer);
}
}, pressSuccessDuration * 1000);
const { isActive } = this.state;
if (isActive) {
this.setState({ isComplete: true });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this changes the way the game works a bit. Now the item is captured immediately instead of after a second?

Probably unimportant, but figured I'd bring it up.

Copy link
Author

@ghost ghost Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's captured the moment it's pressed rather than after a second. Code's a little weird, but it works.

};

handleOrbPress = () => {
handleOrbRelease = () => {
const { isComplete } = this.state;
const { orbId, setOrbTouched } = this.props;

// if already pressed, do nothing
if (isComplete) return;

Expand All @@ -99,12 +94,6 @@ export default class Orb extends PureComponent {
setOrbTouched(orbId, true);
};

handleOrbRelease = () => {
this.setState({ isActive: false });
const { orbId, setOrbTouched } = this.props;
setOrbTouched(orbId, false);
};

render() {
const { isActive, isComplete } = this.state;
// eslint-disable-next-line no-unused-vars
Expand All @@ -121,8 +110,7 @@ export default class Orb extends PureComponent {

&.circle-complete-item-style {
transition: filter 0.5s ease-in-out;
transition: opacity 3s cubic-bezier(0.95, 0.05, 0.795, 0.035);
// filter: grayscale(100%);
transition: opacity 2s cubic-bezier(0.95, 0.05, 0.795, 0.035);
opacity: 0;
}
`;
Expand All @@ -138,8 +126,7 @@ export default class Orb extends PureComponent {

&.circle-complete-item-style {
transition: filter 0.5s ease-in-out;
transition: opacity 3s cubic-bezier(0.95, 0.05, 0.795, 0.035);
// filter: grayscale(100%);
transition: opacity 2s cubic-bezier(0.95, 0.05, 0.795, 0.035);
opacity: 0;
}
`;
Expand All @@ -149,18 +136,17 @@ export default class Orb extends PureComponent {
if (isComplete) orbClass = "circle-complete-item-style";

/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
return (
<div
ref={this.orbRef}
css={css`
${orbContainerStyle};
${sizeStyle};
`}
onMouseDown={this.handleOrbPress}
onMouseUp={this.handleOrbRelease}
onMouseLeave={this.handleOrbRelease}
onTouchStart={this.handleOrbPress}
onTouchEnd={this.handleOrbRelease}
onMouseDown={this.handleOrbRelease}
onTouchStart={this.handleOrbRelease}
onClick={this.handleOrbRelease}
>
<div css={absoluteStyle} className={orbClass}>
<RadialGauge
Expand All @@ -181,6 +167,7 @@ export default class Orb extends PureComponent {
</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions */
/* eslint-enable jsx-a11y/click-events-have-key-events */
}
}

Expand Down