forked from OpenWF/SpaceNinjaServer
		
	
		
			
				
	
	
		
			153 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			153 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { getIndexAfter } from "@/src/helpers/stringHelpers";
 | 
						|
import {
 | 
						|
    dict_de,
 | 
						|
    dict_en,
 | 
						|
    dict_es,
 | 
						|
    dict_fr,
 | 
						|
    dict_it,
 | 
						|
    dict_ja,
 | 
						|
    dict_ko,
 | 
						|
    dict_pl,
 | 
						|
    dict_pt,
 | 
						|
    dict_ru,
 | 
						|
    dict_tc,
 | 
						|
    dict_th,
 | 
						|
    dict_tr,
 | 
						|
    dict_uk,
 | 
						|
    dict_zh,
 | 
						|
    ExportArcanes,
 | 
						|
    ExportCustoms,
 | 
						|
    ExportGear,
 | 
						|
    ExportKeys,
 | 
						|
    ExportRecipes,
 | 
						|
    ExportResources,
 | 
						|
    ExportSentinels,
 | 
						|
    ExportWarframes,
 | 
						|
    ExportWeapons,
 | 
						|
    IPowersuit,
 | 
						|
    IRecipe
 | 
						|
} from "warframe-public-export-plus";
 | 
						|
 | 
						|
export type WeaponTypeInternal =
 | 
						|
    | "LongGuns"
 | 
						|
    | "Pistols"
 | 
						|
    | "Melee"
 | 
						|
    | "SpaceMelee"
 | 
						|
    | "SpaceGuns"
 | 
						|
    | "SentinelWeapons"
 | 
						|
    | "OperatorAmps"
 | 
						|
    | "SpecialItems";
 | 
						|
 | 
						|
export const getWeaponType = (weaponName: string): WeaponTypeInternal => {
 | 
						|
    const weaponInfo = ExportWeapons[weaponName];
 | 
						|
 | 
						|
    if (!weaponInfo) {
 | 
						|
        throw new Error(`unknown weapon ${weaponName}`);
 | 
						|
    }
 | 
						|
 | 
						|
    // Many non-weapon items are "Pistols" in Public Export, so some duck typing is needed.
 | 
						|
    if (weaponInfo.totalDamage == 0) {
 | 
						|
        throw new Error(`${weaponName} doesn't quack like a weapon`);
 | 
						|
    }
 | 
						|
 | 
						|
    return weaponInfo.productCategory;
 | 
						|
};
 | 
						|
 | 
						|
export const getRecipe = (uniqueName: string): IRecipe | undefined => {
 | 
						|
    return ExportRecipes[uniqueName];
 | 
						|
};
 | 
						|
 | 
						|
export const getRecipeByResult = (resultType: string): IRecipe | undefined => {
 | 
						|
    return Object.values(ExportRecipes).find(x => x.resultType == resultType);
 | 
						|
};
 | 
						|
 | 
						|
export const getExalted = (uniqueName: string): string[] | undefined => {
 | 
						|
    return getSuitByUniqueName(uniqueName)?.exalted;
 | 
						|
};
 | 
						|
 | 
						|
export const getItemCategoryByUniqueName = (uniqueName: string): string => {
 | 
						|
    //Lotus/Types/Items/MiscItems/PolymerBundle
 | 
						|
 | 
						|
    let splitWord = "Items/";
 | 
						|
    if (!uniqueName.includes("/Items/")) {
 | 
						|
        splitWord = "/Types/";
 | 
						|
    }
 | 
						|
 | 
						|
    const index = getIndexAfter(uniqueName, splitWord);
 | 
						|
    if (index === -1) {
 | 
						|
        throw new Error(`error parsing item category ${uniqueName}`);
 | 
						|
    }
 | 
						|
    const category = uniqueName.substring(index).split("/")[0];
 | 
						|
    return category;
 | 
						|
};
 | 
						|
 | 
						|
export const getSuitByUniqueName = (uniqueName: string): IPowersuit | undefined => {
 | 
						|
    return ExportWarframes[uniqueName];
 | 
						|
};
 | 
						|
 | 
						|
export const getItemName = (uniqueName: string): string | undefined => {
 | 
						|
    if (uniqueName in ExportArcanes) {
 | 
						|
        return ExportArcanes[uniqueName].name;
 | 
						|
    }
 | 
						|
    if (uniqueName in ExportCustoms) {
 | 
						|
        return ExportCustoms[uniqueName].name;
 | 
						|
    }
 | 
						|
    if (uniqueName in ExportKeys) {
 | 
						|
        return ExportKeys[uniqueName].name;
 | 
						|
    }
 | 
						|
    if (uniqueName in ExportGear) {
 | 
						|
        return ExportGear[uniqueName].name;
 | 
						|
    }
 | 
						|
    if (uniqueName in ExportResources) {
 | 
						|
        return ExportResources[uniqueName].name;
 | 
						|
    }
 | 
						|
    if (uniqueName in ExportSentinels) {
 | 
						|
        return ExportSentinels[uniqueName].name;
 | 
						|
    }
 | 
						|
    if (uniqueName in ExportWarframes) {
 | 
						|
        return ExportWarframes[uniqueName].name;
 | 
						|
    }
 | 
						|
    if (uniqueName in ExportWeapons) {
 | 
						|
        return ExportWeapons[uniqueName].name;
 | 
						|
    }
 | 
						|
    return undefined;
 | 
						|
};
 | 
						|
 | 
						|
export const getDict = (lang: string): Record<string, string> => {
 | 
						|
    switch (lang) {
 | 
						|
        case "de":
 | 
						|
            return dict_de;
 | 
						|
        case "es":
 | 
						|
            return dict_es;
 | 
						|
        case "fr":
 | 
						|
            return dict_fr;
 | 
						|
        case "it":
 | 
						|
            return dict_it;
 | 
						|
        case "ja":
 | 
						|
            return dict_ja;
 | 
						|
        case "ko":
 | 
						|
            return dict_ko;
 | 
						|
        case "pl":
 | 
						|
            return dict_pl;
 | 
						|
        case "pt":
 | 
						|
            return dict_pt;
 | 
						|
        case "ru":
 | 
						|
            return dict_ru;
 | 
						|
        case "tc":
 | 
						|
            return dict_tc;
 | 
						|
        case "th":
 | 
						|
            return dict_th;
 | 
						|
        case "tr":
 | 
						|
            return dict_tr;
 | 
						|
        case "uk":
 | 
						|
            return dict_uk;
 | 
						|
        case "zh":
 | 
						|
            return dict_zh;
 | 
						|
    }
 | 
						|
    return dict_en;
 | 
						|
};
 | 
						|
 | 
						|
export const getString = (key: string, dict: Record<string, string>): string => {
 | 
						|
    return dict[key] ?? key;
 | 
						|
};
 |