forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.js
More file actions
144 lines (127 loc) · 3.78 KB
/
Copy pathcore.js
File metadata and controls
144 lines (127 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* @private
* @function
* @name _typeLookup
* @description Create look up table for types
*/
var _typeLookup = function () {
var result = { };
var names = ["Array", "Object", "Function", "Date", "RegExp", "Float32Array"];
for (var i = 0; i < names.length; i++)
result["[object " + names[i] + "]"] = names[i].toLowerCase();
return result;
}();
/**
* @name pc
* @namespace
* @description Root namespace for the PlayCanvas Engine
* @preserve PlayCanvas Engine v__CURRENT_SDK_VERSION__ revision __REVISION__
* http://playcanvas.com
* Copyright 2011-2018 PlayCanvas Ltd. All rights reserved.
// #ifdef DEBUG
* DEBUG BUILD
// #endif
// #ifdef PROFILER
* PROFILER BUILD
// #endif
*/
var pc = {
version: "__CURRENT_SDK_VERSION__",
revision: "__REVISION__",
config: { },
common: { },
apps: { }, // Storage for the applications using the PlayCanvas Engine
data: { }, // Storage for exported entity data
/**
* @private
* @function
* @name pc.unpack
* @description Copy a set of common PlayCanvas functions/classes/namespaces into the global namespace
*/
unpack: function () {
console.warn("pc.unpack has been deprecated and will be removed shortly. Please update your code.");
},
/**
* @private
* @function
* @name pc.makeArray
* @description Convert an array-like object into a normal array.
* For example, this is useful for converting the arguments object into an array.
* @param {Object} arr The array to convert
* @returns {Array} An array
*/
makeArray: function (arr) {
var i,
ret = [],
length = arr.length;
for (i = 0; i < length; ++i) {
ret.push(arr[i]);
}
return ret;
},
/**
* @private
* @function
* @name pc.type
* @description Extended typeof() function, returns the type of the object.
* @param {Object} obj The object to get the type of
* @returns {String} The type string: "null", "undefined", "number", "string", "boolean", "array", "object", "function", "date", "regexp" or "float32array"
*/
type: function (obj) {
if (obj === null) {
return "null";
}
var type = typeof obj;
if (type === "undefined" || type === "number" || type === "string" || type === "boolean") {
return type;
}
return _typeLookup[Object.prototype.toString.call(obj)];
},
/**
* @private
* @function
* @name pc.extend
* @description Merge the contents of two objects into a single object
* @param {Object} target The target object of the merge
* @param {Object} ex The object that is merged with target
* @returns {Object} The target object
* @example
* var A = {a: function() {console.log(this.a}};
* var B = {b: function() {console.log(this.b}};
*
* pc.extend(A,B);
* A.a();
* // logs "a"
* A.b();
* // logs "b"
*/
extend: function (target, ex) {
var prop,
copy;
for (prop in ex) {
copy = ex[prop];
if (pc.type(copy) == "object") {
target[prop] = pc.extend({}, copy);
} else if (pc.type(copy) == "array") {
target[prop] = pc.extend([], copy);
} else {
target[prop] = copy;
}
}
return target;
},
/**
* @private
* @function
* @name pc.isDefined
* @description Return true if the Object is not undefined
* @param {Object} o The Object to test
* @returns {Boolean} True if the Object is not undefined
*/
isDefined: function (o) {
var a;
return (o !== a);
}
};
if (typeof exports !== 'undefined')
exports.pc = pc;