SHIT
parent
0aa539b6cf
commit
c98c75bd6e
|
@ -7,9 +7,6 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Graphics = function (
|
GameLib.D3.API.Graphics = function (
|
||||||
id,
|
|
||||||
name,
|
|
||||||
graphicsType,
|
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -21,20 +18,7 @@ GameLib.D3.API.Graphics = function (
|
||||||
parentEntity
|
parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
||||||
id = GameLib.Utils.RandomId();
|
|
||||||
}
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'Graphics (' + id + ')';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(graphicsType)) {
|
|
||||||
graphicsType = GameLib.D3.Graphics.GRAPHICS_TYPE_THREE;
|
|
||||||
}
|
|
||||||
this.graphicsType = graphicsType;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.Graphics.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Graphics.prototype = Object.create(GameLib.Component.prototype);
|
|
@ -47,6 +47,7 @@ GameLib.Component.COMPONENT_VIEWPORT = 0x13;
|
||||||
GameLib.Component.COMPONENT_SYSTEM = 0x14;
|
GameLib.Component.COMPONENT_SYSTEM = 0x14;
|
||||||
GameLib.Component.COMPONENT_GRAPHICS = 0x15;
|
GameLib.Component.COMPONENT_GRAPHICS = 0x15;
|
||||||
GameLib.Component.COMPONENT_HELPER = 0x16;
|
GameLib.Component.COMPONENT_HELPER = 0x16;
|
||||||
|
GameLib.Component.COMPONENT_CUSTOM_CODE = 0x17;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Components are linked at runtime - for storing, we just store the ID
|
* Components are linked at runtime - for storing, we just store the ID
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/**
|
||||||
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param code String
|
||||||
|
* @param domElementId
|
||||||
|
* @param parentEntity
|
||||||
|
* @param args
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.CustomCode = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
code,
|
||||||
|
domElementId,
|
||||||
|
parentEntity,
|
||||||
|
args
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_CUSTOM_CODE,
|
||||||
|
{
|
||||||
|
'args' : [GameLib.Component]
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'CustomCode (' + this.id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(code)) {
|
||||||
|
code = '';
|
||||||
|
}
|
||||||
|
this.code = code;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
|
||||||
|
domElementId = "CustomCode_" + this.id;
|
||||||
|
}
|
||||||
|
this.domElementId = domElementId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(args)) {
|
||||||
|
args = [];
|
||||||
|
}
|
||||||
|
this.args = args;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.CustomCode.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.CustomCode.prototype.constructor = GameLib.D3.API.CustomCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.CustomCode
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.API.CustomCode}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.CustomCode.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.CustomCode(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.code,
|
||||||
|
objectComponent.domElementId,
|
||||||
|
objectComponent.parentEntity,
|
||||||
|
objectComponent.args
|
||||||
|
);
|
||||||
|
};
|
|
@ -2,7 +2,7 @@
|
||||||
* Raw Editor API object - should always correspond with the Editor Schema
|
* Raw Editor API object - should always correspond with the Editor Schema
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param games [GameLib.API.D3.Game]
|
* @param game [GameLib.API.D3.Game]
|
||||||
* @param allSelected
|
* @param allSelected
|
||||||
* @param selectedObjects
|
* @param selectedObjects
|
||||||
* @param viewports
|
* @param viewports
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
GameLib.D3.API.Editor = function(
|
GameLib.D3.API.Editor = function(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
games,
|
game,
|
||||||
allSelected,
|
allSelected,
|
||||||
selectedObjects,
|
selectedObjects,
|
||||||
viewports,
|
viewports,
|
||||||
|
@ -21,7 +21,9 @@ GameLib.D3.API.Editor = function(
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_EDITOR,
|
GameLib.Component.COMPONENT_EDITOR,
|
||||||
null,
|
{
|
||||||
|
'game' : GameLib.D3.Game
|
||||||
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
);
|
);
|
||||||
|
@ -36,10 +38,10 @@ GameLib.D3.API.Editor = function(
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(games)) {
|
if (GameLib.Utils.UndefinedOrNull(game)) {
|
||||||
games = [];
|
game = null;
|
||||||
}
|
}
|
||||||
this.games = games;
|
this.game = game;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(allSelected)) {
|
if (GameLib.Utils.UndefinedOrNull(allSelected)) {
|
||||||
allSelected = false;
|
allSelected = false;
|
||||||
|
@ -70,7 +72,7 @@ GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) {
|
||||||
return new GameLib.D3.API.Editor(
|
return new GameLib.D3.API.Editor(
|
||||||
objectEditor.id,
|
objectEditor.id,
|
||||||
objectEditor.name,
|
objectEditor.name,
|
||||||
objectEditor.games,
|
objectEditor.game,
|
||||||
objectEditor.allSelected,
|
objectEditor.allSelected,
|
||||||
objectEditor.selectedObjects,
|
objectEditor.selectedObjects,
|
||||||
objectEditor.viewports,
|
objectEditor.viewports,
|
||||||
|
|
|
@ -37,18 +37,13 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
parentEntity
|
parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.meshMoveMode = false;
|
|
||||||
this.meshMoveXMode = false;
|
|
||||||
this.meshMoveYMode = false;
|
|
||||||
this.meshMoveZMode = false;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = this.constructor.name;
|
name = 'Input Editor (' + this.id + ')';
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
@ -62,6 +57,11 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
}
|
}
|
||||||
this.domContainerId = domContainerId;
|
this.domContainerId = domContainerId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(editor)) {
|
||||||
|
editor = null;
|
||||||
|
}
|
||||||
|
this.editor = editor;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
camera = null;
|
camera = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/**
|
||||||
|
* Coder
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param coderType
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Coder = function Coder(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
coderType
|
||||||
|
) {
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Coder (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(coderType)) {
|
||||||
|
coderType = GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR;
|
||||||
|
}
|
||||||
|
this.coderType = coderType;
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Coder.prototype = Object.create(GameLib.D3.API.Coder.prototype);
|
||||||
|
GameLib.D3.Coder.prototype.constructor = GameLib.D3.Coder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameLib.D3.Coder Types
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR = 0x1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {THREE.Coder}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Coder.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
} else {
|
||||||
|
instance = CodeMirror;
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Coder.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if THREE physics
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Coder.prototype.isCodeMirror = function() {
|
||||||
|
return (this.coderType == GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a warning and throws an error if not cannon
|
||||||
|
*/
|
||||||
|
GameLib.D3.Coder.prototype.isNotCodeMirrorThrow = function() {
|
||||||
|
if (this.coderType != GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR) {
|
||||||
|
console.warn('Only CodeMirror supported for this function');
|
||||||
|
throw new Error('Only CodeMirror supported for this function');
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,98 @@
|
||||||
|
/**
|
||||||
|
* Creates a CustomCode object
|
||||||
|
* @param apiCustomCode GameLib.D3.API.CustomCode
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.CustomCode = function(
|
||||||
|
apiCustomCode
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiCustomCode)) {
|
||||||
|
apiCustomCode = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.CustomCode.call(
|
||||||
|
this,
|
||||||
|
apiCustomCode.id,
|
||||||
|
apiCustomCode.name,
|
||||||
|
apiCustomCode.code,
|
||||||
|
apiCustomCode.domElementId,
|
||||||
|
apiCustomCode.parentEntity,
|
||||||
|
apiCustomCode.args
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.CustomCode.prototype = Object.create(GameLib.D3.API.CustomCode.prototype);
|
||||||
|
GameLib.D3.CustomCode.prototype.constructor = GameLib.D3.CustomCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||||||
|
* @returns {THREE.CustomCode}
|
||||||
|
*/
|
||||||
|
GameLib.D3.CustomCode.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = function(deltaTime) {
|
||||||
|
this.args['deltaTime'] = deltaTime;
|
||||||
|
var f = new Function(this.code).apply(this.parentEntity, this.args);
|
||||||
|
f();
|
||||||
|
};
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.CustomCode.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.CustomCode to a new GameLib.D3.API.CustomCode
|
||||||
|
* @returns {GameLib.D3.API.CustomCode}
|
||||||
|
*/
|
||||||
|
GameLib.D3.CustomCode.prototype.toApiCustomCode = function() {
|
||||||
|
|
||||||
|
var apiArgs = [];
|
||||||
|
|
||||||
|
if (this.args) {
|
||||||
|
apiArgs = this.args.map(
|
||||||
|
function(arg) {
|
||||||
|
return GameLib.Utils.IdOrNull(arg);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GameLib.D3.API.CustomCode(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.code,
|
||||||
|
this.domElementId,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||||
|
apiArgs
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object CustomCode to a GameLib.D3.CustomCode
|
||||||
|
* @param objectCustomCode Object
|
||||||
|
* @returns {GameLib.D3.CustomCode}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.CustomCode.FromObjectCustomCode = function(objectCustomCode) {
|
||||||
|
|
||||||
|
var apiCustomCode = GameLib.D3.API.CustomCode.FromObjectCustomCode(objectCustomCode);
|
||||||
|
|
||||||
|
return new GameLib.D3.CustomCode(
|
||||||
|
apiCustomCode
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GameLib.D3.CustomCode.prototype.update = function(deltaTime) {
|
||||||
|
this.instance(deltaTime);
|
||||||
|
};
|
|
@ -2,12 +2,13 @@
|
||||||
* Creates a Editor object
|
* Creates a Editor object
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiEditor GameLib.D3.API.Editor
|
* @param apiEditor GameLib.D3.API.Editor
|
||||||
|
* @param onSelectionChanged
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Editor = function(
|
GameLib.D3.Editor = function(
|
||||||
graphics,
|
graphics,
|
||||||
apiEditor,
|
apiEditor,
|
||||||
onSelectionChange
|
onSelectionChanged
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
@ -21,28 +22,25 @@ GameLib.D3.Editor = function(
|
||||||
this,
|
this,
|
||||||
apiEditor.id,
|
apiEditor.id,
|
||||||
apiEditor.name,
|
apiEditor.name,
|
||||||
apiEditor.games,
|
apiEditor.game,
|
||||||
apiEditor.allSelected,
|
apiEditor.allSelected,
|
||||||
apiEditor.selectedObjects,
|
apiEditor.selectedObjects,
|
||||||
apiEditor.viewports,
|
apiEditor.viewports,
|
||||||
apiEditor.parentEntity
|
apiEditor.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.games = this.games.map(
|
if (this.game) {
|
||||||
function(apiGame) {
|
if (this.game instanceof GameLib.D3.API.Game) {
|
||||||
|
this.game = new GameLib.D3.Game(
|
||||||
if (apiGame instanceof GameLib.D3.API.Game) {
|
|
||||||
return GameLib.D3.Game(
|
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiGame
|
this.game
|
||||||
)
|
)
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
console.warn('Game not of type API.Game');
|
console.warn('Game not of type API.Game');
|
||||||
throw new Error('Game not of type API.Game');
|
throw new Error('Game not of type API.Game');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.viewports = this.viewports.map(
|
this.viewports = this.viewports.map(
|
||||||
function(apiViewport) {
|
function(apiViewport) {
|
||||||
|
@ -60,10 +58,10 @@ GameLib.D3.Editor = function(
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(onSelectionChange)) {
|
if (GameLib.Utils.UndefinedOrNull(onSelectionChanged)) {
|
||||||
onSelectionChange = null;
|
onSelectionChanged = null;
|
||||||
}
|
}
|
||||||
this.onSelectionChange = onSelectionChange;
|
this.onSelectionChanged = onSelectionChanged;
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
@ -99,19 +97,15 @@ GameLib.D3.Editor.prototype.updateInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Editor.prototype.toApiEditor = function() {
|
GameLib.D3.Editor.prototype.toApiEditor = function() {
|
||||||
|
|
||||||
var apiGames = [];
|
var apiGame = null;
|
||||||
if (this.games) {
|
if (this.game) {
|
||||||
apiGames = this.games.map(
|
if (this.game instanceof GameLib.D3.Game) {
|
||||||
function(game) {
|
apiGame = this.game.toApiGame();
|
||||||
if (game instanceof GameLib.D3.Game) {
|
|
||||||
return game.toApiGame();
|
|
||||||
} else {
|
} else {
|
||||||
console.warn('Game not an instance of Game');
|
console.warn('Game not an instance of Game');
|
||||||
throw new Error('Game not an instance of Game');
|
throw new Error('Game not an instance of Game');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiViewports = [];
|
var apiViewports = [];
|
||||||
if (this.viewports) {
|
if (this.viewports) {
|
||||||
|
@ -130,7 +124,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
|
||||||
return new GameLib.D3.API.Editor(
|
return new GameLib.D3.API.Editor(
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
apiGames,
|
apiGame,
|
||||||
this.allSelected,
|
this.allSelected,
|
||||||
this.selectedObjects,
|
this.selectedObjects,
|
||||||
apiViewports,
|
apiViewports,
|
||||||
|
|
|
@ -186,28 +186,28 @@ GameLib.D3.Game.prototype.createInstance = function(update) {
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Game.prototype.setSize = function(width, height) {
|
// GameLib.D3.Game.prototype.setSize = function(width, height) {
|
||||||
|
|
||||||
// var w = 0;
|
|
||||||
// var h = 0;
|
|
||||||
|
|
||||||
this.viewports.map(
|
|
||||||
function(viewport) {
|
|
||||||
// w = viewport.width;
|
|
||||||
// h = viewport.height;
|
|
||||||
//
|
//
|
||||||
// //TODO : calculate width and height decrease or increase ratio and adjust viewport x and y offset according
|
// // var w = 0;
|
||||||
// var wx = width / w;
|
// // var h = 0;
|
||||||
// var hx = height / h;
|
//
|
||||||
|
// this.viewports.map(
|
||||||
viewport.width = width;
|
// function(viewport) {
|
||||||
viewport.height = height;
|
// // w = viewport.width;
|
||||||
|
// // h = viewport.height;
|
||||||
viewport.updateInstance();
|
// //
|
||||||
}
|
// // //TODO : calculate width and height decrease or increase ratio and adjust viewport x and y offset according
|
||||||
)
|
// // var wx = width / w;
|
||||||
|
// // var hx = height / h;
|
||||||
};
|
//
|
||||||
|
// viewport.width = width;
|
||||||
|
// viewport.height = height;
|
||||||
|
//
|
||||||
|
// viewport.updateInstance();
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the instance with the current state
|
* Updates the instance with the current state
|
||||||
|
|
|
@ -1,23 +1,29 @@
|
||||||
/**
|
/**
|
||||||
* Graphics Superset
|
* Graphics
|
||||||
* @param apiGraphics
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param graphicsType
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Graphics = function Graphics(
|
GameLib.D3.Graphics = function Graphics(
|
||||||
apiGraphics
|
id,
|
||||||
|
name,
|
||||||
|
graphicsType
|
||||||
) {
|
) {
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiGraphics)) {
|
id = GameLib.Utils.RandomId();
|
||||||
apiGraphics = {};
|
|
||||||
}
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
GameLib.D3.API.Graphics.call(
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
this,
|
name = 'Graphics (' + id + ')';
|
||||||
apiGraphics.id,
|
}
|
||||||
apiGraphics.name,
|
this.name = name;
|
||||||
apiGraphics.graphicsType,
|
|
||||||
apiGraphics.parentEntity
|
if (GameLib.Utils.UndefinedOrNull(graphicsType)) {
|
||||||
);
|
graphicsType = GameLib.D3.Graphics.GRAPHICS_TYPE_THREE;
|
||||||
|
}
|
||||||
|
this.graphicsType = graphicsType;
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
@ -54,37 +60,6 @@ GameLib.D3.Graphics.prototype.updateInstance = function() {
|
||||||
this.instance = this.createInstance(true);
|
this.instance = this.createInstance(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a GameLib.D3.Graphics to a new GameLib.D3.API.Graphics
|
|
||||||
* @returns {GameLib.D3.API.Graphics}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Graphics.prototype.toApiGraphics = function() {
|
|
||||||
return new GameLib.D3.API.Graphics(
|
|
||||||
this.id,
|
|
||||||
this.name,
|
|
||||||
this.graphicsType,
|
|
||||||
this.parentEntity
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts from an Object Graphics to a GameLib.D3.Graphics
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
|
||||||
* @param objectGraphics Object
|
|
||||||
* @returns {GameLib.D3.Graphics}
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.Graphics.FromObjectGraphics = function(graphics, objectGraphics) {
|
|
||||||
|
|
||||||
var apiGraphics = GameLib.D3.API.Graphics.FromObjectComponent(objectGraphics);
|
|
||||||
|
|
||||||
return new GameLib.D3.Graphics(
|
|
||||||
graphics,
|
|
||||||
apiGraphics
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if THREE physics
|
* True if THREE physics
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
|
|
|
@ -42,6 +42,11 @@ GameLib.D3.Input.Editor = function (
|
||||||
this.element = null;
|
this.element = null;
|
||||||
this.container = null;
|
this.container = null;
|
||||||
|
|
||||||
|
this.meshMoveMode = false;
|
||||||
|
this.meshMoveXMode = false;
|
||||||
|
this.meshMoveYMode = false;
|
||||||
|
this.meshMoveZMode = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We need new function pointers with scope bound to this so we can remove the
|
* We need new function pointers with scope bound to this so we can remove the
|
||||||
* window event handlers when we need to
|
* window event handlers when we need to
|
||||||
|
@ -61,48 +66,50 @@ GameLib.D3.Input.Editor.prototype.constructor = GameLib.D3.Input.Editor;
|
||||||
|
|
||||||
GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
|
GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
this.element = this.dom.document.getElementById(this.domElementId);
|
||||||
|
if (!this.element) {
|
||||||
if (update) {
|
|
||||||
instance = this.instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
instance = this.dom.document.getElementById(this.domElementId);
|
|
||||||
|
|
||||||
if (!instance) {
|
|
||||||
console.warn('Could not locate DOM element with ID: ' + this.domElementId);
|
console.warn('Could not locate DOM element with ID: ' + this.domElementId);
|
||||||
throw new Error('Could not locate DOM element with ID: ' + this.domElementId);
|
throw new Error('Could not locate DOM element with ID: ' + this.domElementId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.element = instance;
|
|
||||||
|
|
||||||
this.container = this.dom.document.getElementById(this.domContainerId);
|
this.container = this.dom.document.getElementById(this.domContainerId);
|
||||||
|
|
||||||
if (!this.container) {
|
if (!this.container) {
|
||||||
console.warn('Could not locate DOM container with ID: ' + this.domContainerId);
|
console.warn('Could not locate DOM container with ID: ' + this.domContainerId);
|
||||||
throw new Error('Could not locate DOM container with ID: ' + this.domContainerId);
|
throw new Error('Could not locate DOM container with ID: ' + this.domContainerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.addEventListener(
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
instance.camera = this.camera.instance;
|
||||||
|
return instance;
|
||||||
|
} else {
|
||||||
|
instance = new THREE.EditorControls(
|
||||||
|
this.camera.instance,
|
||||||
|
this.element
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.element.addEventListener(
|
||||||
'mousemove',
|
'mousemove',
|
||||||
this.mouseMove,
|
this.mouseMove,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
instance.addEventListener(
|
this.element.addEventListener(
|
||||||
'contextmenu',
|
'contextmenu',
|
||||||
this.contextMenu,
|
this.contextMenu,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
instance.addEventListener(
|
this.element.addEventListener(
|
||||||
'mousedown',
|
'mousedown',
|
||||||
this.mouseDown,
|
this.mouseDown,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
instance.addEventListener(
|
this.element.addEventListener(
|
||||||
'keydown',
|
'keydown',
|
||||||
this.keyPress,
|
this.keyPress,
|
||||||
false
|
false
|
||||||
|
@ -131,8 +138,13 @@ GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.domElementId,
|
this.domElementId,
|
||||||
|
this.domContainerId,
|
||||||
GameLib.Utils.IdOrNull(this.editor),
|
GameLib.Utils.IdOrNull(this.editor),
|
||||||
GameLib.Utils.IdOrNull(this.camera),
|
GameLib.Utils.IdOrNull(this.camera),
|
||||||
|
this.widthOffset,
|
||||||
|
this.heightOffset,
|
||||||
|
this.containerWidthOffset,
|
||||||
|
this.containerHeightOffset,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -154,14 +166,26 @@ GameLib.D3.Input.Editor.prototype.onWindowResize = function() {
|
||||||
this.container.style.height = (this.window.innerHeight - this.containerHeightOffset) + 'px';
|
this.container.style.height = (this.window.innerHeight - this.containerHeightOffset) + 'px';
|
||||||
this.container.style.width = (this.window.innerWidth - this.containerWidthOffset) + 'px';
|
this.container.style.width = (this.window.innerWidth - this.containerWidthOffset) + 'px';
|
||||||
|
|
||||||
this.games.map(
|
var width = this.window.innerWidth - this.widthOffset;
|
||||||
function(width, height) {
|
|
||||||
return function(game) {
|
var height = this.window.innerHeight - this.heightOffset;
|
||||||
game.width = width;
|
|
||||||
game.height = height;
|
//TODO: map the relative viewport sizes and offsets with the size differences
|
||||||
game.updateInstance();
|
|
||||||
|
this.editor.viewports.map(
|
||||||
|
function(viewport) {
|
||||||
|
viewport.width = width;
|
||||||
|
viewport.height = height;
|
||||||
|
viewport.updateInstance();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.editor.game.viewports.map(
|
||||||
|
function(viewport) {
|
||||||
|
viewport.width = width;
|
||||||
|
viewport.height = height;
|
||||||
|
viewport.updateInstance();
|
||||||
}
|
}
|
||||||
}(this.window.innerWidth - this.widthOffset, this.window.innerHeight - this.heightOffset)
|
|
||||||
);
|
);
|
||||||
//
|
//
|
||||||
// this.scene.cameras[this.scene.activeCameraIndex].aspect = () / window.innerHeight;
|
// this.scene.cameras[this.scene.activeCameraIndex].aspect = () / window.innerHeight;
|
||||||
|
|
|
@ -60,6 +60,8 @@ GameLib.D3.Viewport = function (
|
||||||
GameLib.D3.Viewport.prototype = Object.create(GameLib.D3.API.Viewport.prototype);
|
GameLib.D3.Viewport.prototype = Object.create(GameLib.D3.API.Viewport.prototype);
|
||||||
GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport;
|
GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport;
|
||||||
|
|
||||||
|
//GameLib.D3.Viewport.VIEWPORT_TYPE_GAME = 0x1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param update
|
* @param update
|
||||||
|
|
|
@ -90,7 +90,7 @@ GameLib.System.prototype.start = function() {
|
||||||
* @callback
|
* @callback
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.update = function() {
|
GameLib.System.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
if (this.systemType == GameLib.System.SYSTEM_TYPE_INPUT) {
|
if (this.systemType == GameLib.System.SYSTEM_TYPE_INPUT) {
|
||||||
this.driveInputObjects.forEach(
|
this.driveInputObjects.forEach(
|
||||||
|
@ -100,14 +100,6 @@ GameLib.System.prototype.update = function() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.systemType == GameLib.System.SYSTEM_TYPE_RENDER) {
|
|
||||||
this.viewports.forEach(
|
|
||||||
function (viewport) {
|
|
||||||
viewport.update(deltaTime);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType == GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
if (this.systemType == GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||||
this.pathFollowingObjects.forEach(
|
this.pathFollowingObjects.forEach(
|
||||||
function(object) {
|
function(object) {
|
||||||
|
@ -146,6 +138,14 @@ GameLib.System.prototype.update = function() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.systemType == GameLib.System.SYSTEM_TYPE_RENDER) {
|
||||||
|
this.viewports.forEach(
|
||||||
|
function (viewport) {
|
||||||
|
viewport.update(deltaTime);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue