-
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 #2753 from serge-web/2743-new-mapping-channel
2743: introduce new mapping channel
- Loading branch information
Showing
22 changed files
with
410 additions
and
84 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { ChannelMapping, MappingMessage, MessageChannel } from 'src/custom-types' | ||
import { | ||
getAllWargameMessages, sendMappingMessage | ||
} from '../ActionsAndReducers/playerUi/playerUi_ActionCreators' | ||
|
||
import 'src/themes/App.scss' | ||
import { usePlayerUiDispatch, usePlayerUiState } from '../Store/PlayerUi' | ||
|
||
import { Phase } from 'src/config' | ||
import CoreMapping from './local/atoms/core-mapping' | ||
|
||
const CoreMappingChannel: React.FC<{ channelId: string, isCustomChannel?: boolean }> = ({ channelId }) => { | ||
const state = usePlayerUiState() | ||
const playerUiDispatch = usePlayerUiDispatch() | ||
const [channelTabClass, setChannelTabClass] = useState<string>('') | ||
const { selectedRole, selectedForce } = state | ||
const channelUI = state.channels[channelId] | ||
// const selectedForceId = state.selectedForce ? state.selectedForce.uniqid : '' | ||
if (selectedForce === undefined) throw new Error('selectedForce is undefined') | ||
|
||
const channel = channelUI.cData as ChannelMapping | ||
const messages = state.channels[channelId].messages as Array<MessageChannel> | ||
|
||
useEffect(() => { | ||
const channelClassName = state.channels[channelId].name.toLowerCase().replace(/ /g, '-') | ||
if (state.channels[channelId].messages!.length === 0) { | ||
getAllWargameMessages(state.currentWargame)(playerUiDispatch) | ||
} | ||
setChannelTabClass(`tab-content-${channelClassName}`) | ||
}, []) | ||
|
||
const messageHandler = (message: MappingMessage): void => { | ||
sendMappingMessage(state.currentWargame, message) | ||
} | ||
|
||
return ( | ||
<div className={channelTabClass} data-channel-id={channelId}> | ||
<CoreMapping | ||
postBack={messageHandler} | ||
channel={channel} | ||
currentPhase={Phase.Planning} | ||
currentTurn={1} | ||
forces={[]} | ||
messages={messages} | ||
playerForce={selectedForce} | ||
playerRole={selectedRole} | ||
openPanelAsDefault={true} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default CoreMappingChannel |
103 changes: 103 additions & 0 deletions
103
client/src/Components/local/atoms/core-mapping/helper/circle-to-linestring.tsx
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,103 @@ | ||
|
||
/** code taken from here: https://github.com/gabzim/circle-to-polygon/blob/master/index.js */ | ||
|
||
import { Polygon, Position } from 'geojson' | ||
|
||
const defaultEarthRadius = 6378137 // equatorial Earth radius | ||
|
||
function toRadians (angleInDegrees: number): number { | ||
return (angleInDegrees * Math.PI) / 180 | ||
} | ||
|
||
function toDegrees (angleInRadians: number): number { | ||
return (angleInRadians * 180) / Math.PI | ||
} | ||
|
||
function offset (c1: [number, number], distance: number, earthRadius: number, bearing: number): [number, number] { | ||
const lat1: number = toRadians(c1[1]) | ||
const lon1: number = toRadians(c1[0]) | ||
const dByR: number = distance / earthRadius | ||
const lat: number = Math.asin( | ||
Math.sin(lat1) * Math.cos(dByR) + Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing) | ||
) | ||
const lon: number = | ||
lon1 + | ||
Math.atan2( | ||
Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1), | ||
Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat) | ||
) | ||
return [toDegrees(lon), toDegrees(lat)] | ||
} | ||
|
||
export default function circleToPolygon (center: [number, number], radius: number, options: { | ||
numberOfEdges?: number | ||
earthRadius?: number | ||
bearing?: number | ||
rightHandRule?: boolean | ||
}): Polygon { | ||
const n: number = getNumberOfEdges(options) | ||
const earthRadius: number = getEarthRadius(options) | ||
const bearing: number = getBearing(options) | ||
const direction: number = getDirection(options) | ||
|
||
const start: number = toRadians(bearing) | ||
const coordinates: Position[][] = [[]] | ||
for (let i = 0; i < n; ++i) { | ||
coordinates[0].push( | ||
offset( | ||
center, radius, earthRadius, start + (direction * 2 * Math.PI * -i) / n | ||
) | ||
) | ||
} | ||
coordinates[0].push(coordinates[0][0]) | ||
|
||
return { | ||
type: 'Polygon', | ||
coordinates: coordinates | ||
} | ||
} | ||
|
||
function getNumberOfEdges (options: { numberOfEdges?: number }): number { | ||
if (isUndefinedOrNull(options)) { | ||
return 32 | ||
} else if (isObjectNotArray(options)) { | ||
const numberOfEdges: number | undefined = options.numberOfEdges | ||
return numberOfEdges === undefined ? 32 : numberOfEdges | ||
} | ||
return options as number | ||
} | ||
|
||
function getEarthRadius (options: { earthRadius?: number }): number { | ||
if (isUndefinedOrNull(options)) { | ||
return defaultEarthRadius | ||
} else if (isObjectNotArray(options)) { | ||
const earthRadius: number | undefined = options.earthRadius | ||
return earthRadius === undefined ? defaultEarthRadius : earthRadius | ||
} | ||
return options as number | ||
} | ||
|
||
function getDirection (options: { rightHandRule?: boolean }): number { | ||
if (isObjectNotArray(options) && options.rightHandRule) { | ||
return -1 | ||
} | ||
return 1 | ||
} | ||
|
||
function getBearing (options: { bearing?: number }): number { | ||
if (isUndefinedOrNull(options)) { | ||
return 0 | ||
} else if (isObjectNotArray(options)) { | ||
const bearing: number | undefined = options.bearing | ||
return bearing === undefined ? 0 : bearing | ||
} | ||
return options as number | ||
} | ||
|
||
function isObjectNotArray (argument: any): boolean { | ||
return argument !== null && typeof argument === 'object' && !Array.isArray(argument) | ||
} | ||
|
||
function isUndefinedOrNull (argument: any): boolean { | ||
return argument === null || argument === undefined | ||
} |
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
Oops, something went wrong.