Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
biuuu committed Mar 7, 2018
1 parent f3b002a commit 1d2c6f2
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 碧蓝幻想 微风 机翻团
# 碧蓝幻想微风机翻团
## Devlopment
全局安装 yarn
```
Expand Down
18 changes: 13 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs')
const path = require('path')
const { dirname } = require('path')
const mkdirp = require('mkdirp')
const { USER_DATA_PATH } = require('./store/')

const config = {
// 游戏的主要数据接口
Expand All @@ -26,11 +27,20 @@ const config = {
// 是否使用前置代理
frontAgent: false,
frontAgentHost: '127.0.0.1',
frontAgentPort: 1080
frontAgentPort: 1080,

transService: 'google',
baidu: {
appid: '',
appSecret: ''
},
youdao: {
appKey: '',
appSecret: ''
}
}

const userDataPath = path.resolve(process.env.APPDATA, 'blhxjf')
const LOCAL_CONFIG_PATH = path.resolve(userDataPath, 'config.json')
const LOCAL_CONFIG_PATH = path.resolve(USER_DATA_PATH, 'config.json')

const getLocalConfig = () => {
let localConfig = {}
Expand All @@ -51,6 +61,4 @@ const getLocalConfig = () => {

getLocalConfig()

config.userDataPath = userDataPath

module.exports = config
14 changes: 9 additions & 5 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"appId": "com.danmu9.blhx",
"productName": "GBF翻译",
"appId": "com.danmu9.blhxfy",
"productName": "碧蓝幻想翻译",
"copyright": "Copyright © 2018 biuuu",
"mac": {
"category": "public.app-category.utilities"
},
"files": ["!config.local.json", "!local${/*}"],
"asar": true,
"publish": {
"publish": [{
"provider": "github",
"repo": "BLHXJF",
"owner": "biuuu"
"repo": "BLHXFY",
"owner": "biuuu",
"token": ""
}],
"nsis": {
"artifactName": "${productName}${version}.${ext}"
}
}
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>碧蓝幻想机翻</title>
<title>碧蓝幻想翻译</title>
<link rel="stylesheet" href="./node_modules/element-ui/lib/theme-chalk/index.css">
<style>
html, body {
Expand All @@ -19,7 +19,7 @@
<el-button icon="el-icon-edit" plain type="primary" @click="openConfigWin">修改配置</el-button>
</div>
<div v-else>
<h3>碧蓝幻想机翻启动</h3>
<h3>碧蓝幻想翻译启动</h3>
<el-button icon="el-icon-document" size="small" @click="openCsvFolder">打开数据文件夹</el-button>
<p>代理地址:<br>127.0.0.1:{{port}}(本机访问)
<br>{{ip}}:{{port}}(局域网其它设备)</p>
Expand Down
16 changes: 15 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,23 @@ ipcMain.on('show-win-config', () => {
})))
})

const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
if (win) {
if (win.isMinimized()) win.restore()
win.focus()
}
})

if (shouldQuit) {
app.quit()
}

function createWindow () {
// 创建浏览器窗口。
win = new BrowserWindow({width: 360, height: 200})
win = new BrowserWindow({
width: 360, height: 200,
icon: __dirname + '/build/icon.ico'
})

// 然后加载应用的 index.html。
win.loadURL(url.format({
Expand Down
11 changes: 8 additions & 3 deletions modules/translate/scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const saveNames = require('../../utils/saveNames')
const saveScenario = require('../../utils/saveScenario')
const readScenario = require('../../utils/readScenario')

const transApi = googleTrans
let transApi = googleTrans
if (CONFIG.transService === 'youdao') transApi = youdaoTrans
if (CONFIG.transService === 'baidu') transApi = baiduTrans

const WORDS_LIMIT = 4500
const txtKeys = ['chapter_name', 'synopsis', 'detail', 'sel1_txt', 'sel2_txt']

Expand Down Expand Up @@ -125,10 +128,12 @@ module.exports = async (data, uid, pathname) => {
.catch(err => console.error(`保存剧情CSV失败:${err}\n${err.stack}`))
}
} else {
const transList = await transMulti(txtList, lang, userName)
const transList = CONFIG.transService
? await transMulti(txtList, lang, userName)
: []
infoList.forEach((info, index) => {
const obj = transMap.get(info.id) || {}
obj[info.type] = transList[index]
obj[info.type] = transList[index] || ''
transMap.set(info.id, obj)
})
if (scenarioState.status === 'loaded') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "blhxjf",
"name": "blhxfy",
"version": "0.1.6",
"description": "碧蓝幻想微风机翻团",
"main": "main.js",
Expand Down
3 changes: 3 additions & 0 deletions store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const path = require('path')

exports.USER_DATA_PATH = path.resolve(process.env.APPDATA, 'blhxfy')
12 changes: 6 additions & 6 deletions store/nameMap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { readCsv, sortKeywords, writeCsv } = require('../utils/')
const { USER_DATA_PATH } = require('../store/')
const path = require('path')
const chokidar = require('chokidar')
const { debounce } = require('lodash')
Expand All @@ -12,14 +13,13 @@ const nameData = {
}

const cwd = process.cwd()
const userDataPath = path.resolve(process.env.APPDATA, 'blhxjf')

const NAME_EN_PATH = path.resolve(__dirname, '../data', 'npc-name-en.csv')
const NAME_JP_PATH = path.resolve(__dirname, '../data', 'npc-name-jp.csv')
const NAME_EN_PATH_LOCAL = path.resolve(userDataPath, 'local', 'npc-name-en.csv')
const NAME_JP_PATH_LOCAL = path.resolve(userDataPath, 'local', 'npc-name-jp.csv')
const NAME_EN_PATH_LOCAL = path.resolve(USER_DATA_PATH, 'local', 'npc-name-en.csv')
const NAME_JP_PATH_LOCAL = path.resolve(USER_DATA_PATH, 'local', 'npc-name-jp.csv')
const NOUN_PATH = path.resolve(__dirname, '../data', 'noun.csv')
const NOUN_PATH_LOCAL = path.resolve(userDataPath, 'local', 'noun.csv')
const NOUN_PATH_LOCAL = path.resolve(USER_DATA_PATH, 'local', 'noun.csv')

const mergeList = async (pathLocal, pathStable, key = 'name') => {
const list = []
Expand Down Expand Up @@ -79,10 +79,10 @@ const nounFileChange = debounce((file) => {

setTimeout(() => {
chokidar.watch(['local/npc-name-*.csv'], {
cwd: userDataPath
cwd: USER_DATA_PATH
}).on('change', nameFileChange)
chokidar.watch(['local/noun.csv'], {
cwd: userDataPath
cwd: USER_DATA_PATH
}).on('change', nounFileChange)
}, 3000)

Expand Down
8 changes: 4 additions & 4 deletions store/scenarioState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const glob = require('glob')
const path = require('path')
const { readCsv } = require('../utils/')
const chokidar = require('chokidar')
const { userDataPath } = require('../config')
const { USER_DATA_PATH } = require('../store')

const scenarioMap = new Map()

Expand All @@ -12,7 +12,7 @@ const state = {
}

const readInfo = async (file, stable) => {
const csvPath = stable ? path.resolve(__dirname, '../', file) : path.resolve(userDataPath, file)
const csvPath = stable ? path.resolve(__dirname, '../', file) : path.resolve(USER_DATA_PATH, file)
const list = await readCsv(csvPath)
const filename = path.basename(file, '.csv')
const rlist = list.reverse()
Expand All @@ -30,7 +30,7 @@ const readInfo = async (file, stable) => {
}
}

glob('local/scenario/*.csv', { cwd: userDataPath }, (err, files) => {
glob('local/scenario/*.csv', { cwd: USER_DATA_PATH }, (err, files) => {
Promise.all(files.map(file => {
return readInfo(file, false)
})).then(() => {
Expand All @@ -46,7 +46,7 @@ glob('local/scenario/*.csv', { cwd: userDataPath }, (err, files) => {

setTimeout(() => {
chokidar.watch('local/scenario/*.csv', {
cwd: userDataPath
cwd: USER_DATA_PATH
}).on('add', file => {
readInfo(file)
})
Expand Down
3 changes: 2 additions & 1 deletion utils/readScenario.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const path = require('path')
const CONFIG = require('../config')
const { readCsv, replaceWords } = require('./index')
const { USER_DATA_PATH } = require('../store/')

const readScenario = async ({ filename, stable }, userName) => {
const csvPath = stable
? path.resolve(__dirname, '../data/scenario', `${filename}.csv`)
: path.resolve(CONFIG.userDataPath, `local/scenario`, `${filename}.csv`)
: path.resolve(USER_DATA_PATH, `local/scenario`, `${filename}.csv`)
const list = await readCsv(csvPath)
const transMap = new Map()
list.forEach(item => {
Expand Down
4 changes: 2 additions & 2 deletions utils/saveNames.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path')
const { writeCsv, readCsv, sortByStr } = require('./index')
const { userDataPath } = require('../config')
const { USER_DATA_PATH } = require('../store/')

const saveNames = async (names, lang) => {
if (!lang) return
const FILE_PATH = path.resolve(userDataPath, 'local/', `npc-name-${lang}.csv`)
const FILE_PATH = path.resolve(USER_DATA_PATH, 'local/', `npc-name-${lang}.csv`)
let list = []
try {
list = await readCsv(FILE_PATH)
Expand Down
5 changes: 3 additions & 2 deletions utils/saveScenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const scenarioState = require('../store/scenarioState')
const path = require('path')
const { readCsv, writeCsv, replaceWords } = require('./index')
const CONFIG = require('../config')
const { USER_DATA_PATH } = require('../store/')

const txtKeys = ['chapter_name', 'synopsis', 'detail', 'sel1_txt', 'sel2_txt']

Expand All @@ -21,7 +22,7 @@ const replaceName = (content, userName) => {

const saveScenario = async (map, data, filename, userName, lang) => {
const info = scenarioState.map.get(filename)
const scenarioPath = path.resolve(CONFIG.userDataPath, 'local/scenario/', `${filename}.csv`)
const scenarioPath = path.resolve(USER_DATA_PATH, 'local/scenario/', `${filename}.csv`)
const result = []
if (!info) {
data.forEach(item => {
Expand Down Expand Up @@ -56,7 +57,7 @@ const saveScenario = async (map, data, filename, userName, lang) => {
if (info.en && info.jp) return
if (info.en && lang === 'en') return
if (info.jp && lang === 'jp') return
const existPath = path.resolve(CONFIG.userDataPath, 'local/scenario/', `${info.filename}.csv`)
const existPath = path.resolve(USER_DATA_PATH, 'local/scenario/', `${info.filename}.csv`)
const list = await readCsv(existPath)
const localMap = new Map()
list.filter(row => row.id).forEach(row => {
Expand Down

0 comments on commit 1d2c6f2

Please sign in to comment.