94 lines
1.9 KiB
JavaScript
94 lines
1.9 KiB
JavaScript
|
/**
|
||
|
* Canvas object
|
||
|
* @param apiCanvas
|
||
|
* @returns {GameLib.Canvas}
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.Canvas = function(
|
||
|
apiCanvas
|
||
|
) {
|
||
|
if (GameLib.Utils.UndefinedOrNull(apiCanvas)) {
|
||
|
apiCanvas = {};
|
||
|
}
|
||
|
|
||
|
if (apiCanvas instanceof GameLib.Canvas) {
|
||
|
return apiCanvas;
|
||
|
}
|
||
|
|
||
|
GameLib.API.Canvas.call(
|
||
|
this,
|
||
|
apiCanvas.id,
|
||
|
apiCanvas.name,
|
||
|
apiCanvas.width,
|
||
|
apiCanvas.height,
|
||
|
apiCanvas.parentEntity
|
||
|
);
|
||
|
|
||
|
GameLib.Component.call(
|
||
|
this,
|
||
|
GameLib.Component.COMPONENT_CANVAS
|
||
|
);
|
||
|
};
|
||
|
|
||
|
GameLib.Canvas.prototype = Object.create(GameLib.API.Canvas.prototype);
|
||
|
GameLib.Canvas.prototype.constructor = GameLib.Canvas;
|
||
|
|
||
|
/**
|
||
|
* Creates a light instance
|
||
|
* @returns {*}
|
||
|
*/
|
||
|
GameLib.Canvas.prototype.createInstance = function() {
|
||
|
|
||
|
this.instance = document.createElement('canvas');
|
||
|
|
||
|
this.instance.width = this.width;
|
||
|
this.instance.height = this.height;
|
||
|
|
||
|
GameLib.Component.prototype.createInstance.call(this);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Updates the instance with the current state
|
||
|
*/
|
||
|
GameLib.Canvas.prototype.updateInstance = function(property) {
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(property)) {
|
||
|
console.warn('unknown property update for Canvas: ' + property);
|
||
|
}
|
||
|
|
||
|
if (property === 'width') {
|
||
|
this.instance.width = this.width;
|
||
|
}
|
||
|
|
||
|
if (property === 'height') {
|
||
|
this.instance.height = this.height;
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Converts a GameLib.Canvas to a GameLib.API.Canvas
|
||
|
* @returns {GameLib.API.Canvas}
|
||
|
*/
|
||
|
GameLib.Canvas.prototype.toApiObject = function() {
|
||
|
return new GameLib.API.Canvas(
|
||
|
this.id,
|
||
|
this.name,
|
||
|
this.width,
|
||
|
this.height,
|
||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||
|
);
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Returns a new GameLib.Canvas from a GameLib.API.Canvas
|
||
|
* @param objectCanvas GameLib.API.Canvas
|
||
|
* @returns {GameLib.Canvas}
|
||
|
*/
|
||
|
GameLib.Canvas.FromObject = function(objectCanvas) {
|
||
|
|
||
|
return new GameLib.Canvas(
|
||
|
GameLib.API.Canvas.FromObject(objectCanvas)
|
||
|
);
|
||
|
|
||
|
};
|