Files

49 lines
1.9 KiB
JavaScript
Raw Permalink 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.
/**
* 画个标 · 表情技能资源库(核心:注册表 + 通用工具)
* 表情专属技能(动态表情/贴纸),主分类 motion(动画),统一 workspaces:['emoji']
*
* 与共享技能库(HGB_Skills)/ 海报技能库(HGB_PosterSkills)的关系:
* - 复用:共享技能库的构图/配色等通用技能跨工作区复用
* - 区分:本库收录表情专属技能(动画节奏/物理/循环/体积/平台等)
* 每个技能标准化字段:id / name / category / emoji / scene / summary / params / source / run / test
*/
const HGB_StickerSkills = (function () {
'use strict';
const skills = [];
const DEFAULT_WORKSPACES = ['emoji'];
function register(defs) {
for (const d of (defs || [])) skills.push(d);
return skills.length;
}
function all() { return skills; }
function categories() {
const map = {};
for (const s of skills) map[s.category] = (map[s.category] || 0) + 1;
return Object.entries(map).map(([id, count]) => ({ id, count }));
}
function get(id) { return skills.find(s => s.id === id) || null; }
function run(id, args) {
const s = get(id);
if (!s) return { error: '表情技能不存在: ' + id };
try { return s.run(args || {}); }
catch (e) { return { error: '表情技能执行失败: ' + e.message }; }
}
function test(id) {
const s = get(id);
if (!s) return { error: '表情技能不存在: ' + id };
try { return s.test ? s.test() : { note: '该技能未提供自测' }; }
catch (e) { return { error: '表情技能自测失败: ' + e.message }; }
}
function workspacesOf(id) {
const s = get(id);
return (s && s.workspaces) || DEFAULT_WORKSPACES;
}
function forWorkspace(ws) {
return skills.filter(s => workspacesOf(s.id).includes(ws));
}
return { register, all, categories, get, run, test, workspacesOf, forWorkspace };
})();