-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new feature: replace static assets in game
- Loading branch information
Showing
10 changed files
with
133 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+78.3 KB
...ic/default/assets/img/sp/banner/events/treasureraid066/banner_event_start_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const glob = require('glob') | ||
const path = require('path') | ||
const chokidar = require('chokidar') | ||
const { STATIC_PATH } = require('../store') | ||
const serve = require('serve') | ||
const CONFIG = require('../config') | ||
const fse = require('fs-extra') | ||
const { app } = require('electron') | ||
|
||
const staticMap = new Map() | ||
|
||
try { | ||
if (app) { | ||
fse.copySync(path.resolve(__dirname, '../data/static/default/'), path.resolve(STATIC_PATH, 'default/')) | ||
} | ||
} catch (e) { | ||
console.err(e) | ||
} | ||
|
||
const collectFiles = (type, once) => { | ||
glob(`${type}/**/*`, { | ||
cwd: STATIC_PATH, | ||
nodir: true | ||
}, (err, files) => { | ||
if (!err) { | ||
files.forEach((filePath) => { | ||
const key = filePath.replace(type, '') | ||
if (!staticMap.has(key)) { | ||
staticMap.set(key, filePath) | ||
} | ||
}) | ||
} | ||
if (!once && type !== 'default') collectFiles('default') | ||
}) | ||
} | ||
|
||
collectFiles('local') | ||
|
||
const server = serve(STATIC_PATH, { | ||
port: CONFIG.staticPort, | ||
cors: true | ||
}) | ||
|
||
const watchFile = (type) => { | ||
chokidar.watch(`${type}/**/?*`, { | ||
cwd: STATIC_PATH, | ||
ignored: /(^|[\/\\])\../, | ||
ignoreInitial: true | ||
}).on('add', file => { | ||
const key = file.replace(/\\/g, '/').replace(type, '') | ||
staticMap.set(key, `${type}${key}`) | ||
}).on('unlink', file => { | ||
const key = file.replace(/\\/g, '/').replace(type, '') | ||
if (staticMap.has(key)) { | ||
staticMap.delete(key) | ||
} | ||
if (type === 'local') { | ||
collectFiles(type, true) | ||
} | ||
}).on('error', error => console.error(`Watcher error: ${error}`)) | ||
} | ||
|
||
fse.pathExists(path.resolve(STATIC_PATH, 'local'), (err, exists) => { | ||
if (!exists) { | ||
fse.copy(path.resolve(__dirname, '../assets/tips.png'), path.resolve(STATIC_PATH, 'local/assets/img/sp/quest/assist/parts/tips.png')) | ||
staticMap.set('/assets/img/sp/quest/assist/parts/tips.png', 'local/assets/img/sp/quest/assist/parts/tips.png') | ||
} | ||
}) | ||
|
||
setTimeout(() => { | ||
watchFile('local') | ||
watchFile('default') | ||
}, 3000) | ||
|
||
module.exports = staticMap |