Skip to content

Commit

Permalink
🔥 Remove ct.types.make; replace it with ct.types.copy and ct.types.co…
Browse files Browse the repository at this point in the history
…pyIntoRoom. Add aggressive checks for the target room.
  • Loading branch information
CosmoMyzrailGorynych committed Dec 22, 2021
1 parent 6e7204f commit dbad7e3
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions app/data/ct.release/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,33 +272,39 @@ const Copy = (function Copy() {
*/
templates: { },
/**
* Creates a new copy of a given type.
* Creates a new copy of a given type inside a specific room.
* @param {string} type The name of the type to use
* @param {number} [x] The x coordinate of a new copy. Defaults to 0.
* @param {number} [y] The y coordinate of a new copy. Defaults to 0.
* @param {Room} [room] The room to which add the copy.
* Defaults to the current room.
* @param {object} [exts] An optional object which parameters will be applied
* to the copy prior to its OnCreate event.
* @param {PIXI.Container} [container] The container to which add the copy.
* Defaults to the current room.
* @returns {Copy} the created copy.
* @alias ct.types.copy
*/
make(type, x = 0, y = 0, exts, container) {
copyIntoRoom(type, x = 0, y = 0, room, exts) {
// An advanced constructor. Returns a Copy
if (exts instanceof PIXI.Container) {
container = exts;
exts = void 0;
if (!room || !(room instanceof Room)) {
throw new Error(`Attempt to spawn a copy of type ${type} inside an invalid room. Room's value provided: ${room}`);
}
const obj = new Copy(type, x, y, exts);
if (container) {
container.addChild(obj);
} else {
ct.room.addChild(obj);
}
room.addChild(obj);
ct.stack.push(obj);
onCreateModifier.apply(obj);
return obj;
},
/**
* Creates a new copy of a given type inside the current root room.
* A shorthand for `ct.types.copyIntoRoom(type, x, y, ct.room, exts)`
* @param {string} type The name of the type to use
* @param {number} [x] The x coordinate of a new copy. Defaults to 0.
* @param {number} [y] The y coordinate of a new copy. Defaults to 0.
* @param {object} [exts] An optional object which parameters will be applied
* to the copy prior to its OnCreate event.
*/
copy(type, x = 0, y = 0, exts) {
ct.types.copyIntoRoom(type, x, y, ct.room, exts);
},
/**
* Applies a function to each copy in the current room
* @param {Function} func The function to apply
Expand Down Expand Up @@ -355,7 +361,6 @@ const Copy = (function Copy() {
return obj instanceof Copy;
}
};
ct.types.copy = ct.types.make;
ct.types.addSpd = ct.types.addSpeed;

/*@types@*/
Expand Down

0 comments on commit dbad7e3

Please sign in to comment.