@modlock/modlock 0.1.72 → 0.1.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cast.d.ts CHANGED
@@ -56,12 +56,23 @@ export declare class Cast<M> {
56
56
  * not show yet. seconds is the game clock.
57
57
  */
58
58
  frame(seconds: number): void;
59
- /** settle ends the members whose connection left and makes the new ones. */
59
+ /**
60
+ * settle ends the members whose connection left and makes the new ones,
61
+ * joined at now.
62
+ */
60
63
  private settle;
61
64
  /** kick asks the server to remove a bot, once per connection. */
62
65
  private kick;
63
66
  /** reconcile reads a member's hero and asks for the part of the want it lacks. */
64
67
  private reconcile;
68
+ /**
69
+ * stranded returns 'any' for a human whose hero is free when the game has
70
+ * left them on a team without one for changeSeconds since they joined, and
71
+ * otherwise leaves the hero free. Such a pawn never gets a hero on its own,
72
+ * while a player still choosing one has no pawn and a spectator stands on
73
+ * team 1. A bot is left to the game, which seats it.
74
+ */
75
+ private stranded;
65
76
  /** wantOf is what the member in seat wants now. */
66
77
  private wantOf;
67
78
  /** seated reports whether the member's hero shows the hero and team they want. */
package/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export { poseAt, type Pose, Puppet, type PuppetOptions, type PuppetState, ghostS
25
25
  export { type HeroSnapshot, restoreHero } from './restore.js';
26
26
  export { type ReplayedHit, replayDamage } from './replayed-damage.js';
27
27
  export { type CatalogEntry, Dropper, dropperButtons } from './dropper.js';
28
+ export { type BoardPage, type BoardRead, type BoardRow, type BoardWindow, type MatchPlace, readBoard, reportMatch, reportScore, type ScoreOptions, } from './scores.js';
28
29
  export { decodeSpot, encodeSpot, LoadedSpot, loadSpot, type Placed, type Spot, type SpotObject, triggers, } from './spot.js';
29
30
  export { type ButtonProps, type Child, type Component, type Edges, type ElementProps, Fragment, type Gradient, type HeroLookName, type HeroProps, hide, hideHud, cursorFree, freeCursor, type HudPart, type ImageProps, type JSX, jsx, jsxs, type LabelProps, type LayoutProps, type Length, type Overflow, type PanelProps, route, type Scaling, type Shadow, sheet, show, type Style, toast, type Transition, type UiElement, } from './ui.js';
30
31
  /** LogPart is a value log writes as text. */
package/index.js CHANGED
@@ -13361,8 +13361,8 @@ function watchInput(buttons) {
13361
13361
  function remapInput(from, to, repeat2) {
13362
13362
  return call("RemapInput", RemapInputRequest.toBinary({ from, to, repeat: repeat2 })) !== void 0;
13363
13363
  }
13364
- function callService(service, method, payload) {
13365
- const reply2 = call("CallService", ServiceCall.toBinary({ service, method, payload }));
13364
+ function callService(service2, method, payload) {
13365
+ const reply2 = call("CallService", ServiceCall.toBinary({ service: service2, method, payload }));
13366
13366
  if (reply2 === void 0) return void 0;
13367
13367
  const response = ServiceReply.fromBinary(reply2);
13368
13368
  return response.payload ?? new Uint8Array();
@@ -15912,7 +15912,7 @@ var badgeSize = 18;
15912
15912
  var portraits = new Map(heroes.map((hero) => [hero.id, hero.portrait]));
15913
15913
  function rosterKey(rows) {
15914
15914
  return rows.slice(0, rosterRows).map(
15915
- (row) => `${row.self ? "*" : ""}${row.selected ? "+" : ""}${row.onPress ? ">" : ""}${row.name} ${row.hero} ${row.activity} ${row.steamId ?? ""}`
15915
+ (row2) => `${row2.self ? "*" : ""}${row2.selected ? "+" : ""}${row2.onPress ? ">" : ""}${row2.name} ${row2.hero} ${row2.activity} ${row2.steamId ?? ""}`
15916
15916
  ).join("\n");
15917
15917
  }
15918
15918
  function Roster(props) {
@@ -15930,7 +15930,7 @@ function Roster(props) {
15930
15930
  props.rows.slice(0, rosterRows).map(rosterRow)
15931
15931
  );
15932
15932
  }
15933
- function rosterRow(row, index) {
15933
+ function rosterRow(row2, index) {
15934
15934
  const right = { horizontalAlign: "right", textAlign: "right" };
15935
15935
  const text2 = element(
15936
15936
  "panel",
@@ -15940,18 +15940,18 @@ function rosterRow(row, index) {
15940
15940
  role: "label",
15941
15941
  tone: "text",
15942
15942
  style: right,
15943
- children: clip(row.name.toUpperCase(), rosterName)
15943
+ children: clip(row2.name.toUpperCase(), rosterName)
15944
15944
  }),
15945
15945
  Text({
15946
15946
  role: "caption",
15947
15947
  tone: "muted",
15948
15948
  style: { ...right, margin: [1, 0, 0, 0] },
15949
- children: row.activity
15949
+ children: row2.activity
15950
15950
  })
15951
15951
  ]
15952
15952
  );
15953
- const src = portraits.get(row.hero);
15954
- const badge = row.steamId === void 0 ? false : avatarBadge(row.steamId);
15953
+ const src = portraits.get(row2.hero);
15954
+ const badge = row2.steamId === void 0 ? false : avatarBadge(row2.steamId);
15955
15955
  const image = src === void 0 ? false : portraitImage(src);
15956
15956
  const portrait = element(
15957
15957
  "panel",
@@ -15960,7 +15960,7 @@ function rosterRow(row, index) {
15960
15960
  height: portraitSize,
15961
15961
  padding: 1,
15962
15962
  verticalAlign: "center",
15963
- background: row.self || row.selected ? tones.accent : shades.dim
15963
+ background: row2.self || row2.selected ? tones.accent : shades.dim
15964
15964
  },
15965
15965
  element(
15966
15966
  "panel",
@@ -15973,7 +15973,7 @@ function rosterRow(row, index) {
15973
15973
  horizontalAlign: "right",
15974
15974
  margin: [0, 0, 8, 0]
15975
15975
  };
15976
- const line2 = row.onPress ? {
15976
+ const line2 = row2.onPress ? {
15977
15977
  type: "button",
15978
15978
  props: {
15979
15979
  style: {
@@ -15984,7 +15984,7 @@ function rosterRow(row, index) {
15984
15984
  hover: { background: shades.raised },
15985
15985
  hoverSound: sounds.hover,
15986
15986
  sound: sounds.press,
15987
- onPress: row.onPress,
15987
+ onPress: row2.onPress,
15988
15988
  children: [text2, portrait]
15989
15989
  },
15990
15990
  key: `row-${index}`
@@ -16136,15 +16136,18 @@ var Cast = class {
16136
16136
  */
16137
16137
  frame(seconds) {
16138
16138
  if (this.reported !== void 0) {
16139
- this.settle(this.reported);
16139
+ this.settle(this.reported, seconds);
16140
16140
  this.reported = void 0;
16141
16141
  }
16142
16142
  for (const seat of this.seats.values()) {
16143
16143
  this.reconcile(seat, seconds);
16144
16144
  }
16145
16145
  }
16146
- /** settle ends the members whose connection left and makes the new ones. */
16147
- settle(players2) {
16146
+ /**
16147
+ * settle ends the members whose connection left and makes the new ones,
16148
+ * joined at now.
16149
+ */
16150
+ settle(players2, now4) {
16148
16151
  const present = new Map(players2.map((c) => [c.player.slot, c]));
16149
16152
  for (const [slot, seat] of this.seats) {
16150
16153
  if (present.get(slot)?.generation !== seat.connection.generation) {
@@ -16168,6 +16171,7 @@ var Cast = class {
16168
16171
  fellAt: -Infinity,
16169
16172
  hero: 0,
16170
16173
  heroLostAt: -Infinity,
16174
+ joinedAt: now4,
16171
16175
  askedAt: -Infinity
16172
16176
  });
16173
16177
  }
@@ -16192,7 +16196,8 @@ var Cast = class {
16192
16196
  const changing = had === 0 && now4 - seat.heroLostAt < changeSeconds;
16193
16197
  if (now4 - seat.askedAt < 1 || changing) return;
16194
16198
  const want = this.wantOf(seat);
16195
- const { hero, respawn } = want;
16199
+ const { respawn } = want;
16200
+ const hero = want.hero ?? this.stranded(seat, now4);
16196
16201
  if (hero !== void 0 && !this.seated(seat, want, hero)) {
16197
16202
  seat.askedAt = now4;
16198
16203
  this.seat(seat, want, hero);
@@ -16201,6 +16206,19 @@ var Cast = class {
16201
16206
  seat.connection.player.respawn();
16202
16207
  }
16203
16208
  }
16209
+ /**
16210
+ * stranded returns 'any' for a human whose hero is free when the game has
16211
+ * left them on a team without one for changeSeconds since they joined, and
16212
+ * otherwise leaves the hero free. Such a pawn never gets a hero on its own,
16213
+ * while a player still choosing one has no pawn and a spectator stands on
16214
+ * team 1. A bot is left to the game, which seats it.
16215
+ */
16216
+ stranded(seat, now4) {
16217
+ const { pawn } = seat;
16218
+ const team = pawn?.team;
16219
+ const heroless = pawn?.hero === 0 && (team === 2 || team === 3);
16220
+ return heroless && !seat.connection.bot && now4 - seat.joinedAt >= changeSeconds ? "any" : void 0;
16221
+ }
16204
16222
  /** wantOf is what the member in seat wants now. */
16205
16223
  wantOf(seat) {
16206
16224
  const { want = noWant } = this.options;
@@ -16574,13 +16592,13 @@ var ProbeRun = class {
16574
16592
  * tick runs check for the frame at now until the run ends. step names what
16575
16593
  * the probe waits on, and describe adds the probe's state to a timeout.
16576
16594
  */
16577
- tick(now4, step, check, describe) {
16595
+ tick(now4, step, check, describe2) {
16578
16596
  if (this.finished) {
16579
16597
  return;
16580
16598
  }
16581
16599
  let result;
16582
16600
  if (this.elapsed(now4) > this.timeout) {
16583
- const state = describe ? `: ${describe()}` : "";
16601
+ const state = describe2 ? `: ${describe2()}` : "";
16584
16602
  result = `timed out waiting for ${step}${state}`;
16585
16603
  } else {
16586
16604
  result = check();
@@ -17293,12 +17311,529 @@ function snap(value) {
17293
17311
  return Math.round(value / grid) * grid;
17294
17312
  }
17295
17313
 
17314
+ // src/wasm/scores/scores.pb.ts
17315
+ var Window_Enum = /* @__PURE__ */ createEnumType(
17316
+ "modlock.wasm.scores.Window",
17317
+ [
17318
+ [0, "WINDOW_UNKNOWN"],
17319
+ [1, "WINDOW_ALL_TIME"],
17320
+ [2, "WINDOW_DAY"],
17321
+ [3, "WINDOW_WEEK"]
17322
+ ]
17323
+ );
17324
+ var ScoreReport = /* @__PURE__ */ createMessageType(
17325
+ "modlock.wasm.scores.ScoreReport",
17326
+ () => [
17327
+ [1, "board", 9],
17328
+ [2, "player", 5],
17329
+ [3, "value", 3],
17330
+ [4, "tiebreak", 3],
17331
+ [5, "partition", 9, 584],
17332
+ [6, "key", 9],
17333
+ [7, "earned_at_unix_millis", 3],
17334
+ [8, "evidence", 9]
17335
+ ],
17336
+ {
17337
+ decode: (r, end, m) => {
17338
+ while (r.pos < end) {
17339
+ const t = r.tag();
17340
+ if ((t & 7) === 4) return m;
17341
+ switch (t >>> 3) {
17342
+ case 1:
17343
+ m.board = r.string();
17344
+ break;
17345
+ case 2:
17346
+ m.player = r.int32();
17347
+ break;
17348
+ case 3:
17349
+ m.value = r.int64();
17350
+ break;
17351
+ case 4:
17352
+ m.tiebreak = r.int64();
17353
+ break;
17354
+ case 5: {
17355
+ const [k, v] = r.entry(
17356
+ (r2) => r2.string(),
17357
+ (r2) => r2.string(),
17358
+ "",
17359
+ ""
17360
+ );
17361
+ m.partition ??= newMap();
17362
+ m.partition[k] = v;
17363
+ break;
17364
+ }
17365
+ case 6:
17366
+ m.key = r.string();
17367
+ break;
17368
+ case 7:
17369
+ m.earnedAtUnixMillis = r.int64();
17370
+ break;
17371
+ case 8:
17372
+ m.evidence = r.string();
17373
+ break;
17374
+ default:
17375
+ r.skip(t);
17376
+ }
17377
+ }
17378
+ return m;
17379
+ },
17380
+ encode: (m, w) => {
17381
+ {
17382
+ const v = m.board;
17383
+ if (v) w.uint32(10).string(v);
17384
+ }
17385
+ {
17386
+ const v = m.player;
17387
+ if (v) w.uint32(16).int32(v);
17388
+ }
17389
+ {
17390
+ const v = m.value;
17391
+ if (v) w.uint32(24).int64(v);
17392
+ }
17393
+ {
17394
+ const v = m.tiebreak;
17395
+ if (v) w.uint32(32).int64(v);
17396
+ }
17397
+ {
17398
+ const o = m.partition;
17399
+ if (o != null)
17400
+ for (const [k, v] of Object.entries(o)) {
17401
+ const s = w.uint32(42).fork();
17402
+ w.uint32(10).string(k);
17403
+ w.uint32(18).string(v);
17404
+ w.join(s);
17405
+ }
17406
+ }
17407
+ {
17408
+ const v = m.key;
17409
+ if (v) w.uint32(50).string(v);
17410
+ }
17411
+ {
17412
+ const v = m.earnedAtUnixMillis;
17413
+ if (v) w.uint32(56).int64(v);
17414
+ }
17415
+ {
17416
+ const v = m.evidence;
17417
+ if (v) w.uint32(66).string(v);
17418
+ }
17419
+ }
17420
+ }
17421
+ );
17422
+ var MatchReport = /* @__PURE__ */ createMessageType(
17423
+ "modlock.wasm.scores.MatchReport",
17424
+ () => [
17425
+ [1, "board", 9],
17426
+ [2, "places", 11, 1, Place.codec],
17427
+ [3, "partition", 9, 584],
17428
+ [4, "key", 9],
17429
+ [5, "earned_at_unix_millis", 3],
17430
+ [6, "evidence", 9]
17431
+ ],
17432
+ {
17433
+ decode: (r, end, m) => {
17434
+ while (r.pos < end) {
17435
+ const t = r.tag();
17436
+ if ((t & 7) === 4) return m;
17437
+ switch (t >>> 3) {
17438
+ case 1:
17439
+ m.board = r.string();
17440
+ break;
17441
+ case 2:
17442
+ ;
17443
+ (m.places ??= []).push(Place.decode(r, r.delimited(), {}));
17444
+ break;
17445
+ case 3: {
17446
+ const [k, v] = r.entry(
17447
+ (r2) => r2.string(),
17448
+ (r2) => r2.string(),
17449
+ "",
17450
+ ""
17451
+ );
17452
+ m.partition ??= newMap();
17453
+ m.partition[k] = v;
17454
+ break;
17455
+ }
17456
+ case 4:
17457
+ m.key = r.string();
17458
+ break;
17459
+ case 5:
17460
+ m.earnedAtUnixMillis = r.int64();
17461
+ break;
17462
+ case 6:
17463
+ m.evidence = r.string();
17464
+ break;
17465
+ default:
17466
+ r.skip(t);
17467
+ }
17468
+ }
17469
+ return m;
17470
+ },
17471
+ encode: (m, w) => {
17472
+ {
17473
+ const v = m.board;
17474
+ if (v) w.uint32(10).string(v);
17475
+ }
17476
+ {
17477
+ const a = m.places;
17478
+ if (a != null) for (const e of a) Place.writeField(w, 2, e);
17479
+ }
17480
+ {
17481
+ const o = m.partition;
17482
+ if (o != null)
17483
+ for (const [k, v] of Object.entries(o)) {
17484
+ const s = w.uint32(26).fork();
17485
+ w.uint32(10).string(k);
17486
+ w.uint32(18).string(v);
17487
+ w.join(s);
17488
+ }
17489
+ }
17490
+ {
17491
+ const v = m.key;
17492
+ if (v) w.uint32(34).string(v);
17493
+ }
17494
+ {
17495
+ const v = m.earnedAtUnixMillis;
17496
+ if (v) w.uint32(40).int64(v);
17497
+ }
17498
+ {
17499
+ const v = m.evidence;
17500
+ if (v) w.uint32(50).string(v);
17501
+ }
17502
+ }
17503
+ }
17504
+ );
17505
+ var Place = /* @__PURE__ */ createMessageType(
17506
+ "modlock.wasm.scores.Place",
17507
+ () => [
17508
+ [1, "player", 5],
17509
+ [2, "place", 13],
17510
+ [3, "value", 3]
17511
+ ],
17512
+ {
17513
+ decode: (r, end, m) => {
17514
+ while (r.pos < end) {
17515
+ const t = r.tag();
17516
+ if ((t & 7) === 4) return m;
17517
+ switch (t >>> 3) {
17518
+ case 1:
17519
+ m.player = r.int32();
17520
+ break;
17521
+ case 2:
17522
+ m.place = r.uint32();
17523
+ break;
17524
+ case 3:
17525
+ m.value = r.int64();
17526
+ break;
17527
+ default:
17528
+ r.skip(t);
17529
+ }
17530
+ }
17531
+ return m;
17532
+ },
17533
+ encode: (m, w) => {
17534
+ {
17535
+ const v = m.player;
17536
+ if (v) w.uint32(8).int32(v);
17537
+ }
17538
+ {
17539
+ const v = m.place;
17540
+ if (v) w.uint32(16).uint32(v);
17541
+ }
17542
+ {
17543
+ const v = m.value;
17544
+ if (v) w.uint32(24).int64(v);
17545
+ }
17546
+ }
17547
+ }
17548
+ );
17549
+ var BoardQuery = /* @__PURE__ */ createMessageType(
17550
+ "modlock.wasm.scores.BoardQuery",
17551
+ () => [
17552
+ [1, "board", 9],
17553
+ [2, "partition", 9, 584],
17554
+ [3, "window", 14, 0, Window_Enum],
17555
+ [4, "offset", 13],
17556
+ [5, "limit", 13],
17557
+ [6, "player", 5, 4]
17558
+ ],
17559
+ {
17560
+ decode: (r, end, m) => {
17561
+ while (r.pos < end) {
17562
+ const t = r.tag();
17563
+ if ((t & 7) === 4) return m;
17564
+ switch (t >>> 3) {
17565
+ case 1:
17566
+ m.board = r.string();
17567
+ break;
17568
+ case 2: {
17569
+ const [k, v] = r.entry(
17570
+ (r2) => r2.string(),
17571
+ (r2) => r2.string(),
17572
+ "",
17573
+ ""
17574
+ );
17575
+ m.partition ??= newMap();
17576
+ m.partition[k] = v;
17577
+ break;
17578
+ }
17579
+ case 3:
17580
+ m.window = r.int32();
17581
+ break;
17582
+ case 4:
17583
+ m.offset = r.uint32();
17584
+ break;
17585
+ case 5:
17586
+ m.limit = r.uint32();
17587
+ break;
17588
+ case 6:
17589
+ m.player = r.int32();
17590
+ break;
17591
+ default:
17592
+ r.skip(t);
17593
+ }
17594
+ }
17595
+ return m;
17596
+ },
17597
+ encode: (m, w) => {
17598
+ {
17599
+ const v = m.board;
17600
+ if (v) w.uint32(10).string(v);
17601
+ }
17602
+ {
17603
+ const o = m.partition;
17604
+ if (o != null)
17605
+ for (const [k, v] of Object.entries(o)) {
17606
+ const s = w.uint32(18).fork();
17607
+ w.uint32(10).string(k);
17608
+ w.uint32(18).string(v);
17609
+ w.join(s);
17610
+ }
17611
+ }
17612
+ {
17613
+ const v = m.window;
17614
+ if (v) w.uint32(24).int32(v);
17615
+ }
17616
+ {
17617
+ const v = m.offset;
17618
+ if (v) w.uint32(32).uint32(v);
17619
+ }
17620
+ {
17621
+ const v = m.limit;
17622
+ if (v) w.uint32(40).uint32(v);
17623
+ }
17624
+ {
17625
+ const v = m.player;
17626
+ if (v != null) w.uint32(48).int32(v);
17627
+ }
17628
+ }
17629
+ }
17630
+ );
17631
+ var BoardPage = /* @__PURE__ */ createMessageType(
17632
+ "modlock.wasm.scores.BoardPage",
17633
+ () => [
17634
+ [1, "rows", 11, 1, Standing.codec],
17635
+ [2, "player", 11, 0, Standing.codec],
17636
+ [3, "loading", 8]
17637
+ ],
17638
+ {
17639
+ decode: (r, end, m) => {
17640
+ while (r.pos < end) {
17641
+ const t = r.tag();
17642
+ if ((t & 7) === 4) return m;
17643
+ switch (t >>> 3) {
17644
+ case 1:
17645
+ ;
17646
+ (m.rows ??= []).push(Standing.decode(r, r.delimited(), {}));
17647
+ break;
17648
+ case 2:
17649
+ m.player = Standing.decode(r, r.delimited(), m.player ?? {});
17650
+ break;
17651
+ case 3:
17652
+ m.loading = r.bool();
17653
+ break;
17654
+ default:
17655
+ r.skip(t);
17656
+ }
17657
+ }
17658
+ return m;
17659
+ },
17660
+ encode: (m, w) => {
17661
+ {
17662
+ const a = m.rows;
17663
+ if (a != null) for (const e of a) Standing.writeField(w, 1, e);
17664
+ }
17665
+ {
17666
+ const v = m.player;
17667
+ if (v != null) Standing.writeField(w, 2, v);
17668
+ }
17669
+ {
17670
+ const v = m.loading;
17671
+ if (v) w.uint32(24).bool(v);
17672
+ }
17673
+ }
17674
+ }
17675
+ );
17676
+ var Standing = /* @__PURE__ */ createMessageType(
17677
+ "modlock.wasm.scores.Standing",
17678
+ () => [
17679
+ [1, "rank", 13],
17680
+ [2, "steam_id", 4],
17681
+ [3, "name", 9],
17682
+ [4, "value", 3],
17683
+ [5, "tiebreak", 3],
17684
+ [6, "count", 13]
17685
+ ],
17686
+ {
17687
+ decode: (r, end, m) => {
17688
+ while (r.pos < end) {
17689
+ const t = r.tag();
17690
+ if ((t & 7) === 4) return m;
17691
+ switch (t >>> 3) {
17692
+ case 1:
17693
+ m.rank = r.uint32();
17694
+ break;
17695
+ case 2:
17696
+ m.steamId = r.uint64();
17697
+ break;
17698
+ case 3:
17699
+ m.name = r.string();
17700
+ break;
17701
+ case 4:
17702
+ m.value = r.int64();
17703
+ break;
17704
+ case 5:
17705
+ m.tiebreak = r.int64();
17706
+ break;
17707
+ case 6:
17708
+ m.count = r.uint32();
17709
+ break;
17710
+ default:
17711
+ r.skip(t);
17712
+ }
17713
+ }
17714
+ return m;
17715
+ },
17716
+ encode: (m, w) => {
17717
+ {
17718
+ const v = m.rank;
17719
+ if (v) w.uint32(8).uint32(v);
17720
+ }
17721
+ {
17722
+ const v = m.steamId;
17723
+ if (v) w.uint32(16).uint64(v);
17724
+ }
17725
+ {
17726
+ const v = m.name;
17727
+ if (v) w.uint32(26).string(v);
17728
+ }
17729
+ {
17730
+ const v = m.value;
17731
+ if (v) w.uint32(32).int64(v);
17732
+ }
17733
+ {
17734
+ const v = m.tiebreak;
17735
+ if (v) w.uint32(40).int64(v);
17736
+ }
17737
+ {
17738
+ const v = m.count;
17739
+ if (v) w.uint32(48).uint32(v);
17740
+ }
17741
+ }
17742
+ }
17743
+ );
17744
+
17745
+ // js/src/scores.ts
17746
+ var service = "scores";
17747
+ var windowValues = {
17748
+ allTime: 1 /* ALL_TIME */,
17749
+ day: 2 /* DAY */,
17750
+ week: 3 /* WEEK */
17751
+ };
17752
+ function reportScore(player, board, value, options = {}) {
17753
+ const report = ScoreReport.toBinary({
17754
+ board,
17755
+ player: player.slot,
17756
+ value: int64(value),
17757
+ tiebreak: int64(options.tiebreak ?? 0),
17758
+ partition: options.partition,
17759
+ key: options.key,
17760
+ earnedAtUnixMillis: int64(options.earnedAt ?? 0),
17761
+ evidence: options.evidence
17762
+ });
17763
+ return taken(
17764
+ "Report",
17765
+ report,
17766
+ `${board}${describe(options.partition)}: player ${player.slot} ${value}`
17767
+ );
17768
+ }
17769
+ function reportMatch(board, places, options = {}) {
17770
+ const report = MatchReport.toBinary({
17771
+ board,
17772
+ places: places.map((p) => ({
17773
+ player: p.player.slot,
17774
+ place: p.place,
17775
+ value: int64(p.value ?? 0)
17776
+ })),
17777
+ partition: options.partition,
17778
+ key: options.key,
17779
+ earnedAtUnixMillis: int64(options.earnedAt ?? 0),
17780
+ evidence: options.evidence
17781
+ });
17782
+ const line2 = places.map((p) => `player ${p.player.slot} #${p.place}`).join(", ");
17783
+ return taken(
17784
+ "Match",
17785
+ report,
17786
+ `${board}${describe(options.partition)}: ${line2}`
17787
+ );
17788
+ }
17789
+ function readBoard(board, read = {}) {
17790
+ const query = BoardQuery.toBinary({
17791
+ board,
17792
+ partition: read.partition,
17793
+ window: read.window === void 0 ? void 0 : windowValues[read.window],
17794
+ offset: read.offset,
17795
+ limit: read.limit,
17796
+ player: read.player?.slot
17797
+ });
17798
+ const reply2 = callService(service, "Read", query);
17799
+ if (reply2 === void 0) return void 0;
17800
+ const page = BoardPage.fromBinary(reply2);
17801
+ return {
17802
+ rows: (page.rows ?? []).map(row),
17803
+ player: page.player ? row(page.player) : void 0,
17804
+ loading: page.loading ?? false
17805
+ };
17806
+ }
17807
+ function taken(method, report, line2) {
17808
+ if (callService(service, method, report) !== void 0) return true;
17809
+ log(`score ${line2} (not reported: the host keeps no scores)`);
17810
+ return false;
17811
+ }
17812
+ function row(standing) {
17813
+ return {
17814
+ rank: standing.rank ?? 0,
17815
+ steamId: standing.steamId ?? 0n,
17816
+ name: standing.name ?? "",
17817
+ value: Number(standing.value ?? 0n),
17818
+ tiebreak: Number(standing.tiebreak ?? 0n),
17819
+ count: standing.count ?? 0
17820
+ };
17821
+ }
17822
+ function int64(value) {
17823
+ return BigInt(Math.round(value));
17824
+ }
17825
+ function describe(partition) {
17826
+ const names = Object.keys(partition ?? {}).sort();
17827
+ if (!names.length) return "";
17828
+ return `[${names.map((name) => `${name}=${partition[name]}`).join(" ")}]`;
17829
+ }
17830
+
17296
17831
  // js/src/index.ts
17297
17832
  function log2(...parts) {
17298
17833
  log(parts.map((part) => String(part)).join(" "));
17299
17834
  }
17300
- function serve(service, handler) {
17301
- services.set(service, { handler });
17835
+ function serve(service2, handler) {
17836
+ services.set(service2, { handler });
17302
17837
  }
17303
17838
  function command(name, handler) {
17304
17839
  commands.set(name, { handler });
@@ -17503,8 +18038,12 @@ serveEvents((call2) => serveMod(handlers, call2));
17503
18038
 
17504
18039
  // js/src/quickjs.ts
17505
18040
  var bridge = globalThis.__modlock;
17506
- bind((call2) => bridge.hostCall(call2));
17507
- bridge.event = deliver;
18041
+ var host = (call2) => bridge.hostCall(call2);
18042
+ bind(host);
18043
+ bridge.event = (call2) => {
18044
+ bind(host);
18045
+ return deliver(call2);
18046
+ };
17508
18047
  export {
17509
18048
  Action,
17510
18049
  Banner,
@@ -17619,6 +18158,7 @@ export {
17619
18158
  pushEntity,
17620
18159
  ratingChange,
17621
18160
  ratingStep,
18161
+ readBoard,
17622
18162
  readField,
17623
18163
  readFieldList,
17624
18164
  readFile,
@@ -17627,6 +18167,8 @@ export {
17627
18167
  removeEntities,
17628
18168
  removeEntity,
17629
18169
  replayDamage,
18170
+ reportMatch,
18171
+ reportScore,
17630
18172
  restoreHero,
17631
18173
  restoreNpcs,
17632
18174
  rift,
package/package.json CHANGED
@@ -7,11 +7,11 @@
7
7
  "license": "MIT",
8
8
  "name": "@modlock/modlock",
9
9
  "optionalDependencies": {
10
- "@modlock/darwin-arm64": "0.1.72",
11
- "@modlock/darwin-x64": "0.1.72",
12
- "@modlock/linux-arm64": "0.1.72",
13
- "@modlock/linux-x64": "0.1.72",
14
- "@modlock/win32-x64": "0.1.72"
10
+ "@modlock/darwin-arm64": "0.1.73",
11
+ "@modlock/darwin-x64": "0.1.73",
12
+ "@modlock/linux-arm64": "0.1.73",
13
+ "@modlock/linux-x64": "0.1.73",
14
+ "@modlock/win32-x64": "0.1.73"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -20,5 +20,5 @@
20
20
  "sideEffects": false,
21
21
  "type": "module",
22
22
  "types": "index.d.ts",
23
- "version": "0.1.72"
23
+ "version": "0.1.73"
24
24
  }
package/scores.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { type Player } from './host.gen.js';
2
+ /** BoardWindow is a span of time a board keeps standings for, in UTC; a week starts Monday. */
3
+ export type BoardWindow = 'allTime' | 'day' | 'week';
4
+ /** ScoreOptions describe where a score ranks and the run it came from. */
5
+ export interface ScoreOptions {
6
+ /** partition names a value for each of the board's partitions. */
7
+ partition?: Record<string, string>;
8
+ /** tiebreak ranks equal values, lower first, such as fewer deaths. */
9
+ tiebreak?: number;
10
+ /** key identifies the run, so a resent score counts once. */
11
+ key?: string;
12
+ /** earnedAt is when the score was earned, in Unix milliseconds; the host's clock by default. */
13
+ earnedAt?: number;
14
+ /** evidence names what shows the run, such as a recording. */
15
+ evidence?: string;
16
+ }
17
+ /** MatchPlace is one player's finishing place in a match, 1 for the winner. */
18
+ export interface MatchPlace {
19
+ player: Player;
20
+ place: number;
21
+ /** value is the player's score in the match, for a board that keeps one. */
22
+ value?: number;
23
+ }
24
+ /** BoardRead selects a page of a board. */
25
+ export interface BoardRead {
26
+ /** partition names a value for each of the board's partitions. */
27
+ partition?: Record<string, string>;
28
+ /** window is one of the board's windows; all time by default. */
29
+ window?: BoardWindow;
30
+ /** offset skips that many rows from the top. */
31
+ offset?: number;
32
+ /** limit bounds the rows; ten by default. */
33
+ limit?: number;
34
+ /** player asks for this player's own row too. */
35
+ player?: Player;
36
+ }
37
+ /** BoardRow is one player's place on a board. */
38
+ export interface BoardRow {
39
+ rank: number;
40
+ steamId: bigint;
41
+ name: string;
42
+ value: number;
43
+ tiebreak: number;
44
+ count: number;
45
+ }
46
+ /** BoardPage is a page of a board. */
47
+ export interface BoardPage {
48
+ /** rows are the standings in rank order. */
49
+ rows: BoardRow[];
50
+ /** player is the asked player's row, when they hold a standing. */
51
+ player?: BoardRow;
52
+ /** loading is set until the host has read the board; read again on a later frame. */
53
+ loading: boolean;
54
+ }
55
+ /**
56
+ * reportScore reports one score for player to a board the manifest declares.
57
+ * It reports whether the host took it; a host without the scores service
58
+ * takes none, and the mod logs the score instead.
59
+ */
60
+ export declare function reportScore(player: Player, board: string, value: number, options?: ScoreOptions): boolean;
61
+ /**
62
+ * reportMatch reports one match's places to a rating or match board the
63
+ * manifest declares. Players who tie, such as one team's members, share a
64
+ * place. It reports whether the host took it, as reportScore does.
65
+ */
66
+ export declare function reportMatch(board: string, places: readonly MatchPlace[], options?: Omit<ScoreOptions, 'tiebreak'>): boolean;
67
+ /**
68
+ * readBoard reads a page of a board the manifest declares, as the host last
69
+ * read it, or undefined when the host serves no scores. A page the host has
70
+ * not read yet comes back loading.
71
+ */
72
+ export declare function readBoard(board: string, read?: BoardRead): BoardPage | undefined;
package/scriptc.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import './index.js';
2
2
  /**
3
- * event answers the Call the host holds, size bytes long. call hands the
4
- * host an encoded Call and returns the size of its Reply; read copies the
5
- * bytes the host holds, the Call first and then each Reply, into its
6
- * argument.
3
+ * event answers the Call the host holds, size bytes long. Each Call binds the
4
+ * host again, as the QuickJS entry does, so a transport bound during one
5
+ * event lasts only until the next.
7
6
  */
8
- export declare function event(size: number, call: (data: Uint8Array) => number, read: (data: Uint8Array) => void): Uint8Array;
7
+ export declare function event(size: number): Uint8Array;