From 9ee7b26c1ee1bb6d09468e3d01b90cc46ac2b822 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sun, 7 Jan 2018 12:58:15 +0100 Subject: [PATCH] api objects can no longer be instances of runtime objects --- src/game-lib-api-color.js | 63 ----------------- src/game-lib-canvas.js | 4 -- src/game-lib-clock.js | 4 -- src/game-lib-color.js | 67 +++++++++++++++++-- src/game-lib-controls-0.js | 6 +- src/game-lib-custom-code.js | 6 +- src/game-lib-d3-api-z-animation.js | 6 +- src/game-lib-d3-audio.js | 4 -- src/game-lib-d3-bone-weight.js | 6 +- src/game-lib-d3-bone.js | 6 +- src/game-lib-d3-broadphase.js | 4 -- src/game-lib-d3-camera.js | 4 -- src/game-lib-d3-composer.js | 6 +- src/game-lib-d3-face.js | 4 -- src/game-lib-d3-fog.js | 6 +- src/game-lib-d3-font.js | 4 -- src/game-lib-d3-friction-contact-material.js | 4 -- src/game-lib-d3-friction-material.js | 4 -- src/game-lib-d3-light.js | 4 -- src/game-lib-d3-material.js | 6 +- src/game-lib-d3-mesh-0.js | 6 +- src/game-lib-d3-mesh-box.js | 4 -- src/game-lib-d3-mesh-curve.js | 4 -- src/game-lib-d3-mesh-cylinder.js | 4 -- src/game-lib-d3-mesh-line.js | 4 -- src/game-lib-d3-mesh-sphere.js | 4 -- src/game-lib-d3-mesh-text.js | 4 -- src/game-lib-d3-particle-engine.js | 4 -- src/game-lib-d3-particle.js | 4 -- src/game-lib-d3-pass.js | 6 +- src/game-lib-d3-physics-world.js | 4 -- src/game-lib-d3-raycast-vehicle.js | 4 -- src/game-lib-d3-raycast-wheel.js | 4 -- src/game-lib-d3-raycaster.js | 6 +- src/game-lib-d3-render-target.js | 6 +- src/game-lib-d3-renderer.js | 6 +- src/game-lib-d3-rigid-body.js | 4 -- src/game-lib-d3-scene.js | 6 +- src/game-lib-d3-shape-0.js | 6 +- src/game-lib-d3-shape-box.js | 4 -- src/game-lib-d3-shape-convex-hull-0.js | 4 -- src/game-lib-d3-shape-convex-hull-cylinder.js | 4 -- src/game-lib-d3-shape-height-map.js | 4 -- src/game-lib-d3-shape-plane.js | 4 -- src/game-lib-d3-shape-sphere.js | 4 -- src/game-lib-d3-shape-tri-mesh.js | 4 -- src/game-lib-d3-skeleton.js | 6 +- src/game-lib-d3-solver.js | 4 -- src/game-lib-d3-spline.js | 6 +- src/game-lib-d3-texture.js | 6 +- src/game-lib-d3-vertex.js | 4 -- src/game-lib-d3-viewport.js | 6 +- src/game-lib-dom-element.js | 4 -- src/game-lib-entity-manager.js | 4 -- src/game-lib-entity.js | 6 +- src/game-lib-gui.js | 4 -- src/game-lib-image.js | 4 -- src/game-lib-matrix-4.js | 6 +- src/game-lib-mouse.js | 6 +- src/game-lib-quaternion.js | 6 +- src/game-lib-server.js | 4 -- src/game-lib-socket-0.js | 4 -- src/game-lib-stats.js | 4 -- src/game-lib-system-0.js | 6 +- src/game-lib-vector2.js | 6 +- src/game-lib-vector3.js | 6 +- src/game-lib-vector4.js | 4 -- 67 files changed, 89 insertions(+), 353 deletions(-) diff --git a/src/game-lib-api-color.js b/src/game-lib-api-color.js index 7af68f4..e1107ff 100644 --- a/src/game-lib-api-color.js +++ b/src/game-lib-api-color.js @@ -49,66 +49,3 @@ GameLib.API.Color.FromObject = function(objectColor) { ); }; - -/** - * Converts the current color to HTML hex format (ex. #ffffff) - * @returns {string} - */ -GameLib.API.Color.prototype.toHex = function() { - - if (this.r < 0) { - this.r = 0; - } - - if (this.g < 0) { - this.g = 0; - } - - if (this.b < 0) { - this.b = 0; - } - - if (this.r > 1) { - this.r = 1; - } - - if (this.g > 1) { - this.g = 1; - } - - if (this.b > 1) { - this.b = 1; - } - - var rf = Math.floor(this.r >= 1? 255 : this.r * 256.0).toString(16); - var gf = Math.floor(this.g >= 1? 255 : this.g * 256.0).toString(16); - var bf = Math.floor(this.b >= 1? 255 : this.b * 256.0).toString(16); - - if (rf.length < 2) { - rf = '0' + rf; - } - - if (gf.length < 2) { - gf = '0' + gf; - } - - if (bf.length < 2) { - bf = '0' + bf; - } - - return '#' + rf + gf + bf; -}; - -/** - * Sets this object color to what the hex value is - * @param hex - * @returns {string} - */ -GameLib.API.Color.prototype.fromHex = function(hex) { - - var matches = hex.match(new RegExp('#+(..)(..)(..)')); - - this.r = parseInt(matches[1], 16) / 255.0; - this.g = parseInt(matches[2], 16) / 255.0; - this.b = parseInt(matches[3], 16) / 255.0; -}; diff --git a/src/game-lib-canvas.js b/src/game-lib-canvas.js index 8742cf3..620d3f5 100644 --- a/src/game-lib-canvas.js +++ b/src/game-lib-canvas.js @@ -11,10 +11,6 @@ GameLib.Canvas = function( apiCanvas = {}; } - if (apiCanvas instanceof GameLib.Canvas) { - return apiCanvas; - } - GameLib.API.Canvas.call( this, apiCanvas.id, diff --git a/src/game-lib-clock.js b/src/game-lib-clock.js index 0c70493..6274948 100644 --- a/src/game-lib-clock.js +++ b/src/game-lib-clock.js @@ -16,10 +16,6 @@ GameLib.Clock = function( apiClock = {}; } - if (apiClock instanceof GameLib.Clock) { - return apiClock; - } - GameLib.API.Clock.call( this, apiClock.id, diff --git a/src/game-lib-color.js b/src/game-lib-color.js index 52f1a03..a49b31b 100644 --- a/src/game-lib-color.js +++ b/src/game-lib-color.js @@ -20,10 +20,6 @@ GameLib.Color = function ( apiColor = {}; } - if (apiColor instanceof GameLib.Color) { - return apiColor; - } - GameLib.API.Color.call( this, apiColor.r, @@ -87,3 +83,66 @@ GameLib.Color.prototype.toApiObject = function() { this.a ); }; + +/** + * Converts the current color to HTML hex format (ex. #ffffff) + * @returns {string} + */ +GameLib.Color.prototype.toHex = function() { + + if (this.r < 0) { + this.r = 0; + } + + if (this.g < 0) { + this.g = 0; + } + + if (this.b < 0) { + this.b = 0; + } + + if (this.r > 1) { + this.r = 1; + } + + if (this.g > 1) { + this.g = 1; + } + + if (this.b > 1) { + this.b = 1; + } + + var rf = Math.floor(this.r >= 1? 255 : this.r * 256.0).toString(16); + var gf = Math.floor(this.g >= 1? 255 : this.g * 256.0).toString(16); + var bf = Math.floor(this.b >= 1? 255 : this.b * 256.0).toString(16); + + if (rf.length < 2) { + rf = '0' + rf; + } + + if (gf.length < 2) { + gf = '0' + gf; + } + + if (bf.length < 2) { + bf = '0' + bf; + } + + return '#' + rf + gf + bf; +}; + +/** + * Sets this object color to what the hex value is + * @param hex + * @returns {string} + */ +GameLib.Color.prototype.fromHex = function(hex) { + + var matches = hex.match(new RegExp('#+(..)(..)(..)')); + + this.r = parseInt(matches[1], 16) / 255.0; + this.g = parseInt(matches[2], 16) / 255.0; + this.b = parseInt(matches[3], 16) / 255.0; +}; \ No newline at end of file diff --git a/src/game-lib-controls-0.js b/src/game-lib-controls-0.js index 649c88b..b77dbf1 100644 --- a/src/game-lib-controls-0.js +++ b/src/game-lib-controls-0.js @@ -11,11 +11,7 @@ GameLib.Controls = function ( apiControls = {}; } - if (apiControls instanceof GameLib.Controls) { - return apiControls; - } - - GameLib.API.Controls.call( + GameLib.API.Controls.call( this, apiControls.id, apiControls.controlsType, diff --git a/src/game-lib-custom-code.js b/src/game-lib-custom-code.js index 5d74fd8..c06e3bd 100644 --- a/src/game-lib-custom-code.js +++ b/src/game-lib-custom-code.js @@ -11,11 +11,7 @@ GameLib.CustomCode = function( apiCustomCode = {}; } - if (apiCustomCode instanceof GameLib.CustomCode) { - return apiCustomCode; - } - - GameLib.API.CustomCode.call( + GameLib.API.CustomCode.call( this, apiCustomCode.id, apiCustomCode.name, diff --git a/src/game-lib-d3-api-z-animation.js b/src/game-lib-d3-api-z-animation.js index c255005..af0f3ce 100644 --- a/src/game-lib-d3-api-z-animation.js +++ b/src/game-lib-d3-api-z-animation.js @@ -11,11 +11,7 @@ GameLib.D3.Animation = function( apiAnimation = {}; } - if (apiAnimation instanceof GameLib.D3.Animation) { - return apiAnimation; - } - - GameLib.D3.API.Animation.call( + GameLib.D3.API.Animation.call( this, apiAnimation.id, apiAnimation.name, diff --git a/src/game-lib-d3-audio.js b/src/game-lib-d3-audio.js index 0e9ef67..2f5ed41 100644 --- a/src/game-lib-d3-audio.js +++ b/src/game-lib-d3-audio.js @@ -16,10 +16,6 @@ GameLib.D3.Audio = function( apiAudio = {}; } - if (apiAudio instanceof GameLib.D3.Audio) { - return apiAudio; - } - GameLib.D3.API.Audio.call( this, apiAudio.id, diff --git a/src/game-lib-d3-bone-weight.js b/src/game-lib-d3-bone-weight.js index d0e154e..f897f63 100644 --- a/src/game-lib-d3-bone-weight.js +++ b/src/game-lib-d3-bone-weight.js @@ -15,11 +15,7 @@ GameLib.D3.BoneWeight = function ( apiBoneWeight = {}; } - if (apiBoneWeight instanceof GameLib.D3.BoneWeight) { - return apiBoneWeight; - } - - GameLib.D3.API.BoneWeight.call( + GameLib.D3.API.BoneWeight.call( this, apiBoneWeight.boneIndex, apiBoneWeight.weight diff --git a/src/game-lib-d3-bone.js b/src/game-lib-d3-bone.js index 65b81c8..fb6faea 100644 --- a/src/game-lib-d3-bone.js +++ b/src/game-lib-d3-bone.js @@ -15,11 +15,7 @@ GameLib.D3.Bone = function ( apiBone = {}; } - if (apiBone instanceof GameLib.D3.Bone) { - return apiBone; - } - - GameLib.D3.API.Bone.call( + GameLib.D3.API.Bone.call( this, apiBone.id, apiBone.name, diff --git a/src/game-lib-d3-broadphase.js b/src/game-lib-d3-broadphase.js index 0946080..9770ce1 100644 --- a/src/game-lib-d3-broadphase.js +++ b/src/game-lib-d3-broadphase.js @@ -16,10 +16,6 @@ GameLib.D3.Broadphase = function ( apiBroadphase = {}; } - if (apiBroadphase instanceof GameLib.D3.Broadphase) { - return apiBroadphase; - } - GameLib.D3.API.Broadphase.call( this, apiBroadphase.id, diff --git a/src/game-lib-d3-camera.js b/src/game-lib-d3-camera.js index 95e377f..266715c 100644 --- a/src/game-lib-d3-camera.js +++ b/src/game-lib-d3-camera.js @@ -16,10 +16,6 @@ GameLib.D3.Camera = function( apiCamera = {}; } - if (apiCamera instanceof GameLib.D3.Camera) { - return apiCamera; - } - GameLib.D3.API.Camera.call( this, apiCamera.id, diff --git a/src/game-lib-d3-composer.js b/src/game-lib-d3-composer.js index a6e17ee..6a14965 100644 --- a/src/game-lib-d3-composer.js +++ b/src/game-lib-d3-composer.js @@ -16,11 +16,7 @@ GameLib.D3.Composer = function ( apiComposer = {}; } - if (apiComposer instanceof GameLib.D3.Composer) { - return apiComposer; - } - - GameLib.D3.API.Composer.call( + GameLib.D3.API.Composer.call( this, apiComposer.id, apiComposer.name, diff --git a/src/game-lib-d3-face.js b/src/game-lib-d3-face.js index b935e67..04cfd9f 100644 --- a/src/game-lib-d3-face.js +++ b/src/game-lib-d3-face.js @@ -22,10 +22,6 @@ GameLib.D3.Face = function Face( apiFace = {}; } - if (apiFace instanceof GameLib.D3.Face) { - return apiFace; - } - GameLib.D3.API.Face.call( this, apiFace.id, diff --git a/src/game-lib-d3-fog.js b/src/game-lib-d3-fog.js index f81593b..45cedf3 100644 --- a/src/game-lib-d3-fog.js +++ b/src/game-lib-d3-fog.js @@ -16,11 +16,7 @@ GameLib.D3.Fog = function ( apiFog = {}; } - if (apiFog instanceof GameLib.D3.Fog) { - return apiFog; - } - - GameLib.D3.API.Fog.call( + GameLib.D3.API.Fog.call( this, apiFog.id, apiFog.name, diff --git a/src/game-lib-d3-font.js b/src/game-lib-d3-font.js index 9cc4adf..8e422e7 100644 --- a/src/game-lib-d3-font.js +++ b/src/game-lib-d3-font.js @@ -15,10 +15,6 @@ GameLib.D3.Font = function( apiFont = {}; } - if (apiFont instanceof GameLib.D3.Font) { - return apiFont; - } - GameLib.D3.API.Font.call( this, apiFont.id, diff --git a/src/game-lib-d3-friction-contact-material.js b/src/game-lib-d3-friction-contact-material.js index b41bb4e..b257e23 100644 --- a/src/game-lib-d3-friction-contact-material.js +++ b/src/game-lib-d3-friction-contact-material.js @@ -16,10 +16,6 @@ GameLib.D3.FrictionContactMaterial = function ( apiFrictionContactMaterial = {}; } - if (apiFrictionContactMaterial instanceof GameLib.D3.FrictionContactMaterial) { - return apiFrictionContactMaterial; - } - GameLib.D3.API.FrictionContactMaterial.call( this, apiFrictionContactMaterial.id, diff --git a/src/game-lib-d3-friction-material.js b/src/game-lib-d3-friction-material.js index 4ef12ab..9b6396e 100644 --- a/src/game-lib-d3-friction-material.js +++ b/src/game-lib-d3-friction-material.js @@ -16,10 +16,6 @@ GameLib.D3.FrictionMaterial = function ( apiFrictionMaterial = {}; } - if (apiFrictionMaterial instanceof GameLib.D3.FrictionMaterial) { - return apiFrictionMaterial; - } - GameLib.D3.API.FrictionMaterial.call( this, apiFrictionMaterial.id, diff --git a/src/game-lib-d3-light.js b/src/game-lib-d3-light.js index 88fa167..21c77df 100644 --- a/src/game-lib-d3-light.js +++ b/src/game-lib-d3-light.js @@ -15,10 +15,6 @@ GameLib.D3.Light = function( apiLight = {}; } - if (apiLight instanceof GameLib.D3.Light) { - return apiLight; - } - GameLib.D3.API.Light.call( this, apiLight.id, diff --git a/src/game-lib-d3-material.js b/src/game-lib-d3-material.js index ee78b90..7543ee3 100644 --- a/src/game-lib-d3-material.js +++ b/src/game-lib-d3-material.js @@ -18,11 +18,7 @@ GameLib.D3.Material = function( apiMaterial = {}; } - if (apiMaterial instanceof GameLib.D3.Material) { - return apiMaterial; - } - - GameLib.D3.API.Material.call( + GameLib.D3.API.Material.call( this, apiMaterial.id, apiMaterial.materialType, diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index 1e43a71..64493ce 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -17,11 +17,7 @@ GameLib.D3.Mesh = function ( }; } - if (apiMesh instanceof GameLib.D3.Mesh) { - return apiMesh; - } - - GameLib.D3.API.Mesh.call( + GameLib.D3.API.Mesh.call( this, apiMesh.id, apiMesh.meshType, diff --git a/src/game-lib-d3-mesh-box.js b/src/game-lib-d3-mesh-box.js index 4929afd..6232b9e 100644 --- a/src/game-lib-d3-mesh-box.js +++ b/src/game-lib-d3-mesh-box.js @@ -23,10 +23,6 @@ GameLib.D3.Mesh.Box = function ( }; } - if (apiMesh instanceof GameLib.D3.Mesh.Box) { - return apiMesh; - } - if (GameLib.Utils.UndefinedOrNull(width)) { width = 1; } diff --git a/src/game-lib-d3-mesh-curve.js b/src/game-lib-d3-mesh-curve.js index 63ed564..0089127 100644 --- a/src/game-lib-d3-mesh-curve.js +++ b/src/game-lib-d3-mesh-curve.js @@ -17,10 +17,6 @@ GameLib.D3.Mesh.Curve = function ( }; } - if (apiMesh instanceof GameLib.D3.Mesh.Curve) { - return apiMesh; - } - GameLib.D3.Mesh.call( this, this.graphics, diff --git a/src/game-lib-d3-mesh-cylinder.js b/src/game-lib-d3-mesh-cylinder.js index d46c8fb..24b2782 100644 --- a/src/game-lib-d3-mesh-cylinder.js +++ b/src/game-lib-d3-mesh-cylinder.js @@ -34,10 +34,6 @@ GameLib.D3.Mesh.Cylinder = function ( }; } - if (apiMesh instanceof GameLib.D3.Mesh.Cylinder) { - return apiMesh; - } - if (GameLib.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } diff --git a/src/game-lib-d3-mesh-line.js b/src/game-lib-d3-mesh-line.js index 2690f17..2f37752 100644 --- a/src/game-lib-d3-mesh-line.js +++ b/src/game-lib-d3-mesh-line.js @@ -19,10 +19,6 @@ GameLib.D3.Mesh.Line = function ( }; } - if (apiMesh instanceof GameLib.D3.Mesh.Line) { - return apiMesh; - } - if (GameLib.Utils.UndefinedOrNull(lineWidth)) { lineWidth = 1; } diff --git a/src/game-lib-d3-mesh-sphere.js b/src/game-lib-d3-mesh-sphere.js index d5c78aa..56d2117 100644 --- a/src/game-lib-d3-mesh-sphere.js +++ b/src/game-lib-d3-mesh-sphere.js @@ -23,10 +23,6 @@ GameLib.D3.Mesh.Sphere = function ( }; } - if (apiMesh instanceof GameLib.D3.Mesh.Sphere) { - return apiMesh; - } - if (GameLib.Utils.UndefinedOrNull(radius)) { radius = 1; } diff --git a/src/game-lib-d3-mesh-text.js b/src/game-lib-d3-mesh-text.js index d573a84..a98d753 100644 --- a/src/game-lib-d3-mesh-text.js +++ b/src/game-lib-d3-mesh-text.js @@ -35,10 +35,6 @@ GameLib.D3.Mesh.Text = function ( }; } - if (apiMesh instanceof GameLib.D3.Mesh.Text) { - return apiMesh; - } - if (GameLib.Utils.UndefinedOrNull(text)) { text = '-=