MCPcopy Create free account
hub / github.com/melonjs/melonJS / constructor

Method constructor

packages/spine-plugin/src/AssetManager.js:17–62  ·  view source on GitHub ↗

* @param {CanvasRenderer|WebGLRenderer} renderer - a melonJS renderer instance * @param {string} [pathPrefix=""] - a default path prefix for assets location

(renderer, pathPrefix = "")

Source from the content-addressed store, hash-verified

15 * @param {string} [pathPrefix=""] - a default path prefix for assets location
16 */
17 constructor(renderer, pathPrefix = "") {
18 /**
19 * the underlying Spine asset manager
20 * @ignore
21 */
22 this.spineAssetManager =
23 renderer.WebGLVersion >= 1
24 ? new spineWebGL.AssetManager(
25 // the shared canvas-backed managed context, so loaded
26 // GLTextures survive a WebGL context loss
27 getManagedContext(renderer.getCanvas()),
28 pathPrefix,
29 )
30 : new spineCanvas.AssetManager(pathPrefix);
31
32 // register the spine custom parser with the melonJS loader
33 loader.setParser("spine", (data, onload, onerror) => {
34 const ext = utils.file.getExtension(data.src);
35 const basename = utils.file.getBasename(data.src);
36 const path = data.src.substring(0, data.src.lastIndexOf("/") + 1);
37 const filename = `${basename}.${ext}`;
38
39 this.setPrefix(path);
40
41 switch (ext) {
42 case "atlas":
43 this.loadTextureAtlas(filename, onload, onerror);
44 break;
45 case "json":
46 this.loadText(filename, onload, onerror);
47 break;
48 case "skel":
49 this.loadBinary(filename, onload, onerror);
50 break;
51 default:
52 if (onerror) {
53 onerror(
54 `Spine plugin: unknown extension "${ext}" when preloading spine assets`,
55 );
56 }
57 return 0;
58 }
59
60 return 1;
61 });
62 }
63
64 /**
65 * Set a default path prefix for assets location.

Callers

nothing calls this directly

Calls 6

setPrefixMethod · 0.95
loadTextureAtlasMethod · 0.95
loadTextMethod · 0.95
loadBinaryMethod · 0.95
getManagedContextFunction · 0.90
getCanvasMethod · 0.80

Tested by

no test coverage detected