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

108 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-10-14 12:32:53 +02:00
/**
* Image
* @constructor
2017-06-08 18:17:03 +02:00
* @param apiImage
2016-10-14 12:32:53 +02:00
*/
2017-12-02 12:11:14 +01:00
GameLib.Image = function(
2017-06-08 18:17:03 +02:00
apiImage
2016-10-14 12:32:53 +02:00
) {
2017-08-15 22:26:12 +02:00
2017-06-08 18:17:03 +02:00
if (GameLib.Utils.UndefinedOrNull(apiImage)) {
apiImage = {};
2016-11-17 18:31:41 +01:00
}
2016-10-14 12:32:53 +02:00
2017-12-02 12:11:14 +01:00
if (apiImage instanceof GameLib.Image) {
2017-06-08 18:17:03 +02:00
return apiImage;
2016-10-14 12:32:53 +02:00
}
2017-12-02 12:11:14 +01:00
GameLib.API.Image.call(
2017-06-08 18:17:03 +02:00
this,
apiImage.id,
apiImage.name,
2017-08-15 22:26:12 +02:00
apiImage.fileName,
apiImage.extension,
2017-06-08 18:17:03 +02:00
apiImage.path,
apiImage.contentType,
2017-06-13 16:35:19 +02:00
apiImage.size,
2017-06-08 18:17:03 +02:00
apiImage.parentEntity
);
2016-10-14 12:32:53 +02:00
2017-12-04 13:23:15 +01:00
GameLib.Component.call(this);
2017-06-08 18:17:03 +02:00
};
2016-10-14 12:32:53 +02:00
2017-12-02 12:11:14 +01:00
GameLib.Image.prototype = Object.create(GameLib.API.Image.prototype);
GameLib.Image.prototype.constructor = GameLib.Image;
2016-10-14 12:32:53 +02:00
2017-06-08 18:17:03 +02:00
/**
* Creates an image instance
2017-06-08 18:17:03 +02:00
* @returns {*}
*/
2017-12-02 12:11:14 +01:00
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)
);
2017-06-08 18:17:03 +02:00
};
/**
* Updates the instance with the current state
*/
2017-12-02 12:11:14 +01:00
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();
}
2017-06-08 18:17:03 +02:00
};
/**
*
2017-12-02 12:11:14 +01:00
* @returns {GameLib.API.Image}
2017-06-08 18:17:03 +02:00
*/
2017-12-02 12:11:14 +01:00
GameLib.Image.prototype.toApiObject = function() {
2017-06-08 18:17:03 +02:00
2017-12-02 12:11:14 +01:00
var apiImage = new GameLib.API.Image(
2017-06-08 18:17:03 +02:00
this.id,
this.name,
2017-08-15 22:26:12 +02:00
this.fileName,
this.extension,
2017-06-08 18:17:03 +02:00
this.path,
this.contentType,
2017-06-13 16:35:19 +02:00
this.size,
2017-06-08 18:17:03 +02:00
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiImage;
};
/**
* @param objectImage
2017-12-02 12:11:14 +01:00
* @returns {GameLib.Image}
2017-06-08 18:17:03 +02:00
* @constructor
*/
2017-12-02 12:11:14 +01:00
GameLib.Image.FromObject = function(objectImage) {
return new GameLib.Image(
GameLib.API.Image.FromObject(objectImage)
2017-06-08 18:17:03 +02:00
);
2016-11-17 18:31:41 +01:00
};