72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
import { DB_BASE_URL } from '../../lib/db';
|
|
|
|
export type Item = {
|
|
id: string;
|
|
name: string;
|
|
iconFilePath: string;
|
|
};
|
|
|
|
export type Offering = {
|
|
id: string;
|
|
name: string;
|
|
iconFilePath: string;
|
|
role: number;
|
|
};
|
|
|
|
export type Addon = {
|
|
id: string;
|
|
name: string;
|
|
iconFilePath: string;
|
|
role: number;
|
|
};
|
|
|
|
export type ItemType =
|
|
| 'all'
|
|
| 'toolbox'
|
|
| 'flashlight'
|
|
| 'medkit'
|
|
| 'key'
|
|
| 'map'
|
|
| 'other';
|
|
export type OfferingRole = 'all' | 'shared' | 'killer' | 'survivor';
|
|
|
|
export const ITEM_TYPE_LABELS: Record<ItemType, string> = {
|
|
all: 'All',
|
|
toolbox: 'Toolbox',
|
|
flashlight: 'Flashlight',
|
|
medkit: 'Med-Kit',
|
|
key: 'Key',
|
|
map: 'Map',
|
|
other: 'Other'
|
|
};
|
|
|
|
export const getItemType = (id: string): ItemType => {
|
|
if (/toolbox/i.test(id)) return 'toolbox';
|
|
if (/flashlight/i.test(id)) return 'flashlight';
|
|
if (/medkit|med_?kit/i.test(id)) return 'medkit';
|
|
if (/key/i.test(id)) return 'key';
|
|
if (/map/i.test(id)) return 'map';
|
|
return 'other';
|
|
};
|
|
|
|
export const getItemIconUrl = (iconFilePath: string) => {
|
|
const file = (iconFilePath.split('/').pop() ?? '').split('.')[0];
|
|
return `${DB_BASE_URL}/icons/item-icons/${file}.png`;
|
|
};
|
|
|
|
export const getOfferingIconUrl = (iconFilePath: string) => {
|
|
const file = (iconFilePath.split('/').pop() ?? '').split('.')[0];
|
|
return `${DB_BASE_URL}/icons/offering-icons/${file}.png`;
|
|
};
|
|
|
|
export const getAddonIconUrl = (iconFilePath: string) => {
|
|
const file = (iconFilePath.split('/').pop() ?? '').split('.')[0];
|
|
return `${DB_BASE_URL}/icons/addon-icons/${file}.png`;
|
|
};
|
|
|
|
export const randInRange = (min: number, max: number) => {
|
|
const lo = Math.min(min, max);
|
|
const hi = Math.max(min, max);
|
|
return Math.floor(Math.random() * (hi - lo + 1)) + lo;
|
|
};
|