diff options
Diffstat (limited to 'frontend/src/components/game/ProductionBar.jsx')
-rw-r--r-- | frontend/src/components/game/ProductionBar.jsx | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/frontend/src/components/game/ProductionBar.jsx b/frontend/src/components/game/ProductionBar.jsx index 623389aa..ec924b31 100644 --- a/frontend/src/components/game/ProductionBar.jsx +++ b/frontend/src/components/game/ProductionBar.jsx @@ -3,41 +3,40 @@ import type { ApiCountedResource, ApiProduction, ApiResourceType } from '../../a import './ProductionBar.css' type ProductionBarProps = { + gold: number, production: ApiProduction, } -export const ProductionBar = ({production}: ProductionBarProps) => { +export const ProductionBar = ({gold, production}: ProductionBarProps) => { return <div className='production-bar'> + <GoldIndicator amount={gold}/> <FixedResources resources={production.fixedResources}/> <AlternativeResources resources={production.alternativeResources}/> </div>; }; +type GoldIndicatorProps = { + amount: number, +} +const GoldIndicator = ({amount}: GoldIndicatorProps) => { + return <TokenWithCount tokenName="coin" count={amount} otherClasses="gold-indicator"/> +}; + type FixedResourcesProps = { resources: ApiCountedResource[], } - const FixedResources = ({resources}: FixedResourcesProps) => { return <div className="fixed-resources"> - {resources.map(r => <ResourceCount key={r.type} resource={r}/>)} - </div> -}; - -type ResourceCountProps = { - resource: ApiCountedResource, -} - -const ResourceCount = ({resource}: ResourceCountProps) => { - return <div className="resource-with-count"> - <ResourceImage type={resource.type}/> - <span className="resource-count">× {resource.count}</span> + {resources.map(r => <TokenWithCount key={r.type} + tokenName={getTokenName(r.type)} + count={r.count} + otherClasses="resource-with-count"/>)} </div> }; type AlternativeResourcesProps = { resources: ApiResourceType[][], } - const AlternativeResources = ({resources}: AlternativeResourcesProps) => { return <div className="alternative-resources"> {resources.map((types, i) => <ResourceChoice key={i} types={types}/>)} @@ -47,28 +46,42 @@ const AlternativeResources = ({resources}: AlternativeResourcesProps) => { type ResourceChoiceProps = { types: ApiResourceType[], } - const ResourceChoice = ({types}: ResourceChoiceProps) => { - let typeImages = types.map(type => <ResourceImage key={type} type={type}/>); + let typeImages = types.map(type => <TokenImage key={type} tokenName={getTokenName(type)}/>); let separator = <span className="choice-separator">∕</span>; return <div className="resource-choice"> {intersperce(typeImages, separator)} </div> }; -function intersperce(array: T[], separator: T): T[] { +function intersperce(array, separator) { let result = array.reduce((acc, elt) => acc.concat(elt, separator), []); return result.slice(0, -1); } -type ResourceImageProps = { - type: ApiResourceType, +type TokenWithCountProps = { + tokenName: string, + count: number, + otherClasses?: string, } +const TokenWithCount = ({tokenName, count, otherClasses = ""}: TokenWithCountProps) => { + return <div className={`token-with-count ${otherClasses}`}> + <TokenImage tokenName={tokenName}/> + <span className="token-count">× {count}</span> + </div> +}; -const ResourceImage = ({type}: ResourceImageProps) => { - return <img src={getImagePath(type)} title={type} alt={type} className="resource-img"/> +type TokenImageProps = { + tokenName: string, +} +const TokenImage = ({tokenName}: TokenImageProps) => { + return <img src={getTokenImagePath(tokenName)} title={tokenName} alt={tokenName} className="token-img"/> }; -function getImagePath(resourceType: ApiResourceType): string { - return `/images/resources/${resourceType.toLowerCase()}.png`; +function getTokenImagePath(tokenName: number): string { + return `/images/tokens/${tokenName}.png`; +} + +function getTokenName(resourceType: ApiResourceType): string { + return `resources/${resourceType.toLowerCase()}`; } |