mirror of
https://github.com/Grasscutters/GrassClipper.git
synced 2024-11-16 04:45:34 +00:00
disable play buttons when game is not set
This commit is contained in:
parent
c81c6b7a2d
commit
dc2815131b
@ -8,7 +8,7 @@
|
||||
"dev": "neu run",
|
||||
"build": "npm run clean_dist && neu build && npm run move_files && npm run move_bgs && npm run rename_exe",
|
||||
"move_files": "cp -r ./ext ./dist/GrassClipper && cp -r ./proxy ./dist/GrassClipper && cp install.cmd ./dist/GrassClipper && cp -r ./scripts ./dist/GrassClipper",
|
||||
"move_bgs": "mkdir dist\\GrassClipper\\resources\\bg\\private && cp -r ./resources/bg/private ./dist/GrassClipper/resources/bg/private",
|
||||
"move_bgs": "mkdir dist\\GrassClipper\\resources\\bg\\private && cp -r ./resources/bg/private ./dist/GrassClipper/resources/bg",
|
||||
"rename_exe": "mv ./dist/GrassClipper/GrassClipper-win_x64.exe ./dist/GrassClipper/GrassClipper.exe",
|
||||
"clean_dist": "rm -rf ./dist"
|
||||
}
|
||||
|
@ -21,12 +21,12 @@
|
||||
</div>
|
||||
<div id="halvesContainer">
|
||||
<div id="firstHalf">
|
||||
<button class="playBtn" onclick="launchOfficial()">Play Official</button>
|
||||
<button class="playBtn" id="playOfficial" onclick="launchOfficial()">Play Official</button>
|
||||
</div>
|
||||
<div id="secondHalf">
|
||||
<div id="secondControlContainer">
|
||||
<input type="text" id="ip" placeholder="IP Address" />
|
||||
<button class="playBtn" onclick="launchPrivate()">Play Private</button>
|
||||
<button class="playBtn" id="playPrivate" onclick="launchPrivate()">Play Private</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -4,6 +4,12 @@ Neutralino.init();
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
setBackgroundImage();
|
||||
displayGenshinFolder();
|
||||
|
||||
const config = await getCfg()
|
||||
|
||||
if (!config.genshinImpactFolder) {
|
||||
handleGenshinFolderNotSet()
|
||||
}
|
||||
})
|
||||
|
||||
async function getCfg() {
|
||||
@ -14,13 +20,40 @@ async function getCfg() {
|
||||
lastConnect: ''
|
||||
}))
|
||||
})
|
||||
|
||||
if (!cfgStr) return {
|
||||
|
||||
const config = cfgStr ? JSON.parse(cfgStr) : {
|
||||
genshinImpactFolder: '',
|
||||
lastConnect: ''
|
||||
}
|
||||
|
||||
return JSON.parse(cfgStr)
|
||||
return config
|
||||
}
|
||||
|
||||
async function enableButtons() {
|
||||
const offBtn = document.querySelector('#playOfficial')
|
||||
const privBtn = document.querySelector('#playPrivate')
|
||||
|
||||
offBtn.classList.remove('disabled')
|
||||
offBtn.disabled = false
|
||||
|
||||
privBtn.classList.remove('disabled')
|
||||
privBtn.disabled = false
|
||||
}
|
||||
|
||||
async function handleGenshinFolderNotSet() {
|
||||
// Set buttons to greyed out and disable
|
||||
document.querySelector('#genshinPath').innerHTML = 'Not set'
|
||||
|
||||
const offBtn = document.querySelector('#playOfficial')
|
||||
const privBtn = document.querySelector('#playPrivate')
|
||||
|
||||
offBtn.classList.add('disabled')
|
||||
offBtn.disabled = true
|
||||
|
||||
privBtn.classList.add('disabled')
|
||||
privBtn.disabled = true
|
||||
|
||||
// TODO show a dialog of sorts
|
||||
}
|
||||
|
||||
async function displayGenshinFolder() {
|
||||
@ -33,14 +66,6 @@ async function displayGenshinFolder() {
|
||||
async function setBackgroundImage() {
|
||||
const config = await getCfg()
|
||||
|
||||
const officialImages = (await Neutralino.filesystem.readDirectory(config.genshinImpactFolder + '/bg')).filter(file => file.type === 'FILE')
|
||||
const privImages = (await Neutralino.filesystem.readDirectory(NL_CWD + '/resources/bg/private')).filter(file => file.type === 'FILE')
|
||||
|
||||
// Pick one of the images
|
||||
const image = officialImages[Math.floor(Math.random() * officialImages.length)].entry
|
||||
const privImage = privImages[Math.floor(Math.random() * privImages.length)].entry
|
||||
const path = config.genshinImpactFolder.replace('\\', '/') + '/bg/' + image
|
||||
|
||||
// Check if resources folder exists
|
||||
const mainDir = await Neutralino.filesystem.readDirectory(NL_CWD)
|
||||
if (!mainDir.find(dir => dir.entry === 'resources')) {
|
||||
@ -59,15 +84,29 @@ async function setBackgroundImage() {
|
||||
await Neutralino.filesystem.createDirectory(NL_CWD + '/resources/bg/official')
|
||||
}
|
||||
|
||||
// Copy to backgrounds folder
|
||||
const officialBgs = (await Neutralino.filesystem.readDirectory(NL_CWD + '/resources/bg/official/')).filter(file => file.type === 'FILE')
|
||||
if (config.genshinImpactFolder) {
|
||||
const officialImages = (await Neutralino.filesystem.readDirectory(config.genshinImpactFolder + '/bg')).filter(file => file.type === 'FILE')
|
||||
|
||||
if (!officialBgs.find(file => file.entry === image)) {
|
||||
await Neutralino.filesystem.copyFile(path, NL_CWD + '/resources/bg/official/' + image)
|
||||
// Pick one of the images
|
||||
const image = officialImages[Math.floor(Math.random() * officialImages.length)].entry
|
||||
const path = config.genshinImpactFolder.replace('\\', '/') + '/bg/' + image
|
||||
|
||||
// Copy to backgrounds folder
|
||||
const officialBgs = (await Neutralino.filesystem.readDirectory(NL_CWD + '/resources/bg/official/')).filter(file => file.type === 'FILE')
|
||||
if (!officialBgs.find(file => file.entry === image)) {
|
||||
await Neutralino.filesystem.copyFile(path, NL_CWD + '/resources/bg/official/' + image).catch(e => {
|
||||
// TODO: Handle error
|
||||
})
|
||||
}
|
||||
|
||||
// Set background image
|
||||
document.querySelector('#firstHalf').style.backgroundImage = `url("../bg/official/${image}")`
|
||||
}
|
||||
|
||||
const privImages = (await Neutralino.filesystem.readDirectory(NL_CWD + '/resources/bg/private')).filter(file => file.type === 'FILE')
|
||||
const privImage = privImages[Math.floor(Math.random() * privImages.length)].entry
|
||||
|
||||
// Set the background image
|
||||
document.querySelector('#firstHalf').style.backgroundImage = `url("../bg/official/${image}")`
|
||||
document.querySelector('#secondHalf').style.backgroundImage = `url("../bg/private/${privImage}")`
|
||||
}
|
||||
|
||||
@ -76,13 +115,14 @@ async function setGenshinImpactFolder() {
|
||||
|
||||
// Set the folder in our configuration
|
||||
const config = await getCfg()
|
||||
|
||||
|
||||
config.genshinImpactFolder = folder
|
||||
Neutralino.storage.setData('config', JSON.stringify(config))
|
||||
|
||||
// Refresh background and path
|
||||
setBackgroundImage()
|
||||
displayGenshinFolder()
|
||||
enableButtons()
|
||||
}
|
||||
|
||||
async function getGenshinExecName() {
|
||||
@ -108,7 +148,7 @@ async function launchPrivate() {
|
||||
const config = await getCfg()
|
||||
|
||||
console.log('connecting to ' + ip)
|
||||
|
||||
|
||||
// Pass IP and game folder to the private server launcher
|
||||
Neutralino.os.execCommand(`${NL_CWD}/scripts/private_server_launch.cmd ${ip} "${config.genshinImpactFolder}/Genshin Impact Game/${await getGenshinExecName()}"`).catch(e => console.log(e))
|
||||
}
|
||||
|
@ -86,6 +86,12 @@ body {
|
||||
background: linear-gradient(#ffc61e, #ffd326);
|
||||
}
|
||||
|
||||
.playBtn.disabled {
|
||||
background: linear-gradient(#9c9c9c, #949494);
|
||||
color: rgb(226, 226, 226);
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.smolBtn {
|
||||
padding: 0 20px;
|
||||
border-radius: 5px;
|
||||
|
Loading…
Reference in New Issue
Block a user