Phaser.Utils = { getProperty: function (obj, prop){ var parts = prop.split('.'), last = parts.pop(), l = _AN_Read_length('length', parts), i = 1, current = parts[0]; while (i < l && (obj = obj[current])){ current = parts[i]; i++ ; } if (obj) { return obj[last]; } else { return null ; } } , setProperty: function (obj, prop, value){ var parts = prop.split('.'), last = parts.pop(), l = _AN_Read_length('length', parts), i = 1, current = parts[0]; while (i < l && (obj = obj[current])){ current = parts[i]; i++ ; } if (obj) { obj[last] = value; } return obj; } , chanceRoll: function (chance){ if (chance === undefined) { chance = 50; } return chance > 0 && (Math.random() * 100 <= chance); } , randomChoice: function (choice1, choice2){ return (Math.random() < 0.5)? choice1: choice2; } , parseDimension: function (size, dimension){ var f = 0; var px = 0; if (typeof size === 'string') { if (size.substr(-1) === '%') { f = parseInt(size, 10) / 100; if (dimension === 0) { px = window.innerWidth * f; } else { px = window.innerHeight * f; } } else { px = parseInt(size, 10); } } else { px = size; } return px; } , pad: function (str, len, pad, dir){ if (len === undefined) { var len = 0; } if (pad === undefined) { var pad = ' '; } if (dir === undefined) { var dir = 3; } var padlen = 0; if (len + 1 >= _AN_Read_length('length', str)) { switch (dir){ case 1: str = new Array(len + 1 - (_AN_Read_length('length', str))).join(pad) + str; break ; case 3: var right = Math.ceil((padlen = len - _AN_Read_length('length', str)) / 2); var left = padlen - right; str = new Array(left + 1).join(pad) + str + new Array(right + 1).join(pad); break ; default : { str = str + new Array(len + 1 - (_AN_Read_length('length', str))).join(pad); break ; } } } return str; } , isPlainObject: function (obj){ if (typeof (obj) !== "object" || obj.nodeType || obj === obj.window) { return false ; } try { if (obj.constructor && !({ } ).hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) { return false ; } } catch (e) { return false ; } return true ; } , extend: function (){ var options, name, src, copy, copyIsArray, clone, target = arguments[0] || { } , i = 1, length = _AN_Read_length("length", arguments), deep = false ; if (typeof target === "boolean") { deep = target; target = arguments[1] || { } ; i = 2; } if (length === i) { target = this; --i; } for (; i < length; i++ ){ if ((options = arguments[i]) != null ) { for (name in options){ src = target[name]; copy = options[name]; if (target === copy) { continue ; } if (deep && copy && (Phaser.Utils.isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) { if (copyIsArray) { copyIsArray = false ; clone = src && Array.isArray(src)? src: [] ; } else { clone = src && Phaser.Utils.isPlainObject(src)? src: { } ; } target[name] = Phaser.Utils.extend(deep, clone, copy); } else if (copy !== undefined) { target[name] = copy; } } } } return target; } , mixinPrototype: function (target, mixin, replace){ if (replace === undefined) { replace = false ; } var mixinKeys = Object.keys(mixin); for (var i = 0; i < _AN_Read_length("length", mixinKeys); i++ ){ var key = mixinKeys[i]; var value = mixin[key]; if (!replace && (key in target)) { continue ; } else { if (value && (typeof value.get === 'function' || typeof value.set === 'function')) { if (typeof value.clone === 'function') { target[key] = value.clone(); } else { Object.defineProperty(target, key, value); } } else { target[key] = value; } } } } , mixin: function (from, to){ if (!from || typeof (from) !== "object") { return to; } for (var key in from){ var o = from[key]; if (o.childNodes || o.cloneNode) { continue ; } var type = typeof (from[key]); if (!from[key] || type !== "object") { to[key] = from[key]; } else { if (typeof (to[key]) === type) { to[key] = Phaser.Utils.mixin(from[key], to[key]); } else { to[key] = Phaser.Utils.mixin(from[key], new o.constructor()); } } } return to; } } ;