All files / src/value spotConfig.ts

100% Statements 23/23
100% Branches 0/0
100% Functions 5/5
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 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 14722x           22x                                                                                                                                                           22x                 224x 224x           224x 224x 224x 224x       999x                     100x 100x 100x 100x 100x 100x       28x                     7x 7x 7x 7x 7x 7x      
import { ObjectSupplier, OptionalValueSupplier, PrimitiveValueSupplier, RecordSupplier, ValueSupplier } from './value'
import { Live } from '../model/live'
 
/**
 * {@link Spot} の状態一覧
 */
export const spotAssetTypes = ['locked', 'unvisited', 'disabled', 'normal'] as const
 
/**
 * {@link Spot} の状態一覧
 */
export type SpotAssetType = typeof spotAssetTypes[number]
 
/**
 * {@link Spot} の各状態における表示画像アセット一覧
 */
export type SpotAssetRecord = Record<SpotAssetType, g.ImageAsset>
 
/**
 * {@link Spot} 生成時に利用する設定値
 */
export interface SpotConfig {
  /**
   * 作成する Spot に設定するx座標
   */
  x: number
  /**
   * 作成する Spot に設定するy座標
   */
  y: number
  /**
   * 未解放状態の画像アセット.
   *
   * 放送者(プレイヤー)には存在を見せたいが、条件をみたすまで
   * 訪問させたくない Spot を作成したいときに設定してください.
   */
  locked: g.ImageAsset
  /**
   * 未訪問状態の画像アセット.
   *
   * 放送者(プレイヤー)がまだ訪問していない場合、
   * 強調表示をして訪問を促したい際に設定してください.
   */
  unvisited: g.ImageAsset
  /**
   * 訪問操作受付禁止状態の画像アセット.
   *
   * 放送者(プレイヤー)が他の Spot に向かって移動しているときなど、
   * クリックしても目的地に指定できないことを強調する際に設定してください.
   */
  disabled: g.ImageAsset
  /**
   * 通常時の画像アセット.
   *
   * 放送者(プレイヤー)がクリックすれば目的地に設定される状態の際の画像を設定してください.
   */
  normal: g.ImageAsset
  /**
   * 表示名
   *
   * 指定した値がマップ上で表示されます.
   */
  name: string
  /**
   * スポット名を描画する際、用いるフォント.
   */
  labelFont: g.Font
  /**
   * 訪問時に始まる生放送.
   *
   * 生放送での処理を定義したクラス名を設定してください. インスタンスでない点にご留意ください.
   *
   * @return 生放送処理が定義されたクラス名
   */
  liveClass: new () => Live
  /**
   * ライブラリ利用者が自由に使えるフィールドです
   */
  vars: unknown
}
 
/**
 * {@link Spot} 生成に必要な属性値を設定します.
 */
export class SpotConfigSupplier implements ValueSupplier<SpotConfig> {
  private readonly location: ObjectSupplier<g.CommonOffset>
  private readonly assets: RecordSupplier<SpotAssetType, g.ImageAsset>
  private readonly name: PrimitiveValueSupplier<string>
  private readonly labelFont: PrimitiveValueSupplier<g.Font>
  private readonly liveClass: PrimitiveValueSupplier<new () => Live>
  private readonly vars: OptionalValueSupplier<unknown>
 
  constructor (initial: SpotConfig) {
    this.location = ObjectSupplier.create({ x: initial.x, y: initial.y })
    this.assets = RecordSupplier.create({
      locked: initial.locked,
      unvisited: initial.unvisited,
      disabled: initial.disabled,
      normal: initial.normal
    })
    this.name = PrimitiveValueSupplier.create(initial.name)
    this.labelFont = PrimitiveValueSupplier.create(initial.labelFont)
    this.liveClass = PrimitiveValueSupplier.create(initial.liveClass)
    this.vars = OptionalValueSupplier.create(initial.vars)
  }
 
  get (): SpotConfig {
    return {
      ...this.location.get(),
      ...this.assets.get(),
      name: this.name.get(),
      labelFont: this.labelFont.get(),
      liveClass: this.liveClass.get(),
      vars: this.vars.get()
    }
  }
 
  setIf (obj: Partial<SpotConfig>): void {
    this.location.setIf(obj)
    this.assets.setIf(obj)
    this.name.setIf(obj.name)
    this.labelFont.setIf(obj.labelFont)
    this.liveClass.setIf(obj.liveClass)
    this.vars.setIf(obj.vars)
  }
 
  default (): SpotConfig {
    return {
      ...this.location.default(),
      ...this.assets.default(),
      name: this.name.default(),
      labelFont: this.labelFont.default(),
      liveClass: this.liveClass.default(),
      vars: this.vars.default()
    }
  }
 
  defaultIf (obj: Partial<SpotConfig>): void {
    this.location.defaultIf(obj)
    this.assets.defaultIf(obj)
    this.name.defaultIf(obj.name)
    this.labelFont.defaultIf(obj.labelFont)
    this.liveClass.defaultIf(obj.liveClass)
    this.vars.defaultIf(obj.vars)
  }
}