Skip to content

Commit

Permalink
custom unit sprites (#16)
Browse files Browse the repository at this point in the history
* Custom Unit Sprites

* fixed winter cropping

* fixed retreat shadows

* minor changes

* added default unit files
  • Loading branch information
cryofractal authored Oct 17, 2024
1 parent d2361d6 commit df0e40e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions client/src/assets/icons/Army.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/src/assets/icons/Fleet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 14 additions & 9 deletions client/src/components/world/boards/UnitIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { getNationColour } from '../../../types/enums/nation';
import Unit, { displayUnit } from '../../../types/unit';
import Unit from '../../../types/unit';
import UnitType from '../../../types/enums/unitType';
import { unitWidth } from '../../../utils/constants';

import ArmyIcon from '../../../assets/icons/Army.svg?react';
import FleetIcon from '../../../assets/icons/Fleet.svg?react';

type UnitIconProps = {
unit: Unit;
scaleFactor?: number;
Expand All @@ -10,14 +14,15 @@ type UnitIconProps = {

const UnitIcon = ({ unit, scaleFactor = 1, variant = 'world' }: UnitIconProps) => {
const isWorldVariant = variant === 'world';
const shadow = unit.mustRetreat ? '0px 0px 20px 15px red' : '0px 0px 2px black';
const shadow = unit.mustRetreat ? '0px 0px 2px red' : '0px 0px 2px black';
const Svg = (unit.type === UnitType.Army ? ArmyIcon : FleetIcon);

return (
<div
className="flex justify-center items-center rounded-full"
<Svg

Check failure on line 21 in client/src/components/world/boards/UnitIcon.tsx

View workflow job for this annotation

GitHub Actions / Check client

Empty components are self-closing
className="flex justify-center"
style={{
backgroundColor: getNationColour(unit.owner),
boxShadow: isWorldVariant ? shadow : '',
color: getNationColour(unit.owner),
filter: isWorldVariant ? `drop-shadow(${shadow})` : '',
width: unitWidth * scaleFactor,
height: unitWidth * scaleFactor,
margin: isWorldVariant ? -(unitWidth * scaleFactor) / 2 : 0,
Expand All @@ -26,9 +31,9 @@ const UnitIcon = ({ unit, scaleFactor = 1, variant = 'world' }: UnitIconProps) =
pointerEvents: isWorldVariant ? 'none' : 'auto',
}}
>
<p style={{ fontSize: 16 * scaleFactor }}>{displayUnit(unit)}</p>
</div>
</Svg>
);
};
}

Check failure on line 36 in client/src/components/world/boards/UnitIcon.tsx

View workflow job for this annotation

GitHub Actions / Check client

Missing semicolon


export default UnitIcon;
2 changes: 0 additions & 2 deletions client/src/types/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ type Unit = {
mustRetreat: boolean;
};

export const displayUnit = (unit: Unit | null) => (unit?.type === UnitType.Fleet ? 'F' : 'A');

export default Unit;

0 comments on commit df0e40e

Please sign in to comment.