-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from elmadev/metsavir-levelmap
Add LevelMap
- Loading branch information
Showing
10 changed files
with
130 additions
and
15 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
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 |
---|---|---|
|
@@ -5,12 +5,6 @@ | |
margin-bottom: 20px; | ||
} | ||
|
||
.cover { | ||
height: 100%; | ||
width: 100%; | ||
object-fit: contain; | ||
} | ||
|
||
.info { | ||
padding-top: 10px; | ||
} |
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,82 @@ | ||
/* eslint-disable react/no-danger */ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useStoreState, useStoreActions } from 'easy-peasy'; | ||
import PropTypes from 'prop-types'; | ||
import styled, { css } from 'styled-components'; | ||
import Loading from 'components/Loading'; | ||
|
||
import { levToSvg } from 'elma-js'; | ||
|
||
const MapContainer = styled.div` | ||
height: ${props => props.height}; | ||
> div { | ||
${props => | ||
props.fullscreen && | ||
css` | ||
top: 0; | ||
left: 0; | ||
position: fixed; | ||
z-index: 99; | ||
`} | ||
width: 100%; | ||
height: 100%; | ||
box-sizing: border-box; | ||
background: #333; | ||
border: 10px solid #333; | ||
transition: ${props => (props.fullscreen ? null : 'opacity 0.3s ease')}; | ||
cursor: pointer; | ||
&:hover { | ||
opacity: ${props => (props.fullscreen ? 1 : 0.8)}; | ||
} | ||
} | ||
svg .sky { | ||
} | ||
svg .APPLE { | ||
} | ||
svg .KILLER { | ||
} | ||
svg .FLOWER { | ||
} | ||
svg .START { | ||
} | ||
svg { | ||
overflow: hidden; | ||
object-fit: contain; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
`; | ||
|
||
const LevelMap = ({ LevelIndex }) => { | ||
const [fullscreen, setFullscreen] = useState(false); | ||
const { levelData } = useStoreState(state => state.LevelMap); | ||
const { getLevelData } = useStoreActions(actions => actions.LevelMap); | ||
|
||
useEffect(() => { | ||
getLevelData(LevelIndex); | ||
}, [LevelIndex]); | ||
|
||
if (!levelData) { | ||
return <Loading />; | ||
} | ||
|
||
const svg = levToSvg(levelData.LevelData); | ||
|
||
return ( | ||
<MapContainer | ||
fullscreen={fullscreen} | ||
onClick={() => setFullscreen(!fullscreen)} | ||
height="100%" | ||
> | ||
<div dangerouslySetInnerHTML={{ __html: svg }} /> | ||
</MapContainer> | ||
); | ||
}; | ||
|
||
LevelMap.propTypes = { | ||
LevelIndex: PropTypes.number.isRequired, | ||
}; | ||
|
||
export default LevelMap; |
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,6 @@ | ||
{ | ||
"name": "LevelMap", | ||
"version": "0.0.1", | ||
"private": true, | ||
"main": "./LevelMap.js" | ||
} |
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,16 @@ | ||
/* eslint-disable no-param-reassign */ | ||
import { action, thunk } from 'easy-peasy'; | ||
import { LevelData } from 'data/api'; | ||
|
||
export default { | ||
levelData: null, | ||
setLevelData: action((state, payload) => { | ||
state.levelData = payload; | ||
}), | ||
getLevelData: thunk(async (actions, payload) => { | ||
const levelData = await LevelData(payload); | ||
if (levelData.ok) { | ||
actions.setLevelData(levelData.data); | ||
} | ||
}), | ||
}; |
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