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 | 124x 52x 19x 19x 174x 132x 19x 19x 19x 19x 19x 174x 19x 174x 88x 17x 71x 7x 64x 88x 88x 42x 6x 50x 6x 88x 6x 6x 6x 88x 36x 88x 274x 88x 88x 188x | import type { ChartPlayVariant } from '@be-music/chart-model';
import { PLAYFIELD } from './playfield.ts';
import {
isScratchLaneForVariant,
resolveFallbackLaneLayout,
resolveSkinlessLaneLayout,
type FallbackLaneLayoutRect,
} from './lane-geometry.ts';
import { resolvePortraitLaneLayout, resolveStageOrientation } from './portrait.ts';
import type { BeMusicStage, BeMusicStageOrientation, GameplayLayoutMode } from './types.ts';
/**
* Geometry of the touch layout on the 854x480 stage, in design px. The lanes take the stage from its left margin up to
* the judgement tally's column ({@link STAGE_SIDE_COLUMN} starts at 746), keys are one width each (fingers do not care
* which key is black) capped so a 5K chart does not grow keys wider than a thumb. The judgement line sits a little
* lower than the standard one but stays above the bottom HUD band (from {@link STAGE_BGA_BAND}'s bottom, 340), so the
* built-in skins' gauge / score panels are not covered by the wider lanes; fingers press the lanes anywhere from the
* lower part of the lane down to the stage bottom, so the band under the line is still part of each lane's touch zone.
*/
export const TOUCH_PLAYFIELD = {
left: 16,
right: 730,
/** Below the header band the built-in skins draw along the top of the stage (at most 44 px tall). */
top: 48,
judgementY: 330,
/** Widest a key gets, about 58 CSS px on a landscape phone (stage scale 0.81). */
maxKeyWidth: 72,
/** A scratch lane is this many keys wide. */
scratchWeight: 1.4,
/** Gap between the 1P and 2P banks in double play. */
sideGap: 24,
} as const;
/** Lane geometry of a playfield in either layout mode. */
export interface GameplayLaneGeometry {
/** True when a stage separates independent players around its monitor. */
twoPlayer?: boolean;
/** The layout actually used: `'touch'` falls back to `'standard'` for play modes the touch layout does not cover. */
mode: GameplayLayoutMode;
/** The orientation of the stage the geometry was laid out for. */
orientation: BeMusicStageOrientation;
lanes: FallbackLaneLayoutRect[];
/** Left edge of the leftmost lane / right edge of the rightmost lane. */
left: number;
right: number;
/** Top of the lanes and the judgement line notes land on. */
top: number;
judgementY: number;
}
/**
* Whether the touch layout covers `playVariant`: the That-Which-Must-Not-Be-Named (5 / 7 / 10 / 14 KEY) and PMS (9 KEY) modes. The 24 / 48 KEY
* keyboard modes are played on a keyboard or MIDI controller and keep the standard layout.
*/
export function supportsTouchLayout(playVariant?: ChartPlayVariant): boolean {
return playVariant !== '24' && playVariant !== '48';
}
/**
* Lane rects for the touch layout: every key the same width and a scratch {@link TOUCH_PLAYFIELD.scratchWeight} keys
* wide, sized to fill the touch span (keys at most {@link TOUCH_PLAYFIELD.maxKeyWidth}) and centred in it. Double play
* keeps a {@link TOUCH_PLAYFIELD.sideGap} between the banks. Lane order follows the standard layout.
*/
export function resolveTouchLaneLayout(
channels: readonly string[] | undefined,
laneCount: number | undefined,
playVariant?: ChartPlayVariant,
): { lanes: FallbackLaneLayoutRect[]; left: number; right: number } {
const count = channels && channels.length > 0 ? channels.length : Math.max(1, Math.trunc(laneCount ?? 8));
const scratchCount = channels
? channels.filter((channel) => isScratchLaneForVariant(channel, playVariant)).length
: 0;
const doublePlay = playVariant !== '9' && channels?.some((channel) => channel.startsWith('2')) === true;
const sideGap = doublePlay ? TOUCH_PLAYFIELD.sideGap : 0;
const span = TOUCH_PLAYFIELD.right - TOUCH_PLAYFIELD.left;
const weight = count - scratchCount + scratchCount * TOUCH_PLAYFIELD.scratchWeight;
const key = Math.min(TOUCH_PLAYFIELD.maxKeyWidth, (span - sideGap) / weight);
const placed = resolveFallbackLaneLayout({
channels,
laneCount,
playVariant,
x: 0,
w: span,
sideGap,
fixedWidths: { scratch: key * TOUCH_PLAYFIELD.scratchWeight, white: key, black: key },
});
const width = Math.max(0, ...placed.map((lane) => lane.x + lane.w));
const left = TOUCH_PLAYFIELD.left + (span - width) / 2;
return { lanes: placed.map((lane) => ({ ...lane, x: lane.x + left })), left, right: left + width };
}
/**
* The lane geometry for `mode` on `stage` (the 854x480 landscape stage when omitted). On a landscape stage: the
* standard layout ({@link resolveSkinlessLaneLayout} under the LR2 7K judgement line), or the touch layout when asked
* for and the play mode supports it ({@link supportsTouchLayout}). On a portrait stage: the portrait playfield in either
* mode ({@link resolvePortraitLaneLayout}); hosts only put charts that fit one (`supportsPortraitLayout`) on a portrait
* stage. `twoPlayer` selects separated banks on stages with `twoPlayerSideInset`; a DP chart keeps its joint field.
*/
export function resolveGameplayLaneGeometry(
channels: readonly string[] | undefined,
laneCount: number | undefined,
playVariant: ChartPlayVariant | undefined,
mode: GameplayLayoutMode = 'standard',
stage?: Pick<BeMusicStage, 'width' | 'height' | 'playfield'>,
twoPlayer = false,
): GameplayLaneGeometry {
let geometry: GameplayLaneGeometry;
if (stage && resolveStageOrientation(stage) === 'portrait') {
geometry = {
mode,
orientation: 'portrait',
...resolvePortraitLaneLayout(channels, laneCount, playVariant, mode, stage),
};
} else if (mode === 'touch' && supportsTouchLayout(playVariant)) {
geometry = {
mode: 'touch',
orientation: 'landscape',
...resolveTouchLaneLayout(channels, laneCount, playVariant),
top: TOUCH_PLAYFIELD.top,
judgementY: TOUCH_PLAYFIELD.judgementY,
};
} else {
geometry = {
mode: 'standard',
orientation: 'landscape',
...resolveSkinlessLaneLayout(channels, laneCount, playVariant),
top: PLAYFIELD.y,
judgementY: PLAYFIELD.judgementY,
};
}
const bounds = stage?.playfield?.[geometry.mode];
if (!bounds) return geometry;
if (
twoPlayer &&
(playVariant === '10' || playVariant === '14') &&
bounds.twoPlayerSideInset !== undefined &&
stage &&
geometry.lanes.some((lane) => lane.side === '1P') &&
geometry.lanes.some((lane) => lane.side === '2P')
) {
const inset = bounds.twoPlayerSideInset;
const bankRight = Math.max(...geometry.lanes.filter((lane) => lane.side === '2P').map((lane) => lane.x + lane.w));
const shift1P = inset - geometry.left;
const shift2P = stage.width - inset - bankRight;
return {
...geometry,
twoPlayer: true,
top: bounds.top,
judgementY: bounds.judgementY,
left: inset,
right: stage.width - inset,
lanes: geometry.lanes.map((lane) => ({ ...lane, x: lane.x + (lane.side === '1P' ? shift1P : shift2P) })),
};
}
const right = bounds.maxRight === undefined ? geometry.right : Math.min(geometry.right, bounds.maxRight);
const scale = (right - geometry.left) / (geometry.right - geometry.left || 1);
const doublePlay = supportsTouchLayout(playVariant) && geometry.lanes.some((lane) => lane.side === '2P');
const shift =
bounds.doublePlayCenterX !== undefined && doublePlay
? Math.round(bounds.doublePlayCenterX - (geometry.left + right) / 2)
: 0;
return {
...geometry,
top: bounds.top,
judgementY: bounds.judgementY,
left: geometry.left + shift,
right: right + shift,
lanes:
scale === 1 && shift === 0
? geometry.lanes
: geometry.lanes.map((lane) => ({
...lane,
x: geometry.left + (lane.x - geometry.left) * scale + shift,
w: lane.w * scale,
})),
};
}
|