Skip to content

Commit

Permalink
Merge pull request #2698 from serge-web/2692-core-mapping
Browse files Browse the repository at this point in the history
Initialize Core Mapping
  • Loading branch information
IanMayo authored Nov 23, 2023
2 parents b0b392a + 423ed62 commit 6ee4ba3
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn precommit-msg
yarn lint
yarn test-unit
# yarn precommit-msg
# yarn lint
# yarn test-unit
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,26 @@
[
"./client"
],
"typescript.tsdk": "client/node_modules\\typescript\\lib"
"typescript.tsdk": "client/node_modules\\typescript\\lib",
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#2f7c47",
"activityBar.background": "#2f7c47",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#422c74",
"activityBarBadge.foreground": "#e7e7e7",
"commandCenter.border": "#e7e7e799",
"sash.hoverBorder": "#2f7c47",
"statusBar.background": "#215732",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#2f7c47",
"statusBarItem.remoteBackground": "#215732",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#215732",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#21573299",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#215732",
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
27 changes: 27 additions & 0 deletions client/src/Components/local/atoms/core-mapping/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# CoreMapping Documentation

Core Mapping component

## UI Example

<!-- STORY -->

## Code example

<!-- SOURCE -->

## Props

<!-- PROPS -->

## Usage

### ES6 Import
```js
import CoreMapping from './core-mapping'
```

### CommonJS

```js
const CoreMapping = require('./core-mapping')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Core Mapping component: renders correctly 1`] = `null`;
32 changes: 32 additions & 0 deletions client/src/Components/local/atoms/core-mapping/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* global it expect */
import React from 'react'
import renderer from 'react-test-renderer'
import CoreMapping from './index'
import { Phase } from 'src/config'
import { CHANNEL_CORE_MAPPING, CoreMappingChannel } from 'src/custom-types'

jest.mock('react-leaflet-v4', () => ({
MapContainer: (): React.ReactElement => <></>,
TileLayer: (): React.ReactElement => <></>
}))

const channel: CoreMappingChannel = {
uniqid: 'core',
name: 'core-mapping',
channelType: CHANNEL_CORE_MAPPING,
participants: [],
renderers: [],
constraints: {
bounds: [[1, 1], [2, 2]],
minZoom: 5
}
}

describe('Core Mapping component:', () => {
it('renders correctly', () => {
const tree = renderer
.create(<CoreMapping playerForce={'f-red'} messages={[]} channel={channel} playerRole={'mgr'} currentTurn={1} forces={[]} currentPhase={Phase.Planning}/>)
.toJSON()
expect(tree).toMatchSnapshot()
})
})
160 changes: 160 additions & 0 deletions client/src/Components/local/atoms/core-mapping/index.stories-inc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { withKnobs } from '@storybook/addon-knobs'
import React from 'react'
import CoreMapping from './index'
import docs from './README.md'
import { Phase } from 'src/config'
import { CHANNEL_CORE_MAPPING, CORE_MAPPING, CoreMappingChannel, CoreMappingMessage, CoreProperties, CoreRenderer, EnumProperty, MilSymProperties, MilSymRenderer, PARTICIPANT_CORE_MAPPING } from 'src/custom-types/core-mapping'
import { Feature, FeatureCollection } from 'geojson'

const wrapper: React.FC = (storyFn: any) => <div style={{ height: '600px', position: 'relative' }}>{storyFn()}</div>

export default {
title: 'local/organisms/CoreMapping',
component: CoreMapping,
decorators: [withKnobs, wrapper],
parameters: {
readme: {
// Show readme before story
content: docs
}
}
}

const coreProps: CoreProperties = {
id: 'id-1',
color: '#f00',
phase: Phase.Planning,
label: 'START LINE',
turn: 1,
force: 'f-red',
// additional props for core renderer
important: 'Yes'
}

const milSymProps: MilSymProperties = {
id: 'id-1',
phase: Phase.Planning,
label: 'Headquarters Building',
turn: 1,
force: 'f-red',
sidc: 'ASDF-0-340',
// additional props for mil symbol
category: 'Civilian',
size: 'M'
}

const coreFeature: Feature = {
type: 'Feature',
properties: coreProps,
geometry: {
coordinates: [
[
[-2.519250407617534, 51.91732658109052],
[-2.519250407617534, 51.36084289848887],
[-1.2313772261967983, 51.36084289848887],
[-1.2313772261967983, 51.91732658109052],
[-2.519250407617534, 51.91732658109052]
]
],
type: 'Polygon'
}
}

const milFeature: Feature = {
type: 'Feature',
properties: milSymProps,
geometry: {
coordinates: [-2.519250407617534, 51.91732658109052],
type: 'Point'
}
}

/** note: this will extend `CoreMessage` */
const features: FeatureCollection = {
type: 'FeatureCollection',
features: [coreFeature, milFeature]
}

const coreMessage: CoreMappingMessage = {
_id: 'timestamp-23',
details: {
channel: 'core-mapping',
from: {
force: 'f-red',
forceColor: '#f00',
roleId: 'mar-23',
roleName: 'MARITIME CTRL',
iconURL: 'f-red.svg'
},
messageType: 'custom',
timestamp: '2023-11-23T23:32:00',
turnNumber: 1
},
messageType: CORE_MAPPING,
features: features
}

const importantProp: EnumProperty = {
id: 'important',
label: 'Important',
type: 'EnumProperty',
choices: ['Yes', 'No'],
editable: true
}

const coreRenderer: CoreRenderer = {
id: 'core',
type: 'CoreRenderer',
additionalProps: [importantProp]
}

const categoryProp: EnumProperty = {
id: 'category',
label: 'Category',
type: 'EnumProperty',
choices: ['Infrastructure', 'Military', 'Civilian'],
editable: false
}

const sizeProp: EnumProperty = {
id: 'size',
label: 'Size',
type: 'EnumProperty',
choices: ['S', 'M', 'L'],
editable: false
}

const milSymRenderer: MilSymRenderer = {
id: 'milSym',
type: 'MilSymRenderer',
additionalProps: [categoryProp, sizeProp]
}

const coreMapChannel: CoreMappingChannel = {
uniqid: 'core',
name: 'core mapping',
channelType: CHANNEL_CORE_MAPPING,
constraints: {
bounds: [[1.1, 2.2], [3.3, 5.5]],
minZoom: 3,
tileLayer: {
url: 'https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
attribution: 'Data © <a href="http://osm.org/copyright">OpenStreetMap</a>',
maxNativeZoom: 12
}
},
participants: [
{
canCreateFrom: [coreRenderer.id, milSymRenderer.id],
canSubmitInPhase: [Phase.Planning],
pType: PARTICIPANT_CORE_MAPPING
}
],
renderers: [coreRenderer, milSymRenderer]
}

export const Default: React.FC = () => {
return (
<CoreMapping playerForce={'f-red'} messages={[coreMessage]} channel={coreMapChannel} playerRole={'mgr'} currentTurn={1} forces={[]} currentPhase={Phase.Planning}/>
)
}
18 changes: 18 additions & 0 deletions client/src/Components/local/atoms/core-mapping/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LatLngExpression } from 'leaflet'
import React from 'react'
import { MapContainer, TileLayer } from 'react-leaflet-v4'
import styles from './styles.module.scss'
import PropTypes from './types/props'

const CoreMapping: React.FC<PropTypes> = () => {
const position: LatLngExpression = [51.505, -0.09]

return <MapContainer center={position} zoom={13} scrollWheelZoom={false} className={styles.container}>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
</MapContainer>
}

export default CoreMapping
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.container {
height: 100%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is automatically generated.
// Please do not change this file!
interface CssExports {
'container': string;
}
export const cssExports: CssExports;
export default cssExports;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default interface PropTypes {
playerForce: ForceData['id']
playerRole: Role['id']
currentTurn: number
currentPhase: Phase
forces: ForceStyle[]
channel: CoreMappingChannel
messages: CoreMappingMessage[]
}
Loading

0 comments on commit 6ee4ba3

Please sign in to comment.