[priority: high] Duplicate functions across files (calculateDesignTime, calculateDesignCapacityCost, generateSwarmEnemies) #100

Closed
opened 2026-05-20 10:59:26 +02:00 by Anexim · 3 comments
Owner

Severity: High — duplicated code risks divergence, wastes maintenance effort, and indicates unclear module ownership.

Findings:

  • calculateDesignTime defined identically in both crafting-design.ts and crafting-utils.ts
  • calculateDesignCapacityCost duplicated across crafting-design.ts, crafting-utils.ts, and EnchantmentDesigner/utils.ts (with different signatures)
  • generateSwarmEnemies implemented identically in both enemy-utils.ts and room-utils.ts (93% near-duplicate)

Affected files:

  • src/lib/game/crafting-design.ts, src/lib/game/crafting-utils.ts
  • src/components/game/crafting/EnchantmentDesigner/utils.ts
  • src/lib/game/utils/enemy-utils.ts, src/lib/game/utils/room-utils.ts

Suggested fix: Consolidate to single canonical sources. Remove duplicates and import from the canonical module. Give different-signature variants distinct names to avoid confusion.

Confidence: High
Dimension: convention_outlier (score: 58.0%)

**Severity:** High — duplicated code risks divergence, wastes maintenance effort, and indicates unclear module ownership. **Findings:** - `calculateDesignTime` defined identically in both `crafting-design.ts` and `crafting-utils.ts` - `calculateDesignCapacityCost` duplicated across `crafting-design.ts`, `crafting-utils.ts`, and `EnchantmentDesigner/utils.ts` (with different signatures) - `generateSwarmEnemies` implemented identically in both `enemy-utils.ts` and `room-utils.ts` (93% near-duplicate) **Affected files:** - `src/lib/game/crafting-design.ts`, `src/lib/game/crafting-utils.ts` - `src/components/game/crafting/EnchantmentDesigner/utils.ts` - `src/lib/game/utils/enemy-utils.ts`, `src/lib/game/utils/room-utils.ts` **Suggested fix:** Consolidate to single canonical sources. Remove duplicates and import from the canonical module. Give different-signature variants distinct names to avoid confusion. **Confidence:** High **Dimension:** convention_outlier (score: 58.0%)
Anexim added the ai:todo label 2026-05-20 10:59:26 +02:00
n8n-gitea was assigned by Anexim 2026-05-20 10:59:26 +02:00
Author
Owner

Starting work on consolidating duplicate functions. Will investigate the three duplicate pairs and consolidate to canonical sources.

Starting work on consolidating duplicate functions. Will investigate the three duplicate pairs and consolidate to canonical sources.
Author
Owner

Fix complete. Consolidated all three duplicate function pairs:

  1. calculateDesignCapacityCost — Removed duplicate from crafting-utils.ts. EnchantmentDesigner/utils.ts now delegates to canonical crafting-design.ts version.

  2. calculateDesignTime — Removed duplicate from crafting-utils.ts. EnchantmentDesigner/utils.ts now delegates to canonical crafting-design.ts version.

  3. generateSwarmEnemies — Enhanced enemy-utils.ts version with barrier support (matching the more complete room-utils.ts variant), removed duplicate from room-utils.ts, which now imports from enemy-utils.ts.

Result: 5 files changed, 27 insertions(+), 57 deletions(-). Build passes, all pre-commit checks pass. No new TypeScript errors introduced.

**Fix complete.** Consolidated all three duplicate function pairs: 1. **`calculateDesignCapacityCost`** — Removed duplicate from `crafting-utils.ts`. `EnchantmentDesigner/utils.ts` now delegates to canonical `crafting-design.ts` version. 2. **`calculateDesignTime`** — Removed duplicate from `crafting-utils.ts`. `EnchantmentDesigner/utils.ts` now delegates to canonical `crafting-design.ts` version. 3. **`generateSwarmEnemies`** — Enhanced `enemy-utils.ts` version with barrier support (matching the more complete `room-utils.ts` variant), removed duplicate from `room-utils.ts`, which now imports from `enemy-utils.ts`. **Result:** 5 files changed, 27 insertions(+), 57 deletions(-). Build passes, all pre-commit checks pass. No new TypeScript errors introduced.
Author
Owner

Issue resolved. All three duplicate function pairs consolidated to canonical sources. Commit: 53b3a94

Issue resolved. All three duplicate function pairs consolidated to canonical sources. Commit: 53b3a94
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#100