|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2018 Photon Storm Ltd. |
| 4 | + * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +var AudioFile = require('./AudioFile.js'); |
| 8 | +var Class = require('../../utils/Class'); |
| 9 | +var FileTypesManager = require('../FileTypesManager'); |
| 10 | +var GetFastValue = require('../../utils/object/GetFastValue'); |
| 11 | +var IsPlainObject = require('../../utils/object/IsPlainObject'); |
| 12 | +var JSONFile = require('./JSONFile.js'); |
| 13 | +var LinkFile = require('../LinkFile.js'); |
| 14 | + |
| 15 | +/** |
| 16 | + * @classdesc |
| 17 | + * An Audio Sprite JSON File. |
| 18 | + * |
| 19 | + * @class AudioSpriteFile |
| 20 | + * @extends Phaser.Loader.LinkFile |
| 21 | + * @memberOf Phaser.Loader.FileTypes |
| 22 | + * @constructor |
| 23 | + * @since 3.7.0 |
| 24 | + * |
| 25 | + * @param {string} key - The key of the file within the loader. |
| 26 | + * @param {string} textureURL - The url to load the texture file from. |
| 27 | + * @param {string} atlasURL - The url to load the atlas file from. |
| 28 | + * @param {string} path - The path of the file. |
| 29 | + * @param {XHRSettingsObject} [textureXhrSettings] - Optional texture file specific XHR settings. |
| 30 | + * @param {XHRSettingsObject} [atlasXhrSettings] - Optional atlas file specific XHR settings. |
| 31 | + */ |
| 32 | +var AudioSpriteFile = new Class({ |
| 33 | + |
| 34 | + Extends: LinkFile, |
| 35 | + |
| 36 | + initialize: |
| 37 | + |
| 38 | + function AudioSpriteFile (loader, key, urls, json, config, audioXhrSettings, jsonXhrSettings) |
| 39 | + { |
| 40 | + if (IsPlainObject(key)) |
| 41 | + { |
| 42 | + var config = key; |
| 43 | + |
| 44 | + // key = GetFastValue(config, 'key'); |
| 45 | + // URLs = GetFastValue(config, 'urls'); |
| 46 | + // json = GetFastValue(config, 'json'); |
| 47 | + // atlasURL = GetFastValue(config, 'atlasURL'); |
| 48 | + // textureXhrSettings = GetFastValue(config, 'textureXhrSettings'); |
| 49 | + // atlasXhrSettings = GetFastValue(config, 'atlasXhrSettings'); |
| 50 | + } |
| 51 | + |
| 52 | + var audio = AudioFile.create(loader, key, urls, config, audioXhrSettings) |
| 53 | + var data = new JSONFile(loader, key, json, jsonXhrSettings); |
| 54 | + |
| 55 | + LinkFile.call(this, loader, 'audiosprite', key, [ audio, data ]); |
| 56 | + }, |
| 57 | + |
| 58 | + addToCache: function () |
| 59 | + { |
| 60 | + if (this.isReadyToProcess()) |
| 61 | + { |
| 62 | + var fileA = this.files[0]; |
| 63 | + var fileB = this.files[1]; |
| 64 | + |
| 65 | + /* |
| 66 | + if (fileA.type === 'image') |
| 67 | + { |
| 68 | + this.loader.textureManager.addAtlas(fileA.key, fileA.data, fileB.data); |
| 69 | + fileB.addToCache(); |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + this.loader.textureManager.addAtlas(fileB.key, fileB.data, fileA.data); |
| 74 | + fileA.addToCache(); |
| 75 | + } |
| 76 | + */ |
| 77 | + |
| 78 | + this.complete = true; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | +}); |
| 83 | + |
| 84 | +/** |
| 85 | + * Adds an Audio Sprite file to the current load queue. |
| 86 | + * |
| 87 | + * Note: This method will only be available if the Audio Sprite File type has been built into Phaser. |
| 88 | + * |
| 89 | + * The file is **not** loaded immediately after calling this method. |
| 90 | + * Instead, the file is added to a queue within the Loader, which is processed automatically when the Loader starts. |
| 91 | + * |
| 92 | + * @method Phaser.Loader.LoaderPlugin#audioSprite |
| 93 | + * @since 3.0.0 |
| 94 | + * |
| 95 | + * @param {string} key - [description] |
| 96 | + * @param {(string|string[])} urls - [description] |
| 97 | + * @param {object} json - [description] |
| 98 | + * @param {object} config - [description] |
| 99 | + * @param {XHRSettingsObject} [audioXhrSettings] - Optional file specific XHR settings. |
| 100 | + * @param {XHRSettingsObject} [jsonXhrSettings] - Optional file specific XHR settings. |
| 101 | + * |
| 102 | + * @return {Phaser.Loader.LoaderPlugin} The Loader. |
| 103 | + */ |
| 104 | +FileTypesManager.register('audioSprite', function (key, urls, json, config, audioXhrSettings, jsonXhrSettings) |
| 105 | +{ |
| 106 | + var linkfile; |
| 107 | + |
| 108 | + // Supports an Object file definition in the key argument |
| 109 | + // Or an array of objects in the key argument |
| 110 | + // Or a single entry where all arguments have been defined |
| 111 | + |
| 112 | + if (Array.isArray(key)) |
| 113 | + { |
| 114 | + for (var i = 0; i < key.length; i++) |
| 115 | + { |
| 116 | + linkfile = new AudioSpriteFile(this, key[i]); |
| 117 | + |
| 118 | + this.addFile(linkfile.files); |
| 119 | + } |
| 120 | + } |
| 121 | + else |
| 122 | + { |
| 123 | + linkfile = new AudioSpriteFile(this, key, urls, json, config, audioXhrSettings, jsonXhrSettings); |
| 124 | + |
| 125 | + this.addFile(linkfile.files); |
| 126 | + } |
| 127 | + |
| 128 | + return this; |
| 129 | + |
| 130 | + /* |
| 131 | + var audioFile = AudioFile.create(this, key, urls, config, audioXhrSettings); |
| 132 | +
|
| 133 | + if (audioFile) |
| 134 | + { |
| 135 | + var jsonFile; |
| 136 | +
|
| 137 | + if (typeof json === 'string') |
| 138 | + { |
| 139 | + jsonFile = new JSONFile(this, key, json, jsonXhrSettings); |
| 140 | +
|
| 141 | + this.addFile(jsonFile); |
| 142 | + } |
| 143 | + else |
| 144 | + { |
| 145 | + jsonFile = { |
| 146 | + type: 'json', |
| 147 | + key: key, |
| 148 | + data: json, |
| 149 | + state: CONST.FILE_WAITING_LINKFILE |
| 150 | + }; |
| 151 | + } |
| 152 | +
|
| 153 | + // Link them together |
| 154 | + audioFile.linkFile = jsonFile; |
| 155 | + jsonFile.linkFile = audioFile; |
| 156 | +
|
| 157 | + // Set the type |
| 158 | + audioFile.linkType = 'audioSprite'; |
| 159 | + jsonFile.linkType = 'audioSprite'; |
| 160 | +
|
| 161 | + this.addFile(audioFile); |
| 162 | + } |
| 163 | +
|
| 164 | + return this; |
| 165 | + */ |
| 166 | +}); |
0 commit comments