refactor: improve grid service type safety (partial Phase 3.2)
- Created GridItemData type (GridWeapon | GridSummon | GridCharacter) - Typed GridOperation.data field with GridItemData instead of any - Typed draggedItem and targetItem parameters with object shapes - Made targetPosition flexible (number | string) for swaps/moves - Added type guard for move operation to ensure type safety Partial implementation of Phase 3.2 - reduced any usages in grid operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3b2782ec89
commit
53405da7eb
1 changed files with 7 additions and 5 deletions
|
|
@ -2,14 +2,16 @@ import type { Party, GridWeapon, GridSummon, GridCharacter } from '$lib/types/ap
|
||||||
import { gridAdapter } from '$lib/api/adapters/grid.adapter'
|
import { gridAdapter } from '$lib/api/adapters/grid.adapter'
|
||||||
import { partyAdapter } from '$lib/api/adapters/party.adapter'
|
import { partyAdapter } from '$lib/api/adapters/party.adapter'
|
||||||
|
|
||||||
|
export type GridItemData = GridWeapon | GridSummon | GridCharacter
|
||||||
|
|
||||||
export interface GridOperation {
|
export interface GridOperation {
|
||||||
type: 'add' | 'replace' | 'remove' | 'move' | 'swap'
|
type: 'add' | 'replace' | 'remove' | 'move' | 'swap'
|
||||||
itemId?: string
|
itemId?: string
|
||||||
position?: number
|
position?: number
|
||||||
targetPosition?: number
|
targetPosition?: number | string // Can be position number or gridId string for swaps
|
||||||
uncapLevel?: number
|
uncapLevel?: number
|
||||||
transcendenceLevel?: number
|
transcendenceLevel?: number
|
||||||
data?: any
|
data?: GridItemData
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GridUpdateResult {
|
export interface GridUpdateResult {
|
||||||
|
|
@ -518,9 +520,9 @@ export class GridService {
|
||||||
*/
|
*/
|
||||||
normalizeDragIntent(
|
normalizeDragIntent(
|
||||||
dragType: 'weapon' | 'summon' | 'character',
|
dragType: 'weapon' | 'summon' | 'character',
|
||||||
draggedItem: any,
|
draggedItem: { id: string; gridId?: string },
|
||||||
targetPosition: number,
|
targetPosition: number,
|
||||||
targetItem?: any
|
targetItem?: { id: string; gridId?: string }
|
||||||
): GridOperation {
|
): GridOperation {
|
||||||
// If dropping on an empty slot
|
// If dropping on an empty slot
|
||||||
if (!targetItem) {
|
if (!targetItem) {
|
||||||
|
|
@ -567,7 +569,7 @@ export class GridService {
|
||||||
|
|
||||||
case 'move':
|
case 'move':
|
||||||
const item = updated.find(i => i.id === operation.itemId)
|
const item = updated.find(i => i.id === operation.itemId)
|
||||||
if (item && operation.targetPosition !== undefined) {
|
if (item && operation.targetPosition !== undefined && typeof operation.targetPosition === 'number') {
|
||||||
item.position = operation.targetPosition
|
item.position = operation.targetPosition
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue