MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / constructor

Method constructor

src/actions/Play.ts:206–240  ·  view source on GitHub ↗
([action, type, media, ...props]: string[])

Source from the content-addressed store, hash-verified

204 player: any;
205
206 constructor([action, type, media, ...props]: string[]) {
207 super();
208 this.type = type as MediaType;
209 this.media = '';
210
211 if (this.type === 'music') {
212 this.directory = this.type;
213 } else {
214 // Directories are always plural so we need to add an "s"
215 this.directory = this.type + 's';
216 }
217
218 this.mediaKey = media;
219 this.props = props;
220
221 const volumeSettings = this.engine.preference('Volume') as Record<string, number>;
222
223 this.mediaVolume = volumeSettings[Text.capitalize(this.type)];
224
225 // Check if a media was defined or just a `play music` was stated
226 if (typeof media !== 'undefined' && media !== 'with') {
227 if (typeof this.engine.asset(this.directory, media) !== 'undefined') {
228 this.media = this.engine.asset(this.directory, media) as string;
229 } else {
230 this.media = media;
231 }
232
233 const player = this.engine.mediaPlayer(this.type, this.mediaKey);
234
235 // We'll create the player in the apply method since it's async
236 this.player = typeof player === 'undefined' ? null : player;
237 } else {
238 this.player = this.engine.mediaPlayers(this.type);
239 }
240 }
241
242 async createAudioPlayer(paused = false, volume = 1): Promise<any> {
243 const audioContext = this.engine.audioContext!;

Callers

nothing calls this directly

Calls 4

preferenceMethod · 0.80
assetMethod · 0.80
mediaPlayerMethod · 0.80
mediaPlayersMethod · 0.80

Tested by

no test coverage detected