Merge pull request #1298 from kuangshen04/PR-Branch

为Character类的get 4 增加proxy
This commit is contained in:
Spmario233 2024-05-01 21:41:48 +08:00 committed by GitHub
commit e95f777fe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 82 additions and 47 deletions

View File

@ -32,12 +32,12 @@ export class Character {
group; group;
/** /**
* 武将牌的势力边框颜色如徐庶身在曹营心在汉 * 武将牌的势力边框颜色如徐庶身在曹营心在汉
* @type { string } * @type { string|undefined }
**/ **/
groupBorder; groupBorder;
/** /**
* 神武将牌在国战模式下的势力 * 神武将牌在国战模式下的势力
* @type { string } * @type { string|undefined }
**/ **/
groupInGuozhan; groupInGuozhan;
/** /**
@ -62,17 +62,17 @@ export class Character {
hasHiddenSkill = false; hasHiddenSkill = false;
/** /**
* 垃圾桶用于存储原本Character[4]的垃圾数据 * 垃圾桶用于存储原本Character[4]的垃圾数据
* @type { Array } * @type { any[] }
**/ **/
trashBin = []; trashBin = [];
/** /**
* 武将牌对应的另一半双面武将牌 * 武将牌对应的另一半双面武将牌
* @type { string } * @type { string|undefined }
**/ **/
dualSideCharacter; dualSideCharacter;
/** /**
* 多势力武将牌的全部势力 * 多势力武将牌的全部势力
* @type { Array } * @type { string[] }
**/ **/
doubleGroup = []; doubleGroup = [];
/** /**
@ -97,7 +97,7 @@ export class Character {
isAiForbidden = false; isAiForbidden = false;
/** /**
* 武将牌在炉石模式/挑战模式下的特殊信息 * 武将牌在炉石模式/挑战模式下的特殊信息
* @type { array|undefined } * @type { any[]|undefined }
**/ **/
extraModeData; extraModeData;
/** /**
@ -151,7 +151,7 @@ export class Character {
**/ **/
initFilters = []; initFilters = [];
/** /**
* @param { Array|Object } [data] * @param { Object|[string, string, string|number, string[], any[]|undefined, any[]|undefined] } [data]
*/ */
constructor(data) { constructor(data) {
if (Array.isArray(data)) { if (Array.isArray(data)) {
@ -161,72 +161,96 @@ export class Character {
this.maxHp = get.infoMaxHp(data[2]); this.maxHp = get.infoMaxHp(data[2]);
this.hujia = get.infoHujia(data[2]); this.hujia = get.infoHujia(data[2]);
this.skills = get.copy(data[3] || []); this.skills = get.copy(data[3] || []);
if (data[4]) Character.convertTrashToProperties(this, data[4]); if (data[4]) this.setPropertiesFromTrash(data[4]);
if (data.length > 5) this.extraModeData = data[5]; if (data.length > 5) this.extraModeData = data[5];
} else if (get.is.object(data)) { } else if (get.is.object(data)) {
Object.assign(this, data); Object.assign(this, data);
if (typeof this.maxHp !== "number") this.maxHp = this.hp; if (typeof this.maxHp !== "number") this.maxHp = this.hp;
} }
} }
initializeTrashProperties() {
this.groupInGuozhan = void 0;
this.isZhugong = false;
this.isUnseen = false;
this.isMinskin = false;
this.hasSkinInGuozhan = false;
this.isBoss = false;
this.isChessBoss = false;
this.isJiangeBoss = false;
this.isJiangeMech = false;
this.isBossAllowed = false;
this.isHiddenBoss = false;
this.isAiForbidden = false;
this.isFellowInStoneMode = false;
this.isHiddenInStoneMode = false;
this.isSpecialInStoneMode = false;
this.hasHiddenSkill = false;
this.groupBorder = void 0;
this.dualSideCharacter = void 0;
this.doubleGroup = [];
this.clans = [];
this.initFilters = [];
this.trashBin = [];
}
/** /**
* @param { Character } character * @param { any[] } trash
* @param { Array } trash
*/ */
static convertTrashToProperties(character, trash) { setPropertiesFromTrash(trash) {
let keptTrashes = [], this.initializeTrashProperties();
const keptTrashes = [],
clans = []; clans = [];
for (let i = 0; i < trash.length; i++) { for (let i = 0; i < trash.length; i++) {
let item = trash[i]; const item = trash[i];
if (i === 0 && (lib.group.includes(item) || item === 'key')) { if (i === 0 && (lib.group.includes(item) || item === 'key')) {
character.groupInGuozhan = item; this.groupInGuozhan = item;
} else if(item.startsWith("gzgroup:")){
character.groupInGuozhan = item.slice(8);
} else if (item === "zhu") { } else if (item === "zhu") {
character.isZhugong = true; this.isZhugong = true;
} else if (item === "unseen") { } else if (item === "unseen") {
character.isUnseen = true; this.isUnseen = true;
} else if (item === "minskin") { } else if (item === "minskin") {
character.isMinskin = true; this.isMinskin = true;
} else if (item === "gzskin") { } else if (item === "gzskin") {
character.hasSkinInGuozhan = true; this.hasSkinInGuozhan = true;
} else if (item === "boss") { } else if (item === "boss") {
character.isBoss = true; this.isBoss = true;
} else if (item === "chessboss") { } else if (item === "chessboss") {
character.isChessBoss = true; this.isChessBoss = true;
} else if (item === "jiangeboss") { } else if (item === "jiangeboss") {
character.isJiangeBoss = true; this.isJiangeBoss = true;
} else if (item === "jiangemech") { } else if (item === "jiangemech") {
character.isJiangeMech = true; this.isJiangeMech = true;
} else if (item === "bossallowed") { } else if (item === "bossallowed") {
character.isBossAllowed = true; this.isBossAllowed = true;
} else if (item === "hiddenboss") { } else if (item === "hiddenboss") {
character.isHiddenBoss = true; this.isHiddenBoss = true;
} else if (item === "forbidai") { } else if (item === "forbidai") {
character.isAiForbidden = true; this.isAiForbidden = true;
} else if (item === "stone") { } else if (item === "stone") {
character.isFellowInStoneMode = true; this.isFellowInStoneMode = true;
} else if (item === "stonehidden") { } else if (item === "stonehidden") {
character.isHiddenInStoneMode = true; this.isHiddenInStoneMode = true;
} else if (item === "stonespecial") { } else if (item === "stonespecial") {
character.isSpecialInStoneMode = true; this.isSpecialInStoneMode = true;
} else if (item === "hiddenSkill") { } else if (item === "hiddenSkill") {
character.hasHiddenSkill = true; this.hasHiddenSkill = true;
} else if (item.startsWith("border:")) { } else if (item?.startsWith("border:")) {
character.groupBorder = item.slice(7); this.groupBorder = item.slice(7);
} else if (item.startsWith("dualside:")) { } else if (item?.startsWith("dualside:")) {
character.dualSideCharacter = item.slice(9); this.dualSideCharacter = item.slice(9);
} else if (item.startsWith("doublegroup:")) { } else if (item?.startsWith("gzgroup:")) {
character.doubleGroup = item.slice(12).split(":"); this.groupInGuozhan = item.slice(8);
} else if (item.startsWith("clan:")) { } else if (item?.startsWith("doublegroup:")) {
this.doubleGroup = item.slice(12).split(":");
} else if (item?.startsWith("clan:")) {
clans.push(item.slice(5)); clans.push(item.slice(5));
} else if (item.startsWith("InitFilter:")) { } else if (item?.startsWith("InitFilter:")) {
character.initFilters = item.slice(11).split(":"); this.initFilters = item.slice(11).split(":");
} else { } else {
keptTrashes.push(item); keptTrashes.push(item);
} }
} }
if (clans.length > 0) character.clans = clans; this.clans = clans;
character.trashBin = keptTrashes; this.trashBin = keptTrashes;
} }
/** /**
* @deprecated * @deprecated
@ -274,12 +298,12 @@ export class Character {
/** /**
* 把新格式下的数据转换回传统的屎山 * 把新格式下的数据转换回传统的屎山
* @deprecated * @deprecated
*/ */
get 4() { get 4() {
const trashes = [], const trashes = [],
character = this; character = this;
if (lib.group.includes(character.groupInGuozhan)) { if (character.groupInGuozhan && lib.group.includes(character.groupInGuozhan)) {
trashes.push(`gzgroup:${character.groupInGuozhan}`); trashes.push(`gzgroup:${character.groupInGuozhan}`);
} }
if (character.isZhugong) { if (character.isZhugong) {
@ -343,16 +367,27 @@ export class Character {
trashes.push(`InitFilters:${character.initFilters.join(":")}`); trashes.push(`InitFilters:${character.initFilters.join(":")}`);
} }
return trashes.concat(character.trashBin); return new Proxy(trashes.concat(character.trashBin), {
set(target, prop, newValue) {
const result = Reflect.set(target, prop, newValue);
character.setPropertiesFromTrash(target);
return result;
},
deleteProperty(target, prop) {
const result = Reflect.deleteProperty(target, prop);
character.setPropertiesFromTrash(target);
return result;
}
});
} }
set 4(trashBin) { set 4(trashBin) {
console.warn("你set你🐎的废弃属性"); console.warn("你set你🐎的废弃属性");
} }
get 5(){ get 5() {
return this.extraModeData; return this.extraModeData;
} }
set 5(stoneData){ set 5(stoneData) {
this.extraModeData = stoneData; this.extraModeData = stoneData;
} }
} }