All files / src/builder layerBuilder.ts

100% Statements 38/38
100% Branches 9/9
100% Functions 9/9
100% Lines 38/38

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 16122x 22x             22x           79x                               35x 32x 32x   3x                               7x 5x 5x   2x                               7x 5x 5x   2x                               5x 4x 4x   1x                               7x 6x 6x   1x                 1x 1x   1x 1x   1x 1x       80x 79x   80x 79x               80x 80x                 80x 80x      
import { LayerConfigure, LayerConfigureImpl } from './layerConfigure'
import { LayerConfigSupplier } from '../value/layerConfig'
 
/**
 * レイアウト情報をもとに g.Scene に配置する各エンティティ ({@link Layer}) の構築を支援します.
 *
 * Layer は本クラスを用いて作成してください.
 */
export class LayerBuilder extends LayerConfigureImpl {
  private static lastUsedScene?: g.Scene
  private static defaultConfig?: LayerConfigSupplier
  private static defaultConfigure?: LayerConfigure
 
  constructor (scene: g.Scene) {
    super(false, scene, new LayerConfigSupplier(LayerBuilder.getDefaultConfig(scene).get()))
  }
 
  /**
   * Spot, Broadcaster が配置されるマップの大きさを取得します.
   */
  override field (): Readonly<g.CommonArea>
 
  /**
   * Spot, Broadcaster が配置されるマップの大きさを設定します.
   *
   * @param area 設定する領域
   */
  override field (area: g.CommonArea): LayerBuilder
 
  override field (args?: g.CommonArea): LayerBuilder | Readonly<g.CommonArea> {
    if (args) {
      super.field(args)
      return this
    }
    return super.field()
  }
 
  /**
   * Live が配置される生放送画面の大きさを取得します.
   */
  override screen (): Readonly<g.CommonArea>
 
  /**
   * Live が配置される生放送画面の大きさを設定します.
   *
   * @param area 設定する領域
   */
  override screen (area: g.CommonArea): LayerBuilder
 
  override screen (args?: g.CommonArea): LayerBuilder | Readonly<g.CommonArea> {
    if (args) {
      super.screen(args)
      return this
    }
    return super.screen()
  }
 
  /**
   * コメントが表示される領域の大きさを取得します.
   */
  override comment (): Readonly<g.CommonArea>
 
  /**
   * コメントが表示される領域の大きさを設定します.
   *
   * @param area 設定する領域
   */
  override comment (area: g.CommonArea): LayerBuilder
 
  override comment (args?: g.CommonArea): LayerBuilder | Readonly<g.CommonArea> {
    if (args) {
      super.comment(args)
      return this
    }
    return super.comment()
  }
 
  /**
   * 残り時間と得点が表示される領域の大きさを取得します.
   */
  override header (): Readonly<g.CommonArea>
 
  /**
   * 残り時間と得点が表示される領域の大きさを設定します.
   *
   * @param area 設定する領域
   */
  override header (area: g.CommonArea): LayerBuilder
 
  override header (args?: g.CommonArea): LayerBuilder | Readonly<g.CommonArea> {
    if (args) {
      super.header(args)
      return this
    }
    return super.header()
  }
 
  /**
   * ライブラリ利用者が自由に使えるフィールドを取得します.
   */
  override vars (): unknown
 
  /**
   * ライブラリ利用者が自由に使えるフィールドを設定します.
   *
   * @param vars ライブラリ利用者が自由に使えるフィールド
   */
  override vars (vars: unknown): LayerBuilder
 
  override vars (args?: unknown): unknown | LayerBuilder {
    if (arguments.length > 0) {
      super.vars(args)
      return this
    }
    return super.vars()
  }
 
  /**
   * 各属性値に値を設定しなかった際に使用されるデフォルト値を設定します.
   *
   * @param scene 現在の scene を指定してください.
   */
  static getDefault (scene: g.Scene): LayerConfigure {
    if (LayerBuilder.lastUsedScene !== scene) {
      LayerBuilder.resetDefault()
    }
    if (!LayerBuilder.defaultConfigure) {
      LayerBuilder.defaultConfigure = new LayerConfigureImpl(true, scene, LayerBuilder.getDefaultConfig(scene))
    }
    LayerBuilder.lastUsedScene = scene
    return LayerBuilder.defaultConfigure
  }
 
  private static getDefaultConfig (scene: g.Scene): LayerConfigSupplier {
    if (LayerBuilder.lastUsedScene !== scene) {
      LayerBuilder.resetDefault()
    }
    if (!LayerBuilder.defaultConfig) {
      LayerBuilder.defaultConfig = new LayerConfigSupplier({
        field: { x: 100, y: 100, width: scene.game.width - 200, height: scene.game.height - 200 },
        screen: { x: 100, y: 100, width: scene.game.width - 200, height: scene.game.height - 200 },
        comment: { x: 100, y: 100, width: scene.game.width - 200, height: scene.game.height - 200 },
        header: { x: 0, y: 0, width: scene.game.width, height: 100 },
        vars: undefined
      })
    }
    LayerBuilder.lastUsedScene = scene
    return LayerBuilder.defaultConfig
  }
 
  /**
   * {@link getDefault} で設定した変更を消去します.
   *
   * @internal
   */
  private static resetDefault () {
    delete LayerBuilder.defaultConfig
    delete LayerBuilder.defaultConfigure
  }
}