Skip to content

Commit

Permalink
split some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jeu committed Sep 14, 2022
1 parent ea72c5c commit 88d51ef
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
20 changes: 20 additions & 0 deletions src/player-inventory/components/itemRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ItemType, itemTypes, LevelRarity } from "../inventory";
import { shortenRarity } from "../utils";

export default function (props: {
item: { type: ItemType; leveled: boolean };
lvl: LevelRarity,
count: number;
}) {
const { item, lvl, count } = props;
const lr = item.leveled ? 'L' + lvl : shortenRarity(lvl as string);
const className = (item.leveled ? 'level_' : 'rarity_') + lr;
const name = itemTypes[item.type];
return (
<tr className={className}>
<td>{count}</td>
<td>{lr}</td>
<td>{name}</td>
</tr>
);
}
29 changes: 2 additions & 27 deletions src/player-inventory/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,13 @@ import { Inventory, itemTypes } from './inventory';
import { parseInventory } from './parser';
import { loadLastInventory, loadSettings, storeSettings, saveInventory } from './storage';
import { requestInventory } from './request';
import { shortenRarity, localeCompare } from './utils';
import { createPopup, injectKeys, portalKeyHighlight } from './map';

// eslint-disable-next-line no-unused-vars
import PortalKeyLink from './components/portalKeyLink';

function shortenRarity(v) {
return v
.split('_')
.map((a) => a[0])
.join('');
}

function localeCompare(a, b) {
if (typeof a !== 'string') a = '';
if (typeof b !== 'string') b = '';
return a.localeCompare(b);
}

// eslint-disable-next-line no-unused-vars
function ItemRow(props) {
const { item, lvl, count } = props;
const lr = item.leveled ? 'L' + lvl : shortenRarity(lvl);
const className = (item.leveled ? 'level_' : 'rarity_') + lr;
const name = itemTypes[item.type];
return (
<tr className={className}>
<td>{count}</td>
<td>{lr}</td>
<td>{name}</td>
</tr>
);
}
import ItemRow from './components/itemRow';

function createAllTable(inventory) {
const table = <table></table>;
Expand Down
4 changes: 2 additions & 2 deletions src/player-inventory/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export const levelItemTypes = ['EMITTER_A', 'EMP_BURSTER', 'POWER_CUBE', 'ULTRA_

export const rarity = ['VERY_COMMON', 'COMMON', 'LESS_COMMON', 'RARE', 'VERY_RARE', 'EXTREMELY_RARE'];

type ItemType = keyof typeof itemTypes;
export type ItemType = keyof typeof itemTypes;
type Level = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
type Rarity = 'VERY_COMMON' | 'COMMON' | 'LESS_COMMON' | 'RARE' | 'VERY_RARE' | 'EXTREMELY_RARE';

type LevelRarity = Level | Rarity;
export type LevelRarity = Level | Rarity;

type CapsuleCount = { [name: string]: number };

Expand Down
12 changes: 12 additions & 0 deletions src/player-inventory/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function shortenRarity(v: string) {
return v
.split('_')
.map((a) => a[0])
.join('');
}

export function localeCompare(a: any, b: any) {
if (typeof a !== 'string') a = '';
if (typeof b !== 'string') b = '';
return (a as string).localeCompare(b as string);
}

0 comments on commit 88d51ef

Please sign in to comment.