Skip to content

Commit 9adb02c

Browse files
authored
Remove enums (#552)
* Migrate LootAttributeClass * Migrate LootKindId * Migrate LootAttributeKindId * erasableSyntaxOnly
1 parent c3476c2 commit 9adb02c

File tree

15 files changed

+321
-308
lines changed

15 files changed

+321
-308
lines changed

src/commands/gegenstand.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { ensureChatInputCommand } from "#utils/interactionUtils.ts";
2323
import * as imageService from "#service/image.ts";
2424

2525
import * as lootDataService from "#service/lootData.ts";
26-
import { LootAttributeKindId, LootKindId } from "#service/lootData.ts";
26+
import { LootAttributeKind, LootKind } from "#service/lootData.ts";
2727

2828
import log from "#log";
2929

@@ -156,7 +156,7 @@ export default class GegenstandCommand implements ApplicationCommand {
156156

157157
const wasteContents = await lootService.getUserLootsByTypeId(
158158
interaction.user.id,
159-
LootKindId.RADIOACTIVE_WASTE,
159+
LootKind.RADIOACTIVE_WASTE,
160160
);
161161

162162
if (wasteContents.length === 0) {
@@ -168,7 +168,7 @@ export default class GegenstandCommand implements ApplicationCommand {
168168

169169
const sweetContent = await lootService.getUserLootsWithAttribute(
170170
interaction.user.id,
171-
LootAttributeKindId.SWEET,
171+
LootAttributeKind.SWEET,
172172
);
173173

174174
if (sweetContent.length === 0) {
@@ -222,7 +222,7 @@ export default class GegenstandCommand implements ApplicationCommand {
222222

223223
const rarity =
224224
lootDataService.extractRarityAttribute(attributes) ??
225-
lootDataService.lootAttributeTemplates[LootAttributeKindId.RARITY_NORMAL];
225+
lootDataService.lootAttributeTemplates[LootAttributeKind.RARITY_NORMAL];
226226

227227
const otherAttributes = lootDataService.extractNonRarityAttributes(attributes);
228228

@@ -233,8 +233,7 @@ export default class GegenstandCommand implements ApplicationCommand {
233233
let assetPath = template.asset;
234234
if (template.attributeAsset) {
235235
for (const attribute of otherAttributes) {
236-
const asset =
237-
template.attributeAsset[attribute.attributeKindId as LootAttributeKindId];
236+
const asset = template.attributeAsset[attribute.attributeKindId];
238237
if (asset) {
239238
assetPath = asset;
240239
break;
@@ -265,7 +264,7 @@ export default class GegenstandCommand implements ApplicationCommand {
265264

266265
const nutriScoreColor = lootDataService.getAttributesByClass(
267266
otherAttributes,
268-
lootDataService.LootAttributeClassId.NUTRI_SCORE,
267+
lootDataService.LootAttributeClass.NUTRI_SCORE,
269268
)[0]?.color;
270269

271270
await interaction.reply({

src/commands/inventar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { ApplicationCommand } from "#commands/command.ts";
1212
import * as lootService from "#service/loot.ts";
1313
import { ensureChatInputCommand } from "#utils/interactionUtils.ts";
1414
import * as lootDataService from "#service/lootData.ts";
15-
import { LootAttributeKindId } from "#service/lootData.ts";
15+
import { LootAttributeKind } from "#service/lootData.ts";
1616

1717
import log from "#log";
1818

@@ -58,7 +58,7 @@ export default class InventarCommand implements ApplicationCommand {
5858
const rarityAttribute = lootDataService.extractRarityAttribute(item.attributes);
5959
const rarity =
6060
rarityAttribute &&
61-
rarityAttribute.attributeKindId !== LootAttributeKindId.RARITY_NORMAL
61+
rarityAttribute.attributeKindId !== LootAttributeKind.RARITY_NORMAL
6262
? ` (${rarityAttribute.displayName})`
6363
: "";
6464

src/service/birthday.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ${userString} ${gotPresents ? "Zum Geurtstag habt ihr ein Geschenk erhalten" : "
103103
}
104104

105105
async function awardBirthdayPresents(users: GuildMember[]) {
106-
const present = lootDataService.resolveLootTemplate(lootDataService.LootKindId.GESCHENK);
106+
const present = lootDataService.resolveLootTemplate(lootDataService.LootKind.GESCHENK);
107107
if (!present) {
108108
throw new Error("Could not resolve loot template");
109109
}
@@ -115,9 +115,7 @@ async function awardBirthdayPresents(users: GuildMember[]) {
115115
null,
116116
"birthday",
117117
null,
118-
lootDataService.lootAttributeTemplates[
119-
lootDataService.LootAttributeKindId.RARITY_NORMAL
120-
],
118+
lootDataService.lootAttributeTemplates[lootDataService.LootAttributeKind.RARITY_NORMAL],
121119
);
122120
}
123121
}

src/service/hatching.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import type { Loot } from "#storage/db/model.ts";
77
import log from "#log";
88
import * as time from "#utils/time.ts";
99
import * as lootService from "#service/loot.ts";
10-
import { LootKindId, resolveLootTemplate } from "./lootData.ts";
10+
import { LootKind, resolveLootTemplate } from "./lootData.ts";
1111
import * as randomService from "./random.ts";
1212

1313
export async function hatchEggs(context: BotContext) {
1414
log.info("Checking egg hatching");
1515

1616
const now = Date.now();
1717
const maxEggAge = time.days(30);
18-
const eggs = await lootService.getLootsByKindId(LootKindId.EI);
18+
const eggs = await lootService.getLootsByKindId(LootKind.EI);
1919

2020
for (const e of eggs) {
2121
const itemAge = now - new Date(e.claimedAt).getTime();
@@ -34,15 +34,15 @@ export async function hatchEggs(context: BotContext) {
3434
}
3535

3636
async function hatchEgg(context: BotContext, egg: Loot) {
37-
console.assert(egg.lootKindId === LootKindId.EI, "Can only hatch eggs");
37+
console.assert(egg.lootKindId === LootKind.EI, "Can only hatch eggs");
3838

3939
const hatchCandidates = [
40-
LootKindId.KADSE,
41-
LootKindId.BIBER,
42-
LootKindId.FERRIS,
43-
LootKindId.OETTINGER,
44-
LootKindId.THUNFISCHSHAKE,
45-
LootKindId.EI,
40+
LootKind.KADSE,
41+
LootKind.BIBER,
42+
LootKind.FERRIS,
43+
LootKind.OETTINGER,
44+
LootKind.THUNFISCHSHAKE,
45+
LootKind.EI,
4646
];
4747
const hatchWeights = [10, 10, 10, 1, 1, 5];
4848

src/service/loot.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export async function getLootAttributes(id: LootId) {
3232
return await loot.getLootAttributes(id);
3333
}
3434

35-
export async function getUserLootCountById(userId: Snowflake, lootTypeId: number): Promise<number> {
35+
export async function getUserLootCountById(
36+
userId: Snowflake,
37+
lootTypeId: LootKindId,
38+
): Promise<number> {
3639
return (await loot.getUserLootsByTypeId(userId, lootTypeId)).length;
3740
}
3841

0 commit comments

Comments
 (0)