Restructure
This commit is contained in:
parent
890001a9dc
commit
0974656ad1
@ -49,7 +49,7 @@ editor.prototype.idsInit = function(maps, icons){
|
||||
editor.indexs = [];
|
||||
var MAX_NUM = 400;
|
||||
var getInfoById = function(id){
|
||||
var block = maps.getBlock(0, 0, id);
|
||||
var block = maps.initBlock(0, 0, id);
|
||||
if(hasOwnProp(block, 'event')){
|
||||
return block;
|
||||
}
|
||||
|
||||
1909
libs/actions.js
Normal file
1909
libs/actions.js
Normal file
File diff suppressed because it is too large
Load Diff
2482
libs/control.js
Normal file
2482
libs/control.js
Normal file
File diff suppressed because it is too large
Load Diff
4933
libs/core.js
4933
libs/core.js
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
function data() {
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
data.prototype.init = function() {
|
||||
@ -11,6 +11,4 @@ data.prototype.init = function() {
|
||||
|
||||
data.prototype.getFirstData = function() {
|
||||
return core.clone(this.firstData);
|
||||
}
|
||||
|
||||
main.instance.data = new data();
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
function enemys() {
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
////// 初始化 //////
|
||||
@ -285,6 +285,4 @@ enemys.prototype.getCurrentEnemys = function (floorId) {
|
||||
return a.damage - b.damage;
|
||||
});
|
||||
return enemys;
|
||||
}
|
||||
|
||||
main.instance.enemys = new enemys();
|
||||
}
|
||||
1539
libs/events.js
1539
libs/events.js
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
function icons() {
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
icons.prototype.init = function () {
|
||||
@ -9,6 +9,4 @@ icons.prototype.init = function () {
|
||||
|
||||
icons.prototype.getIcons = function () {
|
||||
return this.icons;
|
||||
}
|
||||
|
||||
main.instance.icons = new icons();
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
function items() {
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
////// 初始化 //////
|
||||
@ -36,8 +36,6 @@ items.prototype.getItems = function () {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
main.instance.items = new items();
|
||||
|
||||
////// “即捡即用类”道具的使用效果 //////
|
||||
items.prototype.getItemEffect = function(itemId, itemNum) {
|
||||
var itemCls = core.material.items[itemId].cls;
|
||||
@ -319,3 +317,57 @@ items.prototype.canUseItem = function (itemId) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////// 获得某个物品的个数 //////
|
||||
items.prototype.itemCount = function (itemId) {
|
||||
if (!core.isset(itemId) || !core.isset(core.material.items[itemId])) return 0;
|
||||
var itemCls = core.material.items[itemId].cls;
|
||||
if (itemCls=="items") return 0;
|
||||
return core.isset(core.status.hero.items[itemCls][itemId]) ? core.status.hero.items[itemCls][itemId] : 0;
|
||||
}
|
||||
|
||||
////// 是否存在某个物品 //////
|
||||
items.prototype.hasItem = function (itemId) {
|
||||
return core.itemCount(itemId) > 0;
|
||||
}
|
||||
|
||||
////// 设置某个物品的个数 //////
|
||||
items.prototype.setItem = function (itemId, itemNum) {
|
||||
var itemCls = core.material.items[itemId].cls;
|
||||
if (itemCls == 'items') return;
|
||||
if (!core.isset(core.status.hero.items[itemCls])) {
|
||||
core.status.hero.items[itemCls] = {};
|
||||
}
|
||||
core.status.hero.items[itemCls][itemId] = itemNum;
|
||||
if (itemCls!='keys' && itemNum==0) {
|
||||
delete core.status.hero.items[itemCls][itemId];
|
||||
}
|
||||
}
|
||||
|
||||
////// 删除某个物品 //////
|
||||
items.prototype.removeItem = function (itemId) {
|
||||
if (!core.hasItem(itemId)) return false;
|
||||
var itemCls = core.material.items[itemId].cls;
|
||||
core.status.hero.items[itemCls][itemId]--;
|
||||
if (itemCls!='keys' && core.status.hero.items[itemCls][itemId]==0) {
|
||||
delete core.status.hero.items[itemCls][itemId];
|
||||
}
|
||||
core.updateStatusBar();
|
||||
return true;
|
||||
}
|
||||
|
||||
////// 增加某个物品的个数 //////
|
||||
items.prototype.addItem = function (itemId, itemNum) {
|
||||
var itemData = core.material.items[itemId];
|
||||
var itemCls = itemData.cls;
|
||||
if (itemCls == 'items') return;
|
||||
if (!core.isset(core.status.hero.items[itemCls])) {
|
||||
core.status.hero.items[itemCls] = {};
|
||||
core.status.hero.items[itemCls][itemId] = 0;
|
||||
}
|
||||
else if (!core.isset(core.status.hero.items[itemCls][itemId])) {
|
||||
core.status.hero.items[itemCls][itemId] = 0;
|
||||
}
|
||||
core.status.hero.items[itemCls][itemId] += itemNum;
|
||||
}
|
||||
|
||||
|
||||
224
libs/loader.js
Normal file
224
libs/loader.js
Normal file
@ -0,0 +1,224 @@
|
||||
/*
|
||||
loader.js:负责对资源的加载
|
||||
|
||||
*/
|
||||
|
||||
function loader() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
loader.prototype.init = function () {
|
||||
|
||||
}
|
||||
|
||||
////// 设置加载进度条进度 //////
|
||||
loader.prototype.setStartProgressVal = function (val) {
|
||||
core.dom.startTopProgress.style.width = val + '%';
|
||||
}
|
||||
|
||||
////// 设置加载进度条提示文字 //////
|
||||
loader.prototype.setStartLoadTipText = function (text) {
|
||||
core.dom.startTopLoadTips.innerHTML = text;
|
||||
}
|
||||
|
||||
loader.prototype.load = function (callback) {
|
||||
|
||||
// 加载图片
|
||||
core.loader.loadImages(core.images, core.material.images, function () {
|
||||
// 加载png图片
|
||||
core.material.images.pngs = {};
|
||||
core.loader.loadImages(core.pngs, core.material.images.pngs, function () {
|
||||
// 加载autotile
|
||||
core.material.images.autotile = {};
|
||||
core.loader.loadImages(Object.keys(core.material.icons.autotile), core.material.images.autotile, function () {
|
||||
core.loader.loadAnimates();
|
||||
core.loader.loadMusic();
|
||||
if (core.isset(callback))
|
||||
callback();
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
loader.prototype.loadImages = function (names, toSave, callback) {
|
||||
if (names.length==0) {
|
||||
if (core.isset(callback)) callback();
|
||||
return;
|
||||
}
|
||||
var items = 0;
|
||||
for (var i=0;i<names.length;i++) {
|
||||
this.loadImage(names[i], function (id, image) {
|
||||
core.loader.setStartLoadTipText('正在加载图片 ' + id + "...");
|
||||
toSave[id] = image;
|
||||
items++;
|
||||
core.loader.setStartProgressVal(items * (100 / names.length));
|
||||
if (items == names.length) {
|
||||
if (core.isset(callback)) callback();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
loader.prototype.loadImage = function (imgName, callback) {
|
||||
try {
|
||||
var name=imgName;
|
||||
if (name.indexOf(".png")<0) // 不包含"png"
|
||||
name=name+".png";
|
||||
var image = new Image();
|
||||
image.src = 'project/images/' + name + "?v=" + main.version;
|
||||
if (image.complete) {
|
||||
callback(imgName, image);
|
||||
return;
|
||||
}
|
||||
image.onload = function () {
|
||||
callback(imgName, image);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
loader.prototype.loadAnimates = function () {
|
||||
core.animates.forEach(function (t) {
|
||||
core.http('GET', 'project/animates/' + t + ".animate", null, function (content) {
|
||||
try {
|
||||
content = JSON.parse(content);
|
||||
var data = {};
|
||||
data.ratio = content.ratio;
|
||||
data.images = [];
|
||||
data.images_rev = [];
|
||||
content.bitmaps.forEach(function (t2) {
|
||||
if (!core.isset(t2) || t2 == "") {
|
||||
data.images.push(null);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
var image = new Image();
|
||||
image.src = t2;
|
||||
data.images.push(image);
|
||||
} catch (e) {
|
||||
data.images.push(null);
|
||||
}
|
||||
}
|
||||
})
|
||||
data.frame = content.frame_max;
|
||||
data.frames = [];
|
||||
content.frames.forEach(function (t2) {
|
||||
var info = [];
|
||||
t2.forEach(function (t3) {
|
||||
info.push({
|
||||
'index': t3[0],
|
||||
'x': t3[1],
|
||||
'y': t3[2],
|
||||
'zoom': t3[3],
|
||||
'opacity': t3[4],
|
||||
'mirror': t3[5] || 0,
|
||||
'angle': t3[6] || 0,
|
||||
})
|
||||
})
|
||||
data.frames.push(info);
|
||||
})
|
||||
core.material.animates[t] = data;
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
core.material.animates[t] = null;
|
||||
}
|
||||
}, function (e) {
|
||||
console.log(e);
|
||||
core.material.animates[t] = null;
|
||||
}, "text/plain; charset=x-user-defined")
|
||||
})
|
||||
}
|
||||
|
||||
////// 加载音频 //////
|
||||
loader.prototype.loadMusic = function () {
|
||||
|
||||
core.bgms.forEach(function (t) {
|
||||
|
||||
// 判断是不是mid
|
||||
if (/^.*\.mid$/i.test(t)) {
|
||||
|
||||
if (core.musicStatus.audioContext!=null) {
|
||||
core.material.bgms[t] = 'loading';
|
||||
|
||||
core.http('GET', 'project/sounds/'+t, null, function (data) {
|
||||
try {
|
||||
var ff = [];
|
||||
var mx = data.length;
|
||||
for (var z = 0; z < mx; z++)
|
||||
ff[z] = String.fromCharCode(data.charCodeAt(z) & 255);
|
||||
var shouldStart = core.material.bgms[t] == 'starting';
|
||||
core.material.bgms[t] = AudioPlayer(core.musicStatus.audioContext, Replayer(MidiFile(ff.join("")), Synth(44100)), true);
|
||||
|
||||
if (shouldStart)
|
||||
core.playBgm(t);
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
core.material.bgms[t] = null;
|
||||
}
|
||||
}, function (e) {
|
||||
console.log(e);
|
||||
core.material.bgms[t] = null;
|
||||
}, "text/plain; charset=x-user-defined")
|
||||
|
||||
}
|
||||
else {
|
||||
core.material.bgms[t] = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
var music = new Audio();
|
||||
music.preload = core.musicStatus.startDirectly?'auto':'none';
|
||||
if (main.bgmRemote) music.src = 'https://gitee.com/ckcz123/h5music/raw/master/'+core.firstData.name+'/'+t;
|
||||
else music.src = 'project/sounds/'+t;
|
||||
music.loop = 'loop';
|
||||
core.material.bgms[t] = music;
|
||||
}
|
||||
});
|
||||
|
||||
core.sounds.forEach(function (t) {
|
||||
|
||||
if (core.musicStatus.audioContext != null) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'project/sounds/'+t, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onload = function(e) { //下载完成
|
||||
try {
|
||||
core.musicStatus.audioContext.decodeAudioData(this.response, function (buffer) {
|
||||
core.material.sounds[t] = buffer;
|
||||
}, function (e) {
|
||||
console.log(e);
|
||||
core.material.sounds[t] = null;
|
||||
})
|
||||
}
|
||||
catch (ee) {
|
||||
console.log(ee);
|
||||
core.material.sounds[t] = null;
|
||||
}
|
||||
};
|
||||
|
||||
xhr.ontimeout = function(e) {
|
||||
console.log(e);
|
||||
core.material.sounds[t] = null;
|
||||
}
|
||||
xhr.onerror = function(e) {
|
||||
console.log(e);
|
||||
core.material.sounds[t] = null;
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
else {
|
||||
var music = new Audio();
|
||||
music.src = 'project/sounds/'+t;
|
||||
core.material.sounds[t] = music;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// 直接开始播放
|
||||
if (core.musicStatus.startDirectly && core.bgms.length>0)
|
||||
core.playBgm(core.bgms[0]);
|
||||
}
|
||||
695
libs/maps.js
695
libs/maps.js
@ -1,4 +1,7 @@
|
||||
function maps() {}
|
||||
function maps() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
maps.prototype.init = function() {
|
||||
this.blocksInfo = maps_90f36752_8815_4be8_b32b_d7fad1d0542e;
|
||||
//delete(maps_90f36752_8815_4be8_b32b_d7fad1d0542e);
|
||||
@ -17,7 +20,7 @@ maps.prototype.loadFloor = function (floorId, map) {
|
||||
var blocks = [];
|
||||
for (var i = 0; i < 13; i++) {
|
||||
for (var j = 0; j < 13; j++) {
|
||||
var block = maps.getBlock(j, i, map[i][j]);
|
||||
var block = maps.initBlock(j, i, map[i][j]);
|
||||
maps.addInfo(block);
|
||||
maps.addEvent(block,j,i,floor.events[j+","+i])
|
||||
maps.addChangeFloor(block,j,i,floor.changeFloor[j+","+i]);
|
||||
@ -37,7 +40,7 @@ maps.prototype.loadFloor = function (floorId, map) {
|
||||
}
|
||||
|
||||
////// 数字和ID的对应关系 //////
|
||||
maps.prototype.getBlock = function (x, y, id) {
|
||||
maps.prototype.initBlock = function (x, y, id) {
|
||||
var enable=null;
|
||||
id = ""+id;
|
||||
if (id.length>2) {
|
||||
@ -199,4 +202,688 @@ maps.prototype.getMapArray = function (blockArray){
|
||||
return blocks;
|
||||
}
|
||||
|
||||
main.instance.maps = new maps();
|
||||
|
||||
|
||||
////// 勇士能否前往某方向 //////
|
||||
maps.prototype.canMoveHero = function(x,y,direction,floorId) {
|
||||
if (!core.isset(x)) x=core.getHeroLoc('x');
|
||||
if (!core.isset(y)) y=core.getHeroLoc('y');
|
||||
if (!core.isset(direction)) direction=core.getHeroLoc('direction');
|
||||
if (!core.isset(floorId)) floorId=core.status.floorId;
|
||||
|
||||
// 检查当前块的cannotMove
|
||||
if (core.isset(core.floors[floorId].cannotMove)) {
|
||||
var cannotMove = core.floors[floorId].cannotMove[x+","+y];
|
||||
if (core.isset(cannotMove) && cannotMove instanceof Array && cannotMove.indexOf(direction)>=0)
|
||||
return false;
|
||||
}
|
||||
|
||||
var nowBlock = core.getBlock(x,y,floorId);
|
||||
if (nowBlock!=null){
|
||||
nowId = nowBlock.block.event.id;
|
||||
var nowIsArrow = nowId.slice(0, 5).toLowerCase() == 'arrow';
|
||||
if(nowIsArrow){
|
||||
var nowArrow = nowId.slice(5).toLowerCase();
|
||||
if (direction != nowArrow) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
var scan = {
|
||||
'up': {'x': 0, 'y': -1},
|
||||
'left': {'x': -1, 'y': 0},
|
||||
'down': {'x': 0, 'y': 1},
|
||||
'right': {'x': 1, 'y': 0}
|
||||
};
|
||||
var nextBlock = core.getBlock(x+scan[direction].x,y+scan[direction].y,floorId);
|
||||
if (nextBlock!=null){
|
||||
nextId = nextBlock.block.event.id;
|
||||
// 遇到单向箭头处理
|
||||
var isArrow = nextId.slice(0, 5).toLowerCase() == 'arrow';
|
||||
if(isArrow){
|
||||
var nextArrow = nextId.slice(5).toLowerCase();
|
||||
if ( (scan[direction].x + scan[nextArrow].x) == 0 && (scan[direction].y + scan[nextArrow].y) == 0 ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////// 能否瞬间移动 //////
|
||||
maps.prototype.canMoveDirectly = function (destX,destY) {
|
||||
if (!core.flags.enableMoveDirectly) return false;
|
||||
|
||||
// 中毒状态:不能
|
||||
if (core.hasFlag('poison')) return false;
|
||||
|
||||
var fromX = core.getHeroLoc('x'), fromY = core.getHeroLoc('y');
|
||||
if (fromX==destX&&fromY==destY) return false;
|
||||
|
||||
if (core.getBlock(fromX,fromY)!=null||core.status.checkBlock.damage[13*fromX+fromY]>0)
|
||||
return false;
|
||||
|
||||
// BFS
|
||||
var visited=[], queue=[];
|
||||
visited[13*fromX+fromY]=true;
|
||||
queue.push(13*fromX+fromY);
|
||||
|
||||
var directions = [[-1,0],[1,0],[0,1],[0,-1]];
|
||||
while (queue.length>0) {
|
||||
var now=queue.shift(), nowX=parseInt(now/13), nowY=now%13;
|
||||
|
||||
for (var dir in directions) {
|
||||
var nx=nowX+directions[dir][0], ny=nowY+directions[dir][1];
|
||||
if (nx<0||nx>=13||ny<0||ny>=13||visited[13*nx+ny]||core.getBlock(nx,ny)!=null||core.status.checkBlock.damage[13*nx+ny]>0) continue;
|
||||
if (nx==destX&&ny==destY) return true;
|
||||
visited[13*nx+ny]=true;
|
||||
queue.push(13*nx+ny);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
////// 绘制某张地图 //////
|
||||
maps.prototype.drawMap = function (mapName, callback) {
|
||||
core.clearMap('all');
|
||||
core.removeGlobalAnimate(null, null, true);
|
||||
var drawBg = function(){
|
||||
var groundId = core.floors[mapName].defaultGround || "ground";
|
||||
var blockIcon = core.material.icons.terrains[groundId];
|
||||
var blockImage = core.material.images.terrains;
|
||||
for (var x = 0; x < 13; x++) {
|
||||
for (var y = 0; y < 13; y++) {
|
||||
core.canvas.bg.drawImage(blockImage, 0, blockIcon * 32, 32, 32, x * 32, y * 32, 32, 32);
|
||||
}
|
||||
}
|
||||
// 如果存在png
|
||||
if (core.isset(core.floors[mapName].png)) {
|
||||
|
||||
var x=0, y=0, size=416;
|
||||
|
||||
var png = core.floors[mapName].png;
|
||||
|
||||
var ratio = size/416;
|
||||
|
||||
if (typeof png == 'string') {
|
||||
if (core.isset(core.material.images.pngs[png])) {
|
||||
core.canvas.bg.drawImage(core.material.images.pngs[png], x, y, size, size);
|
||||
}
|
||||
}
|
||||
else if (png instanceof Array) {
|
||||
png.forEach(function (t) {
|
||||
if (t.length!=3) return;
|
||||
var dx=parseInt(t[0]), dy=parseInt(t[1]), p=t[2];
|
||||
if (core.isset(dx) && core.isset(dy) && core.isset(core.material.images.pngs[p])) {
|
||||
dx*=32; dy*=32;
|
||||
var image = core.material.images.pngs[p];
|
||||
core.canvas.bg.drawImage(image, x+dx*ratio, y+dy*ratio, Math.min(size-dx*ratio, ratio*image.width), Math.min(size-dy*ratio, ratio*image.height));
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if (main.mode=='editor'){
|
||||
main.editor.drawMapBg = function(){
|
||||
core.clearMap('bg', 0, 0, 416, 416);
|
||||
drawBg();
|
||||
}
|
||||
} else {
|
||||
drawBg();
|
||||
}
|
||||
|
||||
core.status.floorId = mapName;
|
||||
core.status.thisMap = core.status.maps[mapName];
|
||||
var drawEvent = function(){
|
||||
var mapData = core.status.maps[core.status.floorId];
|
||||
var mapBlocks = mapData.blocks;
|
||||
|
||||
var mapArray = core.maps.getMapArray(mapBlocks);
|
||||
for (var b = 0; b < mapBlocks.length; b++) {
|
||||
// 事件启用
|
||||
var block = mapBlocks[b];
|
||||
if (core.isset(block.event) && !(core.isset(block.enable) && !block.enable)) {
|
||||
if (block.event.cls == 'autotile') {
|
||||
core.drawAutotile(core.canvas.event, mapArray, block, 32, 0, 0);
|
||||
}
|
||||
else {
|
||||
if (block.event.id!='none') {
|
||||
blockIcon = core.material.icons[block.event.cls][block.event.id];
|
||||
blockImage = core.material.images[block.event.cls];
|
||||
core.canvas.event.drawImage(core.material.images[block.event.cls], 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
|
||||
core.addGlobalAnimate(block.event.animate, block.x * 32, block.y * 32, blockIcon, blockImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (main.mode=='editor'){
|
||||
main.editor.updateMap = function(){
|
||||
core.removeGlobalAnimate(null, null, true);
|
||||
core.clearMap('event', 0, 0, 416, 416);
|
||||
drawEvent();
|
||||
core.setGlobalAnimate(core.values.animateSpeed);
|
||||
}
|
||||
} else {
|
||||
drawEvent();
|
||||
}
|
||||
core.setGlobalAnimate(core.values.animateSpeed);
|
||||
if (core.isset(callback))
|
||||
callback();
|
||||
}
|
||||
|
||||
////// 绘制Autotile //////
|
||||
maps.prototype.drawAutotile = function(ctx, mapArr, block, size, left, top){
|
||||
var indexArrs = [ //16种组合的图块索引数组; // 将autotile分割成48块16*16的小块; 数组索引即对应各个小块
|
||||
// +----+----+----+----+----+----+
|
||||
[10, 9, 4, 3 ], //0 bin:0000 | 1 | 2 | 3 | 4 | 5 | 6 |
|
||||
[10, 9, 4, 13], //1 bin:0001 +----+----+----+----+----+----+
|
||||
[10, 9, 18, 3 ], //2 bin:0010 | 7 | 8 | 9 | 10 | 11 | 12 |
|
||||
[10, 9, 16, 15], //3 bin:0011 +----+----+----+----+----+----+
|
||||
[10, 43, 4, 3 ], //4 bin:0100 | 13 | 14 | 15 | 16 | 17 | 18 |
|
||||
[10, 31, 4, 25], //5 bin:0101 +----+----+----+----+----+----+
|
||||
[10, 7, 2, 3 ], //6 bin:0110 | 19 | 20 | 21 | 22 | 23 | 24 |
|
||||
[10, 31, 16, 5 ], //7 bin:0111 +----+----+----+----+----+----+
|
||||
[48, 9, 4, 3 ], //8 bin:1000 | 25 | 26 | 27 | 28 | 29 | 30 |
|
||||
[ 8, 9, 4, 1 ], //9 bin:1001 +----+----+----+----+----+----+
|
||||
[36, 9, 30, 3 ], //10 bin:1010 | 31 | 32 | 33 | 34 | 35 | 36 |
|
||||
[36, 9, 6, 15], //11 bin:1011 +----+----+----+----+----+----+
|
||||
[46, 45, 4, 3 ], //12 bin:1100 | 37 | 38 | 39 | 40 | 41 | 42 |
|
||||
[46, 11, 4, 25], //13 bin:1101 +----+----+----+----+----+----+
|
||||
[12, 45, 30, 3 ], //14 bin:1110 | 43 | 44 | 45 | 46 | 47 | 48 |
|
||||
[34, 33, 28, 27] //15 bin:1111 +----+----+----+----+----+----+
|
||||
];
|
||||
|
||||
var drawBlockByIndex = function(ctx, dx, dy, autotileImg, index, size){ //index为autotile的图块索引1-48
|
||||
var sx = 16*((index-1)%6), sy = 16*(~~((index-1)/6));
|
||||
ctx.drawImage(autotileImg, sx, sy, 16, 16, dx, dy, size/2, size/2);
|
||||
}
|
||||
var getAutotileAroundId = function(currId, x, y){
|
||||
if(x<0 || y<0 || x>12 || y>12) return 1;
|
||||
else return mapArr[y][x]==currId ? 1:0;
|
||||
}
|
||||
var checkAround = function(x, y){ // 得到周围四个32*32块(周围每块都包含当前块的1/4,不清楚的话画下图你就明白)的数组索引
|
||||
var currId = mapArr[y][x];
|
||||
var pointBlock = [];
|
||||
for(var i=0; i<4; i++){
|
||||
var bsum = 0;
|
||||
var offsetx = i%2, offsety = ~~(i/2);
|
||||
for(var j=0; j<4; j++){
|
||||
var mx = j%2, my = ~~(j/2);
|
||||
var b = getAutotileAroundId(currId, x+offsetx+mx-1, y+offsety+my-1);
|
||||
bsum += b*(Math.pow(2, 3-j));
|
||||
}
|
||||
pointBlock.push(bsum);
|
||||
}
|
||||
return pointBlock;
|
||||
}
|
||||
var getAutotileIndexs = function(x, y){
|
||||
var indexArr = [];
|
||||
var pointBlocks = checkAround(x, y);
|
||||
for(var i=0; i<4; i++){
|
||||
var arr = indexArrs[pointBlocks[i]]
|
||||
indexArr.push(arr[3-i]);
|
||||
}
|
||||
return indexArr;
|
||||
}
|
||||
// 开始绘制autotile
|
||||
var x = block.x, y = block.y;
|
||||
var pieceIndexs = getAutotileIndexs(x, y);
|
||||
|
||||
//修正四个边角的固定搭配
|
||||
if(pieceIndexs[0] == 13){
|
||||
if(pieceIndexs[1] == 16) pieceIndexs[1] = 14;
|
||||
if(pieceIndexs[2] == 31) pieceIndexs[2] = 19;
|
||||
}
|
||||
if(pieceIndexs[1] == 18){
|
||||
if(pieceIndexs[0] == 15) pieceIndexs[0] = 17;
|
||||
if(pieceIndexs[3] == 36) pieceIndexs[3] = 24;
|
||||
}
|
||||
if(pieceIndexs[2] == 43){
|
||||
if(pieceIndexs[0] == 25) pieceIndexs[0] = 37;
|
||||
if(pieceIndexs[3] == 46) pieceIndexs[3] = 44;
|
||||
}
|
||||
if(pieceIndexs[3] == 48){
|
||||
if(pieceIndexs[1] == 30) pieceIndexs[1] = 42;
|
||||
if(pieceIndexs[2] == 45) pieceIndexs[2] = 47;
|
||||
}
|
||||
for(var i=0; i<4; i++){
|
||||
var index = pieceIndexs[i];
|
||||
var dx = x*size + size/2*(i%2), dy = y*size + size/2*(~~(i/2));
|
||||
drawBlockByIndex(ctx, dx+left, dy+top, core.material.images['autotile'][block.event.id], index, size);
|
||||
}
|
||||
}
|
||||
|
||||
////// 某个点是否不可通行 //////
|
||||
maps.prototype.noPassExists = function (x, y, floorId) {
|
||||
var block = core.getBlock(x,y,floorId);
|
||||
if (block==null) return false;
|
||||
return core.isset(block.block.event.noPass) && block.block.event.noPass;
|
||||
}
|
||||
|
||||
////// 某个点是否在区域内且不可通行 //////
|
||||
maps.prototype.noPass = function (x, y) {
|
||||
return x<0 || x>12 || y<0 || y>12 || this.noPassExists(x,y);
|
||||
}
|
||||
|
||||
////// 某个点是否存在NPC //////
|
||||
maps.prototype.npcExists = function (x, y, floorId) {
|
||||
var block = this.getBlock(x,y,floorId);
|
||||
if (block==null) return false;
|
||||
return block.block.event.cls == 'npcs';
|
||||
}
|
||||
|
||||
////// 某个点是否存在(指定的)地形 //////
|
||||
maps.prototype.terrainExists = function (x, y, id, floorId) {
|
||||
var block = this.getBlock(x,y,floorId);
|
||||
if (block==null) return false;
|
||||
return block.block.event.cls=='terrains' && (core.isset(id)?block.block.event.id==id:true);
|
||||
}
|
||||
|
||||
////// 某个点是否存在楼梯 //////
|
||||
maps.prototype.stairExists = function (x, y, floorId) {
|
||||
var block = this.getBlock(x,y,floorId);
|
||||
if (block==null) return false;
|
||||
return block.block.event.cls=='terrains' && (block.block.event.id=='upFloor' || block.block.event.id=='downFloor');
|
||||
}
|
||||
|
||||
////// 当前位置是否在楼梯边 //////
|
||||
maps.prototype.nearStair = function() {
|
||||
var x=core.getHeroLoc('x'), y=core.getHeroLoc('y');
|
||||
return this.stairExists(x,y) || this.stairExists(x-1,y) || this.stairExists(x,y-1) || this.stairExists(x+1,y) || this.stairExists(x,y+1);
|
||||
}
|
||||
|
||||
////// 某个点是否存在(指定的)怪物 //////
|
||||
maps.prototype.enemyExists = function (x, y, id,floorId) {
|
||||
var block = this.getBlock(x,y,floorId);
|
||||
if (block==null) return false;
|
||||
return block.block.event.cls=='enemys' && (core.isset(id)?block.block.event.id==id:true);
|
||||
}
|
||||
|
||||
////// 获得某个点的block //////
|
||||
maps.prototype.getBlock = function (x, y, floorId, needEnable) {
|
||||
if (!core.isset(floorId)) floorId=core.status.floorId;
|
||||
if (!core.isset(needEnable)) needEnable=true;
|
||||
var blocks = core.status.maps[floorId].blocks;
|
||||
for (var n=0;n<blocks.length;n++) {
|
||||
if (blocks[n].x==x && blocks[n].y==y && core.isset(blocks[n].event)) {
|
||||
if (needEnable && core.isset(blocks[n].enable) && !blocks[n].enable) return null;
|
||||
return {"index": n, "block": blocks[n]};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
////// 显示移动某块的动画,达到{“type”:”move”}的效果 //////
|
||||
maps.prototype.moveBlock = function(x,y,steps,time,immediateHide,callback) {
|
||||
time = time || 500;
|
||||
core.status.replay.animate=true;
|
||||
|
||||
//clearInterval(core.interval.tipAnimate);
|
||||
core.saveCanvas('animate');
|
||||
core.clearMap('animate', 0, 0, 416, 416);
|
||||
|
||||
var block = core.getBlock(x,y,core.status.floorId,false);
|
||||
if (block==null) {// 不存在
|
||||
if (core.isset(callback)) callback();
|
||||
return;
|
||||
}
|
||||
|
||||
// 需要删除该块
|
||||
core.removeBlock(x,y);
|
||||
|
||||
core.clearMap('ui', 0, 0, 416, 416);
|
||||
core.setAlpha('ui', 1.0);
|
||||
|
||||
block=block.block;
|
||||
var blockIcon = core.material.icons[block.event.cls][block.event.id];
|
||||
var blockImage = core.material.images[block.event.cls];
|
||||
|
||||
var opacityVal = 1;
|
||||
core.setOpacity('animate', opacityVal);
|
||||
core.canvas.animate.drawImage(blockImage, 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
|
||||
|
||||
// 要运行的轨迹:将steps展开
|
||||
var moveSteps=[];
|
||||
steps.forEach(function (e) {
|
||||
if (typeof e=="string") {
|
||||
moveSteps.push(e);
|
||||
}
|
||||
else {
|
||||
if (!core.isset(e.value)) {
|
||||
moveSteps.push(e.direction)
|
||||
}
|
||||
else {
|
||||
for (var i=0;i<e.value;i++) {
|
||||
moveSteps.push(e.direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var nowX=32*x, nowY=32*y, step=0;
|
||||
var scan = {
|
||||
'up': {'x': 0, 'y': -1},
|
||||
'left': {'x': -1, 'y': 0},
|
||||
'down': {'x': 0, 'y': 1},
|
||||
'right': {'x': 1, 'y': 0}
|
||||
};
|
||||
|
||||
var animateValue = block.event.animate || 1;
|
||||
var animateCurrent = 0;
|
||||
var animateTime = 0;
|
||||
|
||||
var animate=window.setInterval(function() {
|
||||
|
||||
animateTime += time / 16 / core.status.replay.speed;
|
||||
if (animateTime >= core.values.animateSpeed * 2 / animateValue) {
|
||||
animateCurrent++;
|
||||
animateTime = 0;
|
||||
if (animateCurrent>=animateValue) animateCurrent=0;
|
||||
}
|
||||
|
||||
// 已经移动完毕,消失
|
||||
if (moveSteps.length==0) {
|
||||
if (immediateHide) opacityVal=0;
|
||||
else opacityVal -= 0.06;
|
||||
core.setOpacity('animate', opacityVal);
|
||||
core.clearMap('animate', nowX, nowY, 32, 32);
|
||||
core.canvas.animate.drawImage(blockImage, animateCurrent * 32, blockIcon * 32, 32, 32, nowX, nowY, 32, 32);
|
||||
if (opacityVal<=0) {
|
||||
clearInterval(animate);
|
||||
core.loadCanvas('animate');
|
||||
core.clearMap('animate', 0, 0, 416, 416);
|
||||
core.setOpacity('animate', 1);
|
||||
core.status.replay.animate=false;
|
||||
if (core.isset(callback)) callback();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 移动中
|
||||
step++;
|
||||
nowX+=scan[moveSteps[0]].x*2;
|
||||
nowY+=scan[moveSteps[0]].y*2;
|
||||
core.clearMap('animate', nowX-32, nowY-32, 96, 96);
|
||||
// 绘制
|
||||
core.canvas.animate.drawImage(blockImage, animateCurrent * 32, blockIcon * 32, 32, 32, nowX, nowY, 32, 32);
|
||||
if (step==16) {
|
||||
// 该移动完毕,继续
|
||||
step=0;
|
||||
moveSteps.shift();
|
||||
}
|
||||
}
|
||||
}, time / 16 / core.status.replay.speed);
|
||||
}
|
||||
|
||||
////// 显示/隐藏某个块时的动画效果 //////
|
||||
maps.prototype.animateBlock = function (loc,type,time,callback) {
|
||||
if (type!='hide') type='show';
|
||||
|
||||
//clearInterval(core.interval.tipAnimate);
|
||||
core.saveCanvas('animate');
|
||||
core.clearMap('animate', 0, 0, 416, 416);
|
||||
|
||||
if (typeof loc[0] == 'number' && typeof loc[1] == 'number')
|
||||
loc = [loc];
|
||||
|
||||
var list = [];
|
||||
loc.forEach(function (t) {
|
||||
var block = core.getBlock(t[0],t[1],core.status.floorId,false);
|
||||
if (block==null) return;
|
||||
block=block.block;
|
||||
list.push({
|
||||
'x': t[0], 'y': t[1],
|
||||
'blockIcon': core.material.icons[block.event.cls][block.event.id],
|
||||
'blockImage': core.material.images[block.event.cls]
|
||||
})
|
||||
})
|
||||
|
||||
if (list.length==0) {
|
||||
if (core.isset(callback)) callback();
|
||||
return;
|
||||
}
|
||||
|
||||
core.status.replay.animate=true;
|
||||
var draw = function () {
|
||||
list.forEach(function (t) {
|
||||
core.canvas.animate.drawImage(t.blockImage, 0, t.blockIcon * 32, 32, 32, t.x * 32, t.y * 32, 32, 32);
|
||||
})
|
||||
}
|
||||
|
||||
var opacityVal = 0;
|
||||
if (type=='hide') opacityVal=1;
|
||||
|
||||
core.setOpacity('animate', opacityVal);
|
||||
draw();
|
||||
|
||||
var animate = window.setInterval(function () {
|
||||
if (type=='show') opacityVal += 0.1;
|
||||
else opacityVal -= 0.1;
|
||||
core.setOpacity('animate', opacityVal);
|
||||
core.clearMap('animate',0,0,416,416);
|
||||
|
||||
// core.canvas.animate.drawImage(blockImage, 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
|
||||
draw();
|
||||
if (opacityVal >=1 || opacityVal<=0) {
|
||||
clearInterval(animate);
|
||||
core.loadCanvas('animate');
|
||||
core.clearMap('animate', 0, 0, 416, 416);
|
||||
core.setOpacity('animate', 1);
|
||||
core.status.replay.animate=false;
|
||||
if (core.isset(callback)) callback();
|
||||
}
|
||||
}, time / 10 / core.status.replay.speed);
|
||||
}
|
||||
|
||||
////// 将某个块从禁用变成启用状态 //////
|
||||
maps.prototype.showBlock = function(x, y, floodId) {
|
||||
floodId = floodId || core.status.floorId;
|
||||
var block = core.getBlock(x,y,floodId,false);
|
||||
if (block==null) return; // 不存在
|
||||
block=block.block;
|
||||
// 本身是禁用事件,启用之
|
||||
if (core.isset(block.enable) && !block.enable) {
|
||||
block.enable = true;
|
||||
// 在本层,添加动画
|
||||
if (floodId == core.status.floorId && core.isset(block.event)) {
|
||||
blockIcon = core.material.icons[block.event.cls][block.event.id];
|
||||
blockImage = core.material.images[block.event.cls];
|
||||
core.canvas.event.drawImage(core.material.images[block.event.cls], 0, blockIcon * 32, 32, 32, block.x * 32, block.y * 32, 32, 32);
|
||||
core.addGlobalAnimate(block.event.animate, block.x * 32, block.y * 32, blockIcon, blockImage);
|
||||
// core.setGlobalAnimate(core.values.animateSpeed);
|
||||
core.syncGlobalAnimate();
|
||||
}
|
||||
core.updateStatusBar();
|
||||
}
|
||||
}
|
||||
|
||||
////// 将某个块从启用变成禁用状态 //////
|
||||
maps.prototype.removeBlock = function (x, y, floorId) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
|
||||
var block = core.getBlock(x,y,floorId,false);
|
||||
if (block==null) return; // 不存在
|
||||
|
||||
var index=block.index;
|
||||
|
||||
// 删除动画,清除地图
|
||||
if (floorId==core.status.floorId) {
|
||||
core.removeGlobalAnimate(x, y);
|
||||
core.canvas.event.clearRect(x * 32, y * 32, 32, 32);
|
||||
}
|
||||
|
||||
// 删除Index
|
||||
core.removeBlockById(index, floorId);
|
||||
core.updateFg();
|
||||
}
|
||||
|
||||
////// 根据block的索引删除该块 //////
|
||||
maps.prototype.removeBlockById = function (index, floorId) {
|
||||
|
||||
var blocks = core.status.maps[floorId].blocks;
|
||||
var x=blocks[index].x, y=blocks[index].y;
|
||||
|
||||
// 检查该点是否存在事件
|
||||
var event = core.floors[floorId].events[x+","+y];
|
||||
if (!core.isset(event))
|
||||
event = core.floors[floorId].changeFloor[x+","+y];
|
||||
|
||||
// 不存在事件,直接删除
|
||||
if (!core.isset(event)) {
|
||||
blocks.splice(index,1);
|
||||
return;
|
||||
}
|
||||
blocks[index].enable = false;
|
||||
}
|
||||
|
||||
////// 一次性删除多个block //////
|
||||
maps.prototype.removeBlockByIds = function (floorId, ids) {
|
||||
ids.sort(function (a,b) {return b-a}).forEach(function (id) {
|
||||
core.removeBlockById(id, floorId);
|
||||
});
|
||||
}
|
||||
|
||||
////// 添加一个全局动画 //////
|
||||
maps.prototype.addGlobalAnimate = function (animateMore, x, y, loc, image) {
|
||||
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
|
||||
if (animateMore == 2) {
|
||||
core.status.twoAnimateObjs.push({
|
||||
'x': x,
|
||||
'y': y,
|
||||
'status': 0,
|
||||
'loc': loc,
|
||||
'image': image
|
||||
});
|
||||
}
|
||||
else if (animateMore == 4) {
|
||||
core.status.fourAnimateObjs.push({
|
||||
'x': x,
|
||||
'y': y,
|
||||
'status': 0,
|
||||
'loc': loc,
|
||||
'image': image
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
////// 删除一个或所有全局动画 //////
|
||||
maps.prototype.removeGlobalAnimate = function (x, y, all) {
|
||||
if (all == true) {
|
||||
core.status.twoAnimateObjs = [];
|
||||
core.status.fourAnimateObjs = [];
|
||||
}
|
||||
|
||||
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
|
||||
|
||||
for (var t = 0; t < core.status.twoAnimateObjs.length; t++) {
|
||||
if (core.status.twoAnimateObjs[t].x == x * 32 && core.status.twoAnimateObjs[t].y == y * 32) {
|
||||
core.status.twoAnimateObjs.splice(t, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (var f = 0; f < core.status.fourAnimateObjs.length; f++) {
|
||||
if (core.status.fourAnimateObjs[f].x == x * 32 && core.status.fourAnimateObjs[f].y == y * 32) {
|
||||
core.status.fourAnimateObjs.splice(f, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////// 设置全局动画的显示效果 //////
|
||||
maps.prototype.setGlobalAnimate = function (speed) {
|
||||
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
|
||||
core.syncGlobalAnimate();
|
||||
core.animateFrame.speed = speed;
|
||||
core.animateFrame.globalAnimate = true;
|
||||
}
|
||||
|
||||
////// 同步所有的全局动画效果 //////
|
||||
maps.prototype.syncGlobalAnimate = function () {
|
||||
core.status.twoAnimateObjs.forEach(function (t) {
|
||||
t.status=0;
|
||||
})
|
||||
core.status.fourAnimateObjs.forEach(function (t) {
|
||||
t.status=0;
|
||||
})
|
||||
}
|
||||
|
||||
////// 绘制UI层的box动画 //////
|
||||
maps.prototype.drawBoxAnimate = function () {
|
||||
for (var a = 0; a < core.status.boxAnimateObjs.length; a++) {
|
||||
var obj = core.status.boxAnimateObjs[a];
|
||||
obj.status = ((obj.status||0)+1)%2;
|
||||
core.clearMap('ui', obj.bgx, obj.bgy, obj.bgsize, obj.bgsize);
|
||||
core.fillRect('ui', obj.bgx, obj.bgy, obj.bgsize, obj.bgsize, core.animateFrame.background);
|
||||
core.canvas.ui.drawImage(obj.image, obj.status * 32, obj.icon * 32,
|
||||
32, 32, obj.x, obj.y, 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
////// 绘制动画 //////
|
||||
maps.prototype.drawAnimate = function (name, x, y, callback) {
|
||||
|
||||
// 正在播放录像:不显示动画
|
||||
if (core.isset(core.status.replay) && core.status.replay.replaying) {
|
||||
if (core.isset(callback)) callback();
|
||||
return;
|
||||
}
|
||||
|
||||
// 检测动画是否存在
|
||||
if (!core.isset(core.material.animates[name]) || !core.isset(x) || !core.isset(y)) {
|
||||
if (core.isset(callback)) callback();
|
||||
return;
|
||||
}
|
||||
|
||||
// 清空animate层
|
||||
clearInterval(core.interval.animateInterval);
|
||||
core.clearMap('animate', 0, 0, 416, 416);
|
||||
|
||||
// 开始绘制
|
||||
var animate = core.material.animates[name];
|
||||
var ratio = animate.ratio;
|
||||
var centerX = 32*x+16, centerY = 32*y+16;
|
||||
var index=0;
|
||||
|
||||
var draw = function (index) {
|
||||
core.clearMap('animate', 0, 0, 416, 416);
|
||||
|
||||
var frame = animate.frames[index];
|
||||
frame.forEach(function (t) {
|
||||
var image = animate.images[t.index];
|
||||
if (!core.isset(image)) return;
|
||||
var realWidth = image.width * ratio * t.zoom / 100;
|
||||
var realHeight = image.height * ratio * t.zoom / 100;
|
||||
core.setAlpha('animate', t.opacity / 255);
|
||||
|
||||
var cx = centerX+t.x, cy=centerY+t.y;
|
||||
|
||||
if (!t.mirror && !t.angle) {
|
||||
core.canvas.animate.drawImage(image, cx-realWidth/2, cy-realHeight/2, realWidth, realHeight);
|
||||
}
|
||||
else {
|
||||
core.saveCanvas('animate');
|
||||
core.canvas.animate.translate(cx,cy);
|
||||
if (t.angle)
|
||||
core.canvas.animate.rotate(-t.angle*Math.PI/180);
|
||||
if (t.mirror)
|
||||
core.canvas.animate.scale(-1,1);
|
||||
core.canvas.animate.drawImage(image, -realWidth/2, -realHeight/2, realWidth, realHeight);
|
||||
core.loadCanvas('animate');
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
draw(index++);
|
||||
|
||||
core.interval.animateInterval = setInterval(function (t) {
|
||||
if (index == animate.frames.length) {
|
||||
clearInterval(core.interval.animateInterval);
|
||||
core.clearMap('animate', 0, 0, 416, 416);
|
||||
core.setAlpha('animate', 1);
|
||||
if (core.isset(callback)) callback();
|
||||
return;
|
||||
}
|
||||
draw(index++);
|
||||
}, 50);
|
||||
}
|
||||
240
libs/ui.js
240
libs/ui.js
@ -3,14 +3,146 @@
|
||||
* 包括:
|
||||
* 自动寻路、怪物手册、楼传器、存读档、菜单栏、NPC对话事件、等等
|
||||
*/
|
||||
function ui() {}
|
||||
function ui() {
|
||||
this.init();
|
||||
}
|
||||
var uidata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.ui;
|
||||
// 初始化UI
|
||||
ui.prototype.init = function () {
|
||||
|
||||
}
|
||||
|
||||
main.instance.ui = new ui();
|
||||
////////////////// 地图设置
|
||||
|
||||
////// 清除地图 //////
|
||||
ui.prototype.clearMap = function (map, x, y, width, height) {
|
||||
if (map == 'all') {
|
||||
for (var m in core.canvas) {
|
||||
core.canvas[m].clearRect(0, 0, 416, 416);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.canvas[map].clearRect(x||0, y||0, width||416, height||416);
|
||||
}
|
||||
}
|
||||
|
||||
////// 在某个canvas上绘制一段文字 //////
|
||||
ui.prototype.fillText = function (map, text, x, y, style, font) {
|
||||
if (core.isset(style)) {
|
||||
core.setFillStyle(map, style);
|
||||
}
|
||||
if (core.isset(font)) {
|
||||
core.setFont(map, font);
|
||||
}
|
||||
core.canvas[map].fillText(text, x, y);
|
||||
}
|
||||
|
||||
////// 在某个canvas上绘制一个矩形 //////
|
||||
ui.prototype.fillRect = function (map, x, y, width, height, style) {
|
||||
if (core.isset(style)) {
|
||||
core.setFillStyle(map, style);
|
||||
}
|
||||
core.canvas[map].fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
////// 在某个canvas上绘制一个矩形的边框 //////
|
||||
ui.prototype.strokeRect = function (map, x, y, width, height, style, lineWidth) {
|
||||
if (core.isset(style)) {
|
||||
core.setStrokeStyle(map, style);
|
||||
}
|
||||
if (core.isset(lineWidth)) {
|
||||
core.setLineWidth(map, lineWidth);
|
||||
}
|
||||
core.canvas[map].strokeRect(x, y, width, height);
|
||||
}
|
||||
|
||||
////// 在某个canvas上绘制一条线 //////
|
||||
ui.prototype.drawLine = function (map, x1, y1, x2, y2, style, lineWidth) {
|
||||
if (core.isset(style)) {
|
||||
core.setStrokeStyle(map, style);
|
||||
}
|
||||
if (core.isset(lineWidth)) {
|
||||
core.setLineWidth(map, lineWidth);
|
||||
}
|
||||
core.canvas[map].beginPath();
|
||||
core.canvas[map].moveTo(x1, y1);
|
||||
core.canvas[map].lineTo(x2, y2);
|
||||
core.canvas[map].closePath();
|
||||
core.canvas[map].stroke();
|
||||
}
|
||||
|
||||
////// 设置某个canvas的文字字体 //////
|
||||
ui.prototype.setFont = function (map, font) {
|
||||
core.canvas[map].font = font;
|
||||
}
|
||||
|
||||
////// 设置某个canvas的线宽度 //////
|
||||
ui.prototype.setLineWidth = function (map, lineWidth) {
|
||||
if (map == 'all') {
|
||||
for (var m in core.canvas) {
|
||||
core.canvas[m].lineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
core.canvas[map].lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
////// 保存某个canvas状态 //////
|
||||
ui.prototype.saveCanvas = function (map) {
|
||||
core.canvas[map].save();
|
||||
}
|
||||
|
||||
////// 加载某个canvas状态 //////
|
||||
ui.prototype.loadCanvas = function (map) {
|
||||
core.canvas[map].restore();
|
||||
}
|
||||
|
||||
////// 设置某个canvas边框属性 //////
|
||||
ui.prototype.setStrokeStyle = function (map, style) {
|
||||
if (map == 'all') {
|
||||
for (var m in core.canvas) {
|
||||
core.canvas[m].strokeStyle = style;
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.canvas[map].strokeStyle = style;
|
||||
}
|
||||
}
|
||||
|
||||
////// 设置某个canvas的alpha值 //////
|
||||
ui.prototype.setAlpha = function (map, alpha) {
|
||||
if (map == 'all') {
|
||||
for (var m in core.canvas) {
|
||||
core.canvas[m].globalAlpha = alpha;
|
||||
}
|
||||
}
|
||||
else core.canvas[map].globalAlpha = alpha;
|
||||
}
|
||||
|
||||
////// 设置某个canvas的透明度 //////
|
||||
ui.prototype.setOpacity = function (map, opacity) {
|
||||
if (map == 'all') {
|
||||
for (var m in core.canvas) {
|
||||
core.canvas[m].canvas.style.opacity = opacity;
|
||||
}
|
||||
}
|
||||
else core.canvas[map].canvas.style.opacity = opacity;
|
||||
}
|
||||
|
||||
////// 设置某个canvas的绘制属性(如颜色等) //////
|
||||
ui.prototype.setFillStyle = function (map, style) {
|
||||
if (map == 'all') {
|
||||
for (var m in core.canvas) {
|
||||
core.canvas[m].fillStyle = style;
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.canvas[map].fillStyle = style;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////// UI绘制
|
||||
|
||||
////// 结束一切事件和绘制,关闭UI窗口,返回游戏进程 //////
|
||||
ui.prototype.closePanel = function () {
|
||||
@ -26,6 +158,110 @@ ui.prototype.closePanel = function () {
|
||||
core.status.event.interval = null;
|
||||
}
|
||||
|
||||
////// 左上角绘制一段提示 //////
|
||||
ui.prototype.drawTip = function (text, itemIcon) {
|
||||
var textX, textY, width, height, hide = false, opacityVal = 0;
|
||||
clearInterval(core.interval.tipAnimate);
|
||||
core.setFont('data', "16px Arial");
|
||||
core.saveCanvas('data');
|
||||
core.setOpacity('data', 0);
|
||||
core.canvas.data.textAlign = 'left';
|
||||
if (!core.isset(itemIcon)) {
|
||||
textX = 16;
|
||||
textY = 18;
|
||||
width = textX + core.canvas.data.measureText(text).width + 16;
|
||||
height = 42;
|
||||
}
|
||||
else {
|
||||
textX = 44;
|
||||
textY = 18;
|
||||
width = textX + core.canvas.data.measureText(text).width + 8;
|
||||
height = 42;
|
||||
}
|
||||
core.interval.tipAnimate = window.setInterval(function () {
|
||||
if (hide) {
|
||||
opacityVal -= 0.1;
|
||||
}
|
||||
else {
|
||||
opacityVal += 0.1;
|
||||
}
|
||||
core.setOpacity('data', opacityVal);
|
||||
core.clearMap('data', 5, 5, 400, height);
|
||||
core.fillRect('data', 5, 5, width, height, '#000');
|
||||
if (core.isset(itemIcon)) {
|
||||
core.canvas.data.drawImage(core.material.images.items, 0, itemIcon * 32, 32, 32, 10, 8, 32, 32);
|
||||
}
|
||||
core.fillText('data', text, textX + 5, textY + 15, '#fff');
|
||||
if (opacityVal > 0.6 || opacityVal < 0) {
|
||||
if (hide) {
|
||||
core.loadCanvas('data');
|
||||
core.clearMap('data', 5, 5, 400, height);
|
||||
core.setOpacity('data', 1);
|
||||
clearInterval(core.interval.tipAnimate);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (!core.isset(core.timeout.getItemTipTimeout)) {
|
||||
core.timeout.getItemTipTimeout = window.setTimeout(function () {
|
||||
hide = true;
|
||||
core.timeout.getItemTipTimeout = null;
|
||||
}, 750);
|
||||
}
|
||||
opacityVal = 0.6;
|
||||
core.setOpacity('data', opacityVal);
|
||||
}
|
||||
}
|
||||
}, 30);
|
||||
}
|
||||
|
||||
////// 地图中间绘制一段文字 //////
|
||||
ui.prototype.drawText = function (contents, callback) {
|
||||
if (core.isset(contents)) {
|
||||
|
||||
// 合并
|
||||
if (core.isset(core.status.event)&&core.status.event.id=='action') {
|
||||
core.insertAction(contents,null,null,callback);
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof contents == 'string') {
|
||||
contents = [{'content': contents}];
|
||||
}
|
||||
else if (contents instanceof Object && core.isset(contents.content)) {
|
||||
contents = [contents];
|
||||
}
|
||||
else if (!(contents instanceof Array)) {
|
||||
core.drawTip("出错了");
|
||||
console.log(contents);
|
||||
return;
|
||||
}
|
||||
|
||||
core.status.event = {'id': 'text', 'data': {'list': contents, 'callback': callback}};
|
||||
core.lockControl();
|
||||
|
||||
// wait the hero to stop
|
||||
core.stopAutomaticRoute();
|
||||
setTimeout(function() {
|
||||
core.drawText();
|
||||
}, 30);
|
||||
return;
|
||||
}
|
||||
|
||||
if (core.status.event.data.list.length==0) {
|
||||
var callback = core.status.event.data.callback;
|
||||
core.ui.closePanel(false);
|
||||
if (core.isset(callback)) callback();
|
||||
return;
|
||||
}
|
||||
|
||||
var data=core.status.event.data.list.shift();
|
||||
if (typeof data == 'string')
|
||||
core.ui.drawTextBox(data);
|
||||
else
|
||||
core.ui.drawTextBox(data.content, data.id);
|
||||
// core.drawTextBox(content);
|
||||
}
|
||||
|
||||
////// 绘制一个对话框 //////
|
||||
ui.prototype.drawTextBox = function(content) {
|
||||
|
||||
|
||||
464
libs/utils.js
Normal file
464
libs/utils.js
Normal file
@ -0,0 +1,464 @@
|
||||
/*
|
||||
utils.js 工具类
|
||||
|
||||
*/
|
||||
|
||||
function utils() {
|
||||
|
||||
}
|
||||
|
||||
utils.prototype.init = function () {
|
||||
|
||||
}
|
||||
|
||||
////// 将文字中的${和}(表达式)进行替换 //////
|
||||
utils.prototype.replaceText = function (text) {
|
||||
return text.replace(/\${([^}]+)}/g, function (word, value) {
|
||||
return core.calValue(value);
|
||||
});
|
||||
}
|
||||
|
||||
////// 计算表达式的值 //////
|
||||
utils.prototype.calValue = function (value) {
|
||||
value=value.replace(/status:([\w\d_]+)/g, "core.getStatus('$1')");
|
||||
value=value.replace(/item:([\w\d_]+)/g, "core.itemCount('$1')");
|
||||
value=value.replace(/flag:([\w\d_]+)/g, "core.getFlag('$1', false)");
|
||||
return eval(value);
|
||||
}
|
||||
|
||||
////// 字符串自动换行的分割 //////
|
||||
utils.prototype.splitLines = function(canvas, text, maxLength, font) {
|
||||
if (core.isset(font)) core.setFont(canvas, font);
|
||||
|
||||
var contents = [];
|
||||
var last = 0;
|
||||
for (var i=0;i<text.length;i++) {
|
||||
|
||||
if (text.charAt(i)=='\n') {
|
||||
contents.push(text.substring(last, i));
|
||||
last=i+1;
|
||||
}
|
||||
else if (text.charAt(i)=='\\' && text.charAt(i+1)=='n') {
|
||||
contents.push(text.substring(last, i));
|
||||
last=i+2;
|
||||
}
|
||||
else {
|
||||
var toAdd = text.substring(last, i+1);
|
||||
var width = core.canvas[canvas].measureText(toAdd).width;
|
||||
if (width>maxLength) {
|
||||
contents.push(text.substring(last, i));
|
||||
last=i;
|
||||
}
|
||||
}
|
||||
}
|
||||
contents.push(text.substring(last));
|
||||
return contents;
|
||||
}
|
||||
|
||||
////// 向某个数组前插入另一个数组或元素 //////
|
||||
utils.prototype.unshift = function (a,b) {
|
||||
if (!(a instanceof Array) || !core.isset(b)) return;
|
||||
if (b instanceof Array) {
|
||||
core.clone(b).reverse().forEach(function (e) {
|
||||
a.unshift(e);
|
||||
});
|
||||
}
|
||||
else a.unshift(b);
|
||||
return a;
|
||||
}
|
||||
|
||||
////// 设置本地存储 //////
|
||||
utils.prototype.setLocalStorage = function(key, value) {
|
||||
try {
|
||||
localStorage.setItem(core.firstData.name + "_" + key, JSON.stringify(value));
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
////// 获得本地存储 //////
|
||||
utils.prototype.getLocalStorage = function(key, defaultValue) {
|
||||
var value = localStorage.getItem(core.firstData.name+"_"+key);
|
||||
if (core.isset(value)) return JSON.parse(value);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
////// 移除本地存储 //////
|
||||
utils.prototype.removeLocalStorage = function (key) {
|
||||
localStorage.removeItem(core.firstData.name+"_"+key);
|
||||
}
|
||||
|
||||
////// 深拷贝一个对象 //////
|
||||
utils.prototype.clone = function (data) {
|
||||
if (!core.isset(data)) return data;
|
||||
// date
|
||||
if (data instanceof Date) {
|
||||
var copy=new Date();
|
||||
copy.setTime(data.getTime());
|
||||
return copy;
|
||||
}
|
||||
// array
|
||||
if (data instanceof Array) {
|
||||
var copy=[];
|
||||
// for (var i=0;i<data.length;i++) {
|
||||
for (var i in data) {
|
||||
// copy.push(core.clone(data[i]));
|
||||
copy[i] = core.clone(data[i]);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
// 函数
|
||||
if (data instanceof Function) {
|
||||
return data;
|
||||
}
|
||||
// object
|
||||
if (data instanceof Object) {
|
||||
var copy={};
|
||||
for (var i in data) {
|
||||
if (data.hasOwnProperty(i))
|
||||
copy[i]=core.clone(data[i]);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
////// 格式化时间为字符串 //////
|
||||
utils.prototype.formatDate = function(date) {
|
||||
if (!core.isset(date)) return "";
|
||||
return date.getFullYear()+"-"+core.setTwoDigits(date.getMonth()+1)+"-"+core.setTwoDigits(date.getDate())+" "
|
||||
+core.setTwoDigits(date.getHours())+":"+core.setTwoDigits(date.getMinutes())+":"+core.setTwoDigits(date.getSeconds());
|
||||
}
|
||||
|
||||
////// 格式化时间为最简字符串 //////
|
||||
utils.prototype.formatDate2 = function (date) {
|
||||
if (!core.isset(date)) return "";
|
||||
return date.getFullYear()+core.setTwoDigits(date.getMonth()+1)+core.setTwoDigits(date.getDate())
|
||||
+core.setTwoDigits(date.getHours())+core.setTwoDigits(date.getMinutes())+core.setTwoDigits(date.getSeconds());
|
||||
}
|
||||
|
||||
////// 两位数显示 //////
|
||||
utils.prototype.setTwoDigits = function (x) {
|
||||
return parseInt(x)<10?"0"+x:x;
|
||||
}
|
||||
|
||||
////// 数组转RGB //////
|
||||
utils.prototype.arrayToRGB = function (color) {
|
||||
var nowR = parseInt(color[0])||0, nowG = parseInt(color[1])||0, nowB = parseInt(color[2])||0;
|
||||
if (nowR<0) nowR=0; if (nowB<0) nowB=0;if (nowG<0) nowG=0;
|
||||
if (nowR>255) nowR=255; if (nowB>255) nowB=255; if (nowG>255) nowG=255;
|
||||
return "#"+((1<<24)+(nowR<<16)+(nowG<<8)+nowB).toString(16).slice(1);
|
||||
}
|
||||
|
||||
////// 加密路线 //////
|
||||
utils.prototype.encodeRoute = function (route) {
|
||||
var ans="";
|
||||
var lastMove = "", cnt=0;
|
||||
|
||||
var items=Object.keys(core.material.items).sort();
|
||||
var shops=Object.keys(core.initStatus.shops).sort();
|
||||
route.forEach(function (t) {
|
||||
if (t=='up' || t=='down' || t=='left' || t=='right') {
|
||||
if (t!=lastMove && cnt>0) {
|
||||
ans+=lastMove.substring(0,1).toUpperCase();
|
||||
if (cnt>1) ans+=cnt;
|
||||
cnt=0;
|
||||
}
|
||||
lastMove=t;
|
||||
cnt++;
|
||||
}
|
||||
else {
|
||||
if (cnt>0) {
|
||||
ans+=lastMove.substring(0,1).toUpperCase();
|
||||
if (cnt>1) ans+=cnt;
|
||||
cnt=0;
|
||||
}
|
||||
if (t.indexOf('item:')==0)
|
||||
ans+="I"+items.indexOf(t.substring(5));
|
||||
else if (t.indexOf('fly:')==0)
|
||||
ans+="F"+core.floorIds.indexOf(t.substring(4));
|
||||
else if (t.indexOf('choices:')==0)
|
||||
ans+="C"+t.substring(8);
|
||||
else if (t.indexOf('shop:')==0) {
|
||||
var sp=t.substring(5).split(":");
|
||||
ans+="S"+shops.indexOf(sp[0])+":"+sp[1];
|
||||
}
|
||||
else if (t=='turn')
|
||||
ans+='T';
|
||||
else if (t=='getNext')
|
||||
ans+='G';
|
||||
else if (t.indexOf('input:')==0)
|
||||
ans+="P"+t.substring(6);
|
||||
else if (t=='no')
|
||||
ans+='N';
|
||||
else if (t.indexOf('move:')==0) {
|
||||
ans+="M"+t.substring(5);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (cnt>0) {
|
||||
ans+=lastMove.substring(0,1).toUpperCase();
|
||||
if (cnt>1) ans+=cnt;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
////// 解密路线 //////
|
||||
utils.prototype.decodeRoute = function (route) {
|
||||
|
||||
if (!core.isset(route)) return route;
|
||||
|
||||
var ans=[], index=0;
|
||||
|
||||
var getNumber = function (noparse) {
|
||||
var num="";
|
||||
while (index<route.length && !isNaN(route.charAt(index))) {
|
||||
num+=route.charAt(index++);
|
||||
}
|
||||
if (num.length==0) num="1";
|
||||
return core.isset(noparse)?num:parseInt(num);
|
||||
}
|
||||
|
||||
var items=Object.keys(core.material.items).sort();
|
||||
var shops=Object.keys(core.initStatus.shops).sort();
|
||||
while (index<route.length) {
|
||||
var c=route.charAt(index++);
|
||||
var number=getNumber();
|
||||
|
||||
switch (c) {
|
||||
case "U": for (var i=0;i<number;i++) ans.push("up"); break;
|
||||
case "D": for (var i=0;i<number;i++) ans.push("down"); break;
|
||||
case "L": for (var i=0;i<number;i++) ans.push("left"); break;
|
||||
case "R": for (var i=0;i<number;i++) ans.push("right"); break;
|
||||
case "I": ans.push("item:"+items[number]); break;
|
||||
case "F": ans.push("fly:"+core.floorIds[number]); break;
|
||||
case "C": ans.push("choices:"+number); break;
|
||||
case "S": ++index; ans.push("shop:"+shops[number]+":"+getNumber(true)); break;
|
||||
case "T": ans.push("turn"); break;
|
||||
case "G": ans.push("getNext"); break;
|
||||
case "P": ans.push("input:"+number); break;
|
||||
case "N": ans.push("no"); break;
|
||||
case "M": ++index; ans.push("move:"+number+":"+getNumber()); break;
|
||||
}
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
////// 判断某对象是否不为undefined也不会null //////
|
||||
utils.prototype.isset = function (val) {
|
||||
if (val == undefined || val == null || (typeof val=='number' && isNaN(val))) {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
////// 读取一个本地文件内容 //////
|
||||
utils.prototype.readFile = function (success, error, readType) {
|
||||
|
||||
// step 0: 不为http/https,直接不支持
|
||||
if (!core.platform.isOnline) {
|
||||
alert("离线状态下不支持文件读取!");
|
||||
if (core.isset(error)) error();
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 1: 如果不支持FileReader,直接不支持
|
||||
if (core.platform.fileReader==null) {
|
||||
alert("当前浏览器不支持FileReader!");
|
||||
if (core.isset(error)) error();
|
||||
return;
|
||||
}
|
||||
|
||||
if (core.platform.fileInput==null) {
|
||||
core.platform.fileInput = document.createElement("input");
|
||||
core.platform.fileInput.style.display = 'none';
|
||||
core.platform.fileInput.type = 'file';
|
||||
core.platform.fileInput.onchange = function () {
|
||||
var files = core.platform.fileInput.files;
|
||||
if (files.length==0) {
|
||||
if (core.isset(core.platform.errorCallback))
|
||||
core.platform.errorCallback();
|
||||
return;
|
||||
}
|
||||
if(!readType)core.platform.fileReader.readAsText(core.platform.fileInput.files[0]);
|
||||
else core.platform.fileReader.readAsDataURL(core.platform.fileInput.files[0]);
|
||||
core.platform.fileInput.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
core.platform.successCallback = success;
|
||||
core.platform.errorCallback = error;
|
||||
core.platform.fileInput.click();
|
||||
}
|
||||
|
||||
////// 下载文件到本地 //////
|
||||
utils.prototype.download = function (filename, content) {
|
||||
|
||||
// Step 0: 不为http/https,直接不支持
|
||||
if (!core.platform.isOnline) {
|
||||
alert("离线状态下不支持下载操作!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 1: 如果是iOS平台,直接不支持
|
||||
if (core.platform.isIOS) {
|
||||
alert("iOS平台下不支持下载操作!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2: 如果不是PC平台(Android),则只支持chrome
|
||||
if (!core.platform.isPC) {
|
||||
if (!core.platform.isChrome || core.platform.isQQ || core.platform.isWeChat) { // 检测chrome
|
||||
if (core.copy(content)) {
|
||||
alert("移动端只有Chrome浏览器支持直接下载文件!\n所有应下载内容已经复制到您的剪切板,请自行创建空白文件并粘贴。");
|
||||
}
|
||||
else {
|
||||
alert("该平台或浏览器暂不支持下载操作!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: 如果是Safari浏览器,则提示并打开新窗口
|
||||
if (core.platform.isSafari) {
|
||||
alert("你当前使用的是Safari浏览器,不支持直接下载文件。\n即将打开一个新窗口为应下载内容,请自行全选复制然后创建空白文件并粘贴。");
|
||||
var blob = new Blob([content], {type: 'text/plain;charset=utf-8'});
|
||||
var href = window.URL.createObjectURL(blob);
|
||||
var opened=window.open(href, "_blank");
|
||||
// if (!opened) window.location.href=href;
|
||||
window.URL.revokeObjectURL(href);
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 4: 下载
|
||||
var blob = new Blob([content], {type: 'text/plain;charset=utf-8'});
|
||||
if(window.navigator.msSaveOrOpenBlob) {
|
||||
window.navigator.msSaveBlob(blob, filename);
|
||||
}
|
||||
else {
|
||||
var href = window.URL.createObjectURL(blob);
|
||||
var elem = window.document.createElement('a');
|
||||
elem.href = href;
|
||||
elem.download = filename;
|
||||
document.body.appendChild(elem);
|
||||
elem.click();
|
||||
document.body.removeChild(elem);
|
||||
window.URL.revokeObjectURL(href);
|
||||
}
|
||||
}
|
||||
|
||||
////// 复制一段内容到剪切板 //////
|
||||
utils.prototype.copy = function (data) {
|
||||
if (!core.platform.supportCopy) return false;
|
||||
|
||||
var textArea = document.createElement("textarea");
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.top = 0;
|
||||
textArea.style.left = 0;
|
||||
textArea.style.width = '2em';
|
||||
textArea.style.height = '2em';
|
||||
textArea.style.padding = 0;
|
||||
textArea.style.border = 'none';
|
||||
textArea.style.outline = 'none';
|
||||
textArea.style.boxShadow = 'none';
|
||||
textArea.style.background = 'transparent';
|
||||
textArea.value = data;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
var successful = false;
|
||||
try {
|
||||
successful = document.execCommand('copy');
|
||||
} catch (err) {
|
||||
successful = false;
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea);
|
||||
return successful;
|
||||
}
|
||||
|
||||
////// 动画显示某对象 //////
|
||||
utils.prototype.show = function (obj, speed, callback) {
|
||||
if (!core.isset(speed)) {
|
||||
obj.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
obj.style.display = 'block';
|
||||
if (main.mode!='play'){
|
||||
obj.style.opacity = 1;
|
||||
if (core.isset(callback)) {callback();}
|
||||
return;
|
||||
}
|
||||
obj.style.opacity = 0;
|
||||
var opacityVal = 0;
|
||||
var showAnimate = window.setInterval(function () {
|
||||
opacityVal += 0.03;
|
||||
obj.style.opacity = opacityVal;
|
||||
if (opacityVal > 1) {
|
||||
clearInterval(showAnimate);
|
||||
if (core.isset(callback)) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}, speed);
|
||||
}
|
||||
|
||||
////// 动画使某对象消失 //////
|
||||
utils.prototype.hide = function (obj, speed, callback) {
|
||||
if (!core.isset(speed)) {
|
||||
obj.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
if (main.mode!='play'){
|
||||
obj.style.display = 'none';
|
||||
if (core.isset(callback)) {callback();}
|
||||
return;
|
||||
}
|
||||
var opacityVal = 1;
|
||||
var hideAnimate = window.setInterval(function () {
|
||||
opacityVal -= 0.03;
|
||||
obj.style.opacity = opacityVal;
|
||||
if (opacityVal < 0) {
|
||||
obj.style.display = 'none';
|
||||
clearInterval(hideAnimate);
|
||||
if (core.isset(callback)) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}, speed);
|
||||
}
|
||||
|
||||
utils.prototype.http = function (type, url, formData, success, error, mimeType) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open(type, url, true);
|
||||
if (core.isset(mimeType))
|
||||
xhr.overrideMimeType(mimeType);
|
||||
xhr.onload = function(e) {
|
||||
if (xhr.status==200) {
|
||||
if (core.isset(success)) {
|
||||
success(xhr.response);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (core.isset(error))
|
||||
error("HTTP "+xhr.status);
|
||||
}
|
||||
};
|
||||
xhr.onabort = function () {
|
||||
if (core.isset(error))
|
||||
error("Abort");
|
||||
}
|
||||
xhr.ontimeout = function() {
|
||||
if (core.isset(error))
|
||||
error("Timeout");
|
||||
}
|
||||
xhr.onerror = function() {
|
||||
if (core.isset(error))
|
||||
error("Error on Connection");
|
||||
}
|
||||
if (core.isset(formData))
|
||||
xhr.send(formData);
|
||||
else xhr.send();
|
||||
}
|
||||
17
main.js
17
main.js
@ -47,7 +47,7 @@ function main() {
|
||||
};
|
||||
this.mode = 'play';
|
||||
this.loadList = [
|
||||
'items', 'icons', 'maps', 'enemys', 'events', 'data', 'ui', 'core'
|
||||
'loader', 'control', 'utils', 'items', 'icons', 'maps', 'enemys', 'events', 'actions', 'data', 'ui', 'core'
|
||||
];
|
||||
this.pureData = [
|
||||
"data","enemys","icons","maps","items","functions"
|
||||
@ -142,14 +142,16 @@ main.prototype.init = function (mode) {
|
||||
});
|
||||
|
||||
main.loaderJs(function () {
|
||||
var coreData = {};
|
||||
main.core = core;
|
||||
|
||||
for (i = 0; i < main.loadList.length; i++) {
|
||||
var name = main.loadList[i];
|
||||
if (name === 'core') continue;
|
||||
main[name].init(main.dom);
|
||||
coreData[name] = main[name];
|
||||
main.core[name] = new (eval(name))();
|
||||
}
|
||||
|
||||
main.loaderFloors(function() {
|
||||
var coreData = {};
|
||||
["dom", "statusBar", "canvas", "images", "pngs",
|
||||
"animates", "bgms", "sounds", "floorIds", "floors"].forEach(function (t) {
|
||||
coreData[t] = main[t];
|
||||
@ -168,14 +170,9 @@ main.prototype.loaderJs = function (callback) {
|
||||
main.setMainTipsText('正在加载核心js文件...')
|
||||
for (var i = 0; i < main.loadList.length; i++) {
|
||||
main.loadMod(main.loadList[i], function (modName) {
|
||||
instanceNum = 0;
|
||||
main.setMainTipsText(modName + '.js 加载完毕');
|
||||
for (var key in main.instance) {
|
||||
instanceNum++;
|
||||
}
|
||||
instanceNum++;
|
||||
if (instanceNum === main.loadList.length) {
|
||||
delete main.instance;
|
||||
// main.dom.mainTips.style.display = 'none';
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
@ -88,9 +88,38 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
||||
},
|
||||
////// 战斗结束后触发的事件 //////
|
||||
"afterBattle" : function(enemyId,x,y,callback) {
|
||||
|
||||
|
||||
var enemy = core.material.enemys[enemyId];
|
||||
|
||||
// 扣减体力值
|
||||
core.status.hero.hp -= core.enemys.getDamage(enemyId);
|
||||
if (core.status.hero.hp<=0) {
|
||||
core.status.hero.hp=0;
|
||||
core.updateStatusBar();
|
||||
core.events.lose('battle');
|
||||
return;
|
||||
}
|
||||
// 获得金币和经验
|
||||
var money = enemy.money;
|
||||
if (core.hasItem('coin')) money *= 2;
|
||||
if (core.hasFlag('curse')) money=0;
|
||||
core.status.hero.money += money;
|
||||
var experience =enemy.experience;
|
||||
if (core.hasFlag('curse')) experience=0;
|
||||
core.status.hero.experience += experience;
|
||||
var hint = "打败 " + enemy.name;
|
||||
if (core.flags.enableMoney)
|
||||
hint += ",金币+" + money;
|
||||
if (core.flags.enableExperience)
|
||||
hint += ",经验+" + experience;
|
||||
core.drawTip(hint);
|
||||
|
||||
// 删除该块
|
||||
if (core.isset(x) && core.isset(y)) {
|
||||
core.removeBlock(x, y);
|
||||
core.canvas.event.clearRect(32 * x, 32 * y, 32, 32);
|
||||
}
|
||||
|
||||
// 毒衰咒的处理
|
||||
var special = enemy.special;
|
||||
// 中毒
|
||||
|
||||
Loading…
Reference in New Issue
Block a user