Skip to content

Commit 586e9a5

Browse files
justjuanguiclaude
andcommitted
fix(export): Store variantIndex in GearItem for accurate export
Add variantIndex to GearItem type so gear variants are preserved through export/import cycle. Previously, export relied on sprite matching which could fail and default to wrong variant (index 0). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 720f7d7 commit 586e9a5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/lib/export/collectors.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ import { GEAR_SLOT_MAP, SKILL_SLOT_MAP, RARITY_MAP } from "./format";
2929
// ============================================================================
3030

3131
/**
32-
* Find the variant index for a gear item by matching its properties
32+
* Get the variant index for a gear item
33+
* Uses stored variantIndex, with fallback to sprite matching for backwards compatibility
3334
*/
3435
function findVariantIndex(gearItem: GearItem, gearsHelper: GearsHelper): number {
36+
// Use stored variant index if available
37+
if (gearItem.variantIndex !== undefined) {
38+
return gearItem.variantIndex;
39+
}
40+
41+
// Fallback to sprite matching for backwards compatibility
3542
const def = gearsHelper.getGearDefinitionById(gearItem.defId);
3643
if (!def || !def.variants || def.variants.length === 0) {
3744
return 0;
3845
}
3946

40-
// Try to match by sprite
4147
if (gearItem.sprite) {
4248
for (let i = 0; i < def.variants.length; i++) {
4349
if (def.variants[i].value.sprite === gearItem.sprite) {
@@ -46,7 +52,6 @@ function findVariantIndex(gearItem: GearItem, gearsHelper: GearsHelper): number
4652
}
4753
}
4854

49-
// Default to first variant
5055
return 0;
5156
}
5257

src/lib/hellclock/gears.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type GearDefinition = {
6060
export type GearRoot = { Gear: GearDefinition[] };
6161
export type GearItem = {
6262
defId: number;
63+
variantIndex: number;
6364
slot: GearSlot;
6465
tier: number;
6566
visualTier: number;
@@ -216,6 +217,7 @@ export class GearsHelper {
216217

217218
return {
218219
defId: gd.id,
220+
variantIndex,
219221
slot: gd.slot,
220222
tier: gd.tier,
221223
visualTier: gd.visualTier ?? gd.tier,
@@ -261,6 +263,7 @@ export class GearsHelper {
261263
// If the gear definition has no variants, we create a default item with no mods
262264
items.push({
263265
defId: gd.id,
266+
variantIndex: 0,
264267
slot: gd.slot,
265268
tier: gd.tier,
266269
visualTier: gd.visualTier ?? gd.tier,
@@ -288,7 +291,7 @@ export class GearsHelper {
288291
}
289292
return;
290293
}
291-
gd.variants.forEach((variant) => {
294+
gd.variants.forEach((variant, variantIdx) => {
292295
const rarity = blessed
293296
? this.gearRarity.blessedGearRarity
294297
: undefined;
@@ -303,6 +306,7 @@ export class GearsHelper {
303306
});
304307
items.push({
305308
defId: gd.id,
309+
variantIndex: variantIdx,
306310
slot: gd.slot,
307311
tier: gd.tier,
308312
visualTier: gd.visualTier ?? gd.tier,

0 commit comments

Comments
 (0)