From d90852e413de3401e1d4855b352068bfb1567962 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Tue, 19 Sep 2017 21:27:11 +0200 Subject: [PATCH] tetris stuff --- src/game-lib-a-1-event.js | 4 +++ src/game-lib-a-component-a.js | 39 +++++++++++++++++++++++++++--- src/game-lib-d3-custom-code.js | 4 ++- src/game-lib-d3-mesh-0.js | 2 +- src/game-lib-matrix-4.js | 14 ++++------- src/game-lib-system-animation.js | 18 ++++++++------ src/game-lib-system-custom-code.js | 8 ++++++ 7 files changed, 67 insertions(+), 22 deletions(-) diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index f2e75f1..8770ea4 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -84,6 +84,8 @@ GameLib.Event.PARENT_WORLD_CHANGE = 0x42; GameLib.Event.ANIMATE = 0x43; GameLib.Event.ANIMATION_COMPILE_SUCCESS = 0x44; GameLib.Event.ANIMATION_COMPILE_FAILED = 0x45; +GameLib.Event.CUSTOM_CODE_SYSTEM_STARTED = 0x46; +GameLib.Event.GAME_OVER = 0x47; /** * Returns string name of event ID @@ -163,6 +165,8 @@ GameLib.Event.GetEventName = function(number) { case 0x43 : return 'animate'; case 0x44 : return 'animation_compile_success'; case 0x45 : return 'animation_compile_failed'; + case 0x46 : return 'custom_code_system_started'; + case 0x47 : return 'game_over'; break; } diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 64687ab..bea467b 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -291,10 +291,43 @@ GameLib.Component.prototype.clone = function() { apiObject.id = GameLib.Utils.RandomId(); - apiObject.name = apiObject.name + ' Clone (' + apiObject.id + ')'; + apiObject.name = apiObject.name + ' (Clone)'; + + var runtimeObject = null; + + try { + runtimeObject = new this.constructor(this.graphics, apiObject); + } catch (e){ + console.log(e); + try { + runtimeObject = new this.constructor(this.physics, apiObject); + } catch (e) { + console.log(e); + try { + runtimeObject = new this.constructor(this.coder, apiObject); + } catch (e) { + console.log(e); + console.log('failed to construct a runtime component'); + return; + } + } + } + + GameLib.Event.Emit( + GameLib.Event.COMPONENT_CREATED, + { + component : runtimeObject + } + ); + + runtimeObject.parentEntity = null; + + // if (this.parentEntity instanceof GameLib.Entity) { + // this.parentEntity.addComponent(runtimeObject); + // } + + return runtimeObject; - //TODO - create runtime object - add to parent entity - - //var object = this.constructor.call(this, this.graphics, apiObject); }; GameLib.Component.prototype.getStorageDependencies = function() { diff --git a/src/game-lib-d3-custom-code.js b/src/game-lib-d3-custom-code.js index e72df06..8cc6025 100644 --- a/src/game-lib-d3-custom-code.js +++ b/src/game-lib-d3-custom-code.js @@ -114,7 +114,9 @@ GameLib.D3.CustomCode.prototype.launchEditor = function(){ value : this.code, mode : 'javascript', lineNumbers : true, - scrollbarStyle : 'overlay' + scrollbarStyle : 'overlay', + indentWithTabs: true, + indentUnit : 4 } ); diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index 324b227..c9b6432 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -1171,4 +1171,4 @@ GameLib.D3.Mesh.prototype.computeBoundingBox = function(geometry) { this.size.x = geometry.boundingBox.getSize().x; this.size.y = geometry.boundingBox.getSize().y; this.size.z = geometry.boundingBox.getSize().z; -}; \ No newline at end of file +}; diff --git a/src/game-lib-matrix-4.js b/src/game-lib-matrix-4.js index 9909952..423aec2 100644 --- a/src/game-lib-matrix-4.js +++ b/src/game-lib-matrix-4.js @@ -146,15 +146,11 @@ GameLib.Matrix4.prototype.updateInstance = function() { */ GameLib.Matrix4.prototype.toApiObject = function () { - return this.rows.map( - function(row) { - if (row instanceof GameLib.Vector4) { - return row.toApiObject(); - } else { - console.warn('Incompatible conversion to API matrix for vector: ', row); - throw new Error('Incompatible conversion to API matrix for a vector'); - } - } + return new GameLib.API.Matrix4( + this.rows[0].toApiObject(), + this.rows[1].toApiObject(), + this.rows[2].toApiObject(), + this.rows[3].toApiObject() ); }; diff --git a/src/game-lib-system-animation.js b/src/game-lib-system-animation.js index 30893cd..60411da 100644 --- a/src/game-lib-system-animation.js +++ b/src/game-lib-system-animation.js @@ -46,9 +46,9 @@ GameLib.System.Animation.prototype.start = function() { intermediateAngle : mesh.quaternion.angle, subscription : null, inProcess : false, - blocking : animation.blocking, - callbacks : [], - storedValues : [] + blocking : animation.blocking//, + // callbacks : [], + // storedValues : [] }; var getIntermediateAngle = function() { @@ -57,9 +57,9 @@ GameLib.System.Animation.prototype.start = function() { var getTargetAngle = function() { - if (mesh.animationObject.storedValues.length > 0) { - return mesh.animationObject.storedValues[mesh.animationObject.storedValues.length - 1]; - } + // if (mesh.animationObject.storedValues.length > 0) { + // return mesh.animationObject.storedValues[mesh.animationObject.storedValues.length - 1]; + // } return mesh.animationObject.targetAngle; }; @@ -175,7 +175,7 @@ GameLib.System.Animation.prototype.start = function() { // callback(); // } - mesh.animationObject.storedValues = []; + // mesh.animationObject.storedValues = []; } }; @@ -201,8 +201,10 @@ GameLib.System.Animation.prototype.start = function() { console.log('another animation is already in process'); - GameLib.Utils.PushUnique(mesh.animationObject.storedValues, value); + // setTargetAngle(value); + // GameLib.Utils.PushUnique(mesh.animationObject.storedValues, value); + // // mesh.animationObject.callbacks.push( // function(__value) { // return function(){ diff --git a/src/game-lib-system-custom-code.js b/src/game-lib-system-custom-code.js index 88fb5cf..9e7896b 100644 --- a/src/game-lib-system-custom-code.js +++ b/src/game-lib-system-custom-code.js @@ -41,6 +41,14 @@ GameLib.System.CustomCode.prototype.start = function() { }.bind(this)); + GameLib.Event.Emit( + GameLib.Event.CUSTOM_CODE_SYSTEM_STARTED, + { + system : this, + components : this.customCodeComponents + } + ) + }; /**