Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 | 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x | import { drawJudgements } from './judgements.ts';
import { bindGlassSurface, frostedGlassEnabled, unbindGlassSurface } from './glass.ts';
import { Graphics, type Container } from 'pixi.js';
import { resolveGrooveRect, resolvePortraitHUDColumn } from './layout.ts';
import {
GAUGE_FRAME,
SECOND_PLAYER_FIGURES_WIDTH,
clampPercent,
drawGaugeCells,
drawGauges,
drawLoading,
drawSecondPlayerFigures,
} from './player-hud.ts';
import { cabinetWellBottom, drawSynesthesiaCabinet } from './cabinet.ts';
import { drawSongInfoLayers } from './song-info.ts';
import { drawSynesthesiaMoments } from './moments.ts';
import { ChargeCloud } from './charge-cloud.ts';
import { KICK_REST, stepKick, type KickState } from './kick.ts';
import { createFlock, stepFlock, type Flock } from './boids.ts';
import {
drawFrame,
drawPointCloud,
drawReticle,
type CloudTransform,
drawSchool,
GRAIN_OFFSETS,
grainsFor,
sharedShapeBatch,
type Grains,
} from './draw.ts';
import {
floorRise,
clipSegmentOutsideRect,
emberColor,
cameraBasis,
hsvToHex,
mixCamera,
mixColor,
particleRiverPointInto,
pointCloudPyramid,
projectPoint,
projectViewInto,
REST_CAMERA,
roamingCamera,
scratchProjected,
starfieldInto,
vanishingPoint,
viewPoint,
wanderPoint,
type CameraPose,
type RiverOptions,
} from './space.ts';
import {
SPECTRUM_RIDGE_HEIGHT,
SpectrumHistory,
floorRowStep,
spectrumLevels,
SPECTRUM_WAVE_SPEED,
} from './spectrum-floor.ts';
import {
SYN_AMBER,
SYN_CYAN,
SYN_DIM,
SYN_DISPLAY_FONT,
SYN_EMBER,
SYN_FLARE,
SYN_MAGENTA,
SYN_MIST,
SYN_RED,
SYN_TEXT_FONT,
SYN_VOID,
SYN_WHITE,
displayStyle,
labelStyle,
sceneHue,
} from './style.ts';
import {
AUDIO_BAND_COUNT,
audioDrive,
type AudioDrive,
type BeMusicRect,
comboTier,
effectProfile,
hash01,
impulse,
resolveJudgeWordY,
type BeMusicGameplayLayout,
type BeMusicGameplayRuntime,
type BeMusicLaneKind,
STAGE_BGA_BAND,
STAGE_HEIGHT as DESIGN_HEIGHT,
STAGE_SIDE_COLUMN,
STAGE_WIDTH as DESIGN_WIDTH,
} from '@be-music/player-skin-sdk';
import {
addHUDNumber,
type ChildPool,
type HUDTextOptions,
type PixiChromeContext,
pointLayerFor,
} from '../pixi-kit/index.ts';
import { addSynesthesiaHUDText as addHUDText } from './figures.ts';
type Runtime = BeMusicGameplayRuntime;
/**
* HUD grid (design px): a 16 px page margin and a 12 px gutter. The left column (16..272) stacks the gauge frame and
* the song plate; the score panel fills the right column (284..624) from the gauge frame's top to the plate's bottom.
*/
const HUD_MARGIN = 16;
const SONG_PLATE = { x: HUD_MARGIN, y: 420, w: DESIGN_WIDTH - HUD_MARGIN * 2 - 340 - 12, h: 46 } as const;
/** The score panel sits on the right margin; the track card runs from the left margin up to a gutter before it. */
const SCORE_PANEL = { x: DESIGN_WIDTH - HUD_MARGIN - 340, y: GAUGE_FRAME.y, w: 340, h: 466 - GAUGE_FRAME.y } as const;
/** Score panel's column divider, from its left edge. */
const SCORE_DIVIDER = 200;
const PLAYFIELD_FRAME_BOTTOM = 344;
/** Floor grid: horizon y, camera height above the floor, focal length. */
const FLOOR = { horizon: 326, height: 154, focal: 200 } as const;
/** How far the gameplay camera roams: eye offset (floor frame, floor 154 below) and turn / tilt. */
const CAMERA_RANGE = { x: 230, y: 110, yaw: 0.34, pitch: 0.18 } as const;
const CAMERA_CYCLE_S = 7;
const SCHOOL_SIZE = 70;
/**
* Three schools, each with its own swimming box (floor frame, floor at y 154), light, and seed — their leaders wander
* independently, so the flocks cross, part, and pass in front of one another.
*/
const SCHOOL_SPECS = [
{
seed: 17,
palette: 'ember',
band: 'bass',
bounds: { minX: -650, maxX: 450, minY: -200, maxY: 110, minZ: 160, maxZ: 900 },
},
{
seed: 41,
palette: 'blue',
band: 'mid',
bounds: { minX: -300, maxX: 800, minY: -260, maxY: 40, minZ: 300, maxZ: 1200 },
},
{
seed: 73,
palette: 'magenta',
band: 'high',
bounds: { minX: -800, maxX: 800, minY: -240, maxY: 80, minZ: 700, maxZ: 1700 },
},
] as const;
const SCHOOLS = new WeakMap<object, { flocks: Flock[]; lastMs: number; kick: KickState }>();
/** The dust field's shape; it moves by accumulated travel (see advanceTravel), so its own speed is one unit per unit. */
const DUST_FIELD = { spread: 640, near: 20, far: 900, speed: 1 } as const;
interface Travel {
seconds: number;
dust: number;
floor: number;
river: number;
/** The recent spectrum the floor is shaped from (see spectrum-floor.ts). */
spectrum: SpectrumHistory;
}
const TRAVEL = new WeakMap<object, Travel>();
/**
* Accumulates how far the dust, floor and rivers have travelled at their current `speeds` (world units per second).
* Positions computed as `seconds × speed` jump whenever the speed changes, so the music or the zone changing pace would
* teleport every particle; integrating keeps the motion continuous. Restarts when the clock runs backwards.
*/
function advanceTravel(
key: object,
seconds: number,
speeds: Omit<Travel, 'seconds' | 'spectrum'>,
bands: readonly number[],
): Travel {
let state = TRAVEL.get(key);
if (!state || seconds < state.seconds) {
state = { seconds, dust: 0, floor: 0, river: 0, spectrum: new SpectrumHistory() };
TRAVEL.set(key, state);
}
const dt = Math.min(0.1, seconds - state.seconds);
state.dust += speeds.dust * dt;
state.floor += speeds.floor * dt;
state.river += speeds.river * dt;
state.spectrum.push(spectrumLevels(bands, SCRATCH_LEVELS), dt);
state.seconds = seconds;
return state;
}
/**
* The chrome layer's schools, created on first use (or when their size changes) and stepped to `nowMs`, with the kick
* envelope (from the spectrum `bands` and `onset`) that flicks the fish up.
*/
function advanceSchools(
key: object,
nowMs: number,
size: number,
forces: { gather: number; scatter: number },
bands: readonly number[],
onset: number,
shown: number,
): { flocks: Flock[]; swell: number } {
let state = SCHOOLS.get(key);
if (!state || state.flocks[0]!.count !== size || nowMs < state.lastMs) {
state = {
flocks: SCHOOL_SPECS.map((spec) => createFlock(spec.seed, size, spec.bounds)),
lastMs: nowMs,
kick: KICK_REST,
};
SCHOOLS.set(key, state);
}
const dt = (nowMs - state.lastMs) / 1000;
// Only the schools on screen swim (reduced effects show one); the rest wait where they are.
for (let index = 0; index < Math.min(shown, state.flocks.length); index += 1) {
// Offset each leader's clock so the schools never shadow one another.
stepFlock(state.flocks[index]!, dt, { seconds: nowMs / 1000 + index * 41.7, ...forces });
}
state.kick = stepKick(state.kick, bands, onset, Math.min(0.1, dt));
state.lastMs = nowMs;
return { flocks: state.flocks, swell: state.kick.swell };
}
/**
* The idle monitor's charge cloud, one per chrome layer (it outlives the per-frame pools), with the clock of its last
* simulation step. A smaller cloud than the select screen's: the monitor is small.
*/
const MONITOR_CLOUDS = new WeakMap<Container, MonitorCloud>();
/** A chrome layer's monitor cloud, the clock of its last simulation step, and whether this frame drew it. */
interface MonitorCloud {
cloud: ChargeCloud;
lastSeconds: number | undefined;
drawn: boolean;
}
function monitorCloudFor(layer: Container): MonitorCloud {
let state = MONITOR_CLOUDS.get(layer);
if (state === undefined) {
state = { cloud: new ChargeCloud(192), lastSeconds: undefined, drawn: false };
MONITOR_CLOUDS.set(layer, state);
}
return state;
}
const PYRAMIDS = [pointCloudPyramid(3, 520), pointCloudPyramid(8, 420), pointCloudPyramid(5, 700)];
/** The idle monitor's pyramids: cloud, x, z, scale and resting yaw. */
const MONITOR_PYRAMIDS = [
[PYRAMIDS[2]!, 40, 1500, 520, 0.2],
[PYRAMIDS[0]!, -330, 700, 250, 0.5],
[PYRAMIDS[1]!, 330, 820, 230, -0.3],
] as const;
/** Scratch transform and style for the monitor's pyramids, refilled per pyramid each frame. */
const PYRAMID_TRANSFORM: CloudTransform = { scale: 1, x: 0, y: 0, z: 0, yaw: 0 };
const PYRAMID_STYLE: Parameters<typeof drawPointCloud>[4] = {
colorOf: (point) => emberColor(0.35 + 0.55 * point.weight),
alpha: 0.8,
size: 1,
seconds: 0,
shimmer: 0.3,
referenceScale: 1,
skip: (px, py) => !insideBGA(px, py, -2),
};
/**
* Synesthesia gameplay HUD after a cosmic particle world: a black void lit by an ember horizon, data dust and speed
* dust pouring out of the vanishing point, a floor of light points scrolling toward the player, rivers of particles
* once the run is in the zone, and hairline frames with lock-on corners. With no BGA the monitor idles on a floating
* audio orb roaming in front of particle pyramids. Colour drifts through the ember band and swells on every beat.
*/
export function renderSynesthesiaChrome({
layer,
overlayLayer,
layerPool,
overlayLayerPool,
runtime,
layout,
settings,
}: PixiChromeContext): void {
const frosted = frostedGlassEnabled(settings);
const seconds = (runtime.nowMs ?? 0) / 1000;
// The idle monitor shows its cloud only while there is no BGA; a frame that does not draw it hides it below. Its clock
// carries on across hidden frames: the cloud clamps each step, so a gap just resumes it.
const monitorCloud = MONITOR_CLOUDS.get(layer);
if (monitorCloud) monitorCloud.drawn = false;
const beatPhase = runtime.beatPhase ?? 0;
const pulse = (1 - beatPhase) ** 2;
const hue = sceneHue(seconds, beatPhase);
const accent = hsvToHex(hue, 0.62, 1);
const { left: playfieldLeft, right: playfieldRight } = layout.playfield;
const portrait = layout.orientation === 'portrait';
setView(layout.stage, portrait);
Object.assign(BGA, layout.bga ?? NO_MONITOR);
const hasBGA = runtime.hasBGA === true && BGA.w > 0;
const space = layerPool.acquireGraphics();
space.label = 'synesthesia-gameplay/space';
space.blendMode = 'normal';
// Zone: the space intensifies with the combo (faster, denser dust, a hotter floor, particle rivers).
// Reduced effects cap the escalation; effects off keep the calm tier-0 space.
const effects = effectProfile(runtime.effects);
const tier = effects.enabled ? Math.min(comboTier(runtime.combo ?? 0), effects.screenWide ? 4 : 2) : 0;
// Input reaction: every press surges the dust and tints the sky with the pressed lane's light.
const hit = impulse(runtime.impulseAtMs, runtime.nowMs ?? 0, 280) * effects.amount;
const hitColor = IMPULSE_COLORS[runtime.impulseKind ?? 'white'];
// Camera: the background roams between random shots (flying, sometimes hard-cutting) with a handheld drift,
// reframing floor, rivers, and schools. Reduced effects halve the moves; effects off keep the camera at rest.
const camera =
effects.amount > 0
? mixCamera(REST_CAMERA, roamingCamera(seconds, 7, CAMERA_RANGE, CAMERA_CYCLE_S), effects.amount)
: REST_CAMERA;
const horizon = vanishingPoint(camera, VIEW.centerX, VIEW.horizon, FLOOR.focal).y;
// The space listens to the mix: the ember haze and floor swell on the bass, dust speeds with loudness, rivers weave with the mids, the schools tighten on bass hits and scatter on transients.
const drive = audioDrive(runtime.audio, runtime.effects);
drawGround(space, hasBGA, hit, hitColor, horizon);
const light = layerPool.acquireGraphics();
light.label = 'synesthesia-gameplay/light';
light.blendMode = 'add';
// Dust, floor and rivers move by accumulated travel, so the music and the zone can change their speed smoothly.
const travel = advanceTravel(
layer,
seconds,
{
dust: (120 + 40 * pulse) * (1 + 0.45 * tier) * (1 + 2.2 * hit) * (1 + 1.2 * drive.level),
floor: 150 * (1 + 0.3 * tier),
river: 260 + 60 * tier,
},
drive.bands,
);
drawDust(light, hasBGA, tier, hit, camera, travel.dust);
drawFloor(light, travel.floor, travel.spectrum, seconds, pulse, hasBGA, tier, hit, camera, drive);
const rivers = tier >= 4 ? 3 : tier >= 2 ? 2 : 1;
for (let river = 0; river < rivers; river += 1) {
drawRiver(light, seconds, travel.river, river, hasBGA, tier, camera, drive);
}
if (effects.enabled) {
// Schools of light fish swimming through the space: tighter on the beat, scattering on every key press.
const { flocks: schools, swell } = advanceSchools(
layer,
runtime.nowMs ?? 0,
effects.screenWide ? SCHOOL_SIZE : SCHOOL_SIZE / 2,
{
gather: Math.max(pulse * 0.6, drive.bass),
scatter: Math.max(impulse(runtime.impulseAtMs, runtime.nowMs ?? 0, 520) * effects.amount, 0.8 * drive.onset),
},
drive.bands,
drive.onset,
effects.screenWide ? SCHOOL_SPECS.length : 1,
);
const shown = effects.screenWide ? schools.length : 1;
const schoolBasis = cameraBasis(camera, SCRATCH_BASIS);
for (let school = 0; school < shown; school += 1) {
drawSchool(
light,
schools[school]!,
(out, point) =>
projectViewInto(out, point.x, point.y, point.z, schoolBasis, VIEW.centerX, VIEW.horizon, FLOOR.focal),
{
alpha: 0.95,
palette: SCHOOL_SPECS[school]!.palette,
swell,
glowLevel: drive[SCHOOL_SPECS[school]!.band],
seconds,
skip: (x, y) => x < -10 || x > VIEW.width + 10 || y < 0 || y > VIEW.height || (hasBGA && insideBGA(x, y, 4)),
},
);
}
}
const panels = layerPool.acquireGraphics();
panels.label = 'synesthesia-gameplay/panels';
panels.blendMode = 'normal';
// Landscape: the well runs from the stage's top to just under the judgement line. Portrait: from the top of the lanes
// down to the stage's bottom — the band under the line is where the thumbs rest.
const cabinet = !portrait && layout.mode === 'standard';
const wellTop = portrait ? layout.playfield.top - 2 : 0;
const wellBottom = portrait ? layout.stage.height : cabinet ? cabinetWellBottom(layout) : PLAYFIELD_FRAME_BOTTOM;
if (layout.twoPlayer && cabinet) {
for (const side of Object.values(layout.playfield.sides)) {
if (side) drawPlayfieldWell(panels, side.left, side.right, wellTop, wellBottom, accent);
}
} else drawPlayfieldWell(panels, playfieldLeft, playfieldRight, wellTop, wellBottom, accent);
// The monitor shrinks to fit beside a double-play field; only a page-wide keyboard field leaves no room for it.
if (BGA.w > 0) {
const standby = layerPool.acquireGraphics();
standby.label = 'synesthesia-gameplay/standby';
standby.blendMode = 'add';
drawBGAFrame(panels, standby, layer, hasBGA, seconds, pulse, hue, camera, drive, layerPool, cabinet ? 0 : 6);
}
if (monitorCloud && !monitorCloud.drawn) monitorCloud.cloud.view.visible = false;
// The frosted panels' surface sits under the HUD; with the setting off the panels are plain fills on the HUD itself.
const glass = frosted ? overlayLayerPool.acquireGraphics() : undefined;
if (glass) glass.label = 'synesthesia-gameplay/glass';
const front = overlayLayerPool.acquireGraphics();
if (glass) bindGlassSurface(front, glass);
else unbindGlassSurface(front);
front.label = 'synesthesia-gameplay/header';
drawProgressLight(front, playfieldLeft, wellTop, layout.playfield.judgementY, runtime.progressRatio, accent);
if (portrait) {
drawPortraitHUD(front, overlayLayer, runtime, layout, accent, overlayLayerPool);
drawPortraitHeader(front, overlayLayer, runtime, layout, accent, pulse, overlayLayerPool);
} else if (cabinet) {
drawSynesthesiaCabinet(
{ graphics: front, layer: overlayLayer, pool: overlayLayerPool, accent, pulse },
runtime,
layout,
);
} else {
drawGauges(front, overlayLayer, runtime, accent, overlayLayerPool);
drawChartPlate(front, overlayLayer, runtime, accent, overlayLayerPool);
drawScorePanel(front, overlayLayer, runtime, accent, overlayLayerPool);
// The judge tally owns the side column on the right edge.
if (!runtime.hidesJudgeCounts) drawJudgeTally(front, overlayLayer, runtime, STAGE_SIDE_COLUMN.x, overlayLayerPool);
drawHeader(front, overlayLayer, runtime, layout, accent, pulse, overlayLayerPool);
}
const judgeY = resolveSkinJudgeWordY(layout);
if (runtime.loading) {
drawLoading(
front,
overlayLayer,
runtime.nowMs ?? 0,
(playfieldLeft + playfieldRight) / 2,
judgeY - 50,
Math.min(180, (playfieldRight - playfieldLeft) * 0.8),
runtime.loadingProgress ?? 0,
accent,
overlayLayerPool,
);
} else {
drawJudgements(overlayLayer, runtime, layout, judgeY, overlayLayerPool);
}
drawSynesthesiaMoments(
layer,
overlayLayer,
runtime,
(playfieldLeft + playfieldRight) / 2,
hue,
overlayLayerPool,
layout,
settings,
);
}
/**
* Where the judgement word sits: at its fixed height on the landscape stage, and a little over halfway down the lanes on
* a portrait one.
*/
function resolveSkinJudgeWordY(layout: BeMusicGameplayLayout): number {
const { top, judgementY } = layout.playfield;
const skinY = layout.orientation !== 'portrait' ? 236 : Math.round(top + (judgementY - top) * 0.58);
return resolveJudgeWordY(skinY, layout.playfield);
}
function insideBGA(x: number, y: number, margin = 0): boolean {
return x > BGA.x - margin && x < BGA.x + BGA.w + margin && y > BGA.y - margin && y < BGA.y + BGA.h + margin;
}
/**
* The monitor rect of the frame being drawn: the stage's BGA square for the current playfield (it shrinks beside a
* double-play field). Updated at the top of {@link renderSynesthesiaChrome} and read by the drawing helpers below.
*/
const BGA: BeMusicRect = { x: 0, y: 0, w: 0, h: 0 };
/** Stand-in for a layout without a BGA (a page-wide keyboard field): an empty rect, so no monitor is drawn. */
const NO_MONITOR: BeMusicRect = { x: 0, y: 0, w: 0, h: 0 };
/** Horizontal centre of the stage — the space's vanishing point. */
const CENTER_X = DESIGN_WIDTH / 2;
const IMPULSE_COLORS: Record<BeMusicLaneKind, number> = {
white: SYN_EMBER,
black: SYN_CYAN,
scratch: SYN_MAGENTA,
'wheel-up': SYN_MAGENTA,
'wheel-down': SYN_MAGENTA,
};
/**
* The stage the frame is drawn on, and where the space sits on it: the floor's horizon and the vanishing point the dust
* pours out of (behind the monitor). Updated at the top of {@link renderSynesthesiaChrome} for the frame's stage.
*/
const VIEW: { width: number; height: number; centerX: number; horizon: number; vanishY: number } = {
width: DESIGN_WIDTH,
height: DESIGN_HEIGHT,
centerX: CENTER_X,
horizon: FLOOR.horizon,
vanishY: FLOOR.horizon - 90,
};
/** Points {@link VIEW} at `stage`: a portrait stage puts the horizon just above its lanes. */
function setView(stage: { width: number; height: number }, portrait: boolean): void {
VIEW.width = stage.width;
VIEW.height = stage.height;
VIEW.centerX = stage.width / 2;
VIEW.horizon = portrait ? stage.height * 0.4 : FLOOR.horizon;
VIEW.vanishY = VIEW.horizon - 90;
}
/**
* Warm-black ground (a stack of bands, so a live BGA stays untouched), plus a brief tint of the pressed lane's light on
* each key press above `horizon`, which follows the camera's pitch.
*/
function drawGround(graphics: Graphics, hasBGA: boolean, hit: number, hitColor: number, horizon: number): void {
const bands: ReadonlyArray<readonly [number, number]> = [
[0x090302, 140],
[0x060201, 260],
[0x040100, 380],
[SYN_VOID, DESIGN_HEIGHT],
];
// The bands are authored on the 480 px landscape height and stretch to the stage's.
const stretch = VIEW.height / DESIGN_HEIGHT;
// A key press tints the sky above the horizon: mixed into the flat, opaque bands rather than a second full fill.
const tint = hit > 0 ? 0.06 * hit : 0;
const sky = tint > 0 ? horizon : 0;
let top = 0;
for (const [color, until] of bands) {
const bottom = until * stretch;
const split = Math.max(top, Math.min(bottom, sky));
if (split > top) fillAroundBGA(graphics, 0, top, VIEW.width, split - top, mixColor(color, hitColor, tint), hasBGA);
if (bottom > split) fillAroundBGA(graphics, 0, split, VIEW.width, bottom - split, color, hasBGA);
top = bottom;
}
}
/**
* Data dust (tiny warm squares, the odd blue / magenta mote) flying out of the vanishing point, faster with the combo
* tier and on key presses.
*/
function drawDust(
graphics: Graphics,
hasBGA: boolean,
tier: number,
hit: number,
camera: CameraPose,
distance: number,
): void {
const batch = sharedShapeBatch;
const count = 220 + 50 * tier;
const basis = cameraBasis(camera, SCRATCH_BASIS);
for (let index = 0; index < count; index += 1) {
// `distance` is the field's accumulated travel, so a change of speed accelerates the motes instead of jumping them.
const point = starfieldInto(SCRATCH_POINT, index, distance, DUST_FIELD);
const projected = projectViewInto(SCRATCH_A, point.x, point.y, point.z, basis, VIEW.centerX, VIEW.vanishY, 180);
if (!projected.visible) continue;
if (projected.x < 0 || projected.x > VIEW.width || projected.y < 0 || projected.y > VIEW.height) continue;
if (hasBGA && insideBGA(projected.x, projected.y, 4)) continue;
const nearness = Math.min(1, projected.scale);
const size = 0.5 + 1.3 * nearness;
const color = index % 9 === 0 ? SYN_CYAN : index % 13 === 0 ? SYN_MAGENTA : emberColor(0.35 + 0.65 * nearness);
if (nearness > 0.45) {
// Near motes get a soft bokeh square around them.
const bokeh = size * 3.2;
batch.rect(graphics, color, 0.05 * nearness, projected.x - bokeh / 2, projected.y - bokeh / 2, bokeh, bokeh);
}
batch.rect(graphics, color, 0.3 + 0.6 * nearness, projected.x - size / 2, projected.y - size / 2, size, size);
}
batch.flush();
}
/**
* Particle-world floor: a lattice of light points scrolling toward the player on the beat, over faint radial guide lines.
* The lattice is the music's spectrum: bass on the left to highs on the right, rising as ridges that leave the viewer
* and roll out into the distance (see spectrumRise), over low Perlin-noise ground.
*/
function drawFloor(
graphics: Graphics,
distance: number,
spectrum: SpectrumHistory,
seconds: number,
pulse: number,
hasBGA: boolean,
tier: number,
hit: number,
camera: CameraPose,
drive: AudioDrive,
): void {
const { height, focal } = FLOOR;
const horizon = VIEW.horizon;
const glow = 1 + 0.3 * tier + 0.8 * hit + 1.2 * drive.bass;
const basis = cameraBasis(camera, SCRATCH_BASIS);
// The floor runs up to a live BGA but never over it: lines are clipped around the monitor, points inside it skipped.
const pieces = FLOOR_PIECES;
pieces.length = 0;
for (let x = -1500; x <= 1500; x += 100) {
const near = projectViewInto(SCRATCH_A, x, height, 0, basis, VIEW.centerX, horizon, focal);
const far = projectViewInto(SCRATCH_B, x, height, 2400, basis, VIEW.centerX, horizon, focal);
if (!near.visible || !far.visible) continue;
if (hasBGA) clipSegmentOutsideRect(near.x, near.y, far.x, far.y, BGA, pieces);
else pieces.push(near.x, near.y, far.x, far.y);
}
for (let index = 0; index < pieces.length; index += 4) {
graphics.moveTo(pieces[index]!, pieces[index + 1]!).lineTo(pieces[index + 2]!, pieces[index + 3]!);
}
graphics.stroke({ color: SYN_EMBER, width: 1, alpha: Math.min(0.4, 0.05 * glow) });
// The lattice is the skin's densest draw (thousands of points a frame), so its projection and grains are worked out
// inline: a row shares its depth, size, colour and grain count, and each point goes straight to the point layer.
// Equivalent to `projectViewInto` for the ground and the risen point, then `sharedShapeBatch.rect` of a square.
const points = pointLayerFor(graphics);
const { cosYaw, sinYaw, cosPitch, sinPitch } = basis;
const centerX = VIEW.centerX;
const width = VIEW.width;
const bottom = VIEW.height + 4;
const groundY = height - camera.y;
const grains = FLOOR_GRAINS;
// A silent history (effects off, or a quiet stretch) leaves the floor flat: no point needs its spectrum looked up.
const silent = spectrum.silent;
const spacing = 90;
const offset = distance % spacing;
for (let z = spacing - offset; z < 2400; z += spacing) {
const nearness = 1 - z / 2400;
const alpha = Math.min(1, (0.12 + 0.7 * nearness * nearness) * (0.7 + 0.3 * pulse) * glow);
const size = 0.6 + 1.4 * nearness * nearness;
const color = emberColor(0.3 + 0.65 * nearness);
grainsFor(size, 1, grains);
const grainCount = grains.count;
const grainSize = grains.size;
// A grain's alpha per unit of the point's, before grainsFor's clamp (applied per point below).
const grainAlpha = (size * size * 0.8) / (grainCount * grainSize * grainSize);
const lz = z - camera.z;
const worldZ = z + distance;
if (!silent) spectrum.sampleRow(z / SPECTRUM_WAVE_SPEED, FLOOR_LEVELS);
// Near rows get more points, so they read as continuous waveforms.
const step = floorRowStep(z, focal, FLOOR_SCREEN_GAP);
for (let x = -1500; x <= 1500; x += step) {
const lx = x - camera.x;
const x1 = lx * cosYaw - lz * sinYaw;
const z1 = lx * sinYaw + lz * cosYaw;
// The band follows where the point sits on screen: bass at the left edge, highs at the right.
const groundDepth = focal + groundY * sinPitch + z1 * cosPitch;
if (groundDepth <= 1e-3) continue;
const groundX = centerX + (x1 * focal) / groundDepth;
if (groundX < -4 || groundX > width + 4) continue;
let ridge = 0;
if (!silent) {
const band = Math.max(0, Math.min(1, groundX / width)) * (FLOOR_LEVELS.length - 1);
const low = Math.floor(band);
const level = FLOOR_LEVELS[low]!;
const high = FLOOR_LEVELS[Math.min(low + 1, FLOOR_LEVELS.length - 1)]!;
ridge = SPECTRUM_RIDGE_HEIGHT * (level + (high - level) * (band - low)) ** 1.5;
}
const ly = groundY - ridge - floorRise(x, worldZ, seconds, FLOOR_GROUND);
const y2 = ly * cosPitch - z1 * sinPitch;
const depth = focal + ly * sinPitch + z1 * cosPitch;
if (depth <= 1e-3) continue;
const scale = focal / depth;
const px = centerX + x1 * scale;
const py = horizon + y2 * scale;
if (px < -4 || px > width + 4 || py > bottom) continue;
if (hasBGA && insideBGA(px, py, 2)) continue;
// Crests catch more light than the valleys.
const lit = Math.min(1, alpha * (1 + (1.4 * ridge) / SPECTRUM_RIDGE_HEIGHT));
// The batch drops what rounds to no eighth of alpha.
if (lit < 1 / 16) continue;
const pointAlpha = Math.min(1, lit * grainAlpha);
points.cluster(px, py, GRAIN_OFFSETS, grainCount, size, grainSize, color, pointAlpha);
}
}
sharedShapeBatch.flush();
}
/** Spectrum band levels at the depth of the current floor row. */
const FLOOR_LEVELS = new Float64Array(AUDIO_BAND_COUNT);
const FLOOR_GRAINS: Grains = { count: 0, size: 0, alpha: 0 };
/** Scratch buffer for clipped floor lines (`x0, y0, x1, y1` quads), reused every frame. */
const FLOOR_PIECES: number[] = [];
/** Height (world units) of the Perlin-noise ground under the floor's spectrum ridges. */
const FLOOR_GROUND = 10;
/** Screen gap (px) the floor rows' points aim for, so near rows read as waveforms. */
const FLOOR_SCREEN_GAP = 6;
/** Scratch band levels written each frame into the floor's spectrum history. */
const SCRATCH_LEVELS = new Float32Array(AUDIO_BAND_COUNT);
/** Scratch objects for the allocation-free projection in the hot loops above. */
const SCRATCH_BASIS = cameraBasis(REST_CAMERA);
const SCRATCH_A = scratchProjected();
const SCRATCH_B = scratchProjected();
const SCRATCH_POINT = { x: 0, y: 0, z: 0 };
const RIVER_PARTICLES = 280;
/** Each river's height, depth and diagonal slope. */
const RIVER_BASE_Y = [118, 70, 134];
const RIVER_BASE_Z = [520, 900, 300];
const RIVER_SLOPE = [0.55, -0.4, 0.3];
/** Scratch flow for {@link drawRiver}, refilled per river each frame. */
const RIVER_OPTIONS: RiverOptions = { length: 1500, speed: 260, amplitude: 28, width: 16, seed: 1 };
/**
* A river of light particles streaming low over the floor, receding diagonally into the distance — golden
* flows. Each particle is a short streak along the flow; river 1 runs blue-white, the others ember.
*/
function drawRiver(
graphics: Graphics,
seconds: number,
distance: number,
river: number,
hasBGA: boolean,
tier: number,
camera: CameraPose,
drive: AudioDrive,
): void {
const options = RIVER_OPTIONS;
options.speed = 260 + 60 * tier;
options.amplitude = 28 * (1 + 1.4 * drive.mid);
options.seed = river + 1;
const baseY = RIVER_BASE_Y[river] ?? 118;
const baseZ = RIVER_BASE_Z[river] ?? 520;
const slope = RIVER_SLOPE[river] ?? 0.5;
const basis = cameraBasis(camera, SCRATCH_BASIS);
const local = SCRATCH_POINT;
for (let index = 0; index < RIVER_PARTICLES; index += 1) {
particleRiverPointInto(local, index, seconds, options, distance);
const y = baseY + local.y;
const z = baseZ + local.z;
const head = projectViewInto(
SCRATCH_A,
local.x,
y,
z + local.x * slope,
basis,
VIEW.centerX,
VIEW.horizon,
FLOOR.focal,
);
const tailX = local.x - 26;
const tail = projectViewInto(
SCRATCH_B,
tailX,
y,
z + tailX * slope,
basis,
VIEW.centerX,
VIEW.horizon,
FLOOR.focal,
);
if (!head.visible || !tail.visible) continue;
if (head.x < -20 || head.x > VIEW.width + 20 || head.y < 0 || head.y > VIEW.height) continue;
if (hasBGA && (insideBGA(head.x, head.y, 4) || insideBGA(tail.x, tail.y, 4))) continue;
const heat = hash01(index * 3 + river * 101);
const color = river === 1 ? (heat > 0.7 ? SYN_WHITE : SYN_CYAN) : emberColor(0.5 + 0.5 * heat);
const nearness = Math.min(1, head.scale);
sharedShapeBatch.line(
graphics,
color,
0.25 + 0.55 * heat,
0.4 + 0.9 * nearness * (0.5 + heat),
tail.x,
tail.y,
head.x,
head.y,
);
}
sharedShapeBatch.flush();
}
function fillAroundBGA(
graphics: Graphics,
x: number,
y: number,
w: number,
h: number,
color: number,
hasBGA: boolean,
alpha = 1,
): void {
const fill = { color, alpha };
const right = x + w;
const bottom = y + h;
const holeRight = BGA.x + BGA.w;
const holeBottom = BGA.y + BGA.h;
if (!hasBGA || right <= BGA.x || x >= holeRight || bottom <= BGA.y || y >= holeBottom) {
graphics.rect(x, y, w, h).fill(fill);
return;
}
if (y < BGA.y) graphics.rect(x, y, w, BGA.y - y).fill(fill);
const bandTop = Math.max(y, BGA.y);
const bandBottom = Math.min(bottom, holeBottom);
if (x < BGA.x) graphics.rect(x, bandTop, BGA.x - x, bandBottom - bandTop).fill(fill);
if (right > holeRight) graphics.rect(holeRight, bandTop, right - holeRight, bandBottom - bandTop).fill(fill);
if (bottom > holeBottom) graphics.rect(x, holeBottom, w, bottom - holeBottom).fill(fill);
}
function drawPlayfieldWell(
graphics: Graphics,
playfieldLeft: number,
right: number,
top: number,
bottom: number,
accent: number,
): void {
const left = playfieldLeft - 4;
const w = right - left + 4;
const h = bottom - top;
graphics.rect(left, top, w, h).fill({ color: SYN_VOID, alpha: 0.72 });
// Glowing side rails.
for (const x of [left - 1, right + 2]) {
graphics.rect(x - 2, top, 5, h).fill({ color: accent, alpha: 0.06 });
graphics.rect(x, top, 1, h).fill({ color: accent, alpha: 0.6 });
}
// The floor rule runs from the left rail's outer edge (left - 1) to the right rail's (right + 3), and no further; the
// portrait well runs off the stage's bottom edge instead.
if (bottom < VIEW.height) graphics.rect(left - 1, bottom, w, 1).fill({ color: accent, alpha: 0.7 });
// The portrait well's top edge, under the gauge.
if (top > 0) graphics.rect(left - 1, top, w, 1).fill({ color: accent, alpha: 0.5 });
}
/**
* Song progress as a light falling down the left rail, from the top of the well to the judgement line, where it ends.
* Drawn in front of the lanes, so the lanes never cover it.
*/
function drawProgressLight(
graphics: Graphics,
playfieldLeft: number,
top: number,
judgementY: number,
progressRatio: number | undefined,
accent: number,
): void {
const ratio =
progressRatio !== undefined && Number.isFinite(progressRatio) ? Math.max(0, Math.min(1, progressRatio)) : 0;
if (ratio <= 0) return;
const x = playfieldLeft - 5;
const start = top + 6;
const y = start + (judgementY - start) * ratio;
graphics.rect(x - 2, start, 5, y - start).fill({ color: SYN_WHITE, alpha: 0.12 });
graphics.circle(x, y, 7).fill({ color: accent, alpha: 0.25 });
graphics.circle(x, y, 3).fill({ color: SYN_WHITE, alpha: 0.95 });
}
/**
* Monitor frame: a warm hairline with lock-on corners. With no BGA the screen idles on a miniature particle world — a floating
* visualizer-style orb roaming in front of particle pyramids on an ember horizon — the
* "nothing is playing, but the space is alive" state. The idle scene draws into `light` (additive).
*/
function drawBGAFrame(
graphics: Graphics,
light: Graphics,
layer: Container,
hasBGA: boolean,
seconds: number,
pulse: number,
hue: number,
camera: CameraPose,
drive: AudioDrive,
pool: ChildPool,
margin = 6,
): void {
const color = hsvToHex(hue, 0.6, 1);
const frameX = BGA.x - margin;
const frameY = BGA.y - margin;
const frameW = BGA.w + margin * 2;
const frameH = BGA.h + margin * 2;
graphics.rect(frameX, frameY, frameW, frameH).stroke({ color, width: 4, alpha: 0.06 });
graphics.rect(frameX, frameY, frameW, frameH).stroke({ color, width: 1, alpha: 0.4 });
drawReticle(graphics, frameX, frameY, frameW, frameH, SYN_WHITE, 0.9, { arm: 18, width: 2 });
if (hasBGA) return;
graphics.rect(BGA.x, BGA.y, BGA.w, BGA.h).fill({ color: SYN_VOID, alpha: 0.92 });
const inside = (x: number, y: number) => !insideBGA(x, y, -2);
// The monitor's camera circles the scene: the shot's turn is exaggerated into an orbit, its travel damped.
const orbit = 60;
const orbitCamera: CameraPose = {
x: camera.x * 0.2,
y: camera.y * 0.3,
z: 0,
yaw: camera.yaw * 2.2,
pitch: camera.pitch * 0.8,
};
const cx = BGA.x + BGA.w / 2;
const baseHorizon = BGA.y + BGA.h * 0.66;
const view = { cx, cy: baseHorizon, focal: 220, camera: orbitCamera, orbit };
// Particle pyramids on the horizon.
const transform = PYRAMID_TRANSFORM;
const style = PYRAMID_STYLE;
style.seconds = seconds;
for (const [pyramid, x, z, scale, yaw] of MONITOR_PYRAMIDS) {
transform.scale = scale;
transform.x = x;
transform.z = z;
transform.yaw = yaw + seconds * 0.04;
style.referenceScale = 220 / (220 + z);
drawPointCloud(light, pyramid, transform, view, style);
}
// Floor points scrolling in.
// A coarser lattice than the main floor: the monitor is small, so this keeps the point count down.
const offset = (seconds * 90) % 80;
const orbitBasis = cameraBasis(orbitCamera, SCRATCH_BASIS);
for (let z = 80 - offset; z < 1400; z += 80) {
const nearness = 1 - z / 1400;
for (let x = -600; x <= 600; x += 40) {
const point = projectViewInto(SCRATCH_A, x, 70, z, orbitBasis, cx, baseHorizon, 220, orbit);
if (!point.visible || inside(point.x, point.y)) continue;
const size = 0.5 + 1.1 * nearness * nearness;
sharedShapeBatch.rect(
light,
emberColor(0.3 + 0.6 * nearness),
0.2 + 0.6 * nearness * nearness,
point.x - size / 2,
point.y - size / 2,
size,
size,
);
}
}
sharedShapeBatch.flush();
// The audio orb roams the monitor's little world close to the camera: a small charge cloud, its dark magnet orbs
// wrapped in a fluid of particles, kept inside the monitor.
const roam = wanderPoint(seconds * 0.8, 2, { minX: -55, maxX: 55, minY: -125, maxY: -70, minZ: -120, maxZ: 0 });
const at = projectPoint(viewPoint(roam, view.camera, view.orbit), view.cx, view.cy, view.focal);
const state = monitorCloudFor(layer);
// The cloud sits just under `light` (the slots after it hold `light`'s point layers). Moving a child, even back in
// place, makes Pixi rebuild the whole layer's draw list, so it moves only when out of place.
const host = light.parent!;
const cloudView = state.cloud.view;
if (cloudView.parent !== host || host.getChildIndex(cloudView) !== host.getChildIndex(light) - 1) {
if (cloudView.parent === host) host.removeChild(cloudView);
host.addChildAt(cloudView, host.getChildIndex(light));
}
const scale = at.visible ? 60 * at.scale * (1 + 0.03 * pulse) : 0;
state.cloud.update({
x: at.x,
y: at.y,
scale,
seconds,
dt: state.lastSeconds === undefined ? 0 : seconds - state.lastSeconds,
drive,
alpha: at.visible ? 1 : 0,
clip: { x: BGA.x, y: BGA.y, w: BGA.w, h: BGA.h - 22 },
});
state.lastSeconds = seconds;
state.drawn = true;
// Lock-on reticle tracking it, while it stays inside the monitor.
const lock = scale * 0.55 + 5 * pulse;
if (at.visible && insideBGA(at.x - lock, at.y - lock) && insideBGA(at.x + lock, at.y + lock)) {
drawReticle(light, at.x - lock, at.y - lock, lock * 2, lock * 2, SYN_FLARE, 0.5, { arm: 8, cross: true });
}
// A dark slip under the label, so the monitor's floor horizon never runs through the type.
const slip = pool.acquireGraphics();
slip.label = 'synesthesia-gameplay/standby-slip';
slip.blendMode = 'normal';
slip.rect(cx - 76, BGA.y + BGA.h - 26, 152, 17).fill({ color: SYN_VOID, alpha: 0.9 });
addHUDText(
layer,
'SOUND ONLY',
cx,
BGA.y + BGA.h - 22,
{ ...displayStyle(9, SYN_MIST), letterSpacing: 6, anchorX: 0.5 },
pool,
);
}
/**
* Room the header leaves free in its top corners for a host's controls over the stage (a menu tab on the right, and a
* pause button on the left while playing by touch) — design px, about 48 CSS px on a phone.
*/
const TOUCH_CORNER = 52;
function drawHeader(
graphics: Graphics,
layer: Container,
runtime: Runtime,
layout: BeMusicGameplayLayout,
accent: number,
pulse: number,
pool: ChildPool,
): void {
const autoplay = runtime.autoplay === true;
// The right corner stays clear for a host's menu tab; touch play also keeps the left one clear for its pause button,
// shifting the mode and readouts right to make room.
const inset = layout.mode === 'touch' ? TOUCH_CORNER - HUD_MARGIN : 0;
// Near-opaque, so the playfield rails and lanes stop under the header instead of running through its type.
graphics.rect(0, 0, DESIGN_WIDTH, 34).fill({ color: SYN_VOID, alpha: 0.92 });
graphics.rect(0, 34, DESIGN_WIDTH, 1).fill({ color: accent, alpha: 0.35 + 0.35 * pulse });
drawModeLight(graphics, layer, autoplay, HUD_MARGIN + inset, 17, accent, pulse, 10, pool);
// Readouts on a fixed rhythm after the mode: label, then its value 40 px on; groups 96 px apart.
addHUDText(layer, 'BPM', 172 + inset, 14, labelStyle(), pool);
addHUDNumber(layer, formatBPM(runtime.bpm), 212 + inset, 9, displayStyle(14, SYN_WHITE), pool);
addHUDText(layer, runtime.floatingHiSpeed ? 'FHS' : 'SPEED', 268 + inset, 14, labelStyle(), pool);
addHUDNumber(layer, `x${formatHiSpeed(runtime)}`, 328 + inset, 9, displayStyle(14, SYN_WHITE), pool);
addHUDText(
layer,
formatRuleset(runtime.rulesetLabel),
DESIGN_WIDTH - TOUCH_CORNER,
12,
{ ...displayStyle(9, accent), letterSpacing: 3, anchorX: 1, maxWidth: 110 },
pool,
);
}
/**
* The play-mode light (a glowing dot) and its PLAY / AUTO PLAY label (`autoLabel`, for a shorter one), the dot's left
* edge at `x`.
*/
function drawModeLight(
graphics: Graphics,
layer: Container,
autoplay: boolean,
x: number,
y: number,
accent: number,
pulse: number,
size: number,
pool: ChildPool,
autoLabel = 'AUTO PLAY',
): void {
const color = autoplay ? SYN_AMBER : accent;
graphics.circle(x + 8, y, 3).fill({ color, alpha: 1 });
graphics.circle(x + 8, y, 8).fill({ color, alpha: 0.18 + 0.2 * pulse });
addHUDText(
layer,
autoplay ? autoLabel : 'PLAY',
x + 22,
y - 5,
{ ...displayStyle(size, SYN_WHITE), letterSpacing: 3 },
pool,
);
}
function drawChartPlate(graphics: Graphics, layer: Container, runtime: Runtime, accent: number, pool: ChildPool): void {
const { x, y, h } = SONG_PLATE;
drawFrame(graphics, x, y, SONG_PLATE.w, h, accent);
// A two-player play's 2P figures take the plate's right end.
drawSecondPlayerFigures(layer, runtime, SONG_PLATE, pool);
const w = SONG_PLATE.w - (runtime.secondPlayer !== undefined ? SECOND_PLAYER_FIGURES_WIDTH : 0);
// Genre, title, artist — the order every built-in skin uses; the genre rides a small line above the title.
drawSongInfoLayers(runtime, (info) => {
const genre = info.chartGenre?.trim();
const lift = genre ? 5 : 0;
const artist = info.chartArtist?.trim();
return [
genre
? addHUDText(
layer,
genre.toUpperCase(),
x + 14,
y + 3,
{ size: 8, weight: '500', fill: SYN_DIM, fontFamily: SYN_TEXT_FONT, letterSpacing: 1, maxWidth: w - 28 },
pool,
)
: undefined,
addHUDText(
layer,
info.chartTitle?.trim() || 'Untitled chart',
x + 14,
y + 6 + lift,
{
size: 15,
weight: '500',
fill: SYN_WHITE,
fontFamily: SYN_TEXT_FONT,
maxWidth: w - 28,
dropShadow: { color: accent, alpha: 0.7, blur: 6, distance: 0 },
},
pool,
),
artist
? addHUDText(
layer,
artist,
x + 14,
y + 28,
{ size: 10, weight: '300', fill: SYN_MIST, fontFamily: SYN_TEXT_FONT, maxWidth: w - 28 },
pool,
)
: undefined,
];
});
}
function drawScorePanel(graphics: Graphics, layer: Container, runtime: Runtime, accent: number, pool: ChildPool): void {
const { x, y, w, h } = SCORE_PANEL;
drawFrame(graphics, x, y, w, h, accent);
graphics.rect(x + SCORE_DIVIDER, y + 14, 1, h - 28).fill({ color: accent, alpha: 0.3 });
addHUDText(layer, 'SCORE', x + 14, y + 12, labelStyle(), pool);
addHUDNumber(
layer,
formatCount(runtime.score),
x + SCORE_DIVIDER - 14,
y + 22,
{
...displayStyle(17, SYN_WHITE),
anchorX: 1,
maxWidth: 120,
dropShadow: { color: accent, alpha: 0.8, blur: 6, distance: 0 },
},
pool,
);
addHUDText(layer, 'EX SCORE', x + 14, y + 54, labelStyle(), pool);
addHUDNumber(
layer,
`${formatCount(runtime.exScore)}/${formatCount(runtime.exScoreMax)}`,
x + SCORE_DIVIDER - 14,
y + 52,
{ ...displayStyle(8, SYN_MIST), anchorX: 1, maxWidth: 46 },
pool,
);
addHUDText(layer, 'EX RATE', x + 14, y + 76, labelStyle(), pool);
addHUDNumber(
layer,
formatExRate(runtime.exScore, runtime.exScoreMax),
x + SCORE_DIVIDER - 14,
y + 74,
{ ...displayStyle(8, SYN_MIST), anchorX: 1, maxWidth: 46 },
pool,
);
// Rate meter as a light filament with the That-Which-Must-Not-Be-Named ninth ticks.
const rate =
runtime.exScore !== undefined && runtime.exScoreMax !== undefined && runtime.exScoreMax > 0
? Math.max(0, Math.min(1, runtime.exScore / runtime.exScoreMax))
: 0;
const meterX = x + 14;
const meterW = SCORE_DIVIDER - 28;
graphics.rect(meterX, y + 94, meterW, 2).fill({ color: SYN_DIM, alpha: 0.3 });
if (rate > 0) {
graphics.rect(meterX, y + 92, meterW * rate, 6).fill({ color: accent, alpha: 0.15 });
graphics.rect(meterX, y + 94, meterW * rate, 2).fill({ color: rate >= 8 / 9 ? SYN_AMBER : SYN_WHITE, alpha: 0.95 });
}
for (let ninth = 1; ninth < 9; ninth += 1) {
graphics
.rect(meterX + (meterW * ninth) / 9, y + 91, 1, 8)
.fill({ color: SYN_WHITE, alpha: ninth >= 6 ? 0.45 : 0.18 });
}
addHUDText(layer, 'COMBO', x + SCORE_DIVIDER + 14, y + 12, labelStyle(), pool);
addHUDNumber(
layer,
formatCount(runtime.combo),
x + w - 12,
y + 24,
{ ...displayStyle(14, SYN_WHITE), anchorX: 1, maxWidth: 62 },
pool,
);
addHUDText(layer, 'MAX', x + SCORE_DIVIDER + 14, y + 54, labelStyle(), pool);
addHUDNumber(
layer,
formatCount(runtime.maxCombo),
x + w - 12,
y + 52,
{ ...displayStyle(9, SYN_MIST), anchorX: 1, maxWidth: 48 },
pool,
);
const rank = runtime.rank && runtime.rank !== '-' ? runtime.rank : 'F';
addHUDText(layer, 'RANK', x + SCORE_DIVIDER + 14, y + 76, labelStyle(), pool);
addHUDText(
layer,
rank,
x + w - 12,
// Centred on the RANK label's line, like the other figures sit on theirs.
y + 81,
{
...displayStyle(rank.length >= 3 ? 12 : 16, SYN_AMBER),
anchorX: 1,
anchorY: 0.5,
maxWidth: 46,
dropShadow: { color: SYN_AMBER, alpha: 0.8, blur: 8, distance: 0 },
},
pool,
);
}
const TALLY: ReadonlyArray<readonly [label: string, key: 'perfect' | 'great' | 'good' | 'bad' | 'poor']> = [
['PG', 'perfect'],
['GR', 'great'],
['GD', 'good'],
['BD', 'bad'],
['PR', 'poor'],
];
function drawJudgeTally(graphics: Graphics, layer: Container, runtime: Runtime, x: number, pool: ChildPool): void {
// Level with the monitor's top; with no monitor (the touch layout, 48 KEY) the top of the band it would sit in.
const y = (BGA.h > 0 ? BGA.y : STAGE_BGA_BAND.top) - 6;
const w = DESIGN_WIDTH - HUD_MARGIN - x;
drawFrame(graphics, x, y, w, 186, SYN_EMBER);
for (let row = 0; row < TALLY.length; row += 1) {
const [label, key] = TALLY[row]!;
const rowY = y + 14 + row * 26;
const color = JUDGE_COLORS[TALLY_NAMES[key]] ?? SYN_WHITE;
graphics.circle(x + 9, rowY + 6, 2).fill({ color, alpha: 1 });
graphics.circle(x + 9, rowY + 6, 5).fill({ color, alpha: 0.2 });
addHUDText(layer, label, x + 17, rowY + 1, { ...labelStyle(), fill: color }, pool);
addHUDNumber(
layer,
formatCount(runtime[key]),
x + w - 7,
rowY - 1,
{ ...displayStyle(9, SYN_WHITE), anchorX: 1, maxWidth: w - 46 },
pool,
);
}
const footerY = y + 14 + TALLY.length * 26 + 4;
graphics.rect(x + 8, footerY - 6, w - 16, 1).fill({ color: SYN_EMBER, alpha: 0.35 });
for (const [row, label, color, count] of [
[0, 'FAST', SYN_CYAN, runtime.fast],
[1, 'SLOW', SYN_MAGENTA, runtime.slow],
] as const) {
const rowY = footerY + row * 20;
addHUDText(layer, label, x + 8, rowY + 2, { ...labelStyle(), fill: color }, pool);
addHUDNumber(
layer,
formatCount(count),
x + w - 7,
rowY,
{ ...displayStyle(9, SYN_WHITE), anchorX: 1, maxWidth: w - 52 },
pool,
);
}
}
/** Compact labels keep the portrait HUD beside the monitor, leaving more space for the lanes. */
function portraitLabel(fill: number = SYN_DIM): HUDTextOptions {
return { size: 10, fill, fontFamily: SYN_DISPLAY_FONT, letterSpacing: 0.8 };
}
/**
* Portrait header: the play-mode light and the tempo / speed readouts in one band, with the top corners left free for
* a host's touch controls.
*/
function drawPortraitHeader(
graphics: Graphics,
layer: Container,
runtime: Runtime,
layout: BeMusicGameplayLayout,
accent: number,
pulse: number,
pool: ChildPool,
): void {
const width = layout.stage.width;
graphics.rect(0, 0, width, PORTRAIT_HEADER_H).fill({ color: SYN_VOID, alpha: 0.92 });
graphics.rect(0, PORTRAIT_HEADER_H, width, 1).fill({ color: accent, alpha: 0.35 + 0.35 * pulse });
const cy = PORTRAIT_HEADER_H / 2;
drawModeLight(graphics, layer, runtime.autoplay === true, TOUCH_CORNER, cy, accent, pulse, 10, pool, 'AUTO');
// Readouts on a fixed rhythm, as on the landscape header: label, then its value 40 px on (60 after SPEED).
addHUDText(layer, 'BPM', 190, cy - 3, portraitLabel(), pool);
addHUDNumber(layer, formatBPM(runtime.bpm), 230, cy - 7, displayStyle(13, SYN_WHITE), pool);
addHUDText(layer, runtime.floatingHiSpeed ? 'FHS' : 'SPEED', 300, cy - 3, portraitLabel(), pool);
addHUDNumber(
layer,
`x${formatHiSpeed(runtime)}`,
360,
cy - 7,
{ ...displayStyle(13, SYN_WHITE), maxWidth: width - TOUCH_CORNER - 360 },
pool,
);
}
/** Height of the portrait header band. */
const PORTRAIT_HEADER_H = 40;
/**
* Portrait HUD: a column beside the BGA monitor (song plate, score panel, judgement tally) and the gauge across the
* stage in the band between the monitor and the lanes, its label carrying the ruleset.
*/
function drawPortraitHUD(
graphics: Graphics,
layer: Container,
runtime: Runtime,
layout: BeMusicGameplayLayout,
accent: number,
pool: ChildPool,
): void {
const { plate, score, tally } = resolvePortraitHUDColumn(layout.stage, layout.bga);
// Gauge strip.
const groove = resolveGrooveRect(layout);
graphics.rect(groove.x - 4, groove.y - 24, groove.w + 8, groove.h + 28).fill(SYN_VOID);
const gauge = clampPercent(runtime.gauge ?? 0);
const clear = clampPercent(runtime.clearThreshold ?? 80);
const cleared = runtime.gaugeSurvival === true || clear <= 0 ? gauge > 0 : gauge >= clear;
addHUDText(
layer,
`${formatRuleset(runtime.rulesetLabel)} · ${(runtime.gaugeLabel ?? 'GROOVE').toUpperCase()} GAUGE`,
groove.x,
groove.y - 16,
{ ...portraitLabel(), maxWidth: groove.w - 60 },
pool,
);
addHUDNumber(
layer,
`${Math.round(gauge)}%`,
groove.x + groove.w,
groove.y - 19,
{ ...displayStyle(12, cleared ? SYN_AMBER : SYN_WHITE), anchorX: 1 },
pool,
);
drawGaugeCells(graphics, runtime, groove, groove.h);
// Song plate: genre, title, artist.
drawFrame(graphics, plate.x, plate.y, plate.w, plate.h, accent);
const textX = plate.x + 10;
const textW = plate.w - 20;
drawSongInfoLayers(runtime, (info) => {
const genre = info.chartGenre?.trim();
const artist = info.chartArtist?.trim();
return [
addHUDText(
layer,
genre ? genre.toUpperCase() : 'NOW PLAYING',
textX,
plate.y + 6,
{ size: 10, weight: '500', fill: SYN_DIM, fontFamily: SYN_TEXT_FONT, letterSpacing: 1, maxWidth: textW },
pool,
),
addHUDText(
layer,
info.chartTitle?.trim() || 'Untitled chart',
textX,
plate.y + 19,
{
size: 14,
weight: '500',
fill: SYN_WHITE,
fontFamily: SYN_TEXT_FONT,
maxWidth: textW,
dropShadow: { color: accent, alpha: 0.7, blur: 6, distance: 0 },
},
pool,
),
artist
? addHUDText(
layer,
artist,
textX,
plate.y + 39,
{ size: 10, weight: '300', fill: SYN_MIST, fontFamily: SYN_TEXT_FONT, maxWidth: textW },
pool,
)
: undefined,
];
});
// Score panel: SCORE and EX on the left of a divider, COMBO and RANK on the right, the rate filament along the foot.
drawFrame(graphics, score.x, score.y, score.w, score.h, accent);
const divider = score.x + Math.round(score.w * 0.56);
graphics.rect(divider, score.y + 10, 1, score.h - 20).fill({ color: accent, alpha: 0.3 });
addHUDText(layer, 'SCORE', score.x + 10, score.y + 8, portraitLabel(), pool);
addHUDNumber(
layer,
formatCount(runtime.score),
divider - 10,
score.y + 20,
{
...displayStyle(16, SYN_WHITE),
anchorX: 1,
maxWidth: divider - score.x - 20,
dropShadow: { color: accent, alpha: 0.8, blur: 6, distance: 0 },
},
pool,
);
addHUDText(layer, 'EX', score.x + 10, score.y + 44, portraitLabel(), pool);
addHUDNumber(
layer,
`${formatCount(runtime.exScore)}/${formatCount(runtime.exScoreMax)}`,
divider - 10,
score.y + 43,
{ ...displayStyle(10, SYN_MIST), anchorX: 1, maxWidth: divider - score.x - 44 },
pool,
);
const rate =
runtime.exScore !== undefined && runtime.exScoreMax !== undefined && runtime.exScoreMax > 0
? Math.max(0, Math.min(1, runtime.exScore / runtime.exScoreMax))
: 0;
const meterX = score.x + 10;
const meterW = divider - 10 - meterX;
const meterY = score.y + score.h - 10;
graphics.rect(meterX, meterY, meterW, 2).fill({ color: SYN_DIM, alpha: 0.3 });
if (rate > 0) {
graphics.rect(meterX, meterY - 2, meterW * rate, 6).fill({ color: accent, alpha: 0.15 });
graphics.rect(meterX, meterY, meterW * rate, 2).fill({ color: rate >= 8 / 9 ? SYN_AMBER : SYN_WHITE, alpha: 0.95 });
}
for (let ninth = 1; ninth < 9; ninth += 1) {
graphics
.rect(meterX + (meterW * ninth) / 9, meterY - 3, 1, 8)
.fill({ color: SYN_WHITE, alpha: ninth >= 6 ? 0.45 : 0.18 });
}
const right = score.x + score.w - 10;
addHUDText(layer, 'COMBO', divider + 10, score.y + 8, portraitLabel(), pool);
addHUDNumber(
layer,
formatCount(runtime.combo),
right,
score.y + 20,
{ ...displayStyle(14, SYN_WHITE), anchorX: 1, maxWidth: right - divider - 10 },
pool,
);
const rank = runtime.rank && runtime.rank !== '-' ? runtime.rank : 'F';
addHUDText(layer, 'RANK', divider + 10, score.y + 44, portraitLabel(), pool);
addHUDText(
layer,
rank,
right,
score.y + 49,
{
...displayStyle(rank.length >= 3 ? 11 : 14, SYN_AMBER),
anchorX: 1,
anchorY: 0.5,
maxWidth: 40,
dropShadow: { color: SYN_AMBER, alpha: 0.8, blur: 8, distance: 0 },
},
pool,
);
// Judgement tally: two rows of four cells, label over count.
drawFrame(graphics, tally.x, tally.y, tally.w, tally.h, SYN_EMBER);
const cells: ReadonlyArray<readonly [label: string, color: number, count: number | undefined]> = [
['PG', JUDGE_COLORS.PERFECT!, runtime.perfect],
['GR', JUDGE_COLORS.GREAT!, runtime.great],
['GD', JUDGE_COLORS.GOOD!, runtime.good],
['BD', JUDGE_COLORS.BAD!, runtime.bad],
['PR', JUDGE_COLORS.POOR!, runtime.poor],
['FAST', SYN_CYAN, runtime.fast],
['SLOW', SYN_MAGENTA, runtime.slow],
['MAX', SYN_MIST, runtime.maxCombo],
];
const cellW = (tally.w - 12) / 4;
// The player turned the judgment counts off: the tally keeps its frame.
if (runtime.hidesJudgeCounts) return;
cells.forEach(([label, color, count], index) => {
const x = tally.x + 6 + (index % 4) * cellW;
const y = tally.y + 6 + Math.floor(index / 4) * 28;
addHUDText(layer, label, x + 4, y, { ...portraitLabel(color) }, pool);
addHUDNumber(
layer,
formatCount(count),
x + cellW - 4,
y + 12,
{ ...displayStyle(11, SYN_WHITE), anchorX: 1, maxWidth: cellW - 8 },
pool,
);
});
}
const TALLY_NAMES = { perfect: 'PERFECT', great: 'GREAT', good: 'GOOD', bad: 'BAD', poor: 'POOR' } as const;
const JUDGE_COLORS: Record<string, number> = {
PERFECT: SYN_FLARE,
GREAT: SYN_AMBER,
GOOD: SYN_CYAN,
BAD: SYN_MAGENTA,
POOR: SYN_RED,
};
function formatCount(value: number | undefined): string {
if (value === undefined || !Number.isFinite(value)) return '0';
return String(Math.max(0, Math.floor(value)));
}
function formatBPM(value: number | undefined): string {
if (value === undefined || !Number.isFinite(value)) return '---';
return String(Math.round(value));
}
/** The hi-speed readout: one decimal, or two for the AC floating hi-speed (FHS), as Plain shows them. */
function formatHiSpeed(runtime: Pick<Runtime, 'hiSpeed' | 'floatingHiSpeed'>): string {
const digits = runtime.floatingHiSpeed ? 2 : 1;
const value = runtime.hiSpeed;
if (value === undefined || !Number.isFinite(value)) return (0).toFixed(digits);
return value.toFixed(digits);
}
function formatRuleset(value: string | undefined): string {
switch (value) {
case 'beatoraja':
return 'BEATORAJA';
case '____':
return '????';
case 'plugout':
return 'PLUGOUT';
default:
return 'LR2';
}
}
function formatExRate(exScore: number | undefined, max: number | undefined): string {
if (exScore === undefined || max === undefined || !Number.isFinite(exScore) || !Number.isFinite(max) || max <= 0) {
return '0.0%';
}
return `${((exScore / max) * 100).toFixed(1)}%`;
}
|