* Register an object to the pool. * Pooling must be set to true if more than one such objects will be created. * (Note: for an object to be poolable, it must implement an `onResetEvent` method) * Registered classes are also automatically available as Tiled object factories,
(className, classObj, recycling = false)
| 76 | * me.pool.register("cherrysprite", Cherry, true); |
| 77 | */ |
| 78 | register(className, classObj, recycling = false) { |
| 79 | if (typeof classObj !== "undefined") { |
| 80 | const entry = { |
| 81 | class: classObj, |
| 82 | pool: recycling ? [] : undefined, |
| 83 | }; |
| 84 | this.objectClass[className] = entry; |
| 85 | // also register with "me." prefix for backward compatibility |
| 86 | if (!className.startsWith("me.")) { |
| 87 | this.objectClass["me." + className] = entry; |
| 88 | } |
| 89 | // also register as a Tiled object factory |
| 90 | if (this.autoRegisterTiled && typeof onRegisterCallback === "function") { |
| 91 | onRegisterCallback(className, classObj, this); |
| 92 | // also register with "me." prefix for backward compatibility |
| 93 | if (!className.startsWith("me.")) { |
| 94 | onRegisterCallback("me." + className, classObj, this); |
| 95 | } |
| 96 | } |
| 97 | } else { |
| 98 | throw new Error( |
| 99 | "Cannot register object '" + className + "', invalid class", |
| 100 | ); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Pull a new instance of the requested object (if added into the object pool) |
no outgoing calls
no test coverage detected