• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DaniSomoza / galactic-commander / 12422152220

19 Dec 2024 10:57PM UTC coverage: 52.396% (-13.2%) from 65.587%
12422152220

Pull #11

github

web-flow
Merge e0cd6a508 into 4f9f087f0
Pull Request #11: Build units

204 of 768 branches covered (26.56%)

Branch coverage included in aggregate %.

363 of 886 new or added lines in 84 files covered. (40.97%)

10 existing lines in 7 files now uncovered.

1414 of 2320 relevant lines covered (60.95%)

3.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/frontend/src/components/unit-stats/UnitStats.tsx
1
import List from '@mui/material/List'
2
import ListItem from '@mui/material/ListItem'
3
import Paper from '@mui/material/Paper'
4
import Stack from '@mui/material/Stack'
5
import Divider from '@mui/material/Divider'
6
import Tooltip from '@mui/material/Tooltip'
7
import Typography from '@mui/material/Typography'
8
import GpsFixedIcon from '@mui/icons-material/GpsFixed'
9
import ShieldIcon from '@mui/icons-material/Shield'
10
import FavoriteIcon from '@mui/icons-material/Favorite'
11
import SpeedIcon from '@mui/icons-material/Speed'
12
import InventoryIcon from '@mui/icons-material/Inventory'
13
import AirplanemodeActiveIcon from '@mui/icons-material/AirplanemodeActive'
14
import AirplanemodeInactiveIcon from '@mui/icons-material/AirplanemodeInactive'
15
import AirlineSeatReclineNormalIcon from '@mui/icons-material/AirlineSeatReclineNormal'
16
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'
17
import DiamondIcon from '@mui/icons-material/Diamond'
18
import BugReportIcon from '@mui/icons-material/BugReport'
19
import ParaglidingIcon from '@mui/icons-material/Paragliding'
20
import LocalPoliceIcon from '@mui/icons-material/LocalPolice'
21
import GroupIcon from '@mui/icons-material/Group'
22
import BoltRoundedIcon from '@mui/icons-material/BoltRounded'
23
import AlarmIcon from '@mui/icons-material/Alarm'
24
import StarsIcon from '@mui/icons-material/Stars'
25

26
import { UnitType } from 'game-api-microservice/src/types/Unit'
27
import { PlayerType } from 'game-api-microservice/src/types/Player'
28
import computedBonus from 'game-engine/src/engine/bonus/computedBonus'
29

30
import { useTranslations } from '../../store/TranslationContext'
31
import { useTheme } from '../../store/ThemeContext'
32
import formatNumber from '../../utils/formatNumber'
33
import formatTimer from '../../utils/formatTimer'
34
import millisToSeconds from '../../utils/millisToSeconds'
35

36
type UnitStatsProps = {
37
  unit: UnitType
38
  player: PlayerType
39
}
40

41
// TODO: ADD TRANSLATIONS
42

43
function UnitStats({ unit, player }: UnitStatsProps) {
NEW
44
  const { translate } = useTranslations()
×
NEW
45
  const { theme } = useTheme()
×
46

NEW
47
  const attackBonus = computedBonus(player.perks, 'TROOPS_ATTACK_BONUS')
×
NEW
48
  const attack = unit.stats.attack * (attackBonus / 100)
×
49

NEW
50
  const shieldBonus = computedBonus(player.perks, 'TROOPS_SHIELD_BONUS')
×
NEW
51
  const shield = unit.stats.shield * (shieldBonus / 100)
×
52

NEW
53
  const healthBonus = computedBonus(player.perks, 'TROOPS_HEALTH_BONUS')
×
NEW
54
  const health = unit.stats.health * (healthBonus / 100)
×
55

NEW
56
  const speedBonus = computedBonus(player.perks, 'FLEET_SPEED_BONUS')
×
NEW
57
  const speed = unit.stats.speed * (speedBonus / 100)
×
58

NEW
59
  const cargoBonus = computedBonus(player.perks, 'FLEET_CARGO_BONUS')
×
NEW
60
  const cargo = unit.stats.cargo * (cargoBonus / 100)
×
61

NEW
62
  const buildUnitBonus = computedBonus(player!.perks, 'TROOPS_TRAINING_BONUS')
×
63

NEW
64
  const buildUnitDuration = millisToSeconds(unit.buildBaseTime * (100 / buildUnitBonus))
×
65

NEW
66
  return (
×
67
    <Paper variant="outlined">
68
      <Stack direction={'row'} gap={1}>
69
        <List sx={{ display: 'flex', flexDirection: 'column', gap: 1, flexGrow: 1 }}>
70
          {/* Attack */}
71
          <ListItem disablePadding>
72
            <Tooltip title={translate('ATTACK_UNIT_TOOLTIP', attack, unit.stats.attack)} arrow>
73
              <Stack direction={'row'} gap={1} paddingLeft={1} alignItems={'center'}>
74
                <GpsFixedIcon fontSize="small" />
75
                <Typography fontSize={12}>{formatNumber(attack, true)}</Typography>
76
              </Stack>
77
            </Tooltip>
78
          </ListItem>
79

80
          {/* Health */}
81
          <ListItem disablePadding>
82
            <Tooltip title={translate('HEALTH_UNIT_TOOLTIP', health, unit.stats.health)} arrow>
83
              <Stack direction={'row'} gap={1} paddingLeft={1} alignItems={'center'}>
84
                <FavoriteIcon fontSize="small" />
85
                <Typography fontSize={12}>{formatNumber(health, true)}</Typography>
86
              </Stack>
87
            </Tooltip>
88
          </ListItem>
89

90
          {/* Shield */}
91
          <ListItem disablePadding>
92
            <Tooltip title={translate('SHIELD_UNIT_TOOLTIP', shield, unit.stats.shield)} arrow>
93
              <Stack direction={'row'} gap={1} paddingLeft={1} alignItems={'center'}>
94
                <ShieldIcon fontSize="small" color={unit.stats.shield ? 'action' : 'disabled'} />
×
95
                <Typography fontSize={12} color={unit.stats.shield ? 'action' : '#ffffff4d'}>
×
96
                  {formatNumber(shield, true)}
97
                </Typography>
98
              </Stack>
99
            </Tooltip>
100
          </ListItem>
101

102
          {/* Speed */}
103
          <ListItem disablePadding>
104
            <Tooltip title={translate('SPEED_UNIT_TOOLTIP', speed, unit.stats.speed)} arrow>
105
              <Stack direction={'row'} gap={1} paddingLeft={1} alignItems={'center'}>
106
                <SpeedIcon
107
                  fontSize="small"
108
                  color={unit.type === 'SPACESHIP' ? 'inherit' : 'disabled'}
×
109
                />
110
                <Typography
111
                  fontSize={12}
112
                  color={unit.type === 'SPACESHIP' && unit.stats.speed ? 'action' : '#ffffff4d'}
×
113
                >
114
                  {formatNumber(speed, true)}
115
                </Typography>
116
              </Stack>
117
            </Tooltip>
118
          </ListItem>
119
        </List>
120

121
        <List
122
          sx={{
123
            display: 'flex',
124
            flexDirection: 'column',
125
            gap: 1,
126
            flexGrow: 1
127
          }}
128
        >
129
          {/* Cargo */}
130
          <ListItem disablePadding>
131
            <Tooltip title={translate('CARGO_UNIT_TOOLTIP', cargo, unit.stats.cargo)} arrow>
132
              <Stack direction={'row'} gap={1} paddingRight={1} alignItems={'center'}>
133
                <InventoryIcon
134
                  fontSize="small"
135
                  color={unit.type === 'SPACESHIP' ? 'action' : 'disabled'}
×
136
                />
137
                <Typography
138
                  fontSize={12}
139
                  color={unit.type === 'SPACESHIP' && unit.stats.cargo ? 'action' : '#ffffff4d'}
×
140
                >
141
                  {formatNumber(cargo, true)}
142
                </Typography>
143
              </Stack>
144
            </Tooltip>
145
          </ListItem>
146

147
          {/* Starfighter cargo */}
148
          <ListItem disablePadding>
149
            <Tooltip
150
              title={translate(
151
                'STARFIGHER_CAPACITY_UNIT_TOOLTIP',
152
                unit.stats.starFighterCapacity,
153
                unit.stats.starFighterCapacity
154
              )}
155
              arrow
156
            >
157
              <Stack direction={'row'} gap={1} paddingRight={1} alignItems={'center'}>
158
                {unit.stats.starFighterCapacity ? (
×
159
                  <AirplanemodeActiveIcon fontSize="small" />
160
                ) : (
161
                  <AirplanemodeInactiveIcon
162
                    fontSize="small"
163
                    color={unit.type === 'SPACESHIP' ? 'action' : 'disabled'}
×
164
                  />
165
                )}
166
                <Typography
167
                  fontSize={12}
168
                  color={
169
                    unit.type === 'SPACESHIP' && unit.stats.starFighterCapacity
×
170
                      ? 'action'
171
                      : '#ffffff4d'
172
                  }
173
                >
174
                  {formatNumber(unit.stats.starFighterCapacity, true)}
175
                </Typography>
176
              </Stack>
177
            </Tooltip>
178
          </ListItem>
179

180
          {/* Troops cargo */}
181
          <ListItem disablePadding>
182
            <Tooltip
183
              title={translate(
184
                'TROOPS_CAPACITY_UNIT_TOOLTIP',
185
                unit.stats.troopsCapacity,
186
                unit.stats.troopsCapacity
187
              )}
188
              arrow
189
            >
190
              <Stack direction={'row'} gap={1} paddingRight={1} alignItems={'center'}>
191
                <AirlineSeatReclineNormalIcon
192
                  fontSize="small"
193
                  color={unit.type === 'SPACESHIP' ? 'action' : 'disabled'}
×
194
                />
195
                <Typography
196
                  fontSize={12}
197
                  color={
198
                    unit.type === 'SPACESHIP' && unit.stats.troopsCapacity ? 'action' : '#ffffff4d'
×
199
                  }
200
                >
201
                  {formatNumber(unit.stats.troopsCapacity, true)}
202
                </Typography>
203
              </Stack>
204
            </Tooltip>
205
          </ListItem>
206
        </List>
207

208
        {/* Special traits */}
209
        <List
210
          sx={{
211
            display: 'flex',
212
            flexDirection: 'column',
213
            gap: 1,
214
            paddingRight: 1,
215
            paddingLeft: 1,
216
            borderLeft: `1px solid ${theme.palette.divider}`
217
          }}
218
        >
219
          <ListItem disablePadding>
220
            <Tooltip title={translate('INVISIBLE_UNIT_TOOLTIP')} arrow>
221
              <VisibilityOffIcon fontSize="small" color={unit.isInvisible ? 'info' : 'disabled'} />
×
222
            </Tooltip>
223
          </ListItem>
224

225
          <ListItem disablePadding>
226
            <Tooltip title={translate('ORGANIC_UNIT_TOOLTIP')} arrow>
227
              <BugReportIcon fontSize="small" color={unit.isOrganic ? 'info' : 'disabled'} />
×
228
            </Tooltip>
229
          </ListItem>
230

231
          {/* <ListItem disablePadding>
232
            <Tooltip title={translate('NO_CAPTURABLE_UNIT_TOOLTIP')} arrow>
233
              <ChurchIcon fontSize="small" color={!unit.isCapturable ? 'info' : 'disabled'} />
234
            </Tooltip>
235
          </ListItem> */}
236

237
          <ListItem disablePadding>
238
            <Tooltip title={translate('AIRBORNE_UNIT_TOOLTIP')} arrow>
239
              <ParaglidingIcon fontSize="small" color={unit.isAirborne ? 'info' : 'disabled'} />
×
240
            </Tooltip>
241
          </ListItem>
242

243
          <ListItem disablePadding>
244
            <Tooltip title={translate('SHIELD_PIERCING_UNIT_TOOLTIP')} arrow>
245
              <LocalPoliceIcon
246
                fontSize="small"
247
                color={unit.hasShieldPiercing ? 'info' : 'disabled'}
×
248
              />
249
            </Tooltip>
250
          </ListItem>
251
        </List>
252
      </Stack>
253

254
      <Divider />
255

256
      {/* Unit Cost */}
257
      <List
258
        sx={{ display: 'flex', flexDirection: 'row', padding: 1, justifyContent: 'space-between' }}
259
      >
260
        {/* is Hero label */}
261
        {unit.isHero && (
×
262
          <ListItem disablePadding sx={{ width: 'auto' }}>
263
            <Tooltip title={translate('UNIT_HERO_TOOLTIP')} arrow>
264
              <Stack direction={'row'} gap={0.5} alignItems={'center'} paddingRight={1}>
265
                <StarsIcon fontSize="small" color="info" />
266
              </Stack>
267
            </Tooltip>
268
          </ListItem>
269
        )}
270

271
        {/* Population cost */}
272
        <ListItem disablePadding sx={{ width: 'auto' }}>
273
          <Tooltip title={translate('TROOP_UNIT_POPULATION_COST_TOOLTIP')} arrow>
274
            <Stack direction={'row'} gap={0.5} alignItems={'center'}>
275
              <GroupIcon fontSize="small" color={unit.type == 'TROOP' ? 'action' : 'disabled'} />
×
276
              <Typography fontSize={12} color={unit.type == 'TROOP' ? 'action' : '#ffffff4d'}>
×
277
                {unit.type == 'TROOP' ? 1 : 0}
×
278
              </Typography>
279
            </Stack>
280
          </Tooltip>
281
        </ListItem>
282

283
        {/* Energy cost */}
284
        <ListItem disablePadding sx={{ width: 'auto' }}>
285
          <Tooltip title={translate('TROOP_UNIT_ENERGY_COST_TOOLTIP')} arrow>
286
            <Stack direction={'row'} gap={0.5} paddingLeft={1} alignItems={'center'}>
287
              <BoltRoundedIcon fontSize="small" color={unit.energyCost ? 'action' : 'disabled'} />
×
288
              <Typography fontSize={12} color={unit.energyCost ? 'action' : '#ffffff4d'}>
×
289
                {formatNumber(unit.energyCost, true)}
290
              </Typography>
291
            </Stack>
292
          </Tooltip>
293
        </ListItem>
294

295
        {/* Resource cost */}
296
        <ListItem disablePadding sx={{ width: 'auto' }}>
297
          <Tooltip title={translate('TROOP_UNIT_RESOURCES_COST_TOOLTIP')} arrow>
298
            <Stack direction={'row'} gap={0.5} paddingLeft={1} alignItems={'center'}>
299
              <DiamondIcon fontSize="small" />
300
              <Typography fontSize={12}>{formatNumber(unit.resourceCost, true)}</Typography>
301
            </Stack>
302
          </Tooltip>
303
        </ListItem>
304

305
        {/* Time */}
306
        <ListItem disablePadding sx={{ width: 'auto' }}>
307
          <Tooltip title={translate('TROOP_UNIT_TIME_COST_TOOLTIP')} arrow>
308
            <Stack direction={'row'} gap={0.5} paddingLeft={1} alignItems={'center'}>
309
              <AlarmIcon fontSize="small" />
310
              <Typography fontSize={12}>{formatTimer(buildUnitDuration)}</Typography>
311
            </Stack>
312
          </Tooltip>
313
        </ListItem>
314
      </List>
315
    </Paper>
316
  )
317
}
318

319
export default UnitStats
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc