From 33eecd7cc737cd5a93d3546c58c410b05fa77b07 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Wed, 13 Apr 2016 23:18:29 -0600 Subject: [PATCH] Updated Oversimplified.CopyObject() to allow passing options object to override any GameObject properties. --- Oversimplified.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Oversimplified.js b/Oversimplified.js index 1b1227a..b1d8122 100644 --- a/Oversimplified.js +++ b/Oversimplified.js @@ -559,12 +559,13 @@ Oversimplified.Room.prototype.Draw = function () { // Add a GameObject or PremadeObject to the room. Oversimplified.Room.prototype.AddObject = function (newObjectName, newObjectOptions) { + newObjectOptions = (typeof newObjectOptions !== 'undefined') ? newObjectOptions : {}; var self = this; if (newObjectName.type == "GameObject") { //Create from prefabricated object var newID = Oversimplified.nextID++; 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]; } @@ -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. 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 = {}; if (newID != "identical") { resultingCopy.id = typeof newID !== 'undefined' ? newID : Oversimplified.nextID++; @@ -1293,6 +1294,10 @@ Oversimplified.CopyObject = function (object, newID, newName) { resultingCopy[property] = object[property]; } } + for (var option in objectOptions) { + //Overwrite any properties. + resultingCopy[option] = objectOptions[option]; + } return resultingCopy; }