-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor campfire into its own component
- Loading branch information
1 parent
7b34913
commit 8102558
Showing
4 changed files
with
75 additions
and
57 deletions.
There are no files selected for viewing
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,45 @@ | ||
import {html, Component} from '../../web_modules/htm/preact/standalone.module.js' | ||
import CardChooser from './card-chooser.js' | ||
|
||
export default class CampfireRoom extends Component { | ||
rest() { | ||
this.props.onChoose('rest') | ||
} | ||
choose(choice, reward) { | ||
this.setState({ | ||
choice, | ||
reward, | ||
isChoosingCard: !this.state.isChoosingCard, | ||
}) | ||
if (reward) { | ||
this.props.onChoose(choice, reward) | ||
} | ||
} | ||
onSelectCard(card) { | ||
this.choose(this.state.choice, card) | ||
} | ||
render(props, state) { | ||
const {gameState, room} = props | ||
return html` | ||
<h1 center medium>Campfire ${room.choice}</h1> | ||
<ul class="Options"> | ||
<li><button onclick=${() => this.rest()}>Rest</button></li> | ||
<li><button onclick=${() => this.choose('upgradeCard')}>Upgrade card</button></li> | ||
<li><button onclick=${() => this.choose('removeCard')}>Remove card</button></li> | ||
</ul> | ||
${state.isChoosingCard && | ||
html` <p center>Choose a card to ${state.choice}.</p> | ||
<${CardChooser} | ||
cards=${gameState.deck} | ||
didSelectCard=${(card) => this.onSelectCard(card)} | ||
gameState=${gameState} | ||
/>`} | ||
<p center> | ||
<button onclick=${() => this.props.onContinue()}>Continue</button> | ||
</p> | ||
` | ||
} | ||
} |
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