warframe-worldstate-parser
Version:
An Open parser for Warframe's Worldstate in Javascript
87 lines (86 loc) • 2.64 kB
JavaScript
import RewardTypes_default from "../supporting/RewardTypes.mjs";
import { n as __decorateMetadata, t as __decorate } from "../../decorate-BCC26nnB.mjs";
import { IsArray, IsInt, IsNumber, IsString, Min } from "class-validator";
import { insist, languageString } from "warframe-worldstate-data/utilities";
//#region lib/models/Reward.ts
/**
* Returns the type of a given item
*/
function getItemType(item, types = RewardTypes_default) {
return types.find((t) => t.test(item)).name;
}
/**
* Returns the full type of a given item
*/
function getItemTypeFull(item, types = RewardTypes_default) {
return types.find((t) => t.test(item));
}
/**
* Represents a mission reward
*/
var Reward = class {
/**
* The items being rewarded
*/
items;
/**
* The counted items being rewarded
*/
countedItems;
/**
* The credits being rewarded
*/
credits;
/**
* Thumbnail url
*/
thumbnail;
/**
* Reward color
*/
color;
/**
* @param data The mission data
* @param deps The dependencies object
* @param deps.locale Locale to use for translations
*/
constructor(data, { locale = "en" } = { locale: "en" }) {
insist({ ...data });
this.items = data.items ? data.items.map((i) => languageString(i, locale)) : [];
this.countedItems = data.countedItems ? data.countedItems.map((i) => ({
count: i.ItemCount,
type: languageString(i.ItemType, locale),
key: languageString(i.ItemType)
})) : [];
this.credits = data.credits || 0;
this.thumbnail = this.getTypesFull()[0] ? this.getTypesFull()[0].thumbnail : "https://i.imgur.com/JCKyUXJ.png";
this.color = this.getTypesFull()[0] ? this.getTypesFull()[0].color : 15844367;
}
/**
* The types of all items that are being rewarded
*/
getTypes() {
return this.items.concat(this.countedItems.map((i) => i.key)).map((t) => getItemType(t));
}
/**
* The types of all the items that are being rewarded
*/
getTypesFull() {
return this.items.concat(this.countedItems.map((i) => i.key)).map((t) => getItemTypeFull(t));
}
};
__decorate([
IsArray(),
IsString({ each: true }),
__decorateMetadata("design:type", Array)
], Reward.prototype, "items", void 0);
__decorate([IsArray(), __decorateMetadata("design:type", Array)], Reward.prototype, "countedItems", void 0);
__decorate([
IsInt(),
Min(0),
__decorateMetadata("design:type", Number)
], Reward.prototype, "credits", void 0);
__decorate([IsString(), __decorateMetadata("design:type", String)], Reward.prototype, "thumbnail", void 0);
__decorate([IsNumber(), __decorateMetadata("design:type", Number)], Reward.prototype, "color", void 0);
//#endregion
export { Reward, getItemType, getItemTypeFull };