-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split app into multiple files and add routing
Needed to allow for multiple pages in same app.
- Loading branch information
Showing
9 changed files
with
244 additions
and
93 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import BattleGoalsDeck from './BattleGoalsDeck'; | ||
|
||
class AttackModifierDeck extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
render() { | ||
return ( | ||
<div className="bg-greenscreen h-screen"> | ||
<BattleGoalsDeck /> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default AttackModifierDeck; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import Card from './Card'; | ||
import './App.css'; | ||
|
||
class BattleGoalsDeck extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
deck: [], | ||
shuffledDeck: [], | ||
drawnDeck: [] | ||
}; | ||
this.drawCard = this.drawCard.bind(this); | ||
} | ||
componentDidMount() { | ||
fetch(process.env.PUBLIC_URL + '/gloomhaven/data/battle-goals.js') | ||
.then(res => res.json()) | ||
.then( | ||
(result) => { | ||
const deck = result.filter(c => c.name !== 'battlegoal-back'); | ||
this.setState({ | ||
deck: deck, | ||
shuffledDeck: shuffleDeck(deck), | ||
drawnDeck: [] | ||
}); | ||
}, | ||
(error) => { | ||
console.error(error); | ||
} | ||
) | ||
} | ||
drawCard() { | ||
const shuffledDeck = this.state.shuffledDeck.length > 0 ? | ||
this.state.shuffledDeck : shuffleDeck(this.state.deck); | ||
|
||
const drawnDeck = this.state.shuffledDeck.length > 0 ? | ||
this.state.drawnDeck : []; | ||
|
||
this.setState({ | ||
deck: this.state.deck, | ||
drawnDeck: [shuffledDeck[0], ...drawnDeck], | ||
shuffledDeck: [...shuffledDeck.slice(1)] | ||
}); | ||
} | ||
render() { | ||
const drawnCards = this.state.drawnDeck.map((card) => | ||
<Card key={card.name} image={process.env.PUBLIC_URL + '/gloomhaven/images/' + card.image } name={card.name} /> | ||
); | ||
|
||
return ( | ||
<div className="flex flex-wrap flex-row"> | ||
<Card | ||
name="Draw Battle Card" | ||
onClick={this.drawCard} | ||
image={process.env.PUBLIC_URL + '/gloomhaven/images/battle-goals/battlegoal-back.png' } /> | ||
{drawnCards} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
// Fisher–Yates shuffle | ||
function shuffleDeck(deck) { | ||
var newDeck = [...deck]; | ||
for (let i = newDeck.length - 1; i > 0; i--) { | ||
const j = Math.floor(Math.random() * (i + 1)); | ||
[newDeck[i], newDeck[j]] = [newDeck[j], newDeck[i]]; | ||
} | ||
return newDeck; | ||
} | ||
|
||
export default BattleGoalsDeck; |
Oops, something went wrong.