32 lines
1.7 KiB
JavaScript
32 lines
1.7 KiB
JavaScript
const fs = require('node:fs');
|
||
const path = require('node:path');
|
||
const assert = require('node:assert/strict');
|
||
const directory = path.resolve(__dirname, '../assets/action_bundle/img/dailyQuest');
|
||
function frame(name, character) {
|
||
const meta = Object.values(JSON.parse(fs.readFileSync(path.join(directory, name + '.png.meta'))).subMetas)[0];
|
||
return { character, uuid: meta.uuid, getRect: () => ({ width: meta.width, height: meta.height }) };
|
||
}
|
||
function installCountFrames(daily) {
|
||
daily.rewardDigits = Array.from({ length: 10 }, (_, index) => frame('num/' + index, String(index)));
|
||
daily.weeklyDigits = Array.from({ length: 10 }, (_, index) => frame('weekly_digits/pass_' + index, String(index)));
|
||
daily.taskDigits = Array.from({ length: 10 }, (_, index) => frame('task_digits/' + index, String(index)));
|
||
daily.taskSlash = frame('task_digits/xiegan', '/');
|
||
daily.countPlus = frame('jiahao', '+');
|
||
daily.rewardMultiply = frame('num/cheng', '×');
|
||
daily.rewardMinutes = frame('num/minute', '分钟');
|
||
daily.rewardHours = frame('num/hour', '小时');
|
||
}
|
||
function countText(node) {
|
||
if (!node) return undefined;
|
||
assert.equal(node.getComponent('cc.Label'), null, 'count is a sprite container, not a Label');
|
||
const content = node.getChildByName('RewardCountGlyphs') || node;
|
||
return content.children.filter(child => child.active).map(child => {
|
||
const sprite = child.getComponent('cc.Sprite');
|
||
if (sprite && sprite.enabled !== false) return sprite.spriteFrame.character;
|
||
const text = child.getComponent('cc.Label').string;
|
||
assert.match(text, /^[×.+]$/, 'digits must use supplied sprite frames');
|
||
return text;
|
||
}).join('');
|
||
}
|
||
module.exports = { installCountFrames, countText };
|