All files / lib/components/Game/Screen/Start index.tsx

0% Statements 0/11
0% Branches 0/2
0% Functions 0/2
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                             
import { css } from '@emotion/react';
import { StartScreen as StartScreenModel } from '@uniquegood/realworld-web-interface/lib/models/game/Screen/Start';
import React from 'react';
import StartScreenPageA from '@lib/components/Game/Screen/Start/pageTypes/A';
import StartScreenPageB from '@lib/components/Game/Screen/Start/pageTypes/B';
import StartScreenPageC from '@lib/components/Game/Screen/Start/pageTypes/C';
import StartScreenPageD from '@lib/components/Game/Screen/Start/pageTypes/D';
import { MAX_HEIGHT_DP, MAX_WIDTH_DP } from '@uniquegood/realworld-web-interface/lib/constants/game';
 
const screenDisplayTypeToComponentMap: Record<
  StartScreenModel['displayType'],
  React.FC<{ screen: StartScreenModel }>
> = {
  A: StartScreenPageA,
  B: StartScreenPageB,
  C: StartScreenPageC,
  D: StartScreenPageD
};
 
export default function StartScreen(props: StartScreenModel) {
  const { displayType, style } = props;
  const ScreenComponent = screenDisplayTypeToComponentMap[displayType];
 
  if (!ScreenComponent) throw new Error('Invalid screen display type');
 
  const pageWrapStyle = React.useMemo(() => {
    const cssText = `
      background-color: ${style.backgroundColor};
      background-image: url(${style.backgroundImageUrl});
    `;
 
    return css(cssText);
  }, [style]);
 
  return (
    <div css={pageContainer}>
      <div css={[pageWrap, pageWrapStyle]}>
        <ScreenComponent screen={props} />
      </div>
    </div>
  );
}
const pageContainer = css`
  width: 100%;
  height: 100%;
`;
 
const pageWrap = css`
  width: ${MAX_WIDTH_DP}px;
  height: ${MAX_HEIGHT_DP}px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
`;