Add sheep/goat cookable meat and friends online presence.
Wool animals drop mutton or goat for oven/campfire cooking; the friends list shows online status and the character currently in-world.
@@ -201,12 +201,27 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null, reso
201
201
wrap.className = "friend-account";
202
202
const header = document.createElement("div");
203
203
header.className = "social-row friend-account-header";
204
const status = document.createElement("span");
205
status.className = `friend-status-dot ${account.online ? "online" : "offline"}`;
206
status.title = account.online ? "Online" : "Offline";
207
status.setAttribute("aria-label", account.online ? "Online" : "Offline");
208
const nameCol = document.createElement("div");
209
nameCol.className = "friend-account-copy";
204
210
const nameBtn = document.createElement("button");
205
211
nameBtn.type = "button";
206
212
nameBtn.className = "friend-account-name";
207
213
nameBtn.textContent = account.username || `Account ${account.accountId}`;
208
214
nameBtn.addEventListener("click", onToggle);
209
header.append(nameBtn, actionButton("Remove", onRemove));
215
nameCol.append(nameBtn);
216
if (account.online && account.playingAs)
217
{
218
const playing = document.createElement("span");
219
playing.className = "friend-playing-as";
220
const who = `${account.playingAs.firstName ?? ""} ${account.playingAs.lastName ?? ""}`.trim();
221
playing.textContent = who ? `Playing as ${who}` : "Online";
222
nameCol.append(playing);
223
}
224
header.append(status, nameCol, actionButton("Remove", onRemove));
210
225
wrap.append(header);
211
226
if (expanded)
212
227
{
@@ -201,12 +201,27 @@ export function initSocial ({ socket, MessageType, resolveSpriteUrl = null, reso201
wrap.className = "friend-account";201
wrap.className = "friend-account";202
const header = document.createElement("div");202
const header = document.createElement("div");203
header.className = "social-row friend-account-header";203
header.className = "social-row friend-account-header";204
const status = document.createElement("span");205
status.className = `friend-status-dot ${account.online ? "online" : "offline"}`;206
status.title = account.online ? "Online" : "Offline";207
status.setAttribute("aria-label", account.online ? "Online" : "Offline");208
const nameCol = document.createElement("div");209
nameCol.className = "friend-account-copy";204
const nameBtn = document.createElement("button");210
const nameBtn = document.createElement("button");205
nameBtn.type = "button";211
nameBtn.type = "button";206
nameBtn.className = "friend-account-name";212
nameBtn.className = "friend-account-name";207
nameBtn.textContent = account.username || `Account ${account.accountId}`;213
nameBtn.textContent = account.username || `Account ${account.accountId}`;208
nameBtn.addEventListener("click", onToggle);214
nameBtn.addEventListener("click", onToggle);209
header.append(nameBtn, actionButton("Remove", onRemove));215
nameCol.append(nameBtn);216
if (account.online && account.playingAs)217
{218
const playing = document.createElement("span");219
playing.className = "friend-playing-as";220
const who = `${account.playingAs.firstName ?? ""} ${account.playingAs.lastName ?? ""}`.trim();221
playing.textContent = who ? `Playing as ${who}` : "Online";222
nameCol.append(playing);223
}224
header.append(status, nameCol, actionButton("Remove", onRemove));210
wrap.append(header);225
wrap.append(header);211
if (expanded)226
if (expanded)212
{227
{@@ -527,6 +527,30 @@ a {
527
527
align-items: center;
528
528
}
529
529
530
.friend-status-dot {
531
width: 0.55rem;
532
height: 0.55rem;
533
border-radius: 50%;
534
flex: 0 0 auto;
535
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
536
}
537
538
.friend-status-dot.online {
539
background: #3ecf6a;
540
}
541
542
.friend-status-dot.offline {
543
background: #c44a4a;
544
}
545
546
.friend-account-copy {
547
flex: 1;
548
min-width: 0;
549
display: flex;
550
flex-direction: column;
551
gap: 0.1rem;
552
}
553
530
554
button.friend-account-name {
531
555
flex: 1;
532
556
text-align: left;
@@ -542,6 +566,12 @@ button.friend-account-name:hover {
542
566
color: #e8c84a;
543
567
}
544
568
569
.friend-playing-as {
570
font-size: 0.78rem;
571
opacity: 0.75;
572
line-height: 1.2;
573
}
574
545
575
.friend-character-list {
546
576
display: flex;
547
577
flex-direction: column;
@@ -527,6 +527,30 @@ a {527
align-items: center;527
align-items: center;528
}528
}529
529
530
.friend-status-dot {531
width: 0.55rem;532
height: 0.55rem;533
border-radius: 50%;534
flex: 0 0 auto;535
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);536
}537
538
.friend-status-dot.online {539
background: #3ecf6a;540
}541
542
.friend-status-dot.offline {543
background: #c44a4a;544
}545
546
.friend-account-copy {547
flex: 1;548
min-width: 0;549
display: flex;550
flex-direction: column;551
gap: 0.1rem;552
}553
530
button.friend-account-name {554
button.friend-account-name {531
flex: 1;555
flex: 1;532
text-align: left;556
text-align: left;@@ -542,6 +566,12 @@ button.friend-account-name:hover {542
color: #e8c84a;566
color: #e8c84a;543
}567
}544
568
569
.friend-playing-as {570
font-size: 0.78rem;571
opacity: 0.75;572
line-height: 1.2;573
}574
545
.friend-character-list {575
.friend-character-list {546
display: flex;576
display: flex;547
flex-direction: column;577
flex-direction: column;@@ -1125,6 +1125,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1125
1125
else
1126
1126
{ session.entityId = simulation.spawnCharacter(session.id, character); }
1127
1127
sendEnterWorld(session, character);
1128
notifyFriendPresence(session.account?.account_id);
1128
1129
}
1129
1130
1130
1131
function sendEnterWorld (session, character)
@@ -1155,7 +1156,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1155
1156
restartStatus: deploy?.getStatus?.() ?? { scheduled: false }
1156
1157
});
1157
1158
syncSubscriptions(session, true);
1158
send(session, { type: MessageType.friends, ...friends.snapshot(session.characterId) });
1159
send(session, { type: MessageType.friends, ...friendsPayload(session.characterId) });
1159
1160
const bag = simulation.bagOf(session.entityId);
1160
1161
if (bag)
1161
1162
{ send(session, { type: MessageType.inventory, ...bag }); }
@@ -1197,6 +1198,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1197
1198
{
1198
1199
send(session, { type: MessageType.forceLogout, reason });
1199
1200
const characterId = session.characterId;
1201
const accountId = session.account?.account_id | 0;
1200
1202
session.characterId = null;
1201
1203
session.entityId = null;
1202
1204
session.entitySubscribed.clear();
@@ -1209,10 +1211,13 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1209
1211
session.suppressLeaveWorldOnClose = true;
1210
1212
if (session.socket.readyState === 1)
1211
1213
{ session.socket.close(4000, "Logged in elsewhere"); }
1214
if (accountId)
1215
{ notifyFriendPresence(accountId); }
1212
1216
}
1213
1217
1214
1218
function leaveWorld (session)
1215
1219
{
1220
const accountId = session.account?.account_id | 0;
1216
1221
if (session.characterId)
1217
1222
{ simulation.despawnCharacter(session.characterId); }
1218
1223
publishReplication(simulation.drainReplication());
@@ -1220,6 +1225,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1220
1225
session.entityId = null;
1221
1226
session.entitySubscribed.clear();
1222
1227
session.staticSubscribed.clear();
1228
if (accountId)
1229
{ notifyFriendPresence(accountId); }
1223
1230
}
1224
1231
1225
1232
function syncSubscriptions (session, forceSnapshots)
@@ -1356,6 +1363,53 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1356
1363
}
1357
1364
}
1358
1365
1366
function onlinePresenceByAccount ()
1367
{
1368
const byAccount = new Map();
1369
for (const entry of sessions.values())
1370
{
1371
if (!entry.characterId || !entry.entityId)
1372
{ continue; }
1373
const accountId = entry.account?.account_id | 0;
1374
if (!accountId)
1375
{ continue; }
1376
const row = stateDb.getCharacter(entry.characterId);
1377
if (!row)
1378
{ continue; }
1379
byAccount.set(accountId, {
1380
characterId: row.character_id,
1381
firstName: row.first_name,
1382
lastName: row.last_name
1383
});
1384
}
1385
return byAccount;
1386
}
1387
1388
function friendsPayload (characterId)
1389
{
1390
const snap = friends.snapshot(characterId);
1391
const presence = onlinePresenceByAccount();
1392
for (const account of snap.friends ?? [])
1393
{
1394
const playingAs = presence.get(account.accountId | 0) ?? null;
1395
account.online = !!playingAs;
1396
account.playingAs = playingAs;
1397
}
1398
return snap;
1399
}
1400
1401
/** Refresh friends panels for an account and everyone friended with them. */
1402
function notifyFriendPresence (accountId)
1403
{
1404
const id = accountId | 0;
1405
if (!id)
1406
{ return; }
1407
const refs = [id];
1408
for (const row of stateDb.listAccountFriendRecords(id))
1409
{ refs.push(row.account_id); }
1410
pushFriends(...refs);
1411
}
1412
1359
1413
function pushFriends (...refs)
1360
1414
{
1361
1415
const accountIds = new Set();
@@ -1385,7 +1439,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1385
1439
const accountId = session.account?.account_id | 0;
1386
1440
if (!accountIds.has(accountId))
1387
1441
{ continue; }
1388
send(session, { type: MessageType.friends, ...friends.snapshot(session.characterId) });
1442
send(session, { type: MessageType.friends, ...friendsPayload(session.characterId) });
1389
1443
}
1390
1444
}
1391
1445
@@ -1125,6 +1125,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1125
else1125
else1126
{ session.entityId = simulation.spawnCharacter(session.id, character); }1126
{ session.entityId = simulation.spawnCharacter(session.id, character); }1127
sendEnterWorld(session, character);1127
sendEnterWorld(session, character);1128
notifyFriendPresence(session.account?.account_id);1128
}1129
}1129
1130
1130
function sendEnterWorld (session, character)1131
function sendEnterWorld (session, character)@@ -1155,7 +1156,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1155
restartStatus: deploy?.getStatus?.() ?? { scheduled: false }1156
restartStatus: deploy?.getStatus?.() ?? { scheduled: false }1156
});1157
});1157
syncSubscriptions(session, true);1158
syncSubscriptions(session, true);1158
send(session, { type: MessageType.friends, ...friends.snapshot(session.characterId) });1159
send(session, { type: MessageType.friends, ...friendsPayload(session.characterId) });1159
const bag = simulation.bagOf(session.entityId);1160
const bag = simulation.bagOf(session.entityId);1160
if (bag)1161
if (bag)1161
{ send(session, { type: MessageType.inventory, ...bag }); }1162
{ send(session, { type: MessageType.inventory, ...bag }); }@@ -1197,6 +1198,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1197
{1198
{1198
send(session, { type: MessageType.forceLogout, reason });1199
send(session, { type: MessageType.forceLogout, reason });1199
const characterId = session.characterId;1200
const characterId = session.characterId;1201
const accountId = session.account?.account_id | 0;1200
session.characterId = null;1202
session.characterId = null;1201
session.entityId = null;1203
session.entityId = null;1202
session.entitySubscribed.clear();1204
session.entitySubscribed.clear();@@ -1209,10 +1211,13 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1209
session.suppressLeaveWorldOnClose = true;1211
session.suppressLeaveWorldOnClose = true;1210
if (session.socket.readyState === 1)1212
if (session.socket.readyState === 1)1211
{ session.socket.close(4000, "Logged in elsewhere"); }1213
{ session.socket.close(4000, "Logged in elsewhere"); }1214
if (accountId)1215
{ notifyFriendPresence(accountId); }1212
}1216
}1213
1217
1214
function leaveWorld (session)1218
function leaveWorld (session)1215
{1219
{1220
const accountId = session.account?.account_id | 0;1216
if (session.characterId)1221
if (session.characterId)1217
{ simulation.despawnCharacter(session.characterId); }1222
{ simulation.despawnCharacter(session.characterId); }1218
publishReplication(simulation.drainReplication());1223
publishReplication(simulation.drainReplication());@@ -1220,6 +1225,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1220
session.entityId = null;1225
session.entityId = null;1221
session.entitySubscribed.clear();1226
session.entitySubscribed.clear();1222
session.staticSubscribed.clear();1227
session.staticSubscribed.clear();1228
if (accountId)1229
{ notifyFriendPresence(accountId); }1223
}1230
}1224
1231
1225
function syncSubscriptions (session, forceSnapshots)1232
function syncSubscriptions (session, forceSnapshots)@@ -1356,6 +1363,53 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1356
}1363
}1357
}1364
}1358
1365
1366
function onlinePresenceByAccount ()1367
{1368
const byAccount = new Map();1369
for (const entry of sessions.values())1370
{1371
if (!entry.characterId || !entry.entityId)1372
{ continue; }1373
const accountId = entry.account?.account_id | 0;1374
if (!accountId)1375
{ continue; }1376
const row = stateDb.getCharacter(entry.characterId);1377
if (!row)1378
{ continue; }1379
byAccount.set(accountId, {1380
characterId: row.character_id,1381
firstName: row.first_name,1382
lastName: row.last_name1383
});1384
}1385
return byAccount;1386
}1387
1388
function friendsPayload (characterId)1389
{1390
const snap = friends.snapshot(characterId);1391
const presence = onlinePresenceByAccount();1392
for (const account of snap.friends ?? [])1393
{1394
const playingAs = presence.get(account.accountId | 0) ?? null;1395
account.online = !!playingAs;1396
account.playingAs = playingAs;1397
}1398
return snap;1399
}1400
1401
/** Refresh friends panels for an account and everyone friended with them. */1402
function notifyFriendPresence (accountId)1403
{1404
const id = accountId | 0;1405
if (!id)1406
{ return; }1407
const refs = [id];1408
for (const row of stateDb.listAccountFriendRecords(id))1409
{ refs.push(row.account_id); }1410
pushFriends(...refs);1411
}1412
1359
function pushFriends (...refs)1413
function pushFriends (...refs)1360
{1414
{1361
const accountIds = new Set();1415
const accountIds = new Set();@@ -1385,7 +1439,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1385
const accountId = session.account?.account_id | 0;1439
const accountId = session.account?.account_id | 0;1386
if (!accountIds.has(accountId))1440
if (!accountIds.has(accountId))1387
{ continue; }1441
{ continue; }1388
send(session, { type: MessageType.friends, ...friends.snapshot(session.characterId) });1442
send(session, { type: MessageType.friends, ...friendsPayload(session.characterId) });1389
}1443
}1390
}1444
}1391
1445
@@ -121,9 +121,11 @@ function cookedItemIdForRaw (rawDef)
121
121
{
122
122
if (rawDef.fishSpeciesId)
123
123
{ return cookedFishItemId(rawDef.fishSpeciesId); }
124
if (rawDef.cookedItemId)
125
{ return rawDef.cookedItemId; }
124
126
if (rawDef.itemId === CraftingItemId.rawMeat)
125
127
{ return CraftingItemId.cookedMeat; }
126
return rawDef.cookedItemId ?? CraftingItemId.cookedMeat;
128
return CraftingItemId.cookedMeat;
127
129
}
128
130
129
131
function spawnGroundStack (world, tileX, tileY, stack, now, events)
@@ -121,9 +121,11 @@ function cookedItemIdForRaw (rawDef)121
{121
{122
if (rawDef.fishSpeciesId)122
if (rawDef.fishSpeciesId)123
{ return cookedFishItemId(rawDef.fishSpeciesId); }123
{ return cookedFishItemId(rawDef.fishSpeciesId); }124
if (rawDef.cookedItemId)125
{ return rawDef.cookedItemId; }124
if (rawDef.itemId === CraftingItemId.rawMeat)126
if (rawDef.itemId === CraftingItemId.rawMeat)125
{ return CraftingItemId.cookedMeat; }127
{ return CraftingItemId.cookedMeat; }126
return rawDef.cookedItemId ?? CraftingItemId.cookedMeat;128
return CraftingItemId.cookedMeat;127
}129
}128
130
129
function spawnGroundStack (world, tileX, tileY, stack, now, events)131
function spawnGroundStack (world, tileX, tileY, stack, now, events)@@ -10,6 +10,7 @@ import {
10
10
CRAFT_DURATION_MS
11
11
} from "../../shared/definitions/craftingStations.js";
12
12
import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";
13
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";
13
14
import { WoodItemId, ashItemIdForWood } from "../../shared/definitions/woodItems.js";
14
15
import { WoodTier } from "../../shared/definitions/materialTiers.js";
15
16
import { SkillId } from "../../shared/definitions/skills.js";
@@ -130,6 +131,20 @@ test("eggs cook only in an oven and cannot be eaten raw", () =>
130
131
);
131
132
});
132
133
134
test("sheep and goat drop cookable meats for oven and campfire", () =>
135
{
136
const sheep = mobDefinition(MobId.sheep);
137
assert.ok(sheep.drops.some((drop) => drop.itemId === CraftingItemId.rawMutton));
138
const goat = mobDefinition(MobId.cashmereGoat);
139
assert.ok(goat.drops.some((drop) => drop.itemId === CraftingItemId.rawGoat));
140
const mutton = recipeDefinition("cook-mutton");
141
assert.deepEqual(mutton.stationIds, [CraftingStationId.oven, CraftingStationId.fireplace]);
142
assert.equal(mutton.output.itemId, CraftingItemId.cookedMutton);
143
const goatCook = recipeDefinition("cook-goat");
144
assert.deepEqual(goatCook.stationIds, [CraftingStationId.oven, CraftingStationId.fireplace]);
145
assert.equal(goatCook.output.itemId, CraftingItemId.cookedGoat);
146
});
147
133
148
test("fish cook recipes use the species name as craft label", () =>
134
149
{
135
150
const trout = recipeDefinition("cook-trout");
@@ -10,6 +10,7 @@ import {10
CRAFT_DURATION_MS10
CRAFT_DURATION_MS11
} from "../../shared/definitions/craftingStations.js";11
} from "../../shared/definitions/craftingStations.js";12
import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";12
import { CraftingItemId, tinderboxItemInstance } from "../../shared/definitions/craftingItems.js";13
import { MobId, mobDefinition } from "../../shared/definitions/mobs.js";13
import { WoodItemId, ashItemIdForWood } from "../../shared/definitions/woodItems.js";14
import { WoodItemId, ashItemIdForWood } from "../../shared/definitions/woodItems.js";14
import { WoodTier } from "../../shared/definitions/materialTiers.js";15
import { WoodTier } from "../../shared/definitions/materialTiers.js";15
import { SkillId } from "../../shared/definitions/skills.js";16
import { SkillId } from "../../shared/definitions/skills.js";@@ -130,6 +131,20 @@ test("eggs cook only in an oven and cannot be eaten raw", () =>130
);131
);131
});132
});132
133
134
test("sheep and goat drop cookable meats for oven and campfire", () =>135
{136
const sheep = mobDefinition(MobId.sheep);137
assert.ok(sheep.drops.some((drop) => drop.itemId === CraftingItemId.rawMutton));138
const goat = mobDefinition(MobId.cashmereGoat);139
assert.ok(goat.drops.some((drop) => drop.itemId === CraftingItemId.rawGoat));140
const mutton = recipeDefinition("cook-mutton");141
assert.deepEqual(mutton.stationIds, [CraftingStationId.oven, CraftingStationId.fireplace]);142
assert.equal(mutton.output.itemId, CraftingItemId.cookedMutton);143
const goatCook = recipeDefinition("cook-goat");144
assert.deepEqual(goatCook.stationIds, [CraftingStationId.oven, CraftingStationId.fireplace]);145
assert.equal(goatCook.output.itemId, CraftingItemId.cookedGoat);146
});147
133
test("fish cook recipes use the species name as craft label", () =>148
test("fish cook recipes use the species name as craft label", () =>134
{149
{135
const trout = recipeDefinition("cook-trout");150
const trout = recipeDefinition("cook-trout");