All files / src/builder commentDeployerConfigure.ts

100% Statements 26/26
100% Branches 8/8
100% Functions 8/8
100% Lines 23/23

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  22x                                                                                                             22x       19x 19x 26x             11x 7x 6x   4x             11x 7x 6x   4x             10x 6x 6x   4x               7x 6x 6x   1x             16x 16x      
import { CommentDeployerConfig, CommentDeployerConfigSupplier } from '../value/commentDeployerConfig'
import { CommentDeployer, CommentDeployerImpl } from '../model/commentDeployer'
 
/**
 * {@link CommentDeployer} を新規生成する際の各種設定を保持します.
 */
export interface CommentDeployerConfigure {
  /**
   * 作成する CommentDeployer に設定するコメントの移動速度を取得します.
   */
  speed (): number
 
  /**
   * 作成する CommentDeployer に設定するコメントの移動速度を設定します.
   *
   * @param speed 移動速度
   */
  speed (speed: number): CommentDeployerConfigure
 
  /**
   * 作成する CommentDeployer に設定するコメント間隔(y座標値)を取得します.
   */
  intervalY (): number
 
  /**
   * 作成する CommentDeployer に設定するコメント間隔(y座標値)を設定します.
   *
   * @param intervalY コメント間隔(y座標値)
   */
  intervalY (intervalY: number): CommentDeployerConfigure
 
  /**
   * 作成する CommentDeployer に設定するコメントのフォントを取得します.
   */
  font(): g.Font
 
  /**
   * 作成する CommentDeployer に設定するコメントのフォントを設定します.
   *
   * @param font コメントのフォント
   */
  font(font: g.Font): CommentDeployerConfigure
 
  /**
   * 作成する CommentDeployer のライブラリ利用者が自由に使えるフィールドを取得します.
   */
  vars (): unknown
 
  /**
   * 作成する CommentDeployer のライブラリ利用者が自由に使えるフィールドを設定します.
   *
   * @param vars ライブラリ利用者が自由に使えるフィールド
   */
  vars (vars: unknown): CommentDeployerConfigure
}
 
export class CommentDeployerConfigureImpl implements CommentDeployerConfigure {
  private readonly getter: () => CommentDeployerConfig
  private readonly setter: (obj: Partial<CommentDeployerConfig>) => void
 
  constructor (isDefault: boolean, private readonly scene: g.Scene, private readonly config: CommentDeployerConfigSupplier) {
    this.getter = () => isDefault ? config.default() : config.get()
    this.setter = obj => isDefault ? config.defaultIf(obj) : config.setIf(obj)
  }
 
  speed (): number
  speed (value: number): CommentDeployerConfigure
 
  speed (args?: number): number | CommentDeployerConfigure {
    if (typeof args === 'number') {
      this.setter({ speed: args })
      return this
    }
    return this.getter().speed
  }
 
  intervalY (): number
  intervalY (value: number): CommentDeployerConfigure
 
  intervalY (args?: number): number | CommentDeployerConfigure {
    if (typeof args === 'number') {
      this.setter({ intervalY: args })
      return this
    }
    return this.getter().intervalY
  }
 
  font (): g.Font
  font (value: g.Font): CommentDeployerConfigure
 
  font (args?: g.Font): g.Font | CommentDeployerConfigure {
    if (args) {
      this.setter({ font: args })
      return this
    }
    return this.getter().font
  }
 
  vars (): unknown
 
  vars (vars: unknown): CommentDeployerConfigure
 
  vars (args?: unknown): unknown | CommentDeployerConfigure {
    if (arguments.length > 0) {
      this.setter({ vars: args })
      return this
    }
    return this.getter().vars
  }
 
  /**
   * CommentDeployer を作成します.
   */
  build (): CommentDeployer {
    const config = this.config.get()
    return new CommentDeployerImpl({ scene: this.scene, speed: config.speed, intervalY: config.intervalY, font: config.font, vars: config.vars })
  }
}