commit
86a65c2091
|
@ -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,324 @@
|
|||
import { lib } from "../index.js"
|
||||
import { game } from "../../game/index.js"
|
||||
import { ui } from "../../ui/index.js"
|
||||
import { get } from "../../get/index.js"
|
||||
import { _status } from "../../status/index.js"
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["addGroup"])[]}
|
||||
*/
|
||||
export const addGroup = [
|
||||
function addColor(id, _short, _name, config) {
|
||||
if (typeof config.color != "undefined" && 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
|
||||
game.dynamicStyle.addObject({
|
||||
[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}"`)
|
||||
)
|
||||
)]: {
|
||||
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`
|
||||
)
|
||||
},
|
||||
[cs.group(
|
||||
cs.of(
|
||||
"div",
|
||||
cs.isAttr("data-nature", `"${id}m"`)
|
||||
),
|
||||
cs.of(
|
||||
"span",
|
||||
cs.isAttr("data-nature", `"${id}m"`)
|
||||
)
|
||||
)]: {
|
||||
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"
|
||||
)
|
||||
},
|
||||
[cs.group(
|
||||
cs.of(
|
||||
"div",
|
||||
cs.isAttr("data-nature", `"${id}mm"`)
|
||||
),
|
||||
cs.of(
|
||||
"span",
|
||||
cs.isAttr("data-nature", `"${id}mm"`)
|
||||
)
|
||||
)]: {
|
||||
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"
|
||||
)
|
||||
}
|
||||
})
|
||||
lib.groupnature[id] = id
|
||||
}
|
||||
}
|
||||
},
|
||||
function addImage(id, _short, _name, config) {
|
||||
if (typeof config.image == "string") {
|
||||
Reflect.defineProperty(lib.card, `group_${id}`, {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: {
|
||||
fullskin: true,
|
||||
image: config.image
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["addNature"])[]}
|
||||
*/
|
||||
export const addNature = [
|
||||
function addColor(nature, _translation, config) {
|
||||
if (typeof config != 'object') config = {}
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
// @ts-ignore
|
||||
let linked = config.linked
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
// @ts-ignore
|
||||
let order = config.order
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
// @ts-ignore
|
||||
let background = config.background
|
||||
/**
|
||||
* @type {number[]}
|
||||
*/
|
||||
// @ts-ignore
|
||||
let 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${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 = [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()})`
|
||||
),
|
||||
}
|
||||
// @ts-ignore
|
||||
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()})`,
|
||||
}
|
||||
// @ts-ignore
|
||||
game.dynamicStyle.addObject(result2)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["checkBegin"])[]}
|
||||
*/
|
||||
export const checkBegin = []
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["checkCard"])[]}
|
||||
*/
|
||||
export const 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')
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["checkTarget"])[]}
|
||||
*/
|
||||
export const checkTarget = [
|
||||
function updateInstance(target, event) {
|
||||
// @ts-ignore
|
||||
if (!target.instance) return;
|
||||
['selected', 'selectable'].forEach(className => {
|
||||
if (target.classList.contains(className)) {
|
||||
// @ts-ignore
|
||||
target.instance.classList.add(className)
|
||||
} else {
|
||||
// @ts-ignore
|
||||
target.instance.classList.remove(className)
|
||||
}
|
||||
})
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["checkButton"])[]}
|
||||
*/
|
||||
export const checkButton = []
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["checkEnd"])[]}
|
||||
*/
|
||||
export const checkEnd = [
|
||||
function autoConfirm(event, { ok, auto, autoConfirm }) {
|
||||
if (!event.isMine()) return
|
||||
const skillinfo = get.info(event.skill) || {}
|
||||
if (ok && auto && (autoConfirm || skillinfo.direct) && !_status.touchnocheck
|
||||
&& !_status.mousedown && (!_status.mousedragging || !_status.mouseleft)) {
|
||||
if (ui.confirm) ui.confirm.close()
|
||||
// @ts-ignore
|
||||
if (event.skillDialog === true) event.skillDialog = false
|
||||
ui.click.ok()
|
||||
_status.mousedragging = null
|
||||
if (skillinfo.preservecancel) ui.create.confirm('c')
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["uncheckBegin"])[]}
|
||||
*/
|
||||
export const uncheckBegin = []
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["uncheckCard"])[]}
|
||||
*/
|
||||
export const uncheckCard = [
|
||||
function removeTempname(card, event) {
|
||||
// @ts-ignore
|
||||
if (!card._tempName) return
|
||||
// @ts-ignore
|
||||
card._tempName.delete()
|
||||
// @ts-ignore
|
||||
delete card._tempName
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["uncheckTarget"])[]}
|
||||
*/
|
||||
export const uncheckTarget = [
|
||||
function removeInstance(target, event) {
|
||||
// @ts-ignore
|
||||
if (!target.instance) return
|
||||
// @ts-ignore
|
||||
target.instance.classList.remove('selected')
|
||||
// @ts-ignore
|
||||
target.instance.classList.remove('selectable')
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["uncheckButton"])[]}
|
||||
*/
|
||||
export const uncheckButton = []
|
||||
|
||||
|
||||
/**
|
||||
* @type {(import("./interface.js").NonameHookType["uncheckEnd"])[]}
|
||||
*/
|
||||
export const uncheckEnd = []
|
|
@ -0,0 +1,51 @@
|
|||
import * as buildin from "./buildin.js"
|
||||
|
||||
/**
|
||||
* @template {import("./interface.js").NonameHookType} HookType
|
||||
* @template {keyof HookType} Name
|
||||
*/
|
||||
export class NonameHook {
|
||||
/**
|
||||
* @type {Name}
|
||||
*/
|
||||
#name
|
||||
|
||||
/**
|
||||
* @type {HookType[Name][]}
|
||||
*/
|
||||
#methodList
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Name} name
|
||||
*/
|
||||
constructor(name) {
|
||||
this.#name = name
|
||||
this.#methodList = (name in buildin) ? [...buildin[name]] : []
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.#name
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HookType[Name]} method
|
||||
*/
|
||||
add(method) {
|
||||
return this.#methodList.add(method)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HookType[Name]} method
|
||||
*/
|
||||
push(method) {
|
||||
return this.#methodList.push(method)
|
||||
}
|
||||
|
||||
|
||||
*[Symbol.iterator]() {
|
||||
yield* this.#methodList
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
import { Button, Card, GameEvent, GameEventPromise, Player } from "../element"
|
||||
|
||||
export interface NonameHookType {
|
||||
/**
|
||||
*
|
||||
* @param id - 势力的id
|
||||
* @param short - 势力的短名称(单字称呼)
|
||||
* @param name - 势力的完整名称
|
||||
* @param config - 关于势力的配置情况
|
||||
*/
|
||||
addGroup(id: string, short: string, name: string, config: Record<string, unknown>)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nature - 属性的id
|
||||
* @param translation - 属性的名称
|
||||
* @param config - 关于属性的配置
|
||||
*/
|
||||
addNature(nature: string, translation: string, config: Record<string, unknown>)
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event - 当前检查的事件
|
||||
*/
|
||||
checkBegin(event: GameEvent & GameEventPromise)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event - 当前检查的事件
|
||||
* @param config - 一些配置
|
||||
*/
|
||||
checkEnd(event: GameEvent & GameEventPromise, config: { ok: boolean, auto: boolean, autoConfirm: boolean })
|
||||
|
||||
/**
|
||||
*
|
||||
* @param button - 检查的Button
|
||||
* @param event - 当前检查的事件
|
||||
*/
|
||||
checkButton(button: Button, event: GameEvent & GameEventPromise)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param card - 检查的卡牌
|
||||
* @param event - 当前检查的事件
|
||||
*/
|
||||
checkCard(card: Card, event: GameEvent & GameEventPromise)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target - 检查的玩家
|
||||
* @param event - 当前检查的事件
|
||||
*/
|
||||
checkTarget(target: Player, event: GameEvent & GameEventPromise)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event - 当前检查的事件
|
||||
* @param args - 要取消检查的对象
|
||||
*/
|
||||
uncheckBegin(event: GameEvent & GameEventPromise, args: ("button" | "card" | "target")[] = ["button", "card", "target"])
|
||||
|
||||
/**
|
||||
*
|
||||
* @param event - 当前检查的事件
|
||||
* @param args - 要取消检查的对象
|
||||
*/
|
||||
uncheckEnd(event: GameEvent & GameEventPromise, args: ("button" | "card" | "target")[] = ["button", "card", "target"])
|
||||
|
||||
/**
|
||||
*
|
||||
* @param button - 取消检查的Button
|
||||
* @param event - 当前检查的事件
|
||||
*/
|
||||
uncheckButton(button: Button, event: GameEvent & GameEventPromise)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param card - 取消检查的卡牌
|
||||
* @param event - 当前检查的事件
|
||||
*/
|
||||
uncheckCard(card: Card, event: GameEvent & GameEventPromise)
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target - 取消检查的玩家
|
||||
* @param event - 当前检查的事件
|
||||
*/
|
||||
uncheckTarget(target: Player, event: GameEvent & GameEventPromise)
|
||||
}
|
26564
noname/library/index.js
26564
noname/library/index.js
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue