From d47f8ce1b178205034bcad3c08de9682577a4d5e Mon Sep 17 00:00:00 2001 From: Spmario233 Date: Mon, 22 Apr 2024 23:18:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAlib.element.Character?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/get/index.js | 2 +- noname/library/element/character.js | 98 +++++++++++++++++++++++++++++ noname/library/element/index.js | 1 + noname/library/index.js | 17 ++++- 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 noname/library/element/character.js diff --git a/noname/get/index.js b/noname/get/index.js index b1a632e09..639669fcc 100644 --- a/noname/get/index.js +++ b/noname/get/index.js @@ -604,7 +604,7 @@ export class Get { let info = lib.character[name]; if (!info) { const pack = Object.keys(lib.characterPack).find((pack) => name in lib.characterPack[pack]); - if (pack) info = lib.characterPack[pack][name]; + if (pack) info = new lib.element.Character(lib.characterPack[pack][name]); } if (typeof num === "number") { if (!info) info = []; diff --git a/noname/library/element/character.js b/noname/library/element/character.js new file mode 100644 index 000000000..10d6fba72 --- /dev/null +++ b/noname/library/element/character.js @@ -0,0 +1,98 @@ +import { get } from "../../get/index.js"; +import { game } from "../../game/index.js"; +import { lib } from "../index.js"; +import { _status } from "../../status/index.js"; +import { ui } from "../../ui/index.js"; + +export class Character { + /** @type { string } */ + sex; + /** @type { number } */ + hp; + /** @type { number } */ + maxHp; + /** @type { number } */ + hujia; + /** @type { string } */ + group; + /** @type { string[] } */ + skills; + /** @type { Array } */ + trashBin; + /** + * @param { Array|Object } [data] + */ + constructor(data) { + if (Array.isArray(data)) { + this.sex = data[0]; + this.group = data[1]; + this.hp = get.infoHp(data[2]); + this.maxHp = get.infoMaxHp(data[2]); + this.hujia = get.infoHujia(data[2]); + this.skills = get.copy(data[3] || []); + this.trashBin = get.copy(data[4] || []); + } + else if (get.is.object(data)) { + this.sex = data.sex; + this.group = data.group || ''; + this.hp = data.hp || 1; + this.maxHp = data.maxHp || this.hp; + this.hujia = data.hujia || 0; + this.skills = get.copy(data.skills || []); + this.trashBin = get.copy(data.trashBin || []); + } + }; + /** + * @deprecated + */ + get 0() { + return this.sex; + }; + set 0(sex) { + this.sex = sex; + }; + + /** + * @deprecated + */ + get 1() { + return this.group; + }; + set 1(group) { + this.group = group; + }; + + /** + * @deprecated + */ + get 2() { + if (this.hujia > 0) return `${this.hp}/${this.maxHp}/${this.hujia}`; + else if (this.hp !== this.maxHp) return `${this.hp}/${this.maxHp}`; + return this.hp; + }; + set 2(hp) { + this.hp = get.infoHp(hp); + this.maxHp = get.infoMaxHp(hp); + this.hujia = get.infoHujia(hp); + }; + + /** + * @deprecated + */ + get 3() { + return this.skills; + }; + set 3(skills) { + this.skills = skills; + }; + + /** + * @deprecated + */ + get 4() { + return this.trashBin; + }; + set 4(trashBin) { + this.trashBin = trashBin; + }; +} \ No newline at end of file diff --git a/noname/library/element/index.js b/noname/library/element/index.js index 0b0417fb3..c6ed5ca2d 100644 --- a/noname/library/element/index.js +++ b/noname/library/element/index.js @@ -10,3 +10,4 @@ export { GameEventPromise } from "./gameEventPromise.js"; export { NodeWS } from "./nodeWS.js"; export { Player } from "./player.js"; export { VCard } from "./vcard.js"; +export { Character } from "./character.js" diff --git a/noname/library/index.js b/noname/library/index.js index 7977ceb56..cc94bc8ca 100644 --- a/noname/library/index.js +++ b/noname/library/index.js @@ -10108,6 +10108,7 @@ export class Library { Control: Element.Control, Client: Element.Client, NodeWS: Element.NodeWS, + Character: Element.Character, ws: { onopen: function () { if (_status.connectCallback) { @@ -10213,6 +10214,12 @@ export class Library { get nodews() { return this.NodeWS.prototype; }, + /** + * @legacy Use {@link lib.element.Character.prototype} instead. + */ + get character() { + return this.Character.prototype; + }, }; card = { /** @@ -12771,7 +12778,15 @@ export class Library { }, }, }; - character = {}; + character = new Proxy( + {}, + { + set(target, prop, newValue){ + newValue = new lib.element.Character(newValue); + return Reflect.set(target, prop, newValue); + } + } + ); perfectPair = {}; cardPile = {}; message = {