Fraser commited on
Commit
2e6926b
·
1 Parent(s): ee3dc87
src/lib/components/Pages/Encounters.svelte CHANGED
@@ -140,19 +140,35 @@
140
 
141
  async function startBattle(encounter: Encounter) {
142
  try {
143
- // Get player's first healthy piclet
144
- const roster = await db.picletInstances
145
- .where('isInRoster')
146
- .equals(1)
147
- .toArray();
148
 
149
- const healthyPiclets = roster.filter(p => p.currentHp > 0);
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  if (healthyPiclets.length === 0) {
152
  alert('You need at least one healthy piclet in your roster to battle!');
153
  return;
154
  }
155
 
 
 
 
 
 
 
 
156
  // Generate enemy piclet for battle
157
  const enemyPiclet = await generateEnemyPiclet(encounter);
158
  if (!enemyPiclet) return;
 
140
 
141
  async function startBattle(encounter: Encounter) {
142
  try {
143
+ // Get all piclet instances
144
+ const allPiclets = await db.picletInstances.toArray();
 
 
 
145
 
146
+ // Filter piclets that have a roster position (0-5)
147
+ const rosterPiclets = allPiclets.filter(p =>
148
+ p.rosterPosition !== undefined &&
149
+ p.rosterPosition !== null &&
150
+ p.rosterPosition >= 0 &&
151
+ p.rosterPosition <= 5
152
+ );
153
+
154
+ // Sort by roster position
155
+ rosterPiclets.sort((a, b) => (a.rosterPosition ?? 0) - (b.rosterPosition ?? 0));
156
+
157
+ // Get healthy piclets
158
+ const healthyPiclets = rosterPiclets.filter(p => p.currentHp > 0);
159
 
160
  if (healthyPiclets.length === 0) {
161
  alert('You need at least one healthy piclet in your roster to battle!');
162
  return;
163
  }
164
 
165
+ // Check if there's at least one piclet in position 0
166
+ const hasPosition0 = rosterPiclets.some(p => p.rosterPosition === 0);
167
+ if (!hasPosition0) {
168
+ alert('You need a piclet in the first roster slot (position 0) to battle!');
169
+ return;
170
+ }
171
+
172
  // Generate enemy piclet for battle
173
  const enemyPiclet = await generateEnemyPiclet(encounter);
174
  if (!enemyPiclet) return;
src/lib/components/Pages/Pictuary.svelte CHANGED
@@ -36,8 +36,19 @@
36
  try {
37
  const allInstances = await getAllPicletInstances();
38
 
39
- rosterPiclets = allInstances.filter(p => p.isInRoster);
40
- storagePiclets = allInstances.filter(p => !p.isInRoster);
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  const allMonsters = await getAllMonsters();
43
 
 
36
  try {
37
  const allInstances = await getAllPicletInstances();
38
 
39
+ // Filter based on rosterPosition instead of isInRoster
40
+ rosterPiclets = allInstances.filter(p =>
41
+ p.rosterPosition !== undefined &&
42
+ p.rosterPosition !== null &&
43
+ p.rosterPosition >= 0 &&
44
+ p.rosterPosition <= 5
45
+ );
46
+ storagePiclets = allInstances.filter(p =>
47
+ p.rosterPosition === undefined ||
48
+ p.rosterPosition === null ||
49
+ p.rosterPosition < 0 ||
50
+ p.rosterPosition > 5
51
+ );
52
 
53
  const allMonsters = await getAllMonsters();
54
 
src/lib/db/piclets.ts CHANGED
@@ -129,10 +129,15 @@ export async function getAllPicletInstances(): Promise<PicletInstance[]> {
129
 
130
  // Get roster PicletInstances
131
  export async function getRosterPiclets(): Promise<PicletInstance[]> {
132
- return await db.picletInstances
133
- .where('isInRoster')
134
- .equals(1)
135
- .sortBy('rosterPosition');
 
 
 
 
 
136
  }
137
 
138
  // Update roster position
@@ -185,10 +190,13 @@ export async function moveToStorage(id: number): Promise<void> {
185
 
186
  // Get storage piclets
187
  export async function getStoragePiclets(): Promise<PicletInstance[]> {
188
- return await db.picletInstances
189
- .where('isInRoster')
190
- .equals(0)
191
- .toArray();
 
 
 
192
  }
193
 
194
  // Delete a PicletInstance
 
129
 
130
  // Get roster PicletInstances
131
  export async function getRosterPiclets(): Promise<PicletInstance[]> {
132
+ const allPiclets = await db.picletInstances.toArray();
133
+ return allPiclets
134
+ .filter(p =>
135
+ p.rosterPosition !== undefined &&
136
+ p.rosterPosition !== null &&
137
+ p.rosterPosition >= 0 &&
138
+ p.rosterPosition <= 5
139
+ )
140
+ .sort((a, b) => (a.rosterPosition ?? 0) - (b.rosterPosition ?? 0));
141
  }
142
 
143
  // Update roster position
 
190
 
191
  // Get storage piclets
192
  export async function getStoragePiclets(): Promise<PicletInstance[]> {
193
+ const allPiclets = await db.picletInstances.toArray();
194
+ return allPiclets.filter(p =>
195
+ p.rosterPosition === undefined ||
196
+ p.rosterPosition === null ||
197
+ p.rosterPosition < 0 ||
198
+ p.rosterPosition > 5
199
+ );
200
  }
201
 
202
  // Delete a PicletInstance