From 98b5a47c0fddeaff0b7a1c423c9b351847ff2a58 Mon Sep 17 00:00:00 2001 From: Anibus Date: Sun, 16 Mar 2025 12:07:55 +0300 Subject: [PATCH] Sergeants frontend --- README.md | 72 +----- public/images/MeleeStance_icon_bw.jpg | Bin 0 -> 3318 bytes public/images/RangedStance_icon_bw.jpg | Bin 0 -> 3800 bytes public/images/Resource_orksquadcap.gif | Bin 0 -> 166 bytes src/App.tsx | 5 +- src/Routes.tsx | 8 +- src/classes/ArmorType.tsx | 10 +- src/classes/Item.js | 16 -- src/classes/Sergeant.tsx | 132 +++++++++++ src/classes/UnitsTable.tsx | 140 ++++++++++++ src/classes/Weapon.tsx | 152 ++++++++----- src/classes/WeaponSlot.tsx | 37 ++++ src/css/Unit.css | 11 +- src/pages/ModPage.tsx | 48 ++-- src/pages/ModsPage.tsx | 8 +- src/pages/RacePage.tsx | 296 ------------------------- src/pages/RacePageFast.tsx | 163 ++++++++++++++ src/pages/UnitPage.tsx | 263 ++++++++++++++++++++++ src/types/IUnit.tsx | 40 +++- src/types/IUnitShort.tsx | 16 ++ 20 files changed, 938 insertions(+), 479 deletions(-) create mode 100644 public/images/MeleeStance_icon_bw.jpg create mode 100644 public/images/RangedStance_icon_bw.jpg create mode 100644 public/images/Resource_orksquadcap.gif delete mode 100644 src/classes/Item.js create mode 100644 src/classes/Sergeant.tsx create mode 100644 src/classes/UnitsTable.tsx create mode 100644 src/classes/WeaponSlot.tsx delete mode 100644 src/pages/RacePage.tsx create mode 100644 src/pages/RacePageFast.tsx create mode 100644 src/pages/UnitPage.tsx create mode 100644 src/types/IUnitShort.tsx diff --git a/README.md b/README.md index 58beeac..0d741f5 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,6 @@ -# Getting Started with Create React App +# Soulstorm wiki frontend -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +## Стек технологий: -## Available Scripts - -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in your browser. - -The page will reload when you make changes.\ -You may also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can't go back!** - -If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. - -You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `npm run build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) +- react (вперемешку классы и функции) +- typescript \ No newline at end of file diff --git a/public/images/MeleeStance_icon_bw.jpg b/public/images/MeleeStance_icon_bw.jpg new file mode 100644 index 0000000000000000000000000000000000000000..356a5eb23c9ada7676b013d275576b870cef3b64 GIT binary patch literal 3318 zcma)&cTm$?7RP^~hE8Zf5Fw!`ElB7^X#puxLs5E_BE3p4ikgJpLQzU6N_c=EhNd6} z9-85kIu!Awld zOiW-_Fw3dHtgP&R>9liju(Lz{65oFWVqjzhGlRKUS-JQ)IXVBs|L@DmO8^1}bOBv@ z5CouufaoEhlYXEQ0O;sJpwpQD76UUQ6PW&V8xZ4vW8f6gF)%W510aUeqNh8}&-j;z z4n%*7Aut|h0L}|mH_3&VsTL1H{-j%Xr(Y^0a)!HXxqBVAW)9unjQ?bT>EX3K6mt8z-$fOC0m?9Y zkmI#fU}+j^RgwjzN_>p#XoeVd3anS$TPnZ2Yj?cJQ6FvlTvW}GyUUBt%$p!|)+cDf z_}!fn`R1Nk;D?RsYwk(q-`Y9#M4bq7fR{}E?av!Fv@Lt(;t?nE;A%w!e)vxTl^HUj z5l(<%Bzz3%mLFKUK*^=pl-YxoBf4{}HW3lOh!htXX8x(1qGp_SQGyE-N>l6b%nwKO z40DcZUuCc?p?v;U3EIlMV^Emc)Yq&oJ!i!%i@Lfo!h5cX^1h+O!Sd4hvukhU8$uK> zpt9%DAAnVE?BfoW699wgxoJ|o*LPeVkF8b7fXk1xt@JG<4M}>&!l)+4Gv^+O1+Iuo zUB!)=XAxwKaqD7+OBFWLA+l{+v0>@CqHVv#)!U;4=HHYj3(3c4!-(CN_fxhF={|6A z;DgR|D4DRk8t4Uq2tTo_4Anz-hGO`pN9~Gg>mQbX4>ia=^Zr$mZ0lFAvE!u?u>qj~ zts=NsjXXW^?1X?ci$JA04399DmV{bkuO@d~cNgImnlMQ zCzd-Nz_+sT#i%%`u8=Y7`Km}zQfH7lo7e)VO2{#B%^ENl6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dGKdr#y{Qv*} literal 0 HcmV?d00001 diff --git a/public/images/Resource_orksquadcap.gif b/public/images/Resource_orksquadcap.gif new file mode 100644 index 0000000000000000000000000000000000000000..5e08dd1a11915ded85b8ef87013047ed7a43b099 GIT binary patch literal 166 zcmV;X09pS>Nk%w1VGsZi0J8u9{{R3$007d`(#*`v#KgqByu7osv#P49prD|amzRx= zjf8}RZ*OlqJ39{#4*&oFEC2ui01yBW000DA5XedElOpRaJa8v z%yeDElA-UsfddWIVK{XC8c2jv=|FlU$VOs1Z8n}jq++|ZVxx<2*n5ITT`Ffedu_9^ U6GlKTr+g}S&tuQ;`yUYiI|dO&F8}}l literal 0 HcmV?d00001 diff --git a/src/App.tsx b/src/App.tsx index 21611af..8dcd121 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -24,8 +24,9 @@ function App() { cssVariables: true, }); + return ( -
+
- Soulstorm wiki + Soulstorm autogeneration wiki

{this.state.mod.name} ({this.state.mod.version})

- {this.state.races.map(race =>
    {race.name} -
)} +
; } else { return ""; @@ -59,4 +47,6 @@ class ModPage extends React.Component { } } + + export default withRouter(ModPage); \ No newline at end of file diff --git a/src/pages/ModsPage.tsx b/src/pages/ModsPage.tsx index 2a715c8..5f72d26 100644 --- a/src/pages/ModsPage.tsx +++ b/src/pages/ModsPage.tsx @@ -24,7 +24,13 @@ function Mods (mods: IMod[]) { return(

{modName}

- {sameMods.map(mod =>
    {mod.version}
)} + + {sameMods.filter((m) => !m.isBeta).map(mod => +
    {mod.version}
)} + {sameMods.find((m) => m.isBeta) != null &&
Beta versions:
} + {sameMods.find((m) => m.isBeta) != null && + sameMods.filter((m) => m.isBeta).map(mod => +
    {mod.version}
)}
) } diff --git a/src/pages/RacePage.tsx b/src/pages/RacePage.tsx deleted file mode 100644 index dfa9fe7..0000000 --- a/src/pages/RacePage.tsx +++ /dev/null @@ -1,296 +0,0 @@ -import {AvailableMods, AvailableRacesPart, AvailableUnits, IconUrl} from "../core/api"; -import React, {useState} from "react"; -import {withRouter} from "../core/withrouter"; -import {IMod} from "../types/Imod"; -import {Irace} from "../types/Irace"; -import {IUnit, IUnitResponse, IWeapon} from "../types/IUnit"; -import '../css/Unit.css' -import { - Accordion, - AccordionDetails, - AccordionSummary, - Button, - ButtonGroup, - Grid2, - List, - ListItem, - ListSubheader, - Paper, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TableRow, - ToggleButton, - ToggleButtonClassKey, - ToggleButtonGroup, - Typography -} from "@mui/material"; -import {ArrowBack, ArrowDropDown} from "@mui/icons-material"; -import ArmorType from "../classes/ArmorType"; -import Weapon from "../classes/Weapon"; - -interface RacePageState { - mod: IMod, - modId: Number, - race: Irace, - units: IUnitResponse, -} - - -function Unit (unit: IUnit) { - - const morale = (unit.moraleMax !== null) ? -  {unit.moraleMax} - +{unit.moraleRegeneration}/s - {unit.moraleDeathPenalty > 0 && -{unit.moraleDeathPenalty}} - - : "-" - - const detect = unit.detectRadius > 0 ?   {unit.detectRadius} : -   - - let mapWithUnitWeapons: Map = new Map(); - - unit.weapons.forEach( weapon => { - const weaponList = mapWithUnitWeapons.get(weapon.hardpoint) - if(weaponList == null){ - mapWithUnitWeapons.set(weapon.hardpoint, new Array(weapon.weapon)) - } else { - weaponList.push(weapon.weapon) - } - }) - - function WeaponSlot (hardpoint: number) { - let weaponThisSlot = mapWithUnitWeapons.get(hardpoint) ?? [] - - let header = "Weapon slot " + hardpoint - - return( -
-

{header}

- {weaponThisSlot.map(weapon =>
-
)} -
- ) - } - - - return ( - - } - aria-controls="panel1-content" - id={unit.filename} - > - -

{unit.name}

- {unit.detectRadius > 0 &&  } - -
- - - - - - - - cost - - {unit.buildCostRequisition > 0 &&    - {unit.buildCostRequisition}} - {unit.buildCostPower > 0 &&    - {unit.buildCostPower}} - {unit.capInfantry > 0 &&    - {unit.capInfantry}} - {unit.capSupport > 0 &&    - {unit.capSupport}} - - - - armor type - - - - - - health - -   - {unit.health} {unit.healthRegeneration > 0 && - +{unit.healthRegeneration}/s} - - - - move speed - - {unit.moveSpeed} - - - - morale - - {morale} - - - - detect - - {detect} - - - -
-
-
- -
- {unit.description} -
-
- - {[...mapWithUnitWeapons.keys()].sort(function(a, b) { - return a - b; - }).map(h => WeaponSlot(h))} - -
- {unit.filename} -
-
) -} - -interface UnitsState { - selectedUnits: String | null, -} - -class Units extends React.Component { - - - constructor(props: any) { - super(props); - this.state = ({ - selectedUnits: 'infantry' - }); - } - - - handleChange = (e: React.MouseEvent, newUnitType: String | null) => { - this.setState({ - selectedUnits: newUnitType - }); - } - - render () { - - let unitsToRender: IUnit[] = []; - - if(this.state.selectedUnits === 'infantry'){ - unitsToRender = this.props.units.filter(unit => unit.capInfantry > 0) - } else if (this.state.selectedUnits === 'tech'){ - unitsToRender = this.props.units.filter(unit => unit.capSupport > 0) - } else if (this.state.selectedUnits === 'support'){ - unitsToRender = this.props.units.filter(unit => unit.capSupport == 0 && unit.capInfantry == 0) - } else { - unitsToRender = this.props.units - } - - - if (this.state) { - return (
- - Infantry - Tech - Support - -
- {unitsToRender.map(unit => Unit(unit))} -
- -
) - } else { - return ""; - } - } -} - -class RacePage extends React.Component { - - constructor(props: any) { - super(props); - console.log(this.props.match.params.id); - this.setState({ - modId: this.props.match.params.id - }); - } - - - async componentDidMount() { - - const responseMod = await fetch(AvailableMods + "/" + this.props.match.params.modId); - const modData: IMod = await responseMod.json(); - - this.setState({ - mod: modData - }); - - const response = await fetch(AvailableRacesPart + "/" + this.props.match.params.raceId); - const racesData: Irace = await response.json(); - - this.setState({ - race : racesData - }); - - const unitsResponse = await fetch(AvailableUnits + "/" + this.state.mod.id + "/" + this.props.match.params.raceId); - const unitsData: IUnitResponse = await unitsResponse.json(); - console.log(unitsData); - - this.setState({ - units : unitsData - }); - } - - render() { - - - - if(this.state != null && this.state.units != null ){ - const backRef = "/mod/" + this.state.mod.id - - return
-

{this.state.mod.name} ({this.state.mod.version}) - {this.state.race.name}

- -
; - } else { - return "loading..."; - } - } -} - -export default withRouter(RacePage); \ No newline at end of file diff --git a/src/pages/RacePageFast.tsx b/src/pages/RacePageFast.tsx new file mode 100644 index 0000000..64e2352 --- /dev/null +++ b/src/pages/RacePageFast.tsx @@ -0,0 +1,163 @@ +import {AvailableMods, AvailableRacesPart, AvailableUnits, IconUrl} from "../core/api"; +import React, {useState} from "react"; +import {withRouter} from "../core/withrouter"; +import {IMod} from "../types/Imod"; +import {Irace} from "../types/Irace"; +import '../css/Unit.css' +import { + Accordion, + AccordionDetails, + AccordionSummary, + Button, + ButtonGroup, + Grid2, + List, + ListItem, + ListSubheader, + Paper, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + ToggleButton, + ToggleButtonClassKey, + ToggleButtonGroup, + Typography +} from "@mui/material"; +import {ArrowBack, ArrowDropDown} from "@mui/icons-material"; +import ArmorType from "../classes/ArmorType"; +import Weapon from "../classes/Weapon"; +import {IRaceUnits, IUnitShort} from "../types/IUnitShort"; + +interface RacePageState { + mod: IMod, + race: Irace, + units: IUnitShort[], +} + + +function Unit (unit: IUnitShort, modId: number, raceId: String) { + + return ( + {unit.icon && } + {unit.name} + {unit.canDetect &&  } + + ) +} + +interface UnitsProps{ + raceId: string, + modId: number, +} + +interface UnitsState { + selectedUnits: String | null, + units: IRaceUnits | null, +} + +class Units extends React.Component { + + + constructor(props: any) { + super(props); + let url = AvailableUnits + "/" + this.props.modId + "/" + this.props.raceId; + + + fetch(url) + .then(res => res.json()) + .then((res: IRaceUnits) => { + this.setState({ + units: res, + }) + }) + } + + handleChange = (e: React.MouseEvent, newUnitType: String | null) => { + this.setState({ + selectedUnits: newUnitType + }); + + } + + + render () { + + + if (this.state && this.state.units) { + + return (
+ + + {this.state.units != null ? + + +

Infantry

+ {this.state.units.infantry.map(unit => Unit(unit, this.props.modId, this.props.raceId))} +
+ +

Tech

+ + {this.state.units.tech.map(unit => Unit(unit, this.props.modId, this.props.raceId))} + +
+ +

Support

+ + {this.state.units.support.map(unit => Unit(unit, this.props.modId, this.props.raceId))} + +
+
+ : "Loading"} + +
) + } else { + return "Loading..."; + } + } +} + +class RacePageFast extends React.Component { + + constructor(props: any) { + super(props); + console.log(this.props.match.params.id); + } + + + async componentDidMount() { + + const responseMod = await fetch(AvailableMods + "/" + this.props.match.params.modId); + const modData: IMod = await responseMod.json(); + + this.setState({ + mod: modData + }); + + const response = await fetch(AvailableRacesPart + "/" + this.props.match.params.raceId); + const racesData: Irace = await response.json(); + + this.setState({ + race : racesData + }); + } + + render() { + + if(this.state != null && this.state.mod != null && this.state.race != null ){ + const backRef = "/mod/" + this.state.mod.id + + return
+

{this.state.mod.name} ({this.state.mod.version}) - {this.state.race.name}

+ +
; + } else { + return "loading..."; + } + } +} + +export default withRouter(RacePageFast); \ No newline at end of file diff --git a/src/pages/UnitPage.tsx b/src/pages/UnitPage.tsx new file mode 100644 index 0000000..a824f65 --- /dev/null +++ b/src/pages/UnitPage.tsx @@ -0,0 +1,263 @@ +import {AvailableMods, AvailableUnits, IconUrl} from "../core/api"; +import React from "react"; +import {withRouter} from "../core/withrouter"; +import {IUnit, IWeapon} from "../types/IUnit"; +import '../css/Unit.css' +import { + Accordion, + AccordionDetails, + AccordionSummary, + Button, + Grid2, + Paper, + Table, + TableBody, + TableCell, + TableContainer, + TableRow +} from "@mui/material"; +import {ArrowBack, ExpandMore} from "@mui/icons-material"; +import ArmorType from "../classes/ArmorType"; +import AvTimerOutlinedIcon from '@mui/icons-material/AvTimer'; +import Sergeant from "../classes/Sergeant"; +import WeaponSlot from "../classes/WeaponSlot"; +import UnitsTable from "../classes/UnitsTable"; +import {IMod} from "../types/Imod"; + +interface UintPageState { + unit: IUnit, + mod: IMod, +} + + +function Unit(unit: IUnit, mod: IMod) { + + const morale = (unit.moraleMax !== null) ? +  {unit.moraleMax} + +{unit.moraleRegeneration}/s + {unit.moraleDeathPenalty > 0 && -{unit.moraleDeathPenalty}} + + : "-" + + const detect = unit.detectRadius > 0 ?   {unit.detectRadius} : +   + + let mapWithUnitWeapons: Map> = new Map(); + + unit.weapons.forEach(weapon => { + const weaponMap = mapWithUnitWeapons.get(weapon.hardpoint) + if (weaponMap == null) { + const weaponMap = new Map() + weaponMap.set(weapon.hardpointOrder, weapon.weapon) + mapWithUnitWeapons.set(weapon.hardpoint, weaponMap) + } else { + weaponMap.set(weapon.hardpointOrder, weapon.weapon) + } + }) + + type sergeantProps = { + name: string + icon: String + canDetect: Boolean + } + + const SergeantShort = (props: sergeantProps) => { + + return ( + + {props.icon && } +   {props.name} + {props.canDetect &&  } + + ) + } + + + + console.log(unit); + + + return ( +
+

{mod.name} ({mod.version})

+

{unit.icon && + } {unit.name}

+ + + + + + + + cost + + {unit.buildCostRequisition > 0 && +    + {unit.buildCostRequisition}} + {unit.buildCostPower > 0 &&    + {unit.buildCostPower}} + {(unit.buildCostPopulation !== undefined && unit.buildCostPopulation > 0) && +    + {unit.buildCostPopulation}} + + {unit.capInfantry > 0 &&    + {unit.capInfantry}} + {unit.capSupport > 0 &&    + {unit.capSupport}} + {(unit.buildCostTime !== undefined && unit.buildCostTime > 0) && +    + {unit.buildCostTime}s} + + + {(unit?.reinforceTime !== 0 && unit.reinforceTime !== null) && + + reinforce cost + + {unit.reinforceCostRequisition && unit.reinforceCostRequisition > 0 && +    + {unit.reinforceCostRequisition}} + {unit.reinforceCostPower !== undefined && unit.reinforceCostPower > 0 && +    + {unit.reinforceCostPower}} + {(unit.reinforceCostPopulation !== undefined && unit.reinforceCostPopulation > 0) && +    + {unit.reinforceCostPopulation}} + {(unit.reinforceTime !== undefined && unit.reinforceTime > 0) && +    + {unit.reinforceTime}s} + + + } + + armor type + + + + + + health + +   + {unit.health} {unit.healthRegeneration > 0 && + +{unit.healthRegeneration}/s} + + + + move speed + + {unit.moveSpeed} + + + + morale + + {morale} + + + + detect + + {detect} + + + +
+
+
+ +
+ {unit.description} +
+
+ + {unit.sergeants.map(s => + + } + aria-controls="panel1-content" + id="panel1-header" + > + 0}/> + + + +
+
+ +
)} +
+ + {[...mapWithUnitWeapons.keys()].sort(function (a, b) { + return a - b; + }).map(h => )} + +
+ {unit.filename} +
+ +
) +} + + +class UnitPage extends React.Component { + + + async componentDidMount() { + const unitsResponse = await fetch(AvailableUnits + "/" + this.props.match.params.unitId); + const unitsData: IUnit = await unitsResponse.json(); + + this.setState({ + unit: unitsData + }); + + const responseMod = await fetch(AvailableMods + "/" + this.props.match.params.modId); + const modData: IMod = await responseMod.json(); + + this.setState({ + mod: modData + }); + } + + render() { + + if (this.state != null && this.state.unit != null && this.state.mod != null) { + const backRef = "/mod/" + this.props.match.params.modId + "/race/" + this.props.match.params.raceId + + return
+ {Unit(this.state.unit, this.state.mod)} +
; + } else { + return "loading..."; + } + } +} + +export default withRouter(UnitPage); \ No newline at end of file diff --git a/src/types/IUnit.tsx b/src/types/IUnit.tsx index 45842c9..7d12a0c 100644 --- a/src/types/IUnit.tsx +++ b/src/types/IUnit.tsx @@ -16,6 +16,10 @@ export interface IUnit { description: string buildCostRequisition: number buildCostPower: number + buildCostPopulation: number + buildCostFaith: number + buildCostSouls: number + buildCostTime: number capInfantry: number capSupport: number squadStartSize: number @@ -34,9 +38,36 @@ export interface IUnit { detectRadius: number reinforceCostRequisition?: number reinforceCostPower?: number + reinforceCostPopulation ?: number + reinforceCostFaith ?: number reinforceTime?: number icon: string modId: number + sergeants: ISergeant[] + weapons: WeaponHardpoint[] +} + +export interface ISergeant { + id: number + armorType: IArmorType + armorType2?: IArmorType + name: string + filename: string + description: string + buildCostRequisition: number + buildCostPower: number + buildCostPopulation: number + buildCostFaith: number + buildCostSouls: number + buildCostTime: number + health: number + healthRegeneration: number + moraleDeathPenalty: number + mass: number + upTime: number + sightRadius: number + detectRadius: number + icon: string weapons: WeaponHardpoint[] } @@ -44,11 +75,14 @@ export interface IUnit { export interface WeaponHardpoint { weapon: IWeapon hardpoint: number + hardpointOrder: number } export interface IWeapon { id: number name: string + filename: string + description: string costRequisition: number costPower: number costTimeSeconds: number @@ -64,11 +98,13 @@ export interface IWeapon { isMeleeWeapon: boolean canAttackAir: boolean canAttackGround: boolean + haveEquipButton: boolean + icon: string modId: number - weaponPiercings: WeaponPiercing[] + weaponPiercings: IWeaponPiercing[] } -export interface WeaponPiercing { +export interface IWeaponPiercing { id: number armorType: IArmorType piercingValue: number diff --git a/src/types/IUnitShort.tsx b/src/types/IUnitShort.tsx new file mode 100644 index 0000000..ab6cc57 --- /dev/null +++ b/src/types/IUnitShort.tsx @@ -0,0 +1,16 @@ +import {Irace} from "./Irace"; + +export interface IRaceUnits { + race: Irace + infantry: IUnitShort[] + tech: IUnitShort[] + support: IUnitShort[] +} + +export interface IUnitShort { + name: string + icon: string + id: number + canDetect: boolean + armourTypeName: string +}