All files / skin-beatoraja/src/scene chart-text.ts

100% Statements 16/16
86.66% Branches 26/30
100% Functions 4/4
100% Lines 15/15

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                                            518x                       44x   6x   3x   4x   4x   3x   3x   5x   5x   11x           14x   5x   3x   6x      
import { BEATORAJA_TEXT } from '../runtime-ids.ts';
 
/** What a skin's song texts read of a chart. */
export interface BeatorajaChartTextInput {
  readonly title?: string;
  readonly subtitle?: string;
  readonly genre?: string;
  readonly artist?: string;
  /** The sub-artist line: BMS `#SUBARTIST`, or bmson's `subartists` joined. */
  readonly subartist?: string;
  /** The folder the chart sits in. */
  readonly directory?: string;
}
 
/** What a skin's own texts read: the skin header's name and author. */
export interface BeatorajaSkinTextInput {
  readonly name?: string;
  readonly author?: string;
}
 
/** The non-empty parts joined with a space, as beatoraja's full title and full artist join them. */
export function joinBeatorajaText(...parts: readonly (string | undefined)[]): string {
  return parts.filter((part): part is string => typeof part === 'string' && part.length > 0).join(' ');
}
 
/**
 * A song text (`text[].ref`, `StringPropertyFactory`) of a chart, or `undefined` for another id: the title (10), the
 * subtitle (11), the full title (12, title and subtitle), the genre (13), the artist (14), the sub-artist (15), the full
 * artist (16, artist and sub-artist) and the folder (1000). Each reads empty without a chart or without the field.
 */
export function resolveBeatorajaChartText(
  id: number,
  chartEntry: BeatorajaChartTextInput | undefined,
): string | undefined {
  switch (id) {
    case BEATORAJA_TEXT.TITLE:
      return chartEntry?.title ?? '';
    case BEATORAJA_TEXT.SUBTITLE:
      return chartEntry?.subtitle ?? '';
    case BEATORAJA_TEXT.FULLTITLE:
      return joinBeatorajaText(chartEntry?.title, chartEntry?.subtitle);
    case BEATORAJA_TEXT.GENRE:
      return chartEntry?.genre ?? '';
    case BEATORAJA_TEXT.ARTIST:
      return chartEntry?.artist ?? '';
    case BEATORAJA_TEXT.SUBARTIST:
      return chartEntry?.subartist ?? '';
    case BEATORAJA_TEXT.FULLARTIST:
      return joinBeatorajaText(chartEntry?.artist, chartEntry?.subartist);
    case BEATORAJA_TEXT.DIRECTORY:
      return chartEntry?.directory ?? '';
    default:
      return undefined;
  }
}
 
/** The skin's name (50) or author (51) text, empty when its header has none; `undefined` for another id. */
export function resolveBeatorajaSkinText(id: number, skin: BeatorajaSkinTextInput | undefined): string | undefined {
  switch (id) {
    case BEATORAJA_TEXT.SKIN_NAME:
      return skin?.name ?? '';
    case BEATORAJA_TEXT.SKIN_AUTHOR:
      return skin?.author ?? '';
    default:
      return undefined;
  }
}