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 | 22x 119x 119x 119x 119x 68x 1x 67x 35x 1x 34x 1x 33x 1x 32x 32x 32x 32x 32x 32x 10x 9x 10x 10x 10x 32x 3x 22x 22x 21x 21x 21x 21x 1x 7x 5x 2x 5x | import { Spot } from './spot' import { Live } from './live' import { Broadcaster } from './broadcaster' import { LiveContext } from './liveContext' /** * {@link Broadcaster} が {@link Spot} を訪問すると開始される 生放送 ({@link Live}) を * 画面に描画します. * * {@link ScreenBuilder} を使ってインスタンスを作成してください. */ export interface Screen { /** * 生放送が始まった際に発火するトリガ. */ readonly onLiveStart: g.Trigger<Live> /** * 生放送スクリーンの領域座標. * * {@link container} に値が登録されているとき値を返します. */ readonly area?: Readonly<g.CommonArea> /** * 現在放送中の Live インスタンスを取得します. * * 放送中でない場合 undefined を返します. */ readonly nowOnAir?: Live /** * Live を描画するエンティティ. * * 生放送時の描画内容は本エンティティの子に格納されます. */ container?: g.E /** * Live を開始する際、この値でデフォルトの LiveContext に上書きします. */ customLiveContext?: Partial<LiveContext> /** * ライブラリ利用者が自由に使えるフィールドです. */ vars?: unknown /** * Spot を登録します. * * @param spot 訪問時に生放送を開始するスポット */ addSpot (spot: Spot): void /** * Broadcaster が Spot を訪問したため、登録された生放送を開始します. * * Broadcaster は Spot に滞在している必要があります. * * 本メソッドは Spot 到着時に自動で呼び出されるため、 * ライブラリ利用者が実行する必要はありません. * * @param broadcaster Spot を訪問した Broadcaster * @internal */ startLive (broadcaster: Broadcaster): void } export interface ScreenOptions { scene: g.Scene vars: unknown } export class ScreenImpl implements Screen { readonly onLiveStart = new g.Trigger<Live>() vars?: unknown private readonly scene: g.Scene private _container?: g.E private readonly _view: g.E private _now?: Live private _customLiveContext?: Partial<LiveContext> constructor ({ scene, vars }: ScreenOptions) { this.scene = scene this._view = new g.E({ scene }) this.vars = vars } addSpot (spot: Spot): void { if (spot.screen && spot.screen !== this) { throw new Error('指定されたspotにはすでに他のscreenが登録されています. screenが未登録なspotを指定してください') } spot.attach(this) } startLive (broadcaster: Broadcaster): void { if (!broadcaster.field) { throw new Error('broadcasterがfield上に配置されていません. broadcasterをfieldに配置してから実行してください') } if (!broadcaster.staying) { throw new Error('broadcasterが放送準備ができていません. broadcasterがspotに到着してから実行してください') } if (broadcaster.live || this._now) { throw new Error('放送中にもかかわらず、新規放送を開始しようとしました. 放送終了後に実行してください') } const liveContainer = new g.E({ scene: this.scene, parent: this._view, width: this._view.width, height: this._view.height }) const context: LiveContext = { scene: this.scene, screen: this, field: broadcaster.field, spot: broadcaster.staying, broadcaster, container: liveContainer, vars: undefined, ...(this._customLiveContext ?? {}) } const live = new (broadcaster.staying.liveClass!)() this._now = live broadcaster.goToLive(live) live.start(context, () => { if (!live.satisfiesUnlockSpotCondition || live.satisfiesUnlockSpotCondition()) { context.field.unlock(context.spot) } this._now = undefined liveContainer.destroy() broadcaster.backFromLive() }) this.onLiveStart.fire(live) } get container (): g.E | undefined { return this._container } set container (view: g.E | undefined) { this._container = view if (this._container) { this._view.width = this._container.width this._view.height = this._container.height this._view.modified() this._container.append(this._view) } else { this._view.remove() } } get nowOnAir (): Live | undefined { return this._now } get area (): Readonly<g.CommonArea> | undefined { return this._container ? { x: this._container.x, y: this._container.y, width: this._container.width, height: this._container.height } : undefined } get customLiveContext (): Partial<LiveContext> | undefined { return this._customLiveContext } set customLiveContext (value: Partial<LiveContext>) { this._customLiveContext = value } } |