Skip to content

Commit

Permalink
改了一两个函数的修饰符,此外加了个 TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
iamapig120 committed Feb 5, 2019
1 parent c75d133 commit bdf013d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 30 deletions.
93 changes: 64 additions & 29 deletions manager/Setting.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
const fs = require('fs')
const path = require('path')
const {ipcRenderer, remote} = require('electron')
const {app} = remote
const { ipcRenderer, remote } = require('electron')
const { app } = remote
const configs = require('../configs')
const defaultUserConfig = JSON.parse(require(configs.USER_CONFIG_PATH))

class Settings {

constructor (options = {}) {
constructor(options = {}) {
this.userConfig = options.userConfig || defaultUserConfig
}

_keyToTitle (key) {
static _keyToTitle(key) {
const map = {
window: '窗口',
zoomFactor: '资源管理器缩放(Zoom Factor)',
gameSSAA: '超采样抗锯齿(SSAA)',
renderingMultiple: '% 渲染比率(Rendering Multiple)',
isKioskModeOn: '使用原生模式代替默认全屏幕模式(Use Kiosk Fullscreen Mode)',
isKioskModeOn:
'使用原生模式代替默认全屏幕模式(Use Kiosk Fullscreen Mode)',
update: '更新',
prerelease: '获取浏览版(Get Pre-releases)',
chromium: '核心(需重启软件)',
isHardwareAccelerationDisable: '关闭硬件加速(Turn Hardware Acceleration Off)',
isHardwareAccelerationDisable:
'关闭硬件加速(Turn Hardware Acceleration Off)',
isInProcessGpuOn: '启用进程内GPU处理(Turn in-process-gpu On)',
isNoBorder: '使用无边框窗口进入游戏(Turn BorderLess On)',
localVersion: '雀魂Plus 当前版本'
}
return map[key] || key
}

_getUserLocalConfig () {
_getUserLocalConfig() {
const configPath = path.join(__dirname, '../configs-user.json')
const configJson = fs.readFileSync(configPath)
return JSON.parse(configJson)
}

_renderSection ({settingInner, section, data}) {
_renderSection({ settingInner, section, data }) {
if ('undefined' === typeof this.userConfig[section]) {
this.userConfig[section] = data
}
const sectionName = this._keyToTitle(section)
const sectionName = Settings._keyToTitle(section)
const h3 = document.createElement('h3')
h3.innerText = sectionName
settingInner.append(h3)
Object.entries(data).forEach(([item, data] , index) => {
this._renderSectionItem({settingInner, section, item, data, index})
Object.entries(data).forEach(([item, data], index) => {
this._renderSectionItem({ settingInner, section, item, data, index })
})
}

_renderCheckBoxSectionItem ({settingInner, section, item, data, index}) {
const itemName = this._keyToTitle(item)
_renderCheckBoxSectionItem({ settingInner, section, item, data, index }) {
const itemName = Settings._keyToTitle(item)
const checkBox = document.createElement('input')
checkBox.type = 'checkbox'
checkBox.id = `config${section}${item}${index}`
Expand All @@ -64,8 +65,8 @@ class Settings {
settingInner.append(label)
}

_renderNumberSectionItem ({settingInner, section, item, data, index}) {
const itemName = this._keyToTitle(item)
_renderNumberSectionItem({ settingInner, section, item, data, index }) {
const itemName = Settings._keyToTitle(item)
const input = document.createElement('input')
input.type = 'number'
input.id = `config${section}${item}${index}`
Expand All @@ -82,59 +83,93 @@ class Settings {
settingInner.append(br)
}

_renderSectionItem ({settingInner, section, item, data, index}) {
_renderFunctionSectionItem({ settingInner, section, item, data, index }) {
// TODO 这里将会插入一个按钮,从 item 读取 函数 和 名称
}

_renderSectionItem({ settingInner, section, item, data, index }) {
if ('undefined' === typeof this.userConfig[section][item]) {
this.userConfig[section][item] = data
}
const processes = {
'boolean': () => this._renderCheckBoxSectionItem({settingInner, section, item, data, index}),
'number': () => this._renderNumberSectionItem({settingInner, section, item, data, index})
boolean: () =>
this._renderCheckBoxSectionItem({
settingInner,
section,
item,
data,
index
}),
number: () =>
this._renderNumberSectionItem({
settingInner,
section,
item,
data,
index
}),
/**
* @param {string} data
*/
string: data => {
switch (data) {
case 'function': {
this._renderFunctionSectionItem({})
break
}
default:
break
}
}
}
const type = typeof data
processes[type] && processes[type].call()
processes[type] && processes[type].call(data)
}

_renderSections () {
_renderSections() {
const userLocalConfig = this._getUserLocalConfig()
const settingInner = document.getElementById('settingInner')
settingInner.innerHTML = ''
Object.entries(userLocalConfig).forEach(([section, data]) => {
this._renderSection({settingInner, section, data})
this._renderSection({ settingInner, section, data })
})
}

_renderVersionInfo () {
_renderVersionInfo() {
const settingInner = document.getElementById('settingInner')
const h3 = document.createElement('h3')
h3.innerText = this._keyToTitle('localVersion')
h3.innerText = Settings._keyToTitle('localVersion')
const p = document.createElement('p')
p.innerText = app.getVersion()
settingInner.append(h3)
settingInner.append(p)
}

_saveConfig () {
_saveConfig() {
try {
fs.writeFileSync(configs.USER_CONFIG_PATH, JSON.stringify(this.userConfig))
fs.writeFileSync(
configs.USER_CONFIG_PATH,
JSON.stringify(this.userConfig)
)
ipcRenderer.send('application-message', 'update-user-config')
alert('保存成功')
} catch (error) {
alert(`保存失败\n${error}`)
}
}

_addSaveListener () {
_addSaveListener() {
const saveBtn = document.getElementById('saveConfig')
saveBtn.addEventListener('click', this._saveConfig)
}

render () {
render() {
this._renderSections()
this._renderVersionInfo()
this._renderSaveButton()
}

init () {
init() {
this._addSaveListener()
this.render()
}
Expand Down
11 changes: 11 additions & 0 deletions manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,17 @@ const userConfigInit = () => {
settingInner.append(br)
}
break
case 'string': {
switch (value) {
case 'function': {
// TODO 这里将会插入一个按钮,从 item 读取 函数 和 名称
break
}
default:
break
}
break
}
default:
break
}
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": "majsoul-plus-client",
"version": "1.10.2-alpha.3",
"version": "1.10.2-alpha.4",
"productName": "Majsoul Plus",
"author": "MajsoulPlus Team",
"description": "Majsoul Plus",
Expand Down

0 comments on commit bdf013d

Please sign in to comment.