更新
This commit is contained in:
parent
001e72d27b
commit
7e52b9c382
@ -4,6 +4,14 @@
|
||||
|
||||
# CHANGE
|
||||
|
||||
## 0.8.2
|
||||
|
||||
2023年02月01日
|
||||
|
||||
### 添加
|
||||
|
||||
- 新翻译:通用物品名与详情
|
||||
|
||||
## 0.8.1
|
||||
|
||||
2023年02月01日
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wuhu-torn-helper",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.2",
|
||||
"description": "芜湖助手",
|
||||
"dependencies": {},
|
||||
"scripts": {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,10 +1,20 @@
|
||||
import WuhuBase from "../WuhuBase";
|
||||
import { chatDict, eventsDict, headerDict, propertyDict, sidebarDict } from "../../dictionary/translation";
|
||||
import {
|
||||
chatDict,
|
||||
eventsDict,
|
||||
headerDict,
|
||||
itemNameDict,
|
||||
itemPageDict,
|
||||
propertyDict,
|
||||
sidebarDict
|
||||
} from "../../dictionary/translation";
|
||||
import Log from "../Log";
|
||||
import Timer from "../utils/Timer";
|
||||
import { Button, MiniProfile } from "../../interface/responseType/MiniProfile";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import Sidebar from "../../interface/responseType/Sidebar";
|
||||
import CommonUtils from "../utils/CommonUtils";
|
||||
import InventoryItemInfo from "../../interface/responseType/InventoryItemInfo";
|
||||
|
||||
export default class Translate extends WuhuBase {
|
||||
className = 'Translate';
|
||||
@ -298,8 +308,9 @@ export default class Translate extends WuhuBase {
|
||||
* fetch xhr 返回数据的翻译处理
|
||||
* @param url
|
||||
* @param body
|
||||
* @param opt
|
||||
*/
|
||||
public static responseHandler(url: string, body: { json: unknown, text: string, isModified: boolean }): void {
|
||||
public static responseHandler(url: string, body: { json: unknown, text: string, isModified: boolean }, opt: { method: 'GET' | 'POST', requestBody: string }): void {
|
||||
if (!WuhuConfig.get('transNew')) return;
|
||||
// TODO 字典抽取
|
||||
let map = {
|
||||
@ -582,6 +593,77 @@ export default class Translate extends WuhuBase {
|
||||
nameMapReplace(response.account, map.accountMap);
|
||||
body.isModified = true;
|
||||
}
|
||||
// 物品详情
|
||||
else if (url.includes('inventory.php') && opt?.method === 'POST' &&
|
||||
typeof opt?.requestBody === 'string' && opt?.requestBody.includes('step=info')) {
|
||||
let resp = body.json as InventoryItemInfo;
|
||||
// TODO 维护通用物品数据(对应名称、描述、类型)缓存
|
||||
let map: { [k: string]: Partial<InventoryItemInfo> } = {
|
||||
'Glass of Beer': {
|
||||
itemName: '一杯啤酒',
|
||||
itemInfo: '[译]Only savages drink beer straight out of the bottle. This glass of beer is obtained fresh from the keg, and provides the same level of drunken joy as you\'d get from a regular bottle of suds. Provides a moderate nerve increase when consumed.',
|
||||
itemInfoContent: "\n" +
|
||||
" <div class='m-bottom10'>\n" +
|
||||
" <span class=\"bold\">一杯啤酒</span> 是酒类物品\n" +
|
||||
" </div>\n" +
|
||||
" Only savages drink beer straight out of the bottle. This glass of beer is obtained fresh from the keg, and provides the same level of drunken joy as you'd get from a regular bottle of suds. Provides a moderate nerve increase when consumed.\n" +
|
||||
" <div class=\"t-green bold item-effect m-top10\">效果: 犯罪 + 2,增幅CD + 1h。</div>",
|
||||
},
|
||||
};
|
||||
let idMap = { 816: 'Glass of Beer' };
|
||||
let itemInfo = CommonUtils.getInstance().getItemByIdOrName(resp.itemName, idMap, map);
|
||||
if (itemInfo) {
|
||||
body.isModified = true;
|
||||
resp.itemInfo = itemInfo.itemInfo;
|
||||
resp.itemName = itemInfo.itemName;
|
||||
resp.itemInfoContent = itemInfo.itemInfoContent;
|
||||
}
|
||||
// TODO 老字典
|
||||
let itemName = itemNameDict[resp.itemName];
|
||||
if (itemName) {
|
||||
body.isModified = true;
|
||||
resp.itemInfoContent = resp.itemInfoContent
|
||||
.replace('The ', '')
|
||||
.replace(resp.itemName, `${ itemName }(${ resp.itemName })`);
|
||||
}
|
||||
}
|
||||
// 物品列表
|
||||
else if ((url.includes('item.php') || url.includes('inventory.php')) && opt?.method === 'POST' &&
|
||||
typeof opt?.requestBody === 'string' && (opt?.requestBody.includes('step=getCategoryList') || opt?.requestBody.includes('step=getList'))) {
|
||||
let resp = body.json as { html: string };
|
||||
if (resp.html) {
|
||||
let tmp = document.createElement('div');
|
||||
tmp.innerHTML = resp.html;
|
||||
Log.info(tmp);
|
||||
tmp.childNodes.forEach(li => {
|
||||
if (li.nodeType === 1) {
|
||||
let elem = li as Element;
|
||||
// 物品名
|
||||
let name = elem.querySelector('.name-wrap .name');
|
||||
let nameZh = itemNameDict[name.innerText.trim()];
|
||||
if (nameZh) {
|
||||
name.innerText = `${ name.innerText } ${ nameZh }`;
|
||||
}
|
||||
// 操作按钮
|
||||
let actions = elem.querySelectorAll('.icon-h');
|
||||
actions.forEach(action => {
|
||||
let attrTitle = action.getAttribute('title');
|
||||
// TODO
|
||||
let zh = itemPageDict[attrTitle];
|
||||
if (zh) {
|
||||
action.setAttribute('title', zh);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
resp.html = tmp.innerHTML;
|
||||
body.isModified = true;
|
||||
}
|
||||
}
|
||||
// TODO 物品列表json版
|
||||
else if (url.includes('inventory.php') && opt?.method === 'POST' &&
|
||||
typeof opt?.requestBody === 'string' && opt?.requestBody.includes('step=getList')) {
|
||||
}
|
||||
} catch (e) {
|
||||
Log.error('responseHandler', e.stack || e.message);
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import TornStyleSwitch from "./TornStyleSwitch";
|
||||
import WuhuConfig from "../WuhuConfig";
|
||||
import { MenuItemConfig } from "../ZhongIcon";
|
||||
import TRAVEL_STATE from "../../enum/TravelState";
|
||||
import InventoryItemInfo from "../../interface/responseType/InventoryItemInfo";
|
||||
|
||||
export default class CommonUtils extends WuhuBase {
|
||||
className = 'CommonUtils';
|
||||
@ -391,4 +392,13 @@ export default class CommonUtils extends WuhuBase {
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key id或物品名
|
||||
* @param m1 id->name map
|
||||
* @param m2 name->item map
|
||||
*/
|
||||
public getItemByIdOrName(key: string, m1, m2: { [k: string]: Partial<InventoryItemInfo> }): Partial<InventoryItemInfo> {
|
||||
return m1[key] ? m2[m1[key]] : m2[key];
|
||||
}
|
||||
}
|
||||
|
||||
13
src/ts/interface/responseType/InventoryItemInfo.ts
Normal file
13
src/ts/interface/responseType/InventoryItemInfo.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 物品详情
|
||||
*/
|
||||
export default interface InventoryItemInfo {
|
||||
itemID: 816
|
||||
itemInfo: string
|
||||
// html 格式
|
||||
itemInfoContent: string
|
||||
itemName: string
|
||||
// html 格式
|
||||
itemRareTitle: string
|
||||
itemType: "Item"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user