This repository has been archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.js
52 lines (45 loc) · 1.66 KB
/
func.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs');
const path = require('path');
// Material Design color palette array
const materialColors = [
'#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5',
'#2196F3', '#03A9F4', '#00BCD4', '#009688', '#4CAF50',
'#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800',
'#FF5722', '#795548', '#9E9E9E', '#607D8B'
];
// Function to select a random color from the Material Design color palette
const getRandomMaterialColor = () => {
const randomIndex = Math.floor(Math.random() * materialColors.length);
return materialColors[randomIndex];
}
// Read the card packs from a JSON file
function readDecksFromFolder(folderPath) {
const files = fs.readdirSync(folderPath);
const jsonFiles = files.filter(file => file.endsWith('.json'));
const result = [];
jsonFiles.forEach(file => {
const filePath = path.join(folderPath, file);
const content = fs.readFileSync(filePath, 'utf-8');
const data = JSON.parse(content);
const fileName = path.parse(file).name;
const isVIP = fileName.endsWith('-vip');
result.push({ fileName,isVIP, data });
});
return result;
}
// Function to get a single pack by its file name from the decks read from a folder
function getSinglePackByFileName(folderPath, targetFileName) {
const decks = readDecksFromFolder(folderPath);
const targetDeck = decks.find(deck => deck.fileName === targetFileName);
if (!targetDeck) return null;
return {
deckName: targetDeck.fileName,
isVIP: targetDeck.isVIP,
data: targetDeck.data,
};
}
module.exports = {
getRandomMaterialColor,
readDecksFromFolder,
getSinglePackByFileName
}