pref: modify hooks item.
This commit is contained in:
parent
16a2ac33d5
commit
c1f108bdcd
|
@ -211,8 +211,16 @@ export class Game extends Uninstantable {
|
|||
game.callHook("addGroup", [id, short, name, config]);
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @typedef {import("../library/hooks/interface.js").NonameHookType} NonameHookType
|
||||
*/
|
||||
/**
|
||||
* 通用的调用钩子函数
|
||||
*
|
||||
* @template {NonameHookType} HookType
|
||||
* @template {keyof HookType} Name
|
||||
* @param {Name} name
|
||||
* @param {Parameters<HookType[Name]>} args
|
||||
*/
|
||||
static callHook(name, args) {
|
||||
const callHook = () => {
|
||||
|
@ -5946,7 +5954,7 @@ export class Game extends Uninstantable {
|
|||
if (!event.forced && !event.fakeforce && get.noSelected()) confirm += 'c';
|
||||
if (event.isMine()) game.Check.confirm(event, confirm);
|
||||
|
||||
game.callHook("checkEnd", [event, { ok, auto, auto_confirm }]);
|
||||
game.callHook("checkEnd", [event, { ok, auto, auto_confirm, autoConfirm: auto_confirm }]);
|
||||
|
||||
// if (ui.confirm && ui.confirm.lastChild.link == 'cancel') {
|
||||
// if (_status.event.type == 'phase' && !_status.event.skill) {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import { NonameHook } from "./hook.js"
|
||||
|
||||
export const defaultHooks = {
|
||||
addGroup: new NonameHook("addGroup"),
|
||||
addNature: new NonameHook("addNature"),
|
||||
|
||||
checkBegin: new NonameHook("checkBegin"),
|
||||
checkCard: new NonameHook("checkCard"),
|
||||
checkTarget: new NonameHook("checkTarget"),
|
||||
checkButton: new NonameHook("checkButton"),
|
||||
checkEnd: new NonameHook("checkEnd"),
|
||||
|
||||
uncheckBegin: new NonameHook("uncheckBegin"),
|
||||
uncheckCard: new NonameHook("uncheckCard"),
|
||||
uncheckTarget: new NonameHook("uncheckTarget"),
|
||||
uncheckButton: new NonameHook("uncheckButton"),
|
||||
uncheckEnd: new NonameHook("uncheckEnd")
|
||||
}
|
|
@ -23,6 +23,7 @@ import { Channel } from "./channel/index.js";
|
|||
import { Experimental } from "./experimental/index.js";
|
||||
import * as Element from "./element/index.js";
|
||||
import { updateURLs } from "./update-urls.js";
|
||||
import { defaultHooks } from "./hooks/index.js"
|
||||
|
||||
|
||||
export class Library extends Uninstantable {
|
||||
|
@ -152,240 +153,7 @@ export class Library extends Uninstantable {
|
|||
* 这样当某个地方调用game.callHook(钩子名,[...函数参数])时,就会按顺序将对应数组中的每个函数运行一遍(传参为callHook的第二个参数)。
|
||||
* 你可以将hook机制类比为event.trigger(),但是这里只能放同步代码
|
||||
*/
|
||||
static hooks = {
|
||||
// 本体势力的颜色
|
||||
addGroup: [(id, _short, _name, config) => {
|
||||
if ("color" in config && config.color != null) {
|
||||
let color1, color2, color3, color4;
|
||||
if (typeof config.color == "string" && /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(config.color)) {
|
||||
let c1 = parseInt(`0x${config.color.slice(1, 3)}`);
|
||||
let c2 = parseInt(`0x${config.color.slice(3, 5)}`);
|
||||
let c3 = parseInt(`0x${config.color.slice(5, 7)}`);
|
||||
color1 = color2 = color3 = color4 = [c1, c2, c3, 1];
|
||||
}
|
||||
else if (Array.isArray(config.color) && config.color.length == 4) {
|
||||
if (config.color.every(item => Array.isArray(item))) {
|
||||
color1 = config.color[0];
|
||||
color2 = config.color[1];
|
||||
color3 = config.color[2];
|
||||
color4 = config.color[3];
|
||||
}
|
||||
else color1 = color2 = color3 = color4 = config.color;
|
||||
}
|
||||
if (color1 && color2 && color3 && color4) {
|
||||
const cs = lib.linq.cselector;
|
||||
const g1 = cs.group(
|
||||
cs.of(
|
||||
cs.class("player ", "identity"),
|
||||
cs.isAttr("data-color", `"${id}"`)
|
||||
),
|
||||
cs.of(
|
||||
"div",
|
||||
cs.isAttr("data-nature", `"${id}"`)
|
||||
),
|
||||
cs.of(
|
||||
"span",
|
||||
cs.isAttr("data-nature", `"${id}"`)
|
||||
)
|
||||
);
|
||||
const g2 = cs.group(
|
||||
cs.of(
|
||||
"div",
|
||||
cs.isAttr("data-nature", `"${id}m"`)
|
||||
),
|
||||
cs.of(
|
||||
"span",
|
||||
cs.isAttr("data-nature", `"${id}m"`)
|
||||
)
|
||||
);
|
||||
const g3 = cs.group(
|
||||
cs.of(
|
||||
"div",
|
||||
cs.isAttr("data-nature", `"${id}mm"`)
|
||||
),
|
||||
cs.of(
|
||||
"span",
|
||||
cs.isAttr("data-nature", `"${id}mm"`)
|
||||
)
|
||||
);
|
||||
let result = {};
|
||||
result[g1] = {
|
||||
textShadow: cs.group(
|
||||
"black 0 0 1px",
|
||||
`rgba(${color1.join()}) 0 0 2px`,
|
||||
`rgba(${color2.join()}) 0 0 5px`,
|
||||
`rgba(${color3.join()}) 0 0 10px`,
|
||||
`rgba(${color4.join()}) 0 0 10px`
|
||||
)
|
||||
};
|
||||
result[g2] = {
|
||||
textShadow: cs.group(
|
||||
"black 0 0 1px",
|
||||
`rgba(${color1.join()}) 0 0 2px`,
|
||||
`rgba(${color2.join()}) 0 0 5px`,
|
||||
`rgba(${color3.join()}) 0 0 5px`,
|
||||
`rgba(${color4.join()}) 0 0 5px`,
|
||||
"black 0 0 1px"
|
||||
)
|
||||
};
|
||||
result[g3] = {
|
||||
textShadow: cs.group(
|
||||
"black 0 0 1px",
|
||||
`rgba(${color1.join()}) 0 0 2px`,
|
||||
`rgba(${color2.join()}) 0 0 2px`,
|
||||
`rgba(${color3.join()}) 0 0 2px`,
|
||||
`rgba(${color4.join()}) 0 0 2px`,
|
||||
"black 0 0 1px"
|
||||
)
|
||||
};
|
||||
game.dynamicStyle.addObject(result);
|
||||
lib.groupnature[id] = id;
|
||||
}
|
||||
}
|
||||
if (typeof config.image == 'string') Object.defineProperty(lib.card, `group_${id}`, {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: {
|
||||
fullskin: true,
|
||||
image: config.image
|
||||
}
|
||||
});
|
||||
}],
|
||||
//增加新属性杀
|
||||
addNature: [(nature, _translation, config) => {
|
||||
if (typeof config != 'object') config = {};
|
||||
let linked = config.linked, order = config.order, background = config.background, lineColor = config.lineColor;
|
||||
if (typeof linked != 'boolean') linked = true;
|
||||
if (typeof order != 'number') order = 0;
|
||||
if (typeof background != 'string') background = '';
|
||||
if (!Array.isArray(lineColor) || lineColor.length != 3) lineColor = [];
|
||||
else if (background.startsWith('ext:')) {
|
||||
background = background.replace(/^ext:/, 'extension/');
|
||||
}
|
||||
if (linked) lib.linked.add(nature);
|
||||
if (lineColor.length) lib.lineColor.set(nature, lineColor);
|
||||
lib.nature.set(nature, order);
|
||||
if (background.length > 0) lib.natureBg.set(nature, background);
|
||||
if (config.audio) {
|
||||
for (let key in config.audio) {
|
||||
if (!lib.natureAudio[key]) {
|
||||
lib.natureAudio[key] = config.audio[key];
|
||||
} else {
|
||||
for (let key2 in config.audio[key]) {
|
||||
lib.natureAudio[key][key2] = config.audio[key][key2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let color1, color2;
|
||||
if (typeof config.color == "string" && /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(config.color)) {
|
||||
let c1 = parseInt(`0x${item[1].slice(1, 3)}`);
|
||||
let c2 = parseInt(`0x${item[1].slice(3, 5)}`);
|
||||
let c3 = parseInt(`0x${item[1].slice(5, 7)}`);
|
||||
color1 = color2 = [c1, c2, c3, 1];
|
||||
}
|
||||
else if (Array.isArray(config.color) && config.color.length >= 2 && config.color.length <= 4) {
|
||||
if (config.color.every(item => Array.isArray(item))) {
|
||||
color1 = config.color[0];
|
||||
color2 = config.color[1];
|
||||
}
|
||||
else {
|
||||
let color = config.color.slice();
|
||||
if (color.length == 3) color.push(1);
|
||||
color1 = color2 = color;
|
||||
}
|
||||
}
|
||||
if (color1 && color2) {
|
||||
const cs = lib.linq.cselector;
|
||||
const g1 = cs.group(
|
||||
cs.of(
|
||||
cs.class("card", "fullskin", `${nature}`),
|
||||
'>',
|
||||
cs.class("name")
|
||||
)
|
||||
);
|
||||
let result = {};
|
||||
result[g1] = {
|
||||
color: `rgba(${color1.join()})`,
|
||||
border: cs.merge(
|
||||
'1px',
|
||||
'solid',
|
||||
`rgba(${color2.join()})`
|
||||
),
|
||||
};
|
||||
game.dynamicStyle.addObject(result);
|
||||
|
||||
const g2 = cs.group(
|
||||
cs.of(
|
||||
cs.class("tempname", `${nature}`),
|
||||
':not([data-nature])>',
|
||||
cs.class("span")
|
||||
)
|
||||
);
|
||||
let result2 = {};
|
||||
result2[g2] = {
|
||||
color: `rgba(${color1.join()})`,
|
||||
};
|
||||
game.dynamicStyle.addObject(result2);
|
||||
}
|
||||
}],
|
||||
//game.check
|
||||
checkBegin: [],
|
||||
checkEnd: [
|
||||
function autoConfirm(event, { ok, auto, auto_confirm }) {
|
||||
if (!event.isMine()) return;
|
||||
const skillinfo = get.info(event.skill) || {};
|
||||
if (ok && auto && (auto_confirm || skillinfo.direct) && !_status.touchnocheck
|
||||
&& !_status.mousedown && (!_status.mousedragging || !_status.mouseleft)) {
|
||||
if (ui.confirm) ui.confirm.close();
|
||||
if (event.skillDialog === true) event.skillDialog = false;
|
||||
ui.click.ok();
|
||||
_status.mousedragging = null;
|
||||
if (skillinfo.preservecancel) ui.create.confirm('c');
|
||||
}
|
||||
}
|
||||
],
|
||||
checkButton: [],
|
||||
checkCard: [
|
||||
function updateTempname(card, event) {
|
||||
if (lib.config.cardtempname === 'off') return;
|
||||
if (get.name(card) === card.name && get.is.sameNature(get.nature(card), card.nature, true)) return;
|
||||
const node = ui.create.cardTempName(card);
|
||||
if (lib.config.cardtempname !== 'default') node.classList.remove('vertical');
|
||||
},
|
||||
],
|
||||
checkTarget: [
|
||||
function updateInstance(target, event) {
|
||||
if (!target.instance) return;
|
||||
['selected', 'selectable'].forEach(className => {
|
||||
if (target.classList.contains(className)) {
|
||||
target.instance.classList.add(className);
|
||||
} else {
|
||||
target.instance.classList.remove(className);
|
||||
}
|
||||
});
|
||||
},
|
||||
],
|
||||
uncheckBegin: [],
|
||||
uncheckEnd: [],
|
||||
uncheckButton: [],
|
||||
uncheckCard: [
|
||||
function removeTempname(card, event) {
|
||||
if (!card._tempName) return;
|
||||
card._tempName.delete();
|
||||
delete card._tempName;
|
||||
},
|
||||
],
|
||||
uncheckTarget: [
|
||||
function removeInstance(target, event) {
|
||||
if (!target.instance) return;
|
||||
target.instance.classList.remove('selected');
|
||||
target.instance.classList.remove('selectable');
|
||||
},
|
||||
],
|
||||
};
|
||||
static hooks = { ...defaultHooks };
|
||||
|
||||
/**
|
||||
* **无名杀频道推送机制**
|
||||
|
|
Loading…
Reference in New Issue