Skip to content

Commit

Permalink
Add instant max mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sho-87 committed Mar 27, 2020
1 parent 53ec980 commit 83227c6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class App extends Component {
isShownTotals: true,
isScreenshotStats: false,
isSpeedMode: false,
isInstantMax: false,
isShownMouseXY: false,
isShownTalentID: false
};
Expand All @@ -213,6 +214,7 @@ class App extends Component {
localStorage.getItem('isScreenshotStats')
);
const isSpeedMode = JSON.parse(localStorage.getItem('isSpeedMode'));
const isInstantMax = JSON.parse(localStorage.getItem('isInstantMax'));
const isShownMouseXY = JSON.parse(localStorage.getItem('isShownMouseXY'));
const isShownTalentID = JSON.parse(
localStorage.getItem('isShownTalentID')
Expand All @@ -227,6 +229,7 @@ class App extends Component {
isScreenshotStats:
isScreenshotStats === null ? false : isScreenshotStats,
isSpeedMode: isSpeedMode === null ? false : isSpeedMode,
isInstantMax: isInstantMax === null ? false : isInstantMax,
isShownMouseXY: isShownMouseXY === null ? false : isShownMouseXY,
isShownTalentID: isShownTalentID === null ? false : isShownTalentID
};
Expand Down Expand Up @@ -549,6 +552,27 @@ class App extends Component {
});
};

/**
* Toggle instant max mode
*
* @memberof App
*/
toggleInstantMax = () => {
this.setState(
prevState => ({
isInstantMax: !prevState.isInstantMax
}),
() => {
localStorage.setItem('isInstantMax', this.state.isInstantMax);
}
);

ReactGA.event({
category: 'Settings',
action: 'Toggle instant max'
});
};

/**
* Toggle mouse XY position display
*
Expand Down Expand Up @@ -637,6 +661,7 @@ class App extends Component {
toggleNodeSize={this.toggleNodeSize}
toggleScreenshotStats={this.toggleScreenshotStats}
toggleSpeedMode={this.toggleSpeedMode}
toggleInstantMax={this.toggleInstantMax}
toggleMouseXY={this.toggleMouseXY}
toggleTalentID={this.toggleTalentID}
toggleAnnounce={this.toggleAnnounce}
Expand All @@ -654,6 +679,7 @@ class App extends Component {
isShownTotals={this.state.isShownTotals}
isScreenshotStats={this.state.isScreenshotStats}
isSpeedMode={this.state.isSpeedMode}
isInstantMax={this.state.isInstantMax}
isShownMouseXY={this.state.isShownMouseXY}
isShownTalentID={this.state.isShownTalentID}
/>
Expand Down Expand Up @@ -703,6 +729,7 @@ class App extends Component {
isShownValues={this.state.isShownValues}
isShownTotals={this.state.isShownTotals}
isSpeedMode={this.state.isSpeedMode}
isInstantMax={this.state.isInstantMax}
isShownMouseXY={this.state.isShownMouseXY}
isShownTalentID={this.state.isShownTalentID}
isEmbed={this.props.isEmbed}
Expand Down
2 changes: 2 additions & 0 deletions src/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ class NavBar extends Component {
toggleNodeSize={this.props.toggleNodeSize}
toggleScreenshotStats={this.props.toggleScreenshotStats}
toggleSpeedMode={this.props.toggleSpeedMode}
toggleInstantMax={this.props.toggleInstantMax}
toggleMouseXY={this.props.toggleMouseXY}
toggleTalentID={this.props.toggleTalentID}
isShownInfoPanel={this.props.isShownInfoPanel}
isShownValues={this.props.isShownValues}
isShownTotals={this.props.isShownTotals}
isScreenshotStats={this.props.isScreenshotStats}
isSpeedMode={this.props.isSpeedMode}
isInstantMax={this.props.isInstantMax}
isShownMouseXY={this.props.isShownMouseXY}
isShownTalentID={this.props.isShownTalentID}
nodeSize={this.props.nodeSize}
Expand Down
10 changes: 10 additions & 0 deletions src/NavBarSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ function NavBarSettings(props) {
points"
/>
</div>
<div className="help-wrapper">
<Form.Check
type="switch"
id="settings-instant-max"
label="Instant max"
checked={props.isInstantMax}
onChange={e => props.toggleInstantMax()}
/>
<HelpTooltip tooltip="Assign max points with a single click" />
</div>
</div>

{process.env.NODE_ENV === 'development' && (
Expand Down
20 changes: 17 additions & 3 deletions src/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Node extends Component {
this.props.nodeSize !== nextProps.nodeSize ||
this.props.isShownValues !== nextProps.isShownValues ||
this.props.isShownTalentID !== nextProps.isShownTalentID ||
this.props.isSpeedMode !== nextProps.isSpeedMode
this.props.isSpeedMode !== nextProps.isSpeedMode ||
this.props.isInstantMax !== nextProps.isInstantMax
) {
return true;
} else {
Expand Down Expand Up @@ -91,7 +92,9 @@ class Node extends Component {
* @memberof Node
*/
talentIncrease = () => {
if (this.props.calcPointsRemaining() > 0) {
const pointsRemaining = this.props.calcPointsRemaining();

if (pointsRemaining > 0) {
// Check prerequisites
const prereqs = this.props.treeData[this.props.treeName][this.props.idx]
.prereq;
Expand All @@ -118,11 +121,22 @@ class Node extends Component {

if (prereqsOK) {
if (this.props.value < this.props.max) {
let numberAssignable = 1;

if (this.props.isInstantMax) {
if (this.props.max - this.props.value > pointsRemaining) {
numberAssignable = pointsRemaining;
this.props.showPointLimitToast();
} else {
numberAssignable = this.props.max - this.props.value;
}
}

this.props.changeTalentValue(
this.props.color,
this.props.idx,
'increase',
1
numberAssignable
);
jsPlumb
.select({
Expand Down
1 change: 1 addition & 0 deletions src/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Tree extends Component {
isShownValues={this.props.isShownValues}
isShownTalentID={this.props.isShownTalentID}
isSpeedMode={this.props.isSpeedMode}
isInstantMax={this.props.isInstantMax}
isEmbed={this.props.isEmbed}
nodeSize={this.props.nodeSize}
treeData={this.props.treeData}
Expand Down
1 change: 1 addition & 0 deletions src/TreePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class TreePanel extends Component {
isShownMouseXY: this.props.isShownMouseXY,
isShownTalentID: this.props.isShownTalentID,
isSpeedMode: this.props.isSpeedMode,
isInstantMax: this.props.isInstantMax,
nodeSize: this.props.nodeSize,
treeData: this.props.treeData,
commander: this.props.commander
Expand Down

0 comments on commit 83227c6

Please sign in to comment.