File size: 1,899 Bytes
8fd7a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import PropTypes from 'prop-types';
import React from 'react';
import bindAll from 'lodash.bindall';
import styles from './prehistoric-mode.css';
import {connect} from 'react-redux';
import {isTimeTravel220022BC} from '../../reducers/time-travel';
import torch from './torch.gif';

class PrehistoricMode extends React.Component {
    constructor (props) {
        super(props);
        bindAll(this, [
            'handleMouseMove'
        ]);
        this.state = {
            x: window.innerWidth / 2,
            y: window.innerHeight / 2
        };
    }

    componentDidMount () {
        document.addEventListener('pointermove', this.handleMouseMove);
    }

    componentWillUnmount () {
        document.removeEventListener('pointermove', this.handleMouseMove);
    }

    handleMouseMove (event) {
        this.setState({x: event.clientX, y: event.clientY});
    }

    render () {
        if (!this.props.show) return null;
        return (
            <div
                className={styles.prehistoricMode}
            >
                <div
                    className={styles.prehistoricBackground}
                    style={{
                        backgroundPosition: `${this.state.x + 2000}px ${this.state.y + 2000}px`
                    }}
                /><img
                    className={styles.torch}
                    style={{
                        left: `${this.state.x - 35}px`,
                        top: `${this.state.y - 220}px`
                    }}
                    src={torch}
                    draggable={false}
                />
            </div>
        );
    }
}

PrehistoricMode.propTypes = {
    show: PropTypes.bool
};

const mapStateToProps = state => ({
    // This is the button's mode, as opposed to the actual current state
    show: isTimeTravel220022BC(state)
});

export default connect(
    mapStateToProps
)(PrehistoricMode);