refactor
Browse files
src/lib/components/Piclets/AbilityDisplay.svelte
CHANGED
@@ -1,13 +1,8 @@
|
|
1 |
<script lang="ts">
|
2 |
-
import type { BattleEffect,
|
3 |
|
4 |
interface Props {
|
5 |
-
ability:
|
6 |
-
name: string;
|
7 |
-
description: string;
|
8 |
-
effects?: BattleEffect[];
|
9 |
-
triggers?: AbilityTrigger[];
|
10 |
-
};
|
11 |
expanded?: boolean;
|
12 |
}
|
13 |
|
@@ -71,27 +66,48 @@
|
|
71 |
function formatEffectDescription(effect: BattleEffect): string {
|
72 |
let desc = effect.type.charAt(0).toUpperCase() + effect.type.slice(1);
|
73 |
|
74 |
-
|
|
|
75 |
desc += ` (${effect.target})`;
|
76 |
}
|
77 |
|
78 |
-
|
|
|
79 |
desc += ` when ${effect.condition}`;
|
80 |
}
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
|
97 |
return desc;
|
|
|
1 |
<script lang="ts">
|
2 |
+
import type { SpecialAbility, BattleEffect, Trigger } from '$lib/battle-engine/types';
|
3 |
|
4 |
interface Props {
|
5 |
+
ability: SpecialAbility;
|
|
|
|
|
|
|
|
|
|
|
6 |
expanded?: boolean;
|
7 |
}
|
8 |
|
|
|
66 |
function formatEffectDescription(effect: BattleEffect): string {
|
67 |
let desc = effect.type.charAt(0).toUpperCase() + effect.type.slice(1);
|
68 |
|
69 |
+
// Handle target (most effects have target, but not all)
|
70 |
+
if ('target' in effect && effect.target !== 'self') {
|
71 |
desc += ` (${effect.target})`;
|
72 |
}
|
73 |
|
74 |
+
// Handle condition (common to many effects)
|
75 |
+
if ('condition' in effect && effect.condition) {
|
76 |
desc += ` when ${effect.condition}`;
|
77 |
}
|
78 |
|
79 |
+
// Handle type-specific properties
|
80 |
+
switch (effect.type) {
|
81 |
+
case 'damage':
|
82 |
+
if (effect.amount) desc += ` - ${effect.amount}`;
|
83 |
+
if (effect.formula) desc += ` (${effect.formula})`;
|
84 |
+
break;
|
85 |
+
case 'modifyStats':
|
86 |
+
const statChanges = Object.entries(effect.stats).map(([stat, change]) =>
|
87 |
+
`${stat}: ${change}`
|
88 |
+
).join(', ');
|
89 |
+
desc += ` (${statChanges})`;
|
90 |
+
break;
|
91 |
+
case 'applyStatus':
|
92 |
+
desc += ` - ${effect.status}`;
|
93 |
+
if (effect.chance && effect.chance < 100) desc += ` (${effect.chance}%)`;
|
94 |
+
break;
|
95 |
+
case 'heal':
|
96 |
+
if (effect.amount) desc += ` - ${effect.amount}`;
|
97 |
+
break;
|
98 |
+
case 'manipulatePP':
|
99 |
+
desc += ` - ${effect.action}`;
|
100 |
+
if (effect.amount) desc += ` ${effect.amount}`;
|
101 |
+
break;
|
102 |
+
case 'counter':
|
103 |
+
desc += ` - ${effect.counterType} (${effect.strength})`;
|
104 |
+
break;
|
105 |
+
case 'removeStatus':
|
106 |
+
desc += ` - ${effect.status}`;
|
107 |
+
break;
|
108 |
+
case 'mechanicOverride':
|
109 |
+
desc += ` - ${effect.mechanic}`;
|
110 |
+
break;
|
111 |
}
|
112 |
|
113 |
return desc;
|
src/lib/components/Piclets/MoveDisplay.svelte
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<script lang="ts">
|
2 |
import type { BattleMove as DBBattleMove } from '$lib/db/schema';
|
3 |
-
import type {
|
4 |
|
5 |
interface Props {
|
6 |
move: DBBattleMove;
|
7 |
-
enhancedMove?: { move:
|
8 |
expanded?: boolean;
|
9 |
showPP?: boolean;
|
10 |
}
|
@@ -84,27 +84,48 @@
|
|
84 |
function formatEffectDescription(effect: BattleEffect): string {
|
85 |
let desc = effect.type.charAt(0).toUpperCase() + effect.type.slice(1);
|
86 |
|
87 |
-
|
|
|
88 |
desc += ` (${effect.target})`;
|
89 |
}
|
90 |
|
91 |
-
|
|
|
92 |
desc += ` when ${effect.condition}`;
|
93 |
}
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
|
110 |
return desc;
|
|
|
1 |
<script lang="ts">
|
2 |
import type { BattleMove as DBBattleMove } from '$lib/db/schema';
|
3 |
+
import type { Move, BattleEffect } from '$lib/battle-engine/types';
|
4 |
|
5 |
interface Props {
|
6 |
move: DBBattleMove;
|
7 |
+
enhancedMove?: { move: Move; currentPp: number };
|
8 |
expanded?: boolean;
|
9 |
showPP?: boolean;
|
10 |
}
|
|
|
84 |
function formatEffectDescription(effect: BattleEffect): string {
|
85 |
let desc = effect.type.charAt(0).toUpperCase() + effect.type.slice(1);
|
86 |
|
87 |
+
// Handle target (most effects have target, but not all)
|
88 |
+
if ('target' in effect && effect.target !== 'self') {
|
89 |
desc += ` (${effect.target})`;
|
90 |
}
|
91 |
|
92 |
+
// Handle condition (common to many effects)
|
93 |
+
if ('condition' in effect && effect.condition) {
|
94 |
desc += ` when ${effect.condition}`;
|
95 |
}
|
96 |
|
97 |
+
// Handle type-specific properties
|
98 |
+
switch (effect.type) {
|
99 |
+
case 'damage':
|
100 |
+
if (effect.amount) desc += ` - ${effect.amount}`;
|
101 |
+
if (effect.formula) desc += ` (${effect.formula})`;
|
102 |
+
break;
|
103 |
+
case 'modifyStats':
|
104 |
+
const statChanges = Object.entries(effect.stats).map(([stat, change]) =>
|
105 |
+
`${stat}: ${change}`
|
106 |
+
).join(', ');
|
107 |
+
desc += ` (${statChanges})`;
|
108 |
+
break;
|
109 |
+
case 'applyStatus':
|
110 |
+
desc += ` - ${effect.status}`;
|
111 |
+
if (effect.chance && effect.chance < 100) desc += ` (${effect.chance}%)`;
|
112 |
+
break;
|
113 |
+
case 'heal':
|
114 |
+
if (effect.amount) desc += ` - ${effect.amount}`;
|
115 |
+
break;
|
116 |
+
case 'manipulatePP':
|
117 |
+
desc += ` - ${effect.action}`;
|
118 |
+
if (effect.amount) desc += ` ${effect.amount}`;
|
119 |
+
break;
|
120 |
+
case 'counter':
|
121 |
+
desc += ` - ${effect.counterType} (${effect.strength})`;
|
122 |
+
break;
|
123 |
+
case 'removeStatus':
|
124 |
+
desc += ` - ${effect.status}`;
|
125 |
+
break;
|
126 |
+
case 'mechanicOverride':
|
127 |
+
desc += ` - ${effect.mechanic}`;
|
128 |
+
break;
|
129 |
}
|
130 |
|
131 |
return desc;
|
src/lib/utils/battleConversion.ts
CHANGED
@@ -49,8 +49,8 @@ export function picletInstanceToBattleDefinition(instance: PicletInstance): Picl
|
|
49 |
name: instance.nickname || instance.typeId,
|
50 |
description: instance.concept,
|
51 |
tier,
|
52 |
-
primaryType:
|
53 |
-
secondaryType: instance.secondaryType
|
54 |
baseStats,
|
55 |
nature: instance.nature,
|
56 |
specialAbility,
|
@@ -85,7 +85,7 @@ function convertBattleMoveToMove(battleMove: BattleMove, primaryType: PicletType
|
|
85 |
|
86 |
return {
|
87 |
name: battleMove.name,
|
88 |
-
type:
|
89 |
power: battleMove.power,
|
90 |
accuracy: battleMove.accuracy,
|
91 |
pp: battleMove.pp,
|
@@ -95,51 +95,6 @@ function convertBattleMoveToMove(battleMove: BattleMove, primaryType: PicletType
|
|
95 |
};
|
96 |
}
|
97 |
|
98 |
-
/**
|
99 |
-
* Convert PicletType to battle engine type
|
100 |
-
*/
|
101 |
-
function convertPicletTypeToType(picletType: PicletType): 'beast' | 'bug' | 'aquatic' | 'flora' | 'mineral' | 'space' | 'machina' | 'structure' | 'culture' | 'cuisine' {
|
102 |
-
const typeMap: Record<PicletType, any> = {
|
103 |
-
[PicletType.BEAST]: 'beast',
|
104 |
-
[PicletType.BUG]: 'bug',
|
105 |
-
[PicletType.AQUATIC]: 'aquatic',
|
106 |
-
[PicletType.FLORA]: 'flora',
|
107 |
-
[PicletType.MINERAL]: 'mineral',
|
108 |
-
[PicletType.SPACE]: 'space',
|
109 |
-
[PicletType.MACHINA]: 'machina',
|
110 |
-
[PicletType.STRUCTURE]: 'structure',
|
111 |
-
[PicletType.CULTURE]: 'culture',
|
112 |
-
[PicletType.CUISINE]: 'cuisine'
|
113 |
-
};
|
114 |
-
|
115 |
-
return typeMap[picletType] || 'beast';
|
116 |
-
}
|
117 |
-
|
118 |
-
/**
|
119 |
-
* Convert AttackType to battle engine type
|
120 |
-
*/
|
121 |
-
function convertAttackTypeToType(attackType: AttackType): 'beast' | 'bug' | 'aquatic' | 'flora' | 'mineral' | 'space' | 'machina' | 'structure' | 'culture' | 'cuisine' | 'normal' {
|
122 |
-
// AttackType and PicletType should align, but handle the NORMAL case
|
123 |
-
if (attackType === AttackType.NORMAL) {
|
124 |
-
return 'normal';
|
125 |
-
}
|
126 |
-
|
127 |
-
// Map other attack types to piclet types
|
128 |
-
const typeMap: Record<string, any> = {
|
129 |
-
'beast': 'beast',
|
130 |
-
'bug': 'bug',
|
131 |
-
'aquatic': 'aquatic',
|
132 |
-
'flora': 'flora',
|
133 |
-
'mineral': 'mineral',
|
134 |
-
'space': 'space',
|
135 |
-
'machina': 'machina',
|
136 |
-
'structure': 'structure',
|
137 |
-
'culture': 'culture',
|
138 |
-
'cuisine': 'cuisine'
|
139 |
-
};
|
140 |
-
|
141 |
-
return typeMap[attackType.toString()] || 'normal';
|
142 |
-
}
|
143 |
|
144 |
/**
|
145 |
* Convert battle engine BattlePiclet back to PicletInstance for state updates
|
|
|
49 |
name: instance.nickname || instance.typeId,
|
50 |
description: instance.concept,
|
51 |
tier,
|
52 |
+
primaryType: instance.primaryType,
|
53 |
+
secondaryType: instance.secondaryType,
|
54 |
baseStats,
|
55 |
nature: instance.nature,
|
56 |
specialAbility,
|
|
|
85 |
|
86 |
return {
|
87 |
name: battleMove.name,
|
88 |
+
type: battleMove.type,
|
89 |
power: battleMove.power,
|
90 |
accuracy: battleMove.accuracy,
|
91 |
pp: battleMove.pp,
|
|
|
95 |
};
|
96 |
}
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
/**
|
100 |
* Convert battle engine BattlePiclet back to PicletInstance for state updates
|