All files / src/builder liveOnAirSceneConfigure.ts

100% Statements 97/97
100% Branches 55/55
100% Functions 34/34
100% Lines 76/76

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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371    22x   22x                                                                                                                                                                                                                                                                                                                                     22x                                                           15x 15x 15x 15x   15x 15x 15x 15x 15x 15x 15x 15x 15x 15x   15x 15x 15x 15x 15x 15x 15x 15x 15x 15x               18x 6x 6x   12x               15x 4x 4x   11x               22x 8x 6x   14x               15x 4x 4x   11x               15x 4x 4x   11x               17x 5x 3x 3x 3x   2x   5x   12x               15x 4x 4x   11x               20x 7x 6x   13x               22x 8x 6x   14x               20x 7x 6x   13x               21x 8x 6x   13x             5x      
import { LayerConfig, LayerConfigSupplier } from '../value/layerConfig'
import { BroadcasterConfig, BroadcasterConfigSupplier } from '../value/broadcasterConfig'
import { SpotConfig, SpotConfigSupplier } from '../value/spotConfig'
import { FieldConfig, FieldConfigSupplier } from '../value/fieldConfig'
import { LiveOnAirScene, LiveOnAirSceneImpl } from '../model/liveOnAirScene'
import { ScreenConfig, ScreenConfigSupplier } from '../value/screenConfig'
import { CommentSupplierConfig, CommentSupplierConfigSupplier } from '../value/commentSupplierConfig'
import { CommentDeployerConfig, CommentDeployerConfigSupplier } from '../value/commentDeployerConfig'
import { ScorerConfig, ScorerConfigSupplier } from '../value/scorerConfig'
import { TickerConfig, TickerConfigSupplier } from '../value/tickerConfig'
import { CommentContextConfig, CommentContextConfigSupplier } from '../value/commentContextConfig'
import { LiveContextConfig, LiveContextConfigSupplier } from '../value/liveContextConfig'
 
/**
 * {@link LiveOnAirScene} を新規作成する際の各種設定を格納します.
 */
export interface LiveOnAirSceneConfigure {
  /**
   * g.Scene 上に配置される各レイヤーの領域値を設定します.
   *
   * @param config 各レイヤーの領域の位置・大きさ
   */
  layer(config: Partial<LayerConfig>): LiveOnAirSceneConfigure
 
  /**
   * g.Scene 上に配置される各レイヤーの領域値を取得します.
   *
   */
  layer(): Readonly<LayerConfig>
 
  /**
   * マップ ({@link Field}) の属性情報を設定します.
   *
   * @param config Field の設定値
   */
  field(config: Partial<FieldConfig>): LiveOnAirSceneConfigure
 
  /**
   * マップ ({@link Field}) の属性情報を取得します.
   */
  field(): Readonly<FieldConfig>
 
  /**
   * 作成する {@link Broadcaster} の属性情報を設定します.
   *
   * @param config Broadcaster の設定値
   */
  broadcaster(config: Partial<BroadcasterConfig>): LiveOnAirSceneConfigure
 
  /**
   * 作成する {@link Broadcaster} の属性情報を取得します.
   */
  broadcaster(): Readonly<BroadcasterConfig>
 
  /**
   * 生放送の画面 ({@link Screen}) の属性情報を設定します.
   *
   * @param config Field の設定値
   */
  screen(config: Partial<ScreenConfig>): LiveOnAirSceneConfigure
 
  /**
   * 生放送の画面 ({@link Screen}) の属性情報を取得します.
   */
  screen(): Readonly<ScreenConfig>
 
  /**
   * {@link LiveContext} の初期値を設定します.
   *
   * @param config LiveContext の初期値
   */
  liveContext(config: Partial<LiveContextConfig>): LiveOnAirSceneConfigure
 
  /**
   * {@link LiveContext} の初期値を取得します.
   */
  liveContext(): Readonly<LiveContextConfig>
 
  /**
   * 作成する {@link Spot} の属性情報を設定します.
   *
   * @param config Spot の設定値
   */
  spot(config: Partial<SpotConfig>): LiveOnAirSceneConfigure
 
  /**
   * 作成する {@link Spot} の属性情報を取得します.
   */
  spot(): readonly SpotConfig[]
 
  /**
   * 作成する {@link CommentContext} の属性情報を設定します.
   *
   * @param config CommentContext の設定値
   */
  commentContext(config: Partial<CommentContextConfig>): LiveOnAirSceneConfigure
 
  /**
   * 作成する {@link CommentContext} の属性情報を取得します.
   */
  commentContext(): Readonly<CommentContextConfig>
 
  /**
   * 作成する {@link CommentSupplier} の属性情報を設定します.
   *
   * @param config CommentSupplier の設定値
   */
  commentSupplier(config: Partial<CommentSupplierConfig>): LiveOnAirSceneConfigure
 
  /**
   * 作成する {@link CommentSupplier} の属性情報を取得します.
   */
  commentSupplier(): Readonly<CommentSupplierConfig>
 
  /**
   * 作成する {@link CommentSupplier} の属性情報を設定します.
   *
   * @param config CommentSupplier の設定値
   */
  commentDeployer(config: Partial<CommentDeployerConfig>): LiveOnAirSceneConfigure
 
  /**
   * 作成する {@link CommentSupplier} の属性情報を取得します.
   */
  commentDeployer(): Readonly<CommentDeployerConfig>
 
  /**
   * 作成する {@link Scorer} の属性情報を設定します.
   *
   * @param config Scorer の設定値
   */
  scorer(config: Partial<ScorerConfig>): LiveOnAirSceneConfigure
 
  /**
   * 作成する{@link Scorer} の属性情報を取得します.
   */
  scorer(): Readonly<ScorerConfig>
 
  /**
   * 作成する {@link Ticker} の属性情報を設定します.
   *
   * @param config Ticker の設定値
   */
  ticker(config: Partial<TickerConfig>): LiveOnAirSceneConfigure
 
  /**
   * 作成する {@link Ticker} の属性情報を取得します.
   */
  ticker(): Readonly<TickerConfig>
}
 
export interface LiveOnAirSceneConfigSupplierOptions {
  game: g.Game
  layer: LayerConfigSupplier
  field: FieldConfigSupplier
  broadcaster: BroadcasterConfigSupplier
  screen: ScreenConfigSupplier
  liveContext: LiveContextConfigSupplier
  spot: SpotConfigSupplier
  commentContext: CommentContextConfigSupplier
  commentSupplier: CommentSupplierConfigSupplier
  commentDeployer: CommentDeployerConfigSupplier
  scorer: ScorerConfigSupplier
  ticker: TickerConfigSupplier
  isDefault: boolean
}
 
export class LiveOnAirSceneConfigureImpl implements LiveOnAirSceneConfigure {
  private readonly isDefault: boolean
  private readonly game: g.Game
  private readonly spotConfig: SpotConfigSupplier
 
  private readonly spotConfigs: SpotConfigSupplier[]
 
  private readonly layerGetter: () => LayerConfig
  private readonly fieldGetter: () => FieldConfig
  private readonly broadcasterGetter: () => BroadcasterConfig
  private readonly screenGetter: () => ScreenConfig
  private readonly liveContextGetter: () => LiveContextConfig
  private readonly commentContextGetter: () => CommentContextConfig
  private readonly commentSupplierGetter: () => CommentSupplierConfig
  private readonly commentDeployerGetter: () => CommentDeployerConfig
  private readonly scorerGetter: () => ScorerConfig
  private readonly tickerGetter: () => TickerConfig
 
  private readonly layerSetter: (obj: Partial<LayerConfig>) => void
  private readonly fieldSetter: (obj: Partial<FieldConfig>) => void
  private readonly broadcasterSetter: (obj: Partial<BroadcasterConfig>) => void
  private readonly screenSetter: (obj: Partial<ScreenConfig>) => void
  private readonly liveContextSetter: (obj: Partial<LiveContextConfig>) => void
  private readonly commentContextSetter: (obj: Partial<CommentContextConfig>) => void
  private readonly commentSupplierSetter: (obj: Partial<CommentSupplierConfig>) => void
  private readonly commentDeployerSetter: (obj: Partial<CommentDeployerConfig>) => void
  private readonly scorerSetter: (obj: Partial<ScorerConfig>) => void
  private readonly tickerSetter: (obj: Partial<TickerConfig>) => void
 
  constructor ({ game, layer, field, broadcaster, screen, liveContext, spot, commentContext, commentSupplier, commentDeployer, scorer, ticker, isDefault }: LiveOnAirSceneConfigSupplierOptions) {
    this.isDefault = isDefault
    this.game = game
    this.spotConfig = spot
    this.spotConfigs = []
 
    this.layerGetter = () => isDefault ? layer.default() : layer.get()
    this.fieldGetter = () => isDefault ? field.default() : field.get()
    this.broadcasterGetter = () => isDefault ? broadcaster.default() : broadcaster.get()
    this.screenGetter = () => isDefault ? screen.default() : screen.get()
    this.liveContextGetter = () => isDefault ? liveContext.default() : liveContext.get()
    this.commentContextGetter = () => isDefault ? commentContext.default() : commentContext.get()
    this.commentSupplierGetter = () => isDefault ? commentSupplier.default() : commentSupplier.get()
    this.commentDeployerGetter = () => isDefault ? commentDeployer.default() : commentDeployer.get()
    this.scorerGetter = () => isDefault ? scorer.default() : scorer.get()
    this.tickerGetter = () => isDefault ? ticker.default() : ticker.get()
 
    this.layerSetter = obj => isDefault ? layer.defaultIf(obj) : layer.setIf(obj)
    this.fieldSetter = obj => isDefault ? field.defaultIf(obj) : field.setIf(obj)
    this.broadcasterSetter = obj => isDefault ? broadcaster.defaultIf(obj) : broadcaster.setIf(obj)
    this.screenSetter = obj => isDefault ? screen.defaultIf(obj) : screen.setIf(obj)
    this.liveContextSetter = obj => isDefault ? liveContext.defaultIf(obj) : liveContext.setIf(obj)
    this.commentContextSetter = obj => isDefault ? commentContext.defaultIf(obj) : commentContext.setIf(obj)
    this.commentSupplierSetter = obj => isDefault ? commentSupplier.defaultIf(obj) : commentSupplier.setIf(obj)
    this.commentDeployerSetter = obj => isDefault ? commentDeployer.defaultIf(obj) : commentDeployer.setIf(obj)
    this.scorerSetter = obj => isDefault ? scorer.defaultIf(obj) : scorer.setIf(obj)
    this.tickerSetter = obj => isDefault ? ticker.defaultIf(obj) : ticker.setIf(obj)
  }
 
  layer (config: Partial<LayerConfig>): LiveOnAirSceneConfigure
 
  layer (): Readonly<LayerConfig>
 
  layer (args?: Partial<LayerConfig>): LiveOnAirSceneConfigure | Readonly<LayerConfig> {
    if (args) {
      this.layerSetter(args)
      return this
    }
    return this.layerGetter()
  }
 
  field (config: Partial<FieldConfig>): LiveOnAirSceneConfigure
 
  field (): Readonly<FieldConfig>
 
  field (args?: Partial<FieldConfig>): LiveOnAirSceneConfigure | Readonly<FieldConfig> {
    if (args) {
      this.fieldSetter(args)
      return this
    }
    return this.fieldGetter()
  }
 
  broadcaster (config: Partial<BroadcasterConfig>): LiveOnAirSceneConfigure
 
  broadcaster (): Readonly<BroadcasterConfig>
 
  broadcaster (args?: Partial<BroadcasterConfig>): LiveOnAirSceneConfigure | Readonly<BroadcasterConfig> {
    if (args) {
      this.broadcasterSetter(args)
      return this
    }
    return this.broadcasterGetter()
  }
 
  screen (config: Partial<ScreenConfig>): LiveOnAirSceneConfigure
 
  screen (): Readonly<ScreenConfig>
 
  screen (args?: Partial<ScreenConfig>): LiveOnAirSceneConfigure | Readonly<ScreenConfig> {
    if (args) {
      this.screenSetter(args)
      return this
    }
    return this.screenGetter()
  }
 
  liveContext (config: Partial<LiveContextConfig>): LiveOnAirSceneConfigure
 
  liveContext (): Readonly<LiveContextConfig>
 
  liveContext (args?: Partial<LiveContextConfig>): LiveOnAirSceneConfigure | Readonly<LiveContextConfig> {
    if (args) {
      this.liveContextSetter(args)
      return this
    }
    return this.liveContextGetter()
  }
 
  spot (config: Partial<SpotConfig>): LiveOnAirSceneConfigure
 
  spot (): readonly SpotConfig[]
 
  spot (args?: Partial<SpotConfig>): LiveOnAirSceneConfigure | readonly SpotConfig[] {
    if (args) {
      if (!this.isDefault) {
        const spotConfig = new SpotConfigSupplier(this.spotConfig.default())
        spotConfig.setIf(args)
        this.spotConfigs.push(spotConfig)
      } else {
        this.spotConfig.defaultIf(args)
      }
      return this
    }
    return this.isDefault ? [this.spotConfig.default()] : [...this.spotConfigs.map(config => config.get())]
  }
 
  commentContext (config: Partial<CommentContextConfig>): LiveOnAirSceneConfigure
 
  commentContext (): Readonly<CommentContextConfig>
 
  commentContext (args?: Partial<CommentContextConfig>): LiveOnAirSceneConfigure | Readonly<CommentContextConfig> {
    if (args) {
      this.commentContextSetter(args)
      return this
    }
    return this.commentContextGetter()
  }
 
  commentSupplier (config: Partial<CommentSupplierConfig>): LiveOnAirSceneConfigure
 
  commentSupplier (): Readonly<CommentSupplierConfig>
 
  commentSupplier (args?: Partial<CommentSupplierConfig>): LiveOnAirSceneConfigure | Readonly<CommentSupplierConfig> {
    if (args) {
      this.commentSupplierSetter(args)
      return this
    }
    return this.commentSupplierGetter()
  }
 
  commentDeployer (config: Partial<CommentDeployerConfig>): LiveOnAirSceneConfigure
 
  commentDeployer (): Readonly<CommentDeployerConfig>
 
  commentDeployer (args?: Partial<CommentDeployerConfig>): LiveOnAirSceneConfigure | Readonly<CommentDeployerConfig> {
    if (args) {
      this.commentDeployerSetter(args)
      return this
    }
    return this.commentDeployerGetter()
  }
 
  scorer (config: Partial<ScorerConfig>): LiveOnAirSceneConfigure
 
  scorer (): Readonly<ScorerConfig>
 
  scorer (args?: Partial<ScorerConfig>): LiveOnAirSceneConfigure | Readonly<ScorerConfig> {
    if (args) {
      this.scorerSetter(args)
      return this
    }
    return this.scorerGetter()
  }
 
  ticker (config: Partial<TickerConfig>): LiveOnAirSceneConfigure
 
  ticker (): Readonly<TickerConfig>
 
  ticker (args?: Partial<TickerConfig>): LiveOnAirSceneConfigure | Readonly<TickerConfig> {
    if (args) {
      this.tickerSetter(args)
      return this
    }
    return this.tickerGetter()
  }
 
  /**
   * 指定された設定で {@link LiveOnAirScene} を作成します.
   */
  build (): LiveOnAirScene & g.Scene {
    return new LiveOnAirSceneImpl({ game: this.game, layer: this.layer(), field: this.field(), broadcaster: this.broadcaster(), spots: this.spot(), commentContext: this.commentContext(), commentSupplier: this.commentSupplier(), commentDeployer: this.commentDeployer(), screen: this.screen(), liveContext: this.liveContext(), scorer: this.scorer(), ticker: this.ticker() })
  }
}