make metadata optional

This commit is contained in:
SpikeHD
2022-07-19 17:07:10 -07:00
parent d38459bb8a
commit 8ff06f6d29
4 changed files with 41 additions and 7 deletions

View File

@@ -23,7 +23,8 @@
"grasscutter_with_game": "Automatically launch Grasscutter with game",
"language": "Select Language",
"background": "Set Custom Background (link or image file)",
"theme": "Set Theme"
"theme": "Set Theme",
"patch_metadata": "Automatically Patch Metadata"
},
"downloads": {
"grasscutter_stable_data": "Download Grasscutter Stable Data",

View File

@@ -100,11 +100,13 @@ export default class ServerLaunchSection extends React.Component<{}, IState> {
// Connect to proxy
if (config.toggle_grasscutter) {
const patched = await patchGame()
if (config.patch_metadata) {
const patched = await patchGame()
if (!patched) {
alert('Could not patch game!')
return
if (!patched) {
alert('Could not patch game!')
return
}
}
const game_exe = await getGameExecutable()

View File

@@ -31,6 +31,7 @@ interface IState {
themes: string[]
theme: string
encryption: boolean
patch_metadata: boolean
swag: boolean
// Swag stuff
@@ -52,6 +53,7 @@ export default class Options extends React.Component<IProps, IState> {
themes: ['default'],
theme: '',
encryption: false,
patch_metadata: false,
swag: false,
// Swag stuff
@@ -66,6 +68,7 @@ export default class Options extends React.Component<IProps, IState> {
this.setCustomBackground = this.setCustomBackground.bind(this)
this.toggleEncryption = this.toggleEncryption.bind(this)
this.restoreMetadata = this.restoreMetadata.bind(this)
this.toggleMetadata = this.toggleMetadata.bind(this)
}
async componentDidMount() {
@@ -88,6 +91,7 @@ export default class Options extends React.Component<IProps, IState> {
themes: (await getThemeList()).map((t) => t.name),
theme: config.theme || 'default',
encryption: await translate(encEnabled ? 'options.enabled' : 'options.disabled'),
patch_metadata: config.patch_metadata || false,
swag: config.swag_mode || false,
// Swag stuff
@@ -205,6 +209,16 @@ export default class Options extends React.Component<IProps, IState> {
})
}
async toggleMetadata() {
const changedVal = !(await getConfigOption('patch_metadata'))
await setConfigOption('patch_metadata', changedVal)
this.setState({
patch_metadata: changedVal,
})
}
render() {
return (
<Menu closeFn={this.props.closeFn} className="Options" heading="Options">
@@ -226,6 +240,21 @@ export default class Options extends React.Component<IProps, IState> {
</BigButton>
</div>
</div>
<div className="OptionSection" id="menuOptionsContainerPatchMeta">
<div className="OptionLabel" id="menuOptionsLabelPatchMeta">
<Tr text="options.patch_metadata" />
</div>
<div className="OptionValue" id="menuOptionsCheckboxPatchMeta">
<Checkbox
onChange={this.toggleMetadata}
checked={this.state?.patch_metadata}
id="patchMeta"
/>
</div>
</div>
<Divider />
<div className='OptionSection' id="menuOptionsContainerGCJar">
<div className='OptionLabel' id="menuOptionsLabelGCJar">
<Tr text="options.grasscutter_jar" />

View File

@@ -20,7 +20,8 @@ let defaultConfig: Configuration
cert_generated: false,
theme: 'default',
https_enabled: false,
debug_enabled: false
debug_enabled: false,
patch_metadata: true,
}
})()
@@ -43,6 +44,7 @@ export interface Configuration {
theme: string
https_enabled: boolean
debug_enabled: boolean
patch_metadata: boolean
swag_mode?: boolean
// Swag stuff
@@ -60,7 +62,7 @@ export async function getConfigOption<K extends keyof Configuration>(key: K): Pr
const config = await getConfig()
const defaults = defaultConfig
return config[key] || defaults[key]
return config[key] === null || config[key] === undefined ? defaults[key] : config[key]
}
export async function getConfig() {