r3-legacy/src/game-lib-d3-image.js

99 lines
1.9 KiB
JavaScript

/**
* Image
* @constructor
* @param graphics
* @param apiImage
*/
GameLib.D3.Image = function(
graphics,
apiImage
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiImage)) {
apiImage = {};
}
if (apiImage instanceof GameLib.D3.Image) {
return apiImage;
}
GameLib.D3.API.Image.call(
this,
apiImage.id,
apiImage.name,
apiImage.fileName,
apiImage.extension,
apiImage.path,
apiImage.contentType,
apiImage.size,
apiImage.parentEntity
);
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_IMAGE,
null,
true
);
GameLib.Event.Emit(
GameLib.Event.LOAD_IMAGE,
{
image : this
}
);
};
GameLib.D3.Image.prototype = Object.create(GameLib.D3.API.Image.prototype);
GameLib.D3.Image.prototype.constructor = GameLib.D3.Image;
/**
* Creates an image instance
* @returns {*}
*/
GameLib.D3.Image.prototype.createInstance = function() {
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Image.prototype.updateInstance = function() {
this.createInstance();
};
/**
*
* @returns {GameLib.D3.API.Image}
*/
GameLib.D3.Image.prototype.toApiObject = function() {
var apiImage = new GameLib.D3.API.Image(
this.id,
this.name,
this.fileName,
this.extension,
this.path,
this.contentType,
this.size,
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiImage;
};
/**
* @param graphics
* @param objectImage
* @returns {GameLib.D3.Image}
* @constructor
*/
GameLib.D3.Image.FromObject = function(graphics, objectImage) {
return new GameLib.D3.Image(
graphics,
GameLib.D3.API.Image.FromObject(objectImage)
);
};