2017-06-08 18:17:03 +02:00
|
|
|
/**
|
|
|
|
* Image
|
|
|
|
* @param id
|
|
|
|
* @param name
|
|
|
|
* @param path
|
|
|
|
* @param contentType
|
2017-06-12 15:35:13 +02:00
|
|
|
* @param size
|
2017-06-08 18:17:03 +02:00
|
|
|
* @param parentEntity GameLib.Entity
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Image = function(
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
path,
|
|
|
|
contentType,
|
2017-06-12 15:35:13 +02:00
|
|
|
size,
|
2017-06-08 18:17:03 +02:00
|
|
|
parentEntity
|
|
|
|
) {
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
|
|
|
}
|
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
|
|
name = 'Image ' + GameLib.Utils.RandomId() + '.png';
|
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(path)) {
|
|
|
|
path = '/' + this.name.toLowerCase().replace(' ', '_');
|
|
|
|
}
|
|
|
|
this.path = path;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(contentType)) {
|
|
|
|
|
|
|
|
contentType = 'application/octet-stream';
|
|
|
|
|
|
|
|
if (this.name.match(/(png)$/i)) {
|
|
|
|
contentType = 'image/png';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.name.match(/(jpg|jpeg)$/i)) {
|
|
|
|
contentType = 'image/jpeg';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.name.match(/(gif)$/i)) {
|
|
|
|
contentType = 'image/gif';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.contentType = contentType;
|
2017-06-12 15:35:13 +02:00
|
|
|
|
2017-06-16 20:03:55 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(size)) {
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
this.size = size;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
|
|
parentEntity = null;
|
|
|
|
}
|
|
|
|
this.parentEntity = parentEntity;
|
2017-06-08 18:17:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.API.Image.prototype = Object.create(GameLib.Component.prototype);
|
|
|
|
GameLib.D3.API.Image.prototype.constructor = GameLib.D3.API.Image;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an API light from an Object light
|
|
|
|
* @constructor
|
|
|
|
* @param objectImage
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.Image.FromObject = function(objectImage) {
|
|
|
|
return new GameLib.D3.API.Image(
|
|
|
|
objectImage.id,
|
|
|
|
objectImage.name,
|
|
|
|
objectImage.path,
|
|
|
|
objectImage.contentType,
|
2017-06-12 15:35:13 +02:00
|
|
|
objectImage.size,
|
2017-06-08 18:17:03 +02:00
|
|
|
objectImage.parentEntity
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|