2020-08-07 09:55:56 +08:00

248 lines
7.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let Config = require('config');
let res = {
bubbleCount: 13,
spBubbleCount: 13,
bubble: [[], [], [], []],//4组普通消除
specialBubble: [[], [], [], []],//4组特殊消除
role: {'idle': [], 'happy': [], 'tension': []},
face: {
'asquint': [[], [], [], []],
'blank': [[], [], [], []],
'tsundere': [[], [], [], []],
'twitchmouth': [[], [], [], []],
'weep': [[], [], [], []]
},//普通表情每种都有4组对应4个尺寸
specialFace: {
'asquint': [[], [], [], []],
'blank': [[], [], [], []],
'tsundere': [[], [], [], []],
'twitchmouth': [[], [], [], []],
'weep': [[], [], [], []]
},//巧克力表情
extra: {'comboeliminate': [], 'normaleliminate': [], 'explode': []},
item: {'eat': [], 'hammer': []},
mouth: [],
comp: {},
cookie: {},
revive: [],
initComp: function (frames) {
for (let i = 0; i < frames.length; i++) {
this.comp[frames[i]._name] = frames[i];
}
},
initCookie: function (frames) {
for (let i = 0; i < frames.length; i++) {
this.cookie[frames[i]._name] = frames[i];
}
},
getSpriteFrame: function (name, iscookie) {
return iscookie ? this.cookie[name] : this.comp[name];
},
initBubble: function (frames) {
for (let i = 0; i < frames.length; i++) {
frames[i].index = Number(frames[i]._name);
}
frames.sort(function (a, b) {
return a.index - b.index;
});
frames.forEach(element => {
let n = element.index;
let nsp = Math.floor(n / 100000);
if (nsp > 0) {
let lst = this.specialBubble[nsp - 1];
if (lst.length == 0) {
for (let i = 0; i < this.spBubbleCount; i++) {
lst.push(element);
}
}
} else {
nsp = Math.floor(n / 10000);
if (nsp > 0) {
let lst = this.bubble[nsp - 1];
if (lst.length == 0) {
for (let i = 0; i < this.bubbleCount; i++) {
lst.push(element);
}
}
}
}
});
},
initEmotion: function (frames) {
let firstArr = ['xiaonvhai-daiji', 'xiaonvhai-gaox', 'xiaonvhai-jinzhang'];
let firstSeq = ['idle', 'happy', 'tension'];
for (let i = 0; i < frames.length; i++) {
let nameArr = frames[i]._name.split('_');
frames[i].first = nameArr[0];
frames[i].index = Number(nameArr[1]);
}
for (let j = 0; j < frames.length; j++) {
for (let m = 0; m < 3; m++) {
if (frames[j].first == firstArr[m]) {
this.role[firstSeq[m]].push(frames[j]);
break;
}
}
}
for (let n = 0; n < 3; n++) {
this.role[firstSeq[n]].sort(function (a, b) {
return a.index - b.index;
});
}
},
initFace: function (frames) {
let tag = ['asquint', 'blank', 'tsundere', 'twitchmouth', 'weep'];
let normal = [];
let special = [];
for (let i = 0; i < frames.length; i++) {
let nameArr = frames[i]._name.split('_');
if (nameArr.length === 3) {
//巧克力
special.push(frames[i]);
frames[i].index = Number(nameArr[1]);
frames[i].first = nameArr[2].slice(0, -4);
frames[i].second = Number(nameArr[2].slice(-4));
} else {
//普通
normal.push(frames[i]);
frames[i].index = Number(nameArr[0]);
frames[i].first = nameArr[1].slice(0, -4);
frames[i].second = Number(nameArr[1].slice(-4));
}
}
let analysis = function (srcArr, destArr) {
for (let j = 0; j < srcArr.length; j++) {
for (let m = 0; m < tag.length; m++) {
if (srcArr[j].first == tag[m]) {
destArr[tag[m]][srcArr[j].index - 1].push(srcArr[j]);
break;
}
}
}
for (let n = 0; n < tag.length; n++) {
for (let k = 0; k < 4; k++) {
destArr[tag[n]][k].sort(function (a, b) {
return a.second - b.second;
});
}
}
}
analysis(normal, this.face);
analysis(special, this.specialFace);
},
initExtra: function (frames) {
for (let i = 0; i < frames.length; i++) {
frames[i].first = frames[i]._name.slice(0, -4);
frames[i].index = Number(frames[i]._name.slice(-4));
for (let k in this.extra) {
if (k == frames[i].first) {
this.extra[k].push(frames[i]);
}
}
}
for (let k in this.extra) {
this.extra[k].sort(function (a, b) {
return a.index - b.index;
});
}
},
initItem: function (frames) {
for (let i = 0; i < frames.length; i++) {
frames[i].first = frames[i]._name.slice(0, -4);
frames[i].index = Number(frames[i]._name.slice(-4));
for (let k in this.item) {
if (k == frames[i].first) {
this.item[k].push(frames[i]);
}
}
}
for (let k in this.item) {
this.item[k].sort(function (a, b) {
return a.index - b.index;
});
}
},
initMouth: function (frames) {
for (let i = 0; i < frames.length; i++) {
frames[i].index = Number(frames[i]._name.slice(-4));
}
frames.sort(function (a, b) {
return a.index - b.index;
});
this.mouth = frames;
},
initRevive: function (frames) {
frames.sort(function (a, b) {
return Number(a._name) - Number(b._name);
});
this.revive = frames;
},
initRoleAni: function (animation) {
for (let k in this.role) {
let clip = cc.AnimationClip.createWithSpriteFrames(this.role[k], 7);
clip.wrapMode = cc.WrapMode.Loop;
animation.addClip(clip, k);
}
},
initFaceAniWithGridNum: function (animation, gridNum) {
let fps = Config.ani_default_fps;
for (let k in this.face) {
if (k == 'weep') {
fps = Config.weep_interval;
}
let faces = this.face[k][gridNum - 1].concat(this.face[k][gridNum - 1]);
animation.addClip(cc.AnimationClip.createWithSpriteFrames(faces, fps), k);
}
},
initSpecialFaceAniWithGridNum: function (animation, gridNum) {
let fps = Config.ani_default_fps;
for (let k in this.specialFace) {
if (k == 'weep') {
fps = Config.weep_interval;
}
let faces = this.specialFace[k][gridNum - 1].concat(this.specialFace[k][gridNum - 1]);
animation.addClip(cc.AnimationClip.createWithSpriteFrames(faces, fps), k);
}
},
initExtraAni: function (animation, fps, loop) {
for (let k in this.extra) {
let clip = cc.AnimationClip.createWithSpriteFrames(this.extra[k], fps || Config.ani_default_fps);
clip.wrapMode = loop || cc.WrapMode.Normal;
animation.addClip(clip, k);
}
},
initBubbleAniWithGridNum: function (animation, gridNum) {
animation.addClip(cc.AnimationClip.createWithSpriteFrames(this.bubble[gridNum - 1], Config.bubble_interval), 'bubble');
},
initSpecialBubbleAniWithGridNum: function (animation, gridNum) {
animation.addClip(cc.AnimationClip.createWithSpriteFrames(this.specialBubble[gridNum - 1], Config.bubble_interval), 'specialBubble');
},
initItemAni: function (animation) {
for (let k in this.item) {
let clip = cc.AnimationClip.createWithSpriteFrames(this.item[k], Config.ani_default_fps);
clip.wrapMode = cc.WrapMode.Normal;
animation.addClip(clip, k);
}
},
initMouthAni: function (animation) {
let clip = cc.AnimationClip.createWithSpriteFrames(this.mouth, Config.ani_default_fps);
clip.wrapMode = cc.WrapMode.Loop;
animation.addClip(clip, 'mouth');
},
initReviveAni: function (animation) {
let clip = cc.AnimationClip.createWithSpriteFrames(this.revive, 12);
clip.wrapMode = cc.WrapMode.Normal;
animation.addClip(clip, 'revive');
}
};
module.exports = res;