RpyPlayerWeb/public_html/js/Utils.js

97 lines
2.3 KiB
JavaScript
Raw Normal View History

var baseResDir = 'file:///E:/everlastingsummer/';
//var baseResDir = '/resources/es/';
2015-12-06 13:49:35 +02:00
function FadeInfo() {
this.fadeIn = false;
this.fadeOut = false;
this.duration = 0;
}
function TextUtilsImpl() { }
TextUtilsImpl.prototype.isEmpty = function (text) {
if (text === undefined) return true;
return text.length === 0;
};
var TextUtils = new TextUtilsImpl();
String.prototype.equalsIgnoreCase = function(text) {
return this.toLowerCase() == text.toLowerCase();
};
String.prototype.equals = function(text) {
return this == text;
};
String.prototype.contains = function(text) {
return this.indexOf(text) >= 0;
};
2015-12-07 14:37:31 +02:00
String.prototype.replaceAll = function(search, replace) {
return this.split(search).join(replace);
};
String.prototype.startsWith = function(text) {
2015-12-06 13:49:35 +02:00
return this.indexOf(text) == 0;
2015-12-07 14:37:31 +02:00
};
2015-12-06 13:49:35 +02:00
String.prototype.replaceAll = function (find, replace) {
var str = this;
return str.replace(new RegExp(find, 'g'), replace);
};
function toColor(num) {
num >>>= 0;
var b = num & 0xFF,
g = (num & 0xFF00) >>> 8,
r = (num & 0xFF0000) >>> 16,
a = ( (num & 0xFF000000) >>> 24 ) / 255 ;
return "rgba(" + [r, g, b, a].join(",") + ")";
}
var PathResolver = new function () {
this.background = function (type, name) {
return baseResDir + type.toLowerCase() + "/" + name + ".jpg";
2015-12-06 13:49:35 +02:00
};
this.sprite = function (whoid, params) {
var path = baseResDir + "sprites/";
2015-12-06 13:49:35 +02:00
path += whoid.toLowerCase() + "/";
path += (TextUtils.isEmpty(params) ? "normal" : params);
path += ".png";
return path;
};
this.music = function (name) {
return baseResDir + "music/" + name + ".ogg";
2015-12-06 13:49:35 +02:00
};
this.sound = function (name) {
var path = baseResDir + "sfx/";
2015-12-08 12:27:55 +02:00
if (name.startsWith("sfx_")) path += name.substring(4);
2015-12-06 13:49:35 +02:00
else path += name;
path += ".ogg";
return path;
};
2015-12-07 19:35:47 +02:00
};
function Menu(title) {
this.title = title;
this.items = new Array();
}
Menu.prototype.getTitle = function () { return this.title; };
Menu.prototype.getItems = function () { return this.items; };
Menu.prototype.addItem = function (name, position) {
this.items.push({name: name, position: position});
};
Menu.prototype.getPosition = function (itemIndex) {
return this.items[itemIndex].position;
};