Parcourir la source

Script for updating icons

Robert Autenrieth il y a 8 ans
Parent
révision
a4a3f57799

+ 3
- 1
.gitignore Voir le fichier

@@ -1,3 +1,5 @@
1 1
 /node_modules
2 2
 /generator/js/*.map
3
-/generator/js/*.d.ts
3
+/generator/js/*.d.ts
4
+/temp
5
+/temp.zip

+ 28
- 0
package.json Voir le fichier

@@ -0,0 +1,28 @@
1
+{
2
+  "name": "rpg-cards",
3
+  "version": "1.0.0",
4
+  "description": "RPG card generator",
5
+  "main": "generator/generate.html",
6
+  "devDependencies": {
7
+    "fs-extra": "^3.0.0",
8
+    "mv": "^2.1.1",
9
+    "promise-streams": "^1.0.1",
10
+    "request": "^2.81.0",
11
+    "request-promise-native": "^1.0.3",
12
+    "unzip": "^0.1.11",
13
+    "walk": "^2.3.9"
14
+  },
15
+  "scripts": {
16
+    "test": "echo \"Error: no test specified\" && exit 1"
17
+  },
18
+  "repository": {
19
+    "type": "git",
20
+    "url": "git+https://github.com/crobi/rpg-cards.git"
21
+  },
22
+  "author": "Robert Autenrieth",
23
+  "license": "ISC",
24
+  "bugs": {
25
+    "url": "https://github.com/crobi/rpg-cards/issues"
26
+  },
27
+  "homepage": "https://github.com/crobi/rpg-cards#readme"
28
+}

+ 0
- 1342
resources/tools/icons-list.txt
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 0
- 1
resources/tools/list-files.bat Voir le fichier

@@ -1 +0,0 @@
1
-dir /a-h /b > filelist.txt

+ 0
- 3
resources/tools/make-transparent.bat Voir le fichier

@@ -1,3 +0,0 @@
1
-rem Changes black to transparent in all images in the current folder
2
-mogrify -alpha copy -fx #fff *.png
3
-pause

+ 130
- 0
resources/tools/update-icons.js Voir le fichier

@@ -0,0 +1,130 @@
1
+const mv = require('mv');
2
+const fs = require('fs');
3
+const fse = require('fs-extra');
4
+const http = require('http');
5
+const path = require('path');
6
+const walk = require('walk');
7
+const unzip = require('unzip');
8
+const child_process = require('child_process');
9
+const ncp = require('ncp');
10
+
11
+const gameIconsUrl = "http://game-icons.net/archives/png/zip/ffffff/000000/game-icons.net.png.zip";
12
+const tempFilePath = "./temp.zip";
13
+const tempDir = "./temp";
14
+const imgDir = "./generator/img";
15
+const customIconDir = "./resources/custom-icons";
16
+const cssPath = "./generator/css/icons.css";
17
+//const processIconsCmd = "mogrify -background white -alpha shape *.png";
18
+const processIconsCmd = `mogrify -alpha copy -channel-fx "red=100%, blue=100%, green=100%" *.png`
19
+
20
+
21
+// ----------------------------------------------------------------------------
22
+// Download
23
+// ----------------------------------------------------------------------------
24
+function downloadFile(url, dest) {
25
+    console.log("Downloading...");
26
+    return new Promise((resolve, reject) => {
27
+        http.get(url, response => {
28
+            const file = fs.createWriteStream(dest);
29
+            response.pipe(file);
30
+            file.on('close', resolve);
31
+            file.on('error', reject);
32
+        })
33
+        .on('error', reject);
34
+    });
35
+}
36
+
37
+// ----------------------------------------------------------------------------
38
+// Unzip
39
+// ----------------------------------------------------------------------------
40
+function unzipAll(src, dest) {
41
+    console.log("Unzipping...");
42
+    return new Promise((resolve, reject) => {
43
+        fs.createReadStream(tempFilePath)
44
+        .pipe(unzip.Parse())
45
+        .on('entry', entry => {
46
+            const fileName = entry.path;
47
+            const baseName = path.basename(fileName);
48
+            const type = entry.type;
49
+            if (type === "File") {
50
+                entry.pipe(fs.createWriteStream(path.join(dest, baseName)));
51
+            }
52
+            else {
53
+                entry.autodrain();
54
+            }
55
+        })
56
+        .on('close', resolve)
57
+        .on('error', reject);
58
+    });
59
+}
60
+
61
+// ----------------------------------------------------------------------------
62
+// Process icons
63
+// ----------------------------------------------------------------------------
64
+function processAll(path) {
65
+    console.log("Processing (this will take a while)...");
66
+    return new Promise((resolve, reject) => {
67
+        child_process.exec(processIconsCmd, {cwd: path}, (error, stdout, stderr) => {
68
+            if (error) {
69
+                reject(error);
70
+            }
71
+            else {
72
+                resolve();
73
+            }
74
+        });
75
+    });
76
+}
77
+
78
+// ----------------------------------------------------------------------------
79
+// Generate CSS
80
+// ----------------------------------------------------------------------------
81
+function generateCSS(src, dest) {
82
+    console.log("Generating CSS...");
83
+    return new Promise((resolve, reject) => {
84
+        fs.readdir(src, (err, files) => {
85
+            if (err) {
86
+                reject(err);
87
+            }
88
+            else {
89
+                const content = files
90
+                    .map(name => `.icon-${name.replace(".png", "")} { background-image: url(../img/${name});}\n`)
91
+                    .join("");
92
+                fs.writeFile(dest, content, err => {
93
+                    if (err) {
94
+                        reject(err);
95
+                    }
96
+                    else {
97
+                        resolve();
98
+                    }
99
+                });
100
+            }
101
+        });
102
+    });
103
+}
104
+
105
+// ----------------------------------------------------------------------------
106
+// Copy
107
+// ----------------------------------------------------------------------------
108
+function copyAll(src, dest) {
109
+    console.log("Copying...");
110
+    return new Promise((resolve, reject) => {
111
+        fse.copy(src, dest, err => {
112
+            if (err) {
113
+                reject(err);
114
+            }
115
+            else {
116
+                resolve();
117
+            }
118
+        });
119
+    });
120
+}
121
+
122
+fse.emptyDir(tempDir)
123
+//.then(() => downloadFile(gameIconsUrl, tempFilePath))
124
+.then(() => unzipAll(tempFilePath, tempDir))
125
+.then(() => copyAll(tempDir, imgDir))
126
+.then(() => copyAll(customIconDir, imgDir))
127
+.then(() => processAll(imgDir))
128
+.then(() => generateCSS(imgDir, cssPath))
129
+.then(() => console.log("Done."))
130
+.catch(err => cosole.log("Error", err));

Loading…
Annuler
Enregistrer