Skip to content

Commit

Permalink
Save Event Log state in a cookie
Browse files Browse the repository at this point in the history
Closes #173.
  • Loading branch information
beheh committed Dec 14, 2016
1 parent ae4da25 commit a6234d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Implement Jade Golem text formatting (@azeier)
- Enable `Launcher.locale` after initial render
- Add `Launcher.build: number`
- Save Event Log state in a cookie (#173)

### Changed
- Change `Launcher.fromUrl` to return launcher instance
Expand Down
24 changes: 20 additions & 4 deletions ts/components/GameWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Fullscreen from "fullscreen";
import * as Immutable from "immutable";
import {Zone} from "../enums";
import Entity from "../Entity";
import {cookie} from "cookie_js";

interface GameWidgetState {
gameState?: GameState;
Expand Down Expand Up @@ -44,13 +45,22 @@ export default class GameWidget extends React.Component<GameWidgetProps, GameWid
isRevealingCards: typeof this.props.startRevealed === "undefined" ? true : this.props.startRevealed,
cardOracle: null,
mulliganOracle: null,
isLogVisible: false,
isLogVisible: false, // we might show it once we receive the first game state
isLogMounted: false,
};
}

public componentDidMount() {
this.cb = this.setGameState.bind(this);
this.props.sink.once("gamestate", () => {
const showLog = !!+cookie.get("joust_event_log", "0");
if(showLog) {
this.setState({
isLogVisible: true,
isLogMounted: true,
});
}
});
this.props.sink.on("gamestate", this.cb.bind(this));
this.fullscreen = new Fullscreen(this.ref);
this.fullscreen.on("attain", this.onAttainFullscreen.bind(this));
Expand Down Expand Up @@ -240,7 +250,9 @@ export default class GameWidget extends React.Component<GameWidgetProps, GameWid
);

if (this.props.scrubber) {
parts.push(<Scrubber key="scrubber" scrubber={this.props.scrubber}
parts.push(<Scrubber
key="scrubber"
scrubber={this.props.scrubber}
swapPlayers={() => {
let newSwap = !this.state.swapPlayers;
this.setState({ swapPlayers: newSwap });
Expand Down Expand Up @@ -269,8 +281,12 @@ export default class GameWidget extends React.Component<GameWidgetProps, GameWid
}
}}
isLogVisible={this.state.isLogVisible}
toggleLog={() => this.setState({ isLogVisible: !this.state.isLogVisible, isLogMounted: true })}
enableKeybindings={this.props.enableKeybindings}
toggleLog={() => {
const newState = !this.state.isLogVisible;
this.setState({ isLogVisible: newState, isLogMounted: true });
cookie.set("joust_event_log", "" + (+newState));
}}
enableKeybindings={this.props.enableKeybindings}
/>);
}

Expand Down

0 comments on commit a6234d6

Please sign in to comment.