Skip to content

Commit

Permalink
update skill translate (#57)
Browse files Browse the repository at this point in the history
* add common skill translate
* support + and ++ skill translate
  • Loading branch information
biuuu authored Jun 21, 2018
1 parent 11a1233 commit 4323c12
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 32 deletions.
31 changes: 31 additions & 0 deletions data/common-skill.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
comment,trans,type
Massive $elemt DMG to a foe,$1属性伤害(特大),1
$elemt属性ダメージ(特大),$1属性伤害(特大),1
Boost to $elemt allies' critical hit rate,$1属性角色暴击率上升,1
$elemt属性キャラのクリティカル確率UP,$1属性角色暴击率上升,1
敵に$num~$num倍$elemt属性ダメージ,对敌方单体造成$1~$2倍$3属性伤害,1
"$percent-$percent $elemt DMG to a foe",对敌方单体造成$1-$2的$3属性伤害,1
自分のアビリティダメージ上限UP,提高自身技能伤害上限,2
Boost to skill DMG cap,提高自身技能伤害上限,2
累積,叠加,3
Stackable,叠加,3
追加ダメージ,追加伤害,2
Bonus DMG,追加伤害,2
敵に$elemt属性ダメージ,敌单体$1属性伤害,1
$elemt DMG to a foe,敌单体$1属性伤害,1
Hit to foe DEF,防御DOWN,2
味方全体の全属性ダメージカット($percent),我方全体伤害减免$1,1
$percent DMG cut to all allies,我方全体伤害减免$1,1
Bonus boost to all allies' DEF,我方全体防御上升,3
オーバードライブ時の敵に$num~$num倍$elemt属性ダメージ,对Overdrive状态的敌方单体造成$1~$2倍$3属性伤害,1
モードゲージ減少,Mode bar减少,2
$percent-$percent $elemt DMG to a foe in overdrive,对Overdrive状态的敌方单体造成$1-$2的$3属性伤害,1
Hit to mode bar for a foe in overdrive,降低Overdrive状态敌方单体的Mode bar,2
オーバードライブ時の敵からの被ダメージ減少,减少来自Overdrive状态的敌方的伤害,2
毎ターンステータスUP,每回合状态UP,2
被ダメージで解除,受到伤害后解除,2
Cut to DMG from a foe in overdrive,减少来自Overdrive状态的敌方的伤害,2
Boost to attack specs every turn,每回合提高攻击性能,2
Ends upon taking DMG,受到伤害后解除,2
バトル開始時にパーティの奥義ゲージUP,战斗开始时,我方全体奥义值上升,2
Boost to allies' charge bar at battle start,战斗开始时,我方全体奥义值上升,2
3 changes: 1 addition & 2 deletions data/skill/土-尤格多拉希尔-SSR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ skill-2,金字形神塔,<div class=prt-text-small>土属性角色的暴击机率
skill-3,酸樱的恩宠,回复我方全体HP(500)/再生効果(10%/400)/净化1个异常状态
support-1,慈爱的大树,虽然会更容易被敌人当成目标但受伤时的奥义条上升量UP(+100%)
support-2,永恒不变灵魂,对水属性敌人的最终伤害UP(20% 不能与天司武器叠加)
skill-lb,LB技能,我方全体的被回复上限UP(★+100, +150, +200 ★★★)
active,1,
skill-lb,LB技能,"我方全体的被回复上限UP(★+100, ★★+150, ★★★+200)"
8 changes: 0 additions & 8 deletions data/skill/暗-佐伊(泳装)-SSR.csv

This file was deleted.

38 changes: 29 additions & 9 deletions modules/translate/skill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const path = require('path')
const { USER_DATA_PATH } = require('../../store/')
const skillState = require('../../store/skillMap')
const users = require('../../store/users')
const { cloneDeep } = require('lodash')
const transSkill = require('../../utils/transSkill')

const { skillMap, skillKeys } = skillState
const keys = skillKeys
Expand Down Expand Up @@ -36,18 +38,22 @@ const saveSkill = async (data) => {

const getPlusStr = (str) => {
let plusStr = ''
let plusStr2 = ''
let _str = str
while (_str.endsWith('+') || _str.endsWith('+')) {
plusStr += '+'
plusStr2 += '+'
_str = _str.slice(0, _str.length - 1)
}
return plusStr
return [plusStr, plusStr2]
}

const transSkill = async (data, lang) => {
const parseSkill = async (data, lang) => {
if (skillState.status !== 'loaded' || !data.master || !data.master.id) return data
const npcId = `${data.master.id}`
const skillData = skillMap.get(npcId)
const cData = cloneDeep(data)
const translated = new Map()
if (skillData) {
keys.forEach(item => {
const key1 = item[0]
Expand All @@ -65,28 +71,42 @@ const transSkill = async (data, lang) => {
.replace('ターン', '回合').replace('turns', '回合')
.replace('turn', '回合')
}
const trans = skillData[key2]
if (!trans) return
const [plus1, plus2] = getPlusStr(data[key1].name)
let trans = skillData[key2 + plus2]
if (!trans) {
trans = skillData[key2]
if (!trans) return
}
if (trans.name) {
const str = getPlusStr(data[key1].name)
data[key1].name = trans.name + str
data[key1].name = trans.name + plus1
}
if (trans.detail) {
data[key1].comment = trans.detail
translated.set(key1, true)
}
if (trans.detail) data[key1].comment = trans.detail
})
if (data.master) {
const trans = skillData['npc']
if (trans && trans.name) data.master.name = trans.name
}
} else if (lang === 'jp') {
saveSkill(data)
saveSkill(cData)
}
keys.forEach(item => {
if (!translated.get(item[0])) {
const skill = data[item[0]]
if (skill) {
skill.comment = transSkill(skill.comment)
}
}
})
return data
}

const parseData = async (data, uid) => {
const currentUser = users.get(uid)
const lang = currentUser ? currentUser.lang : 'jp'
const result = await transSkill(data, lang)
const result = await parseSkill(data, lang)
return data
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blhxfy",
"version": "0.5.12",
"version": "0.5.13",
"description": "碧蓝幻想微风机翻团",
"main": "main.js",
"scripts": {
Expand Down
37 changes: 27 additions & 10 deletions store/skillMap.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const glob = require('glob')
const path = require('path')
const { readCsv, readJson } = require('../utils/')
const { readCsv, readJson, sortKeywords } = require('../utils/')
const chokidar = require('chokidar')
const { USER_DATA_PATH, dataPath } = require('./index')
const fse = require('fs-extra')
const { debounce } = require('lodash')

const skillMap = new Map()
const skillNameMap = new Map()

const skillKeys = [
['special_skill', 'special'],
Expand All @@ -24,8 +23,28 @@ const keys = ['skill-1', 'skill-2', 'skill-3', 'skill-4', 'special']

const state = {
status: 'init',
skillMap, skillNameMap,
skillKeys
skillMap,
skillKeys,
commSkillMap: new Map(),
autoTransCache: new Map()
}

const getCommSkillMap = async () => {
const DATA_PATH = await dataPath()
const csvPath = path.resolve(DATA_PATH, 'common-skill.csv')
const list = await readCsv(csvPath)
const sortedList = sortKeywords(list, 'comment')
state.commSkillMap = new Map()
sortedList.forEach(item => {
if (item.comment && item.trans) {
const comment = item.comment.trim()
const trans = item.trans.trim()
const type = item.type.trim() || '1'
if (comment && trans) {
state.commSkillMap.set(comment, { trans, type })
}
}
})
}

const setSkillMap = (list, stable) => {
Expand All @@ -46,19 +65,17 @@ const setSkillMap = (list, stable) => {
const fullData = {}
for (let row of list) {
if (stable || active) {
if (keys.includes(row.id)) {
skillData[row.id] = row
}
fullData[row.id] = row
skillData[row.id] = row
}
}
state.skillMap.set(npcId, fullData)
state.skillNameMap.set(npcId, skillData)
state.skillMap.set(npcId, skillData)
}

const reCollectSkill = async () => {
const DATA_PATH = await dataPath()
const data = await readJson(path.resolve(DATA_PATH, 'skill.json'))
await getCommSkillMap()
state.autoTransCache.clear()
if (data) {
for (let key in data) {
const csvPath = path.resolve(DATA_PATH, 'skill', data[key])
Expand Down
4 changes: 2 additions & 2 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ const sortKeywords = (list, key = 'name') => {

const sortByStr = (list, key = 'name') => {
return list.sort((prev, next) => {
if (prev[key] > next[key]) return -1
else if (prev[key] < next[key]) return 1
if (prev[key] > next[key]) return 1
else if (prev[key] < next[key]) return -1
else return 0
})
}
Expand Down
48 changes: 48 additions & 0 deletions utils/transSkill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { commSkillMap, autoTransCache } = require('../store/skillMap')

const elemtRE = '([光闇水火風土]|light|dark|water|wind|earth|fire)'
const elemtMap = {
light: '光', '光': '光', 'dark': '暗', '闇': '暗', 'water': '水', '水': '水',
wind: '风', '風': '风', 'earth': '土', '土': '土', 'fire': '火', '火': '火'
}
const numRE = '(\\d{1,4})'
const percentRE = '(\\d{1,4}%)'

const parseRegExp = (str) => {
return str.replace(/\(/g, '\\(')
.replace(/\)/g, '\\)').replace(/\$elemt/g, elemtRE)
.replace(/\$num/g, numRE)
.replace(/\$percent/g, percentRE)
}

const transSkill = (comment) => {
if (autoTransCache.has(comment)) return autoTransCache.get(comment)
let result = comment
for (let [key, value] of commSkillMap) {
if (!key.trim()) continue
const { trans, type } = value
if (type === '1') {
const re = new RegExp(parseRegExp(key), 'gi')
result = result.replace(re, (...arr) => {
let _trans = trans
for (let i = 1; i < arr.length - 2; i++) {
let eleKey = arr[i].toLowerCase()
if (elemtMap[eleKey]) {
_trans = _trans.replace(`$${i}`, elemtMap[eleKey])
} else {
_trans = _trans.replace(`$${i}`, arr[i])
}
}
return _trans
})
} else if (type === '2') {
result = result.replace(key, trans)
} else if (type === '3') {
result = result.replace(`(${key})`, `(${trans})`)
}
}
autoTransCache.set(comment, result)
return result
}

module.exports = transSkill
1 change: 1 addition & 0 deletions utils/updateCsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const reCollectData = (packname) => {
const filename = path.resolve(USER_DATA_PATH, 'tmpFile/', packname)
const target = path.resolve(USER_DATA_PATH, 'data/')
fs.emptyDirSync(path.resolve(target, 'scenario'))
fs.emptyDirSync(path.resolve(target, 'skill'))
decompressFile(filename, target, function () {
getData('en')
getData('jp')
Expand Down

0 comments on commit 4323c12

Please sign in to comment.