Created
November 14, 2020 14:06
-
-
Save kungfooman/b25416d5e43ca8181753b4e5f487fcff to your computer and use it in GitHub Desktop.
playcanvas for nodejs to prevent ReferenceError: window is not defined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global.window = { | |
navigator: { | |
userAgent: "node" | |
}, | |
removeEventListener() {} | |
}; | |
var fakeCanvas = { | |
id: "fakecanvas", | |
getBoundingClientRect: function() { | |
return { | |
bottom: 969, | |
height: 969, | |
left: 0, | |
right: 980, | |
top: 0, | |
width: 980, | |
x: 0, | |
y: 0 | |
} | |
}, | |
getContext() { | |
return { | |
getSupportedExtensions: function() { | |
return ["OES_vertex_array_object"]; | |
}, | |
getContextAttributes: function() { | |
return { | |
"alpha": true, | |
"antialias": true, | |
"depth": true, | |
"failIfMajorPerformanceCaveat": false, | |
"powerPreference": "default", | |
"premultipliedAlpha": true, | |
"preserveDrawingBuffer": false, | |
"stencil": true, | |
"desynchronized": false, | |
"xrCompatible": true | |
} | |
}, | |
getParameter: function() { | |
return 0; | |
}, | |
disable: function() {}, | |
enable: function() {}, | |
blendFunc: function() {}, | |
blendEquation: function() {}, | |
colorMask: function() {}, | |
cullFace: function() {}, | |
depthFunc: function() {}, | |
depthMask: function() {}, | |
stencilFunc: function() {}, | |
stencilOp: function() {}, | |
stencilMask: function() {}, | |
clearDepth: function() {}, | |
clearColor: function() {}, | |
clearStencil: function() {}, | |
hint: function() {}, | |
pixelStorei: function() {}, | |
} | |
}, | |
addEventListener() { | |
}, | |
removeEventListener() {}, | |
} | |
global.navigator = { | |
} | |
global.document = { | |
getElementById: function() { | |
return fakeCanvas; | |
}, | |
createElement: function() { | |
console.log("createElement", arguments); | |
return fakeCanvas; | |
}, | |
addEventListener: function() { | |
}, | |
removeEventListener: function() {} | |
} | |
function Element() { | |
console.log("Element()"); | |
} | |
Element.prototype.getPointerLock = function() { | |
console.log("requestPointerLock()") | |
} | |
global.Element = Element; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment