This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
"use strict";
var core = require("@pixi/core");
require("../utils/index.js");
var convertToList = require("../utils/convertToList.js");
class CacheClass {
constructor() {
this._parsers = [], this._cache = /* @__PURE__ */ new Map(), this._cacheMap = /* @__PURE__ */ new Map();
}
/** Clear all entries. */
reset() {
this._cacheMap.clear(), this._cache.clear();
}
/**
* Check if the key exists
* @param key - The key to check
*/
has(key) {
return this._cache.has(key);
}
/**
* Fetch entry by key
* @param key - The key of the entry to get
*/
get(key) {
const result = this._cache.get(key);
return result || console.warn(`[Assets] Asset id ${key} was not found in the Cache`), result;
}
/**
* Set a value by key or keys name
* @param key - The key or keys to set
* @param value - The value to store in the cache or from which cacheable assets will be derived.
*/
set(key, value) {
const keys = convertToList.convertToList(key);
let cacheableAssets;
for (let i = 0; i < this.parsers.length; i++) {
const parser = this.parsers[i];
if (parser.test(value)) {
cacheableAssets = parser.getCacheableAssets(keys, value);
break;
}
}
cacheableAssets || (cacheableAssets = {}, keys.forEach((key2) => {
cacheableAssets[key2] = value;
}));
const cacheKeys = Object.keys(cacheableAssets), cachedAssets = {
cacheKeys,
keys
};
if (keys.forEach((key2) => {
this._cacheMap.set(key2, cachedAssets);
}), cacheKeys.forEach((key2) => {
this._cache.has(key2) && this._cache.get(key2) !== value && console.warn("[Cache] already has key:", key2), this._cache.set(key2, cacheableAssets[key2]);
}), value instanceof core.Texture) {
const texture = value;
keys.forEach((key2) => {
texture.baseTexture !== core.Texture.EMPTY.baseTexture && core.BaseTexture.addToCache(texture.baseTexture, key2), core.Texture.addToCache(texture, key2);
});
}
}
/**
* Remove entry by key
*
* This function will also remove any associated alias from the cache also.
* @param key - The key of the entry to remove
*/
remove(key) {
if (!this._cacheMap.has(key)) {
console.warn(`[Assets] Asset id ${key} was not found in the Cache`);
return;
}
const cacheMap = this._cacheMap.get(key);
cacheMap.cacheKeys.forEach((key2) => {
this._cache.delete(key2);
}), cacheMap.keys.forEach((key2) => {
this._cacheMap.delete(key2);
});
}
/** All loader parsers registered */
get parsers() {
return this._parsers;
}
}
const Cache = new CacheClass();
exports.Cache = Cache;
//# sourceMappingURL=Cache.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,87 @@
import { Texture, BaseTexture } from "@pixi/core";
import "../utils/index.mjs";
import { convertToList } from "../utils/convertToList.mjs";
class CacheClass {
constructor() {
this._parsers = [], this._cache = /* @__PURE__ */ new Map(), this._cacheMap = /* @__PURE__ */ new Map();
}
/** Clear all entries. */
reset() {
this._cacheMap.clear(), this._cache.clear();
}
/**
* Check if the key exists
* @param key - The key to check
*/
has(key) {
return this._cache.has(key);
}
/**
* Fetch entry by key
* @param key - The key of the entry to get
*/
get(key) {
const result = this._cache.get(key);
return result || console.warn(`[Assets] Asset id ${key} was not found in the Cache`), result;
}
/**
* Set a value by key or keys name
* @param key - The key or keys to set
* @param value - The value to store in the cache or from which cacheable assets will be derived.
*/
set(key, value) {
const keys = convertToList(key);
let cacheableAssets;
for (let i = 0; i < this.parsers.length; i++) {
const parser = this.parsers[i];
if (parser.test(value)) {
cacheableAssets = parser.getCacheableAssets(keys, value);
break;
}
}
cacheableAssets || (cacheableAssets = {}, keys.forEach((key2) => {
cacheableAssets[key2] = value;
}));
const cacheKeys = Object.keys(cacheableAssets), cachedAssets = {
cacheKeys,
keys
};
if (keys.forEach((key2) => {
this._cacheMap.set(key2, cachedAssets);
}), cacheKeys.forEach((key2) => {
this._cache.has(key2) && this._cache.get(key2) !== value && console.warn("[Cache] already has key:", key2), this._cache.set(key2, cacheableAssets[key2]);
}), value instanceof Texture) {
const texture = value;
keys.forEach((key2) => {
texture.baseTexture !== Texture.EMPTY.baseTexture && BaseTexture.addToCache(texture.baseTexture, key2), Texture.addToCache(texture, key2);
});
}
}
/**
* Remove entry by key
*
* This function will also remove any associated alias from the cache also.
* @param key - The key of the entry to remove
*/
remove(key) {
if (!this._cacheMap.has(key)) {
console.warn(`[Assets] Asset id ${key} was not found in the Cache`);
return;
}
const cacheMap = this._cacheMap.get(key);
cacheMap.cacheKeys.forEach((key2) => {
this._cache.delete(key2);
}), cacheMap.keys.forEach((key2) => {
this._cacheMap.delete(key2);
});
}
/** All loader parsers registered */
get parsers() {
return this._parsers;
}
}
const Cache = new CacheClass();
export {
Cache
};
//# sourceMappingURL=Cache.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=CacheParser.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CacheParser.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,2 @@
//# sourceMappingURL=CacheParser.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CacheParser.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,6 @@
"use strict";
var Cache = require("./Cache.js");
require("./CacheParser.js");
require("./parsers/index.js");
exports.Cache = Cache.Cache;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}

View File

@@ -0,0 +1,7 @@
import { Cache } from "./Cache.mjs";
import "./CacheParser.mjs";
import "./parsers/index.mjs";
export {
Cache
};
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}

View File

@@ -0,0 +1,17 @@
"use strict";
var core = require("@pixi/core");
const cacheTextureArray = {
extension: core.ExtensionType.CacheParser,
test: (asset) => Array.isArray(asset) && asset.every((t) => t instanceof core.Texture),
getCacheableAssets: (keys, asset) => {
const out = {};
return keys.forEach((key) => {
asset.forEach((item, i) => {
out[key + (i === 0 ? "" : i + 1)] = item;
});
}), out;
}
};
core.extensions.add(cacheTextureArray);
exports.cacheTextureArray = cacheTextureArray;
//# sourceMappingURL=cacheTextureArray.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cacheTextureArray.js","sources":["../../../src/cache/parsers/cacheTextureArray.ts"],"sourcesContent":["import { extensions, ExtensionType, Texture } from '@pixi/core';\n\nimport type { CacheParser } from '../CacheParser';\n\nexport const cacheTextureArray: CacheParser<Texture[]> = {\n extension: ExtensionType.CacheParser,\n\n test: (asset: any[]) => Array.isArray(asset) && asset.every((t) => t instanceof Texture),\n\n getCacheableAssets: (keys: string[], asset: Texture[]) =>\n {\n const out: Record<string, Texture> = {};\n\n keys.forEach((key: string) =>\n {\n asset.forEach((item: Texture, i: number) =>\n {\n out[key + (i === 0 ? '' : i + 1)] = item;\n });\n });\n\n return out;\n }\n};\n\nextensions.add(cacheTextureArray);\n"],"names":["ExtensionType","Texture","extensions"],"mappings":";;AAIO,MAAM,oBAA4C;AAAA,EACrD,WAAWA,KAAc,cAAA;AAAA,EAEzB,MAAM,CAAC,UAAiB,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM,CAAC,MAAM,aAAaC,KAAAA,OAAO;AAAA,EAEvF,oBAAoB,CAAC,MAAgB,UACrC;AACI,UAAM,MAA+B,CAAA;AAEhC,WAAA,KAAA,QAAQ,CAAC,QACd;AACU,YAAA,QAAQ,CAAC,MAAe,MAC9B;AACI,YAAI,OAAO,MAAM,IAAI,KAAK,IAAI,EAAE,IAAI;AAAA,MAAA,CACvC;AAAA,IACJ,CAAA,GAEM;AAAA,EACX;AACJ;AAEAC,KAAAA,WAAW,IAAI,iBAAiB;;"}

View File

@@ -0,0 +1,18 @@
import { ExtensionType, Texture, extensions } from "@pixi/core";
const cacheTextureArray = {
extension: ExtensionType.CacheParser,
test: (asset) => Array.isArray(asset) && asset.every((t) => t instanceof Texture),
getCacheableAssets: (keys, asset) => {
const out = {};
return keys.forEach((key) => {
asset.forEach((item, i) => {
out[key + (i === 0 ? "" : i + 1)] = item;
});
}), out;
}
};
extensions.add(cacheTextureArray);
export {
cacheTextureArray
};
//# sourceMappingURL=cacheTextureArray.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cacheTextureArray.mjs","sources":["../../../src/cache/parsers/cacheTextureArray.ts"],"sourcesContent":["import { extensions, ExtensionType, Texture } from '@pixi/core';\n\nimport type { CacheParser } from '../CacheParser';\n\nexport const cacheTextureArray: CacheParser<Texture[]> = {\n extension: ExtensionType.CacheParser,\n\n test: (asset: any[]) => Array.isArray(asset) && asset.every((t) => t instanceof Texture),\n\n getCacheableAssets: (keys: string[], asset: Texture[]) =>\n {\n const out: Record<string, Texture> = {};\n\n keys.forEach((key: string) =>\n {\n asset.forEach((item: Texture, i: number) =>\n {\n out[key + (i === 0 ? '' : i + 1)] = item;\n });\n });\n\n return out;\n }\n};\n\nextensions.add(cacheTextureArray);\n"],"names":[],"mappings":";AAIO,MAAM,oBAA4C;AAAA,EACrD,WAAW,cAAc;AAAA,EAEzB,MAAM,CAAC,UAAiB,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM,CAAC,MAAM,aAAa,OAAO;AAAA,EAEvF,oBAAoB,CAAC,MAAgB,UACrC;AACI,UAAM,MAA+B,CAAA;AAEhC,WAAA,KAAA,QAAQ,CAAC,QACd;AACU,YAAA,QAAQ,CAAC,MAAe,MAC9B;AACI,YAAI,OAAO,MAAM,IAAI,KAAK,IAAI,EAAE,IAAI;AAAA,MAAA,CACvC;AAAA,IACJ,CAAA,GAEM;AAAA,EACX;AACJ;AAEA,WAAW,IAAI,iBAAiB;"}

View File

@@ -0,0 +1,4 @@
"use strict";
var cacheTextureArray = require("./cacheTextureArray.js");
exports.cacheTextureArray = cacheTextureArray.cacheTextureArray;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}

View File

@@ -0,0 +1,5 @@
import { cacheTextureArray } from "./cacheTextureArray.mjs";
export {
cacheTextureArray
};
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}