Updated Oversimplified.CopyObject() to allow passing options object to override any GameObject properties.
This commit is contained in:
parent
434d7e411e
commit
33eecd7cc7
|
@ -559,12 +559,13 @@ Oversimplified.Room.prototype.Draw = function () {
|
||||||
|
|
||||||
// Add a GameObject or PremadeObject to the room.
|
// Add a GameObject or PremadeObject to the room.
|
||||||
Oversimplified.Room.prototype.AddObject = function (newObjectName, newObjectOptions) {
|
Oversimplified.Room.prototype.AddObject = function (newObjectName, newObjectOptions) {
|
||||||
|
newObjectOptions = (typeof newObjectOptions !== 'undefined') ? newObjectOptions : {};
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (newObjectName.type == "GameObject") { //Create from prefabricated object
|
if (newObjectName.type == "GameObject") { //Create from prefabricated object
|
||||||
var newID = Oversimplified.nextID++;
|
var newID = Oversimplified.nextID++;
|
||||||
var newName = newObjectName.name + newID.toString();
|
var newName = newObjectName.name + newID.toString();
|
||||||
self.objects[newName] = Oversimplified.CopyObject(newObjectName, newID, newName);
|
self.objects[newName] = Oversimplified.CopyObject(newObjectName, newID, newName, newObjectOptions);
|
||||||
|
|
||||||
return self.objects[newName];
|
return self.objects[newName];
|
||||||
}
|
}
|
||||||
|
@ -1256,7 +1257,7 @@ Oversimplified.CreateObject = function (newObjectName, x, y, imageSrc, maskImage
|
||||||
newID and newName are optional. If excluded, they are auto-populated with the next id value and the original object's name.
|
newID and newName are optional. If excluded, they are auto-populated with the next id value and the original object's name.
|
||||||
Use "identical" to copy name and id of original object.
|
Use "identical" to copy name and id of original object.
|
||||||
*/
|
*/
|
||||||
Oversimplified.CopyObject = function (object, newID, newName) {
|
Oversimplified.CopyObject = function (object, newID, newName, objectOptions) {
|
||||||
var resultingCopy = {};
|
var resultingCopy = {};
|
||||||
if (newID != "identical") {
|
if (newID != "identical") {
|
||||||
resultingCopy.id = typeof newID !== 'undefined' ? newID : Oversimplified.nextID++;
|
resultingCopy.id = typeof newID !== 'undefined' ? newID : Oversimplified.nextID++;
|
||||||
|
@ -1293,6 +1294,10 @@ Oversimplified.CopyObject = function (object, newID, newName) {
|
||||||
resultingCopy[property] = object[property];
|
resultingCopy[property] = object[property];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (var option in objectOptions) {
|
||||||
|
//Overwrite any properties.
|
||||||
|
resultingCopy[option] = objectOptions[option];
|
||||||
|
}
|
||||||
|
|
||||||
return resultingCopy;
|
return resultingCopy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue