save fix
@@ -64,7 +64,7 @@ GET /tribegen/api/game/sprite?userId=user123&koboldId=kob_abc123&age=adult
64
64
### Display Kobold Sprite
65
65
```javascript
66
66
// In displayKobolds() method
67
const spriteUrl = `/tribegen/api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
67
const spriteUrl = `/tribegen/api/game/sprite?userId=${this.currentUser.email}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
68
68
const img = document.createElement('img');
69
69
img.src = spriteUrl;
70
70
img.alt = 'Kobold sprite';
@@ -64,7 +64,7 @@ GET /tribegen/api/game/sprite?userId=user123&koboldId=kob_abc123&age=adult64
### Display Kobold Sprite64
### Display Kobold Sprite65
```javascript65
```javascript66
// In displayKobolds() method66
// In displayKobolds() method67
const spriteUrl = `/tribegen/api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;67
const spriteUrl = `/tribegen/api/game/sprite?userId=${this.currentUser.email}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;68
const img = document.createElement('img');68
const img = document.createElement('img');69
img.src = spriteUrl;69
img.src = spriteUrl;70
img.alt = 'Kobold sprite';70
img.alt = 'Kobold sprite';@@ -208,7 +208,10 @@ class TribeGenApp
208
208
{
209
209
const response = await fetch('api/game/list', {
210
210
method: 'GET',
211
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }
211
headers: { 'Authorization': `Bearer ${this.currentUser.token}` },
212
body: JSON.stringify({
213
userId: this.currentUser.email
214
})
212
215
});
213
216
214
217
const dataText = await response.text();
@@ -276,7 +279,7 @@ class TribeGenApp
276
279
},
277
280
body: JSON.stringify({
278
281
saveName: tribeName,
279
userId: this.currentUser.id
282
userId: this.currentUser.email
280
283
})
281
284
});
282
285
@@ -312,7 +315,7 @@ class TribeGenApp
312
315
const card = document.createElement('div');
313
316
card.className = 'kobold-card';
314
317
315
const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
318
const spriteUrl = `api/game/sprite?userId=${this.currentUser.email}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
316
319
317
320
card.innerHTML = `
318
321
<img src="${spriteUrl}" alt="Kobold sprite" class="kobold-sprite">
@@ -579,7 +582,7 @@ class TribeGenApp
579
582
'Authorization': `Bearer ${this.currentUser.token}`
580
583
},
581
584
body: JSON.stringify({
582
userId: this.currentUser.id,
585
userId: this.currentUser.email,
583
586
saveId: this.currentSave.id,
584
587
leaderName: this.pendingSetup.leaderName,
585
588
memberIndices: this.pendingSetup.memberIndices,
@@ -607,7 +610,7 @@ class TribeGenApp
607
610
{
608
611
try
609
612
{
610
const response = await fetch(`api/game/load?saveId=${saveId}&userId=${this.currentUser.id}`, {
613
const response = await fetch(`api/game/load?saveId=${saveId}&userId=${this.currentUser.email}`, {
611
614
method: 'GET',
612
615
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }
613
616
});
@@ -756,7 +759,7 @@ class TribeGenApp
756
759
757
760
placementList.forEach(entry =>
758
761
{
759
const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${entry.kobold.id}&age=${entry.kobold.ageCategory}`;
762
const spriteUrl = `api/game/sprite?userId=${this.currentUser.email}&koboldId=${entry.kobold.id}&age=${entry.kobold.ageCategory}`;
760
763
const img = document.createElement('img');
761
764
img.src = spriteUrl;
762
765
img.alt = entry.kobold.name;
@@ -835,7 +838,7 @@ class TribeGenApp
835
838
836
839
this.currentTribe.kobolds.forEach(kobold =>
837
840
{
838
const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
841
const spriteUrl = `api/game/sprite?userId=${this.currentUser.email}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;
839
842
const item = document.createElement('div');
840
843
const isInjured = kobold.injuries && kobold.injuries.length > 0;
841
844
item.className = `tribe-item ${isInjured ? 'injured' : ''}`;
@@ -910,7 +913,7 @@ class TribeGenApp
910
913
911
914
try
912
915
{
913
const response = await fetch(`api/game/events?saveId=${this.currentSave.id}&userId=${this.currentUser.id}`, {
916
const response = await fetch(`api/game/events?saveId=${this.currentSave.id}&userId=${this.currentUser.email}`, {
914
917
method: 'GET',
915
918
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }
916
919
});
@@ -1072,7 +1075,7 @@ class TribeGenApp
1072
1075
const resp = await fetch('api/game/event', {
1073
1076
method: 'POST',
1074
1077
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser.token}` },
1075
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, eventType: this.currentEventType, participants: selected })
1078
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, eventType: this.currentEventType, participants: selected })
1076
1079
});
1077
1080
1078
1081
const dataText = await resp.text();
@@ -1106,7 +1109,7 @@ class TribeGenApp
1106
1109
'Authorization': `Bearer ${this.currentUser.token}`
1107
1110
},
1108
1111
body: JSON.stringify({
1109
userId: this.currentUser.id, saveId: this.currentSave.id
1112
userId: this.currentUser.email, saveId: this.currentSave.id
1110
1113
})
1111
1114
});
1112
1115
@@ -1241,7 +1244,7 @@ class TribeGenApp
1241
1244
const resp = await fetch('api/game/giveItem', {
1242
1245
method: 'POST',
1243
1246
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },
1244
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, koboldId: koboldId, itemId: item.id })
1247
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: koboldId, itemId: item.id })
1245
1248
});
1246
1249
1247
1250
const dataText = await resp.text();
@@ -1434,7 +1437,7 @@ class TribeGenApp
1434
1437
const resp = await fetch('api/game/cureInjury', {
1435
1438
method: 'POST',
1436
1439
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },
1437
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, koboldId: kobold.id, injuryId: injury.id, itemId: required })
1440
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, injuryId: injury.id, itemId: required })
1438
1441
});
1439
1442
const dataText = await resp.text();
1440
1443
const data = JSON.parse(dataText);
@@ -1529,7 +1532,7 @@ class TribeGenApp
1529
1532
const resp = await fetch('api/game/returnItem', {
1530
1533
method: 'POST',
1531
1534
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },
1532
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, koboldId: kobold.id, itemId: item.id })
1535
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, itemId: item.id })
1533
1536
});
1534
1537
1535
1538
const dataText = await resp.text();
@@ -208,7 +208,10 @@ class TribeGenApp208
{208
{209
const response = await fetch('api/game/list', {209
const response = await fetch('api/game/list', {210
method: 'GET',210
method: 'GET',211
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }211
headers: { 'Authorization': `Bearer ${this.currentUser.token}` },212
body: JSON.stringify({213
userId: this.currentUser.email214
})212
});215
});213
216
214
const dataText = await response.text();217
const dataText = await response.text();@@ -276,7 +279,7 @@ class TribeGenApp276
},279
},277
body: JSON.stringify({280
body: JSON.stringify({278
saveName: tribeName,281
saveName: tribeName,279
userId: this.currentUser.id282
userId: this.currentUser.email280
})283
})281
});284
});282
285
@@ -312,7 +315,7 @@ class TribeGenApp312
const card = document.createElement('div');315
const card = document.createElement('div');313
card.className = 'kobold-card';316
card.className = 'kobold-card';314
317
315
const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;318
const spriteUrl = `api/game/sprite?userId=${this.currentUser.email}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;316
319
317
card.innerHTML = `320
card.innerHTML = `318
<img src="${spriteUrl}" alt="Kobold sprite" class="kobold-sprite">321
<img src="${spriteUrl}" alt="Kobold sprite" class="kobold-sprite">@@ -579,7 +582,7 @@ class TribeGenApp579
'Authorization': `Bearer ${this.currentUser.token}`582
'Authorization': `Bearer ${this.currentUser.token}`580
},583
},581
body: JSON.stringify({584
body: JSON.stringify({582
userId: this.currentUser.id,585
userId: this.currentUser.email,583
saveId: this.currentSave.id,586
saveId: this.currentSave.id,584
leaderName: this.pendingSetup.leaderName,587
leaderName: this.pendingSetup.leaderName,585
memberIndices: this.pendingSetup.memberIndices,588
memberIndices: this.pendingSetup.memberIndices,@@ -607,7 +610,7 @@ class TribeGenApp607
{610
{608
try611
try609
{612
{610
const response = await fetch(`api/game/load?saveId=${saveId}&userId=${this.currentUser.id}`, {613
const response = await fetch(`api/game/load?saveId=${saveId}&userId=${this.currentUser.email}`, {611
method: 'GET',614
method: 'GET',612
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }615
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }613
});616
});@@ -756,7 +759,7 @@ class TribeGenApp756
759
757
placementList.forEach(entry =>760
placementList.forEach(entry =>758
{761
{759
const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${entry.kobold.id}&age=${entry.kobold.ageCategory}`;762
const spriteUrl = `api/game/sprite?userId=${this.currentUser.email}&koboldId=${entry.kobold.id}&age=${entry.kobold.ageCategory}`;760
const img = document.createElement('img');763
const img = document.createElement('img');761
img.src = spriteUrl;764
img.src = spriteUrl;762
img.alt = entry.kobold.name;765
img.alt = entry.kobold.name;@@ -835,7 +838,7 @@ class TribeGenApp835
838
836
this.currentTribe.kobolds.forEach(kobold =>839
this.currentTribe.kobolds.forEach(kobold =>837
{840
{838
const spriteUrl = `api/game/sprite?userId=${this.currentUser.id}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;841
const spriteUrl = `api/game/sprite?userId=${this.currentUser.email}&koboldId=${kobold.id}&age=${kobold.ageCategory}`;839
const item = document.createElement('div');842
const item = document.createElement('div');840
const isInjured = kobold.injuries && kobold.injuries.length > 0;843
const isInjured = kobold.injuries && kobold.injuries.length > 0;841
item.className = `tribe-item ${isInjured ? 'injured' : ''}`;844
item.className = `tribe-item ${isInjured ? 'injured' : ''}`;@@ -910,7 +913,7 @@ class TribeGenApp910
913
911
try914
try912
{915
{913
const response = await fetch(`api/game/events?saveId=${this.currentSave.id}&userId=${this.currentUser.id}`, {916
const response = await fetch(`api/game/events?saveId=${this.currentSave.id}&userId=${this.currentUser.email}`, {914
method: 'GET',917
method: 'GET',915
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }918
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }916
});919
});@@ -1072,7 +1075,7 @@ class TribeGenApp1072
const resp = await fetch('api/game/event', {1075
const resp = await fetch('api/game/event', {1073
method: 'POST',1076
method: 'POST',1074
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser.token}` },1077
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser.token}` },1075
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, eventType: this.currentEventType, participants: selected })1078
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, eventType: this.currentEventType, participants: selected })1076
});1079
});1077
1080
1078
const dataText = await resp.text();1081
const dataText = await resp.text();@@ -1106,7 +1109,7 @@ class TribeGenApp1106
'Authorization': `Bearer ${this.currentUser.token}`1109
'Authorization': `Bearer ${this.currentUser.token}`1107
},1110
},1108
body: JSON.stringify({1111
body: JSON.stringify({1109
userId: this.currentUser.id, saveId: this.currentSave.id1112
userId: this.currentUser.email, saveId: this.currentSave.id1110
})1113
})1111
});1114
});1112
1115
@@ -1241,7 +1244,7 @@ class TribeGenApp1241
const resp = await fetch('api/game/giveItem', {1244
const resp = await fetch('api/game/giveItem', {1242
method: 'POST',1245
method: 'POST',1243
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1246
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1244
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, koboldId: koboldId, itemId: item.id })1247
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: koboldId, itemId: item.id })1245
});1248
});1246
1249
1247
const dataText = await resp.text();1250
const dataText = await resp.text();@@ -1434,7 +1437,7 @@ class TribeGenApp1434
const resp = await fetch('api/game/cureInjury', {1437
const resp = await fetch('api/game/cureInjury', {1435
method: 'POST',1438
method: 'POST',1436
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1439
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1437
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, koboldId: kobold.id, injuryId: injury.id, itemId: required })1440
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, injuryId: injury.id, itemId: required })1438
});1441
});1439
const dataText = await resp.text();1442
const dataText = await resp.text();1440
const data = JSON.parse(dataText);1443
const data = JSON.parse(dataText);@@ -1529,7 +1532,7 @@ class TribeGenApp1529
const resp = await fetch('api/game/returnItem', {1532
const resp = await fetch('api/game/returnItem', {1530
method: 'POST',1533
method: 'POST',1531
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1534
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1532
body: JSON.stringify({ userId: this.currentUser.id, saveId: this.currentSave.id, koboldId: kobold.id, itemId: item.id })1535
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, itemId: item.id })1533
});1536
});1534
1537
1535
const dataText = await resp.text();1538
const dataText = await resp.text();@@ -564,7 +564,7 @@ if ($method === 'POST') {
564
564
} elseif (strpos($apiPath, 'list') !== false) {
565
565
// List saves for user
566
566
try {
567
$userId = $_GET['userId'] ?? $_SESSION['user_id'] ?? null;
567
$userId = $_GET['userId'] ?? null;
568
568
569
569
if (!$userId) {
570
570
throw new \Exception('Not authenticated');
@@ -564,7 +564,7 @@ if ($method === 'POST') {564
} elseif (strpos($apiPath, 'list') !== false) {564
} elseif (strpos($apiPath, 'list') !== false) {565
// List saves for user565
// List saves for user566
try {566
try {567
$userId = $_GET['userId'] ?? $_SESSION['user_id'] ?? null;567
$userId = $_GET['userId'] ?? null;568
568
569
if (!$userId) {569
if (!$userId) {570
throw new \Exception('Not authenticated');570
throw new \Exception('Not authenticated');