This commit is contained in:
Daniel Odendahl Jr
2018-01-31 20:19:01 +00:00
parent d1f4887b03
commit 833a5dfa34
2 changed files with 11 additions and 6 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

+11 -6
View File
@@ -1,5 +1,5 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { createCanvas, registerFont } = require('canvas'); const { createCanvas, loadImage, registerFont } = require('canvas');
const path = require('path'); const path = require('path');
const { elements, colors } = require('../../assets/json/periodic-table'); const { elements, colors } = require('../../assets/json/periodic-table');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' }); registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' });
@@ -42,17 +42,22 @@ module.exports = class PeriodicTableCommand extends Command {
}); });
} }
run(msg, { element }) { async run(msg, { element }) {
const canvas = createCanvas(500, 500); const canvas = createCanvas(500, 500);
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
ctx.fillStyle = 'black'; ctx.fillStyle = 'black';
ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'white'; ctx.fillStyle = 'white';
ctx.fillRect(10, 10, canvas.width - 20, canvas.height - 20); ctx.fillRect(10, 10, canvas.width - 20, canvas.height - 20);
ctx.font = '210px Noto'; if (element.number === 0) {
ctx.textAlign = 'center'; const batman = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'batman.png'));
ctx.fillStyle = colors[element.phase]; ctx.drawImage(batman, 100, 166);
ctx.fillText(element.symbol, 250, 320); } else {
ctx.font = '210px Noto';
ctx.textAlign = 'center';
ctx.fillStyle = colors[element.phase];
ctx.fillText(element.symbol, 250, 320);
}
ctx.fillStyle = 'black'; ctx.fillStyle = 'black';
ctx.font = '45px Noto'; ctx.font = '45px Noto';
ctx.fillText(element.number, 250, 100); ctx.fillText(element.number, 250, 100);