118 lines
2.5 KiB
JavaScript
118 lines
2.5 KiB
JavaScript
/**
|
|
* Image
|
|
* @constructor
|
|
* @param apiImage
|
|
*/
|
|
GameLib.Image = function(
|
|
apiImage
|
|
) {
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiImage)) {
|
|
apiImage = {};
|
|
}
|
|
|
|
if (apiImage instanceof GameLib.Image) {
|
|
return apiImage;
|
|
}
|
|
|
|
GameLib.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.Image.prototype = Object.create(GameLib.API.Image.prototype);
|
|
GameLib.Image.prototype.constructor = GameLib.Image;
|
|
|
|
/**
|
|
* Creates an image instance
|
|
* @returns {*}
|
|
*/
|
|
GameLib.Image.prototype.createInstance = function() {
|
|
|
|
GameLib.Event.Emit(
|
|
GameLib.Event.LOAD_IMAGE,
|
|
{
|
|
image : this
|
|
},
|
|
function(imageInstance) {
|
|
this.instance = imageInstance;
|
|
GameLib.Component.prototype.createInstance.call(this);
|
|
}.bind(this),
|
|
function(error) {
|
|
console.error(error);
|
|
this.instance = null;
|
|
GameLib.Component.prototype.createInstance.call(this);
|
|
}.bind(this)
|
|
);
|
|
|
|
};
|
|
|
|
/**
|
|
* Updates the instance with the current state
|
|
*/
|
|
GameLib.Image.prototype.updateInstance = function(property) {
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(property)) {
|
|
console.warn('unknown property update for Image: ' + property);
|
|
}
|
|
|
|
if (
|
|
property === 'fileName' ||
|
|
property === 'extension' ||
|
|
property === 'path'
|
|
) {
|
|
this.createInstance();
|
|
}
|
|
};
|
|
|
|
GameLib.Image.prototype.updateFromRawObject = function(rawObject) {
|
|
this.id = rawObject.id;
|
|
this.name = rawObject.name;
|
|
this.fileName = rawObject.fileName;
|
|
this.extension = rawObject.extension;
|
|
this.path = rawObject.path;
|
|
this.contentType = rawObject.contentType;
|
|
this.size = rawObject.size;
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @returns {GameLib.API.Image}
|
|
*/
|
|
GameLib.Image.prototype.toApiObject = function() {
|
|
|
|
var apiImage = new GameLib.API.Image(
|
|
this.id,
|
|
this.name,
|
|
this.fileName,
|
|
this.extension,
|
|
this.path,
|
|
this.contentType,
|
|
this.size,
|
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
);
|
|
|
|
return apiImage;
|
|
};
|
|
|
|
/**
|
|
* @param objectImage
|
|
* @returns {GameLib.Image}
|
|
* @constructor
|
|
*/
|
|
GameLib.Image.FromObject = function(objectImage) {
|
|
return new GameLib.Image(
|
|
GameLib.API.Image.FromObject(objectImage)
|
|
);
|
|
};
|