Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

READY FOR REVIEW/MERGE - Modernize and fix several legacy issues #146

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions generator/css/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,6 @@
.icon-level-two { background-image: url(../img/level-two.png);}
.icon-lever { background-image: url(../img/lever.png);}
.icon-libra { background-image: url(../img/libra.png);}
.icon-license.txt { background-image: url(../img/license.txt);}
.icon-life-buoy { background-image: url(../img/life-buoy.png);}
.icon-life-in-the-balance { background-image: url(../img/life-in-the-balance.png);}
.icon-life-support { background-image: url(../img/life-support.png);}
Expand Down Expand Up @@ -1551,7 +1550,6 @@
.icon-linked-rings { background-image: url(../img/linked-rings.png);}
.icon-lion { background-image: url(../img/lion.png);}
.icon-lips { background-image: url(../img/lips.png);}
.icon-list.js { background-image: url(../img/list.js);}
.icon-lit-candelabra { background-image: url(../img/lit-candelabra.png);}
.icon-liver { background-image: url(../img/liver.png);}
.icon-lizard-tongue { background-image: url(../img/lizard-tongue.png);}
Expand Down Expand Up @@ -1690,7 +1688,6 @@
.icon-mite-alt { background-image: url(../img/mite-alt.png);}
.icon-mite { background-image: url(../img/mite.png);}
.icon-mixed-swords { background-image: url(../img/mixed-swords.png);}
.icon-mixed-swords.svg { background-image: url(../img/mixed-swords.svg);}
.icon-modern-city { background-image: url(../img/modern-city.png);}
.icon-moebius-star { background-image: url(../img/moebius-star.png);}
.icon-moebius-triangle { background-image: url(../img/moebius-triangle.png);}
Expand Down
Empty file removed generator/img/list.js
Empty file.
3 changes: 0 additions & 3 deletions generator/js/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,6 @@ var icon_names = [
"level-two",
"lever",
"libra",
"license.txt",
"life-buoy",
"life-in-the-balance",
"life-support",
Expand Down Expand Up @@ -1552,7 +1551,6 @@ var icon_names = [
"linked-rings",
"lion",
"lips",
"list.js",
"lit-candelabra",
"liver",
"lizard-tongue",
Expand Down Expand Up @@ -1691,7 +1689,6 @@ var icon_names = [
"mite-alt",
"mite",
"mixed-swords",
"mixed-swords.svg",
"modern-city",
"moebius-star",
"moebius-triangle",
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"description": "RPG card generator",
"main": "generator/generate.html",
"devDependencies": {
"fs-extra": "^3.0.0",
"fs-extra": "^3.0.1",
"mv": "^2.1.1",
"promise-streams": "^1.0.1",
"request": "^2.81.0",
"request-promise-native": "^1.0.3",
"unzip": "^0.1.11",
"walk": "^2.3.9"
"request": "^2.88.2",
"request-promise-native": "^1.0.8",
"walk": "^2.3.14",
"yauzl": "^2.10.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
78 changes: 52 additions & 26 deletions resources/tools/update-icons.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const mv = require('mv');
const fs = require('fs');
const fse = require('fs-extra');
const http = require('https');
const request = require('request');
const path = require('path');
const walk = require('walk');
const unzip = require('unzip');
const yauzl = require("yauzl");
const child_process = require('child_process');
const ncp = require('ncp');

Expand All @@ -16,7 +16,7 @@ const customIconDir = "./resources/custom-icons";
const cssPath = "./generator/css/icons.css";
const jsPath = "./generator/js/icons.js";
//const processIconsCmd = "mogrify -background white -alpha shape *.png";
const processIconsCmd = `mogrify -alpha copy -channel-fx "red=100%, blue=100%, green=100%" *.png`
const processIconsCmd = `mogrify -alpha copy -fx "red=100%, blue=100%, green=100%" *.png`;


// ----------------------------------------------------------------------------
Expand All @@ -25,13 +25,10 @@ const processIconsCmd = `mogrify -alpha copy -channel-fx "red=100%, blue=100%, g
function downloadFile(url, dest) {
console.log("Downloading...");
return new Promise((resolve, reject) => {
http.get(url, response => {
const file = fs.createWriteStream(dest);
response.pipe(file);
file.on('close', resolve);
file.on('error', reject);
})
.on('error', reject);
request(url)
.pipe(fs.createWriteStream(dest))
.on("close", resolve)
.on("error", reject);
});
}

Expand All @@ -41,21 +38,46 @@ function downloadFile(url, dest) {
function unzipAll(src, dest) {
console.log("Unzipping...");
return new Promise((resolve, reject) => {
fs.createReadStream(tempFilePath)
.pipe(unzip.Parse())
.on('entry', entry => {
const fileName = entry.path;
const baseName = path.basename(fileName);
const type = entry.type;
if (type === "File") {
entry.pipe(fs.createWriteStream(path.join(dest, baseName)));
}
else {
entry.autodrain();
yauzl.open(src, {lazyEntries: true}, function(err, zipfile) {
if (err) {
reject(err);
return;
}
})
.on('close', resolve)
.on('error', reject);
zipfile.readEntry();
zipfile.on("entry", function(entry) {
if (/\/$/.test(entry.fileName)) {
// Directory file names end with '/'. Note that entries for
// directories themselves are optional. An entry's fileName
// implicitly requires its parent directories to exist.
zipfile.readEntry();
} else {
var entryPath = path.parse(entry.fileName);
var fileName = entryPath.base;
var targetFile = path.join(dest, fileName);
var i = 2;
while (true) {
if (!fs.existsSync(targetFile)) {
break;
}
fileName = entryPath.name + "-" + i++ + entryPath.ext;
targetFile = path.join(dest, fileName);
}
zipfile.openReadStream(entry, function(err, readStream) {
if (err) {
reject(err);
return;
}
readStream
.on("end", function() {
zipfile.readEntry();
}).pipe(
fs.createWriteStream(targetFile)
.on("error", reject)
).on("error", reject);
});
}
}).on("close", resolve);
});
});
}

Expand Down Expand Up @@ -88,7 +110,9 @@ function generateCSS(src, dest) {
}
else {
const content = files
.map(name => `.icon-${name.replace(".png", "")} { background-image: url(../img/${name});}\n`)
.filter(function (fileName) {
return path.extname(fileName) === ".png";
}).map(name => `.icon-${name.replace(".png", "")} { background-image: url(../img/${name});}\n`)
.join("");
fs.writeFile(dest, content, err => {
if (err) {
Expand All @@ -115,7 +139,9 @@ function generateJS(src, dest) {
}
else {
const content = "var icon_names = [\n" + files
.map(name => ` "${name.replace(".png", "")}"`)
.filter(function (fileName) {
return path.extname(fileName) === ".png";
}).map(name => ` "${name.replace(".png", "")}"`)
.join(",\n") +
`
];
Expand Down