HumanBreak/public/libs/icons.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-12-29 23:08:44 +08:00
///<reference path="../../src/types/core.d.ts" />
2022-11-16 23:01:23 +08:00
'use strict';
2022-11-13 18:02:05 +08:00
2022-11-16 23:01:23 +08:00
function icons() {
2022-11-13 18:02:05 +08:00
this._init();
}
icons.prototype._init = function () {
this.icons = icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1;
//delete(icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1);
// tileset的起点
this.tilesetStartOffset = 10000;
2022-11-16 23:01:23 +08:00
};
2022-11-13 18:02:05 +08:00
icons.prototype.getIcons = function () {
var icons = core.clone(this.icons);
icons.hero.leftup = icons.hero.leftdown = icons.hero.left;
icons.hero.rightup = icons.hero.rightdown = icons.hero.right;
return icons;
2022-11-16 23:01:23 +08:00
};
2022-11-13 18:02:05 +08:00
////// 根据道具ID获得其cls //////
icons.prototype.getClsFromId = function (id) {
for (var cls in core.material.icons) {
2022-11-16 23:01:23 +08:00
if (cls != 'hero' && id in core.material.icons[cls]) return cls;
2022-11-13 18:02:05 +08:00
}
return null;
2022-11-16 23:01:23 +08:00
};
2022-11-13 18:02:05 +08:00
icons.prototype.getAllIconIds = function () {
if (this.allIconIds) return this.allIconIds;
this.allIconIds = [];
for (var type in this.icons) {
this.allIconIds = this.allIconIds.concat(Object.keys(this.icons[type]));
}
return this.allIconIds;
2022-11-16 23:01:23 +08:00
};
2022-11-13 18:02:05 +08:00
2022-11-16 23:01:23 +08:00
icons.prototype.getAnimateFrames = function (cls) {
2022-11-13 18:02:05 +08:00
if (cls == 'enemys' || cls == 'npcs') {
return 2;
}
if (cls == 'animates' || cls == 'enemy48' || cls == 'npc48') {
return 4;
}
return 1;
2022-11-16 23:01:23 +08:00
};
2022-11-13 18:02:05 +08:00
////// 根据图块数字或ID获得所在的tileset和坐标信息 //////
icons.prototype.getTilesetOffset = function (id) {
if (typeof id == 'string') {
id = core.getIdOfThis(id);
// Tileset的ID必须是 X+数字 的形式
if (!/^X\d+$/.test(id)) return null;
id = parseInt(id.substring(1));
2022-11-16 23:01:23 +08:00
} else if (typeof id != 'number') {
2022-11-13 18:02:05 +08:00
return null;
}
core.tilesets = core.tilesets || [];
var startOffset = this.tilesetStartOffset;
for (var i in core.tilesets) {
var imgName = core.tilesets[i];
var img = core.material.images.tilesets[imgName];
2022-11-16 23:01:23 +08:00
var width = Math.floor(parseInt(img.getAttribute('_width')) / 32),
height = Math.floor(parseInt(img.getAttribute('_height')) / 32);
2022-11-13 18:02:05 +08:00
if (id >= startOffset && id < startOffset + width * height) {
2022-11-16 23:01:23 +08:00
var x = (id - startOffset) % width,
y = parseInt((id - startOffset) / width);
return { image: imgName, x: x, y: y };
2022-11-13 18:02:05 +08:00
}
startOffset += this.tilesetStartOffset;
}
return null;
2022-11-16 23:01:23 +08:00
};