Skip to content

Claude/audit typescript quality #1

Merged
laffan merged 5 commits intomainfrom
claude/audit-typescript-quality-jAjyE
Dec 27, 2025
Merged

Claude/audit typescript quality #1
laffan merged 5 commits intomainfrom
claude/audit-typescript-quality-jAjyE

Conversation

@laffan
Copy link
Owner

@laffan laffan commented Dec 27, 2025

No description provided.

Comprehensive audit identifying DRY violations, type safety issues,
and maintainability concerns with prioritized refactoring roadmap.
This addresses Critical Issue #1 from the TypeScript audit:

- Create src/types/ directory with centralized type definitions:
  - psd.ts: PSD layer types (SpriteLayer, TilesetLayer, etc.)
  - plugin.ts: Plugin configuration types
  - index.ts: Re-exports all types

- Add type guards for safe type narrowing:
  - isSpriteLayer, isTilesetLayer, isZoneLayer, isPointLayer, isGroupLayer
  - isAtlasSprite, isSpritesheetSprite, isAnimationSprite, isDefaultSprite

- Update all modules to use proper types instead of `any`:
  - PsdToPhaser.ts: Use ProcessedPsdData type
  - place modules: Use PsdLayer union with type guards
  - load modules: Use SpriteLayer, TilesetLayer, CategorizedLayers
  - shared utilities: Use typed parameters

- Add public getAllKeys() method to plugin to avoid private member access
Support for layer and group masks exported by psd-to-json with
`mask: true` and `maskPath: "masks/layer_mask.png"` properties.

Features:
- Masks automatically applied during place() for sprites, tiles, and groups
- New getMask() method for independent mask retrieval
- New applyMask shared utility for consistent mask application
- Mask images loaded alongside their parent layers

Type updates:
- Add mask and maskPath properties to BaseLayer
- Add hasMask() type guard function
- Export new types and guards from types/index.ts

Usage:
- Automatic: Just call place() - masks are applied automatically
- Manual: Use psd.getMask(scene, 'psdKey', 'layerPath') to get
  the bitmap mask for independent use
Addresses Critical Issue #2 from the TypeScript audit:
The addDebugVisualization function was copy-pasted across 4 files
with only color variations.

Changes:
- Rewrote shared/debugVisualizer.ts with a consolidated API
- Removed duplicate addDebugVisualization functions from:
  - sprites/index.ts (was 38 lines)
  - tiles.ts (was 34 lines)
  - zones.ts (was 46 lines)
  - points.ts (was 28 lines)
- Total: ~146 lines of duplicated code removed

The new shared utility:
- Takes consistent parameters (scene, plugin, group, options)
- Supports all layer types with appropriate visualizations:
  - sprite: green rectangle
  - tileset: red rectangle
  - zone: blue polygon/rectangle
  - point: red circle
  - group: yellow rectangle
- Handles type-specific label positioning
- Exports DEBUG_COLORS constant for customization
- Create shared spriteSetup.ts with common utilities:
  - setupSprite() for single sprite configuration
  - setupSpriteGroup() for group configuration
  - applyMaskToGroupChildren() for mask application
  - getTextureKey() for texture key resolution
  - setupSpriteInstance() for individual instances
- Refactor all four sprite placement files to use shared utilities
- Bump version to 0.0.6 in package.json and console log
@laffan laffan merged commit 0001396 into main Dec 27, 2025
1 check passed
@laffan laffan deleted the claude/audit-typescript-quality-jAjyE branch December 27, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants