current state

beta.r3js.org
-=yb4f310 2017-12-10 12:57:24 +01:00
parent aef4286386
commit 0bb9a01863
9 changed files with 422 additions and 55 deletions

28
build/game-lib-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
// COMPILE TIME DEFINITIONS (Generated via gulp)
var __DATE__ = "Tue Dec 05 2017 21:13:00 GMT+0100 (CET)";
var __DATE__ = "Sun Dec 10 2017 12:56:56 GMT+0100 (CET)";
// END COMPILE TIME DEFINITIONS
/**
@ -168,7 +168,7 @@ GameLib.Event.FONT_NOT_FOUND = 0x56;
GameLib.Event.STOP_ALL_AUDIO = 0x57;
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
GameLib.Event.GAME_LOADED = 0x59;
//GameLib.Event.GAME_RESTART = 0x5a;
GameLib.Event.COMPONENT_UPDATE = 0x5a;
GameLib.Event.LOAD_PROGRESS = 0x5b;
GameLib.Event.ENTITY_LOADED = 0x5c;
GameLib.Event.MOUSE_DOWN = 0x5d;
@ -288,7 +288,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x57 : return 'stop_all_audio';
case 0x58 : return 'register_dependencies';
case 0x59 : return 'game_loaded';
case 0x5a : return 'unused';//'game_restart';
case 0x5a : return 'component_update';
case 0x5b : return 'load_progress';
case 0x5c : return 'entity_loaded';
case 0x5d : return 'mouse_down';
@ -2639,7 +2639,7 @@ GameLib.API.Canvas.FromObject = function(objectCanvas) {
* @param source
* @param sourceProperties
* @param roomId
* @param peer
* @param peerId
* @param serverIp
* @param port
* @param parentEntity
@ -2652,7 +2652,7 @@ GameLib.API.Cast = function(
source,
sourceProperties,
roomId,
peer,
peerId,
serverIp,
port,
parentEntity
@ -2669,7 +2669,7 @@ GameLib.API.Cast = function(
this.name = name;
if (GameLib.Utils.UndefinedOrNull(castType)) {
castType = GameLib.Cast.CAST_TYPE_ROOM;
castType = GameLib.API.Cast.CAST_TYPE_ROOM;
}
this.castType = castType;
@ -2688,10 +2688,10 @@ GameLib.API.Cast = function(
}
this.roomId = roomId;
if (GameLib.Utils.UndefinedOrNull(peer)) {
peer = null;
if (GameLib.Utils.UndefinedOrNull(peerId)) {
peerId = null;
}
this.peer = peer;
this.peerId = peerId;
if (GameLib.Utils.UndefinedOrNull(serverIp)) {
serverIp = '127.0.0.1';
@ -2733,7 +2733,7 @@ GameLib.API.Cast.FromObject = function(objectCast) {
objectCast.source,
objectCast.sourceProperties,
objectCast.roomId,
objectCast.peer,
objectCast.peerId,
objectCast.serverIp,
objectCast.port,
objectCast.parentEntity
@ -4121,6 +4121,114 @@ GameLib.API.Quaternion.Points.prototype.toOrigin = function () {
this.vectors[i].translate(distanceFromOrigin);
}
};
/**
* Raw Receive API object - should always correspond with the Receive Schema
* @param id
* @param name
* @param receiveType
* @param source
* @param sourceProperties
* @param roomId
* @param peerId
* @param serverIp
* @param port
* @param parentEntity
* @constructor
*/
GameLib.API.Receive = function(
id,
name,
receiveType,
source,
sourceProperties,
roomId,
peerId,
serverIp,
port,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Receive (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(castType)) {
castType = GameLib.API.Receive.CAST_TYPE_ROOM;
}
this.castType = castType;
if (GameLib.Utils.UndefinedOrNull(source)) {
source = null;
}
this.source = source;
if (GameLib.Utils.UndefinedOrNull(sourceProperties)) {
sourceProperties = null;
}
this.sourceProperties = sourceProperties;
if (GameLib.Utils.UndefinedOrNull(roomId)) {
roomId = 'default';
}
this.roomId = roomId;
if (GameLib.Utils.UndefinedOrNull(peerId)) {
peerId = null;
}
this.peerId = peerId;
if (GameLib.Utils.UndefinedOrNull(serverIp)) {
serverIp = '127.0.0.1';
}
this.serverIp = serverIp;
if (GameLib.Utils.UndefinedOrNull(port)) {
port = 80;
}
this.port = port;
GameLib.API.Component.call(
this,
GameLib.Component.CAST,
parentEntity
);
};
GameLib.API.Receive.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.Receive.prototype.constructor = GameLib.API.Receive;
GameLib.API.Receive.CAST_TYPE_ROOM = 0x1;
GameLib.API.Receive.CAST_TYPE_PEER = 0x2;
/**
* Creates an API Receive from an Object Receive
* @param objectReceive
* @constructor
*/
GameLib.API.Receive.FromObject = function(objectReceive) {
return new GameLib.API.Receive(
objectReceive.id,
objectReceive.name,
objectReceive.castType,
objectReceive.source,
objectReceive.sourceProperties,
objectReceive.roomId,
objectReceive.peerId,
objectReceive.serverIp,
objectReceive.port,
objectReceive.parentEntity
);
};
/**
* Raw Stats API object - should always correspond with the Stats Schema
* @param id
@ -4762,7 +4870,7 @@ GameLib.Cast = function(
apiCast.source,
apiCast.sourceProperties,
apiCast.roomId,
apiCast.peer,
apiCast.peerId,
apiCast.serverIp,
apiCast.port,
apiCast.parentEntity
@ -4773,8 +4881,7 @@ GameLib.Cast = function(
GameLib.Component.call(
this,
{
source : GameLib.Component,
peer : GameLib.Component
source : GameLib.Component
}
);
@ -4790,6 +4897,48 @@ GameLib.Cast.prototype.createInstance = function() {
GameLib.Component.prototype.createInstance.call(this);
};
GameLib.Cast.prototype.buildVectorSource = function(result, name, dimension) {
if (dimension === 2) {
result[name] = {};
result[name].x = false;
result[name].y = false;
return;
}
if (dimension === 3) {
result[name] = {};
result[name].x = false;
result[name].y = false;
result[name].y = false;
return;
}
if (dimension === 4) {
result[name] = {};
result[name].x = false;
result[name].y = false;
result[name].z = false;
result[name].w = false;
return;
}
console.warn('unknown dimension : ' + dimension);
};
GameLib.Cast.prototype.buildQuaternionSource = function(result, name) {
result[name] = {};
result[name].axis = {};
result[name].axis.x = false;
result[name].axis.y = false;
result[name].axis.z = false;
result[name].angle = false;
result[name].x = false;
result[name].y = false;
result[name].z = false;
result[name].w = false;
};
/**
* Updates the instance with the current state
*/
@ -4799,11 +4948,30 @@ GameLib.Cast.prototype.updateInstance = function(property) {
this.sourceProperties = Object.keys(this.source).reduce(
function(result, propertyId) {
if (typeof this.source[propertyId] !== 'function') {
result[propertyId] = false;
if (typeof this.source[propertyId] === 'function') {
return result;
}
result[propertyId] = false;
// if (this.source[propertyId] instanceof GameLib.Vector2) {
// this.buildVectorSource(result, propertyId, 2);
// }
//
// if (this.source[propertyId] instanceof GameLib.Vector3) {
// this.buildVectorSource(result, propertyId, 3);
// }
//
// if (this.source[propertyId] instanceof GameLib.Vector4) {
// this.buildVectorSource(result, propertyId, 4);
// }
// if (this.source[propertyId] instanceof GameLib.Quaternion) {
// this.buildQuaternionSource(result, propertyId);
// }
return result;
}.bind(this),
{}
)
@ -4837,7 +5005,7 @@ GameLib.Cast.prototype.toApiObject = function() {
GameLib.Utils.IdOrNull(this.source),
this.sourceProperties,
this.roomId,
GameLib.Utils.IdOrNull(this.peer),
this.peerId,
this.serverIp,
this.port,
GameLib.Utils.IdOrNull(this.parentEntity)
@ -22709,10 +22877,12 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) {
if (property === 'wrapS') {
this.instance.wrapS = this.wrapS;
this.instance.needsUpdate = true;
}
if (property === 'wrapT') {
this.instance.wrapT = this.wrapT;
this.instance.needsUpdate = true;
}
if (property === 'animated') {
@ -23289,6 +23459,23 @@ GameLib.EntityManager.prototype.findComponentById = function(id) {
return this.idRegister[id];
};
GameLib.EntityManager.prototype.findComponentByName = function(name) {
return Object.keys(this.idRegister).reduce(
function(result, componentId) {
if (this.idRegister[componentId].name === name) {
result = this.idRegister[componentId];
}
return result;
}.bind(this),
null
);
};
GameLib.EntityManager.prototype.findHelperByObject = function(object) {
if (typeof this.register[GameLib.Component.HELPER] === 'undefined') {
@ -26885,7 +27072,7 @@ GameLib.System.GUI.prototype.controller = function(folder, object, property, sub
) {
min = -1000;
max = 1000;
step = 0.00001;
step = 0.01;
}
var handle = folder.add(
@ -27258,9 +27445,6 @@ GameLib.System.GUI.prototype.buildObjectControl = function(folder, componentTemp
}
if (property === 'sourceProperties') {
Object.keys(object).map(
function(propertyId) {
folder.add(
@ -27288,7 +27472,7 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp
*/
var constructors = null;
if (componentTemplate.template.linkedObjects[property]) {
if (componentTemplate.template.linkedObjects && componentTemplate.template.linkedObjects[property]) {
constructors = componentTemplate.template.linkedObjects[property];
} else {
if (componentTemplate.template[property]) {

View File

@ -104,7 +104,7 @@ GameLib.Event.FONT_NOT_FOUND = 0x56;
GameLib.Event.STOP_ALL_AUDIO = 0x57;
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
GameLib.Event.GAME_LOADED = 0x59;
//GameLib.Event.GAME_RESTART = 0x5a;
GameLib.Event.COMPONENT_UPDATE = 0x5a;
GameLib.Event.LOAD_PROGRESS = 0x5b;
GameLib.Event.ENTITY_LOADED = 0x5c;
GameLib.Event.MOUSE_DOWN = 0x5d;
@ -224,7 +224,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x57 : return 'stop_all_audio';
case 0x58 : return 'register_dependencies';
case 0x59 : return 'game_loaded';
case 0x5a : return 'unused';//'game_restart';
case 0x5a : return 'component_update';
case 0x5b : return 'load_progress';
case 0x5c : return 'entity_loaded';
case 0x5d : return 'mouse_down';

View File

@ -6,7 +6,7 @@
* @param source
* @param sourceProperties
* @param roomId
* @param peer
* @param peerId
* @param serverIp
* @param port
* @param parentEntity
@ -19,7 +19,7 @@ GameLib.API.Cast = function(
source,
sourceProperties,
roomId,
peer,
peerId,
serverIp,
port,
parentEntity
@ -36,7 +36,7 @@ GameLib.API.Cast = function(
this.name = name;
if (GameLib.Utils.UndefinedOrNull(castType)) {
castType = GameLib.Cast.CAST_TYPE_ROOM;
castType = GameLib.API.Cast.CAST_TYPE_ROOM;
}
this.castType = castType;
@ -55,10 +55,10 @@ GameLib.API.Cast = function(
}
this.roomId = roomId;
if (GameLib.Utils.UndefinedOrNull(peer)) {
peer = null;
if (GameLib.Utils.UndefinedOrNull(peerId)) {
peerId = null;
}
this.peer = peer;
this.peerId = peerId;
if (GameLib.Utils.UndefinedOrNull(serverIp)) {
serverIp = '127.0.0.1';
@ -100,7 +100,7 @@ GameLib.API.Cast.FromObject = function(objectCast) {
objectCast.source,
objectCast.sourceProperties,
objectCast.roomId,
objectCast.peer,
objectCast.peerId,
objectCast.serverIp,
objectCast.port,
objectCast.parentEntity

107
src/game-lib-api-receive.js Normal file
View File

@ -0,0 +1,107 @@
/**
* Raw Receive API object - should always correspond with the Receive Schema
* @param id
* @param name
* @param receiveType
* @param source
* @param sourceProperties
* @param roomId
* @param peerId
* @param serverIp
* @param port
* @param parentEntity
* @constructor
*/
GameLib.API.Receive = function(
id,
name,
receiveType,
source,
sourceProperties,
roomId,
peerId,
serverIp,
port,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Receive (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(castType)) {
castType = GameLib.API.Receive.CAST_TYPE_ROOM;
}
this.castType = castType;
if (GameLib.Utils.UndefinedOrNull(source)) {
source = null;
}
this.source = source;
if (GameLib.Utils.UndefinedOrNull(sourceProperties)) {
sourceProperties = null;
}
this.sourceProperties = sourceProperties;
if (GameLib.Utils.UndefinedOrNull(roomId)) {
roomId = 'default';
}
this.roomId = roomId;
if (GameLib.Utils.UndefinedOrNull(peerId)) {
peerId = null;
}
this.peerId = peerId;
if (GameLib.Utils.UndefinedOrNull(serverIp)) {
serverIp = '127.0.0.1';
}
this.serverIp = serverIp;
if (GameLib.Utils.UndefinedOrNull(port)) {
port = 80;
}
this.port = port;
GameLib.API.Component.call(
this,
GameLib.Component.CAST,
parentEntity
);
};
GameLib.API.Receive.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.Receive.prototype.constructor = GameLib.API.Receive;
GameLib.API.Receive.CAST_TYPE_ROOM = 0x1;
GameLib.API.Receive.CAST_TYPE_PEER = 0x2;
/**
* Creates an API Receive from an Object Receive
* @param objectReceive
* @constructor
*/
GameLib.API.Receive.FromObject = function(objectReceive) {
return new GameLib.API.Receive(
objectReceive.id,
objectReceive.name,
objectReceive.castType,
objectReceive.source,
objectReceive.sourceProperties,
objectReceive.roomId,
objectReceive.peerId,
objectReceive.serverIp,
objectReceive.port,
objectReceive.parentEntity
);
};

View File

@ -28,7 +28,7 @@ GameLib.Cast = function(
apiCast.source,
apiCast.sourceProperties,
apiCast.roomId,
apiCast.peer,
apiCast.peerId,
apiCast.serverIp,
apiCast.port,
apiCast.parentEntity
@ -39,8 +39,7 @@ GameLib.Cast = function(
GameLib.Component.call(
this,
{
source : GameLib.Component,
peer : GameLib.Component
source : GameLib.Component
}
);
@ -56,6 +55,48 @@ GameLib.Cast.prototype.createInstance = function() {
GameLib.Component.prototype.createInstance.call(this);
};
GameLib.Cast.prototype.buildVectorSource = function(result, name, dimension) {
if (dimension === 2) {
result[name] = {};
result[name].x = false;
result[name].y = false;
return;
}
if (dimension === 3) {
result[name] = {};
result[name].x = false;
result[name].y = false;
result[name].y = false;
return;
}
if (dimension === 4) {
result[name] = {};
result[name].x = false;
result[name].y = false;
result[name].z = false;
result[name].w = false;
return;
}
console.warn('unknown dimension : ' + dimension);
};
GameLib.Cast.prototype.buildQuaternionSource = function(result, name) {
result[name] = {};
result[name].axis = {};
result[name].axis.x = false;
result[name].axis.y = false;
result[name].axis.z = false;
result[name].angle = false;
result[name].x = false;
result[name].y = false;
result[name].z = false;
result[name].w = false;
};
/**
* Updates the instance with the current state
*/
@ -65,11 +106,30 @@ GameLib.Cast.prototype.updateInstance = function(property) {
this.sourceProperties = Object.keys(this.source).reduce(
function(result, propertyId) {
if (typeof this.source[propertyId] !== 'function') {
result[propertyId] = false;
if (typeof this.source[propertyId] === 'function') {
return result;
}
result[propertyId] = false;
// if (this.source[propertyId] instanceof GameLib.Vector2) {
// this.buildVectorSource(result, propertyId, 2);
// }
//
// if (this.source[propertyId] instanceof GameLib.Vector3) {
// this.buildVectorSource(result, propertyId, 3);
// }
//
// if (this.source[propertyId] instanceof GameLib.Vector4) {
// this.buildVectorSource(result, propertyId, 4);
// }
// if (this.source[propertyId] instanceof GameLib.Quaternion) {
// this.buildQuaternionSource(result, propertyId);
// }
return result;
}.bind(this),
{}
)
@ -103,7 +163,7 @@ GameLib.Cast.prototype.toApiObject = function() {
GameLib.Utils.IdOrNull(this.source),
this.sourceProperties,
this.roomId,
GameLib.Utils.IdOrNull(this.peer),
this.peerId,
this.serverIp,
this.port,
GameLib.Utils.IdOrNull(this.parentEntity)

View File

@ -307,10 +307,12 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) {
if (property === 'wrapS') {
this.instance.wrapS = this.wrapS;
this.instance.needsUpdate = true;
}
if (property === 'wrapT') {
this.instance.wrapT = this.wrapT;
this.instance.needsUpdate = true;
}
if (property === 'animated') {

View File

@ -191,6 +191,23 @@ GameLib.EntityManager.prototype.findComponentById = function(id) {
return this.idRegister[id];
};
GameLib.EntityManager.prototype.findComponentByName = function(name) {
return Object.keys(this.idRegister).reduce(
function(result, componentId) {
if (this.idRegister[componentId].name === name) {
result = this.idRegister[componentId];
}
return result;
}.bind(this),
null
);
};
GameLib.EntityManager.prototype.findHelperByObject = function(object) {
if (typeof this.register[GameLib.Component.HELPER] === 'undefined') {

View File

@ -247,7 +247,7 @@ GameLib.System.GUI.prototype.controller = function(folder, object, property, sub
) {
min = -1000;
max = 1000;
step = 0.00001;
step = 0.01;
}
var handle = folder.add(
@ -620,9 +620,6 @@ GameLib.System.GUI.prototype.buildObjectControl = function(folder, componentTemp
}
if (property === 'sourceProperties') {
Object.keys(object).map(
function(propertyId) {
folder.add(
@ -650,7 +647,7 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp
*/
var constructors = null;
if (componentTemplate.template.linkedObjects[property]) {
if (componentTemplate.template.linkedObjects && componentTemplate.template.linkedObjects[property]) {
constructors = componentTemplate.template.linkedObjects[property];
} else {
if (componentTemplate.template[property]) {