78 lines
1.6 KiB
JavaScript
78 lines
1.6 KiB
JavaScript
|
/**
|
||
|
* Image
|
||
|
* @param id
|
||
|
* @param name
|
||
|
* @param path
|
||
|
* @param contentType
|
||
|
* @param parentEntity GameLib.Entity
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.API.Image = function(
|
||
|
id,
|
||
|
name,
|
||
|
path,
|
||
|
contentType,
|
||
|
parentEntity
|
||
|
) {
|
||
|
|
||
|
GameLib.Component.call(
|
||
|
this,
|
||
|
GameLib.Component.COMPONENT_IMAGE,
|
||
|
null,
|
||
|
null,
|
||
|
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;
|
||
|
};
|
||
|
|
||
|
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,
|
||
|
objectImage.parentEntity
|
||
|
);
|
||
|
};
|
||
|
|