123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- const AssetHandler = {
- cachedTextures: [],
- cachedAudio: [],
- cachedFonts: [],
- loadTexture: function(name, link)
- {
- let textRes = new TextureRes(name, null);
- this.cachedTextures.push(textRes);
- loadImage(link, img =>
- {
- textRes.P5Image = img;
- });
- },
- getTextureByName: function(name)
- {
- for (let i = 0; i < this.cachedTextures.length; i++)
- {
- if (this.cachedTextures[i].name == name)
- {
- return this.cachedTextures[i];
- }
- }
- return null;
- },
- getP5ImageByName: function(name)
- {
- for (let i = 0; i < this.cachedTextures.length; i++)
- {
- if (this.cachedTextures[i].name == name)
- {
- return this.cachedTextures[i].P5Image;
- }
- }
- return null;
- },
- loadAudio: function(name, link)
- {
- let audio = createAudio(link);
- this.cachedAudio.push(new AudioRes(name, audio));
- },
- getAudioByName: function(name)
- {
- for (let i = 0; i < this.cachedAudio.length; i++)
- {
- if (this.cachedAudio[i].name == name)
- {
- return this.cachedAudio[i];
- }
- }
- return null;
- },
- getP5AudioByName: function(name)
- {
- for (let i = 0; i < this.cachedAudio.length; i++)
- {
- if (this.cachedAudio[i].name == name)
- {
- return this.cachedAudio[i].P5Audio;
- }
- }
- return null;
- },
- loadFont: function(name, link)
- {
- let fontRes = new FontRes(name, null);
- this.cachedFonts.push(fontRes);
- loadFont(link, font =>
- {
- fontRes.P5Font = font;
- })
- },
- getFontByName: function(name)
- {
- for (let i = 0; i < this.cachedFonts.length; i++)
- {
- if (this.cachedFonts[i].name == name)
- {
- return this.cachedFonts[i];
- }
- }
- return null;
- },
- getP5FontByName: function(name)
- {
- for (let i = 0; i < this.cachedFonts.length; i++)
- {
- if (this.cachedFonts[i].name == name)
- {
- return this.cachedFonts[i].P5Font;
- }
- }
- return null;
- }
- };
|