-
Notifications
You must be signed in to change notification settings - Fork 7
/
Map.jsx
64 lines (55 loc) · 1.51 KB
/
Map.jsx
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
import React from 'react';
import styled from 'styled-components';
// Due to Dota 2's Y coordinate being flipped compared to web coordinates most
// of this styling uses `bottom` as well as various flipped Y transforms.
const StyledMap = styled.div`
position: absolute;
// Adding an additional 8% to place the camera a bit higher up for comfort
bottom: 58%;
left: 50%;
`;
const StyledOffset = styled.div`
position: relative;
> img {
position: relative;
display: block;
}
`;
const StyledWebPFallback = styled.div`
width: 300px;
position: absolute;
bottom: 0;
left: 0;
transform: translate(-50%, 50%);
text-align: center;
p {
margin: 10px 10px;
}
`;
const Map = React.forwardRef((props, ref) => {
const { children, patch, style } = props;
const { map } = patch;
return (
<StyledMap style={style}>
<StyledOffset>
<StyledWebPFallback>
<p>Loading the Dota 2 map background...</p>
<p>If it never loads, your browser may not support the WebP image format.</p>
<p>¯\_(ツ)_/¯</p>
</StyledWebPFallback>
<img
ref={ref}
src={`./images/map/${map.id}.webp`}
alt={`Dota 2 map v${map.id}`}
style={{
transform: `translate(${-50 + map.backdrop.offset.x}%, ${50 + map.backdrop.offset.y}%)`,
width: `${map.backdrop.size}px`,
height: `${map.backdrop.size}px`,
}}
/>
{children}
</StyledOffset>
</StyledMap>
);
});
export default Map;