This commit is contained in:
Documentation 2021-08-21 20:16:05 +00:00
parent 0cd5a07962
commit ffcd8e1c79
3 changed files with 310 additions and 13 deletions

View file

@ -139,6 +139,82 @@
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="canvasSize"><span class="type-signature"></span>canvasSize<span class="type-signature"> :<a href="CardCreator.html#~CanvasDimensions">CardCreator~CanvasDimensions</a></span></h4>
<div class="description">
The canvas's dimensions.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="CardCreator.html#~CanvasDimensions">CardCreator~CanvasDimensions</a></span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="create-card.js.html">create-card.js</a>, <a href="create-card.js.html#line101">line 101</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
@ -149,7 +225,7 @@
<h4 class="name" id="createCard"><span class="type-signature">(async) </span>createCard<span class="signature">(charaId)</span><span class="type-signature"> &rarr; {Promise.&lt;Buffer>}</span></h4>
<h4 class="name" id="createCard"><span class="type-signature">(async) </span>createCard<span class="signature">(charaId, customImage)</span><span class="type-signature"> &rarr; {Promise.&lt;Buffer>}</span></h4>
@ -216,6 +292,42 @@
</tr>
<tr>
<td class="name"><code>customImage</code></td>
<td class="type">
<span class="param-type">string</span>
|
<span class="param-type">Buffer</span>
|
<span class="param-type">null</span>
|
<span class="param-type">undefined</span>
</td>
<td class="description last">Optional parameter providing a custom
image to be drawn between the background of the character card and the black information boxes.
The image should be the same resolution as the default image. The default image size can be
retrieved with <a href="CardCreator.html#canvasSize">CardCreator#canvasSize</a>. May be a URL, `data: `URI, a local file path,
or a Buffer instance.</td>
</tr>
</tbody>
</table>
@ -253,7 +365,7 @@
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="create-card.js.html">create-card.js</a>, <a href="create-card.js.html#line277">line 277</a>
<a href="create-card.js.html">create-card.js</a>, <a href="create-card.js.html#line302">line 302</a>
</li></ul></dd>
@ -380,7 +492,7 @@ generation methods.
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="create-card.js.html">create-card.js</a>, <a href="create-card.js.html#line97">line 97</a>
<a href="create-card.js.html">create-card.js</a>, <a href="create-card.js.html#line114">line 114</a>
</li></ul></dd>
@ -436,6 +548,153 @@ generation methods.
<h3 class="subsection-title">Type Definitions</h3>
<h4 class="name" id="~CanvasDimensions">CanvasDimensions</h4>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>width</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">The width of the canvas.</td>
</tr>
<tr>
<td class="name"><code>height</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last">The height of the canvas.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="create-card.js.html">create-card.js</a>, <a href="create-card.js.html#line91">line 91</a>
</li></ul></dd>
</dl>
</article>
@ -454,7 +713,7 @@ generation methods.
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sun May 30 2021 14:07:32 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sat Aug 21 2021 20:16:04 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>

View file

@ -116,6 +116,23 @@ class CardCreator {
this.isInit = false;
}
/**
* @typedef {Object} CardCreator~CanvasDimensions
* @property {number} width The width of the canvas.
* @property {number} height The height of the canvas.
*/
/**
* The canvas's dimensions.
* @type {CardCreator~CanvasDimensions}
*/
get canvasSize() {
return {
width: 890,
height: 720,
};
}
/**
* Ensures that the instance is ready to generate character cards.
* This function must be resolved before using character card
@ -276,7 +293,10 @@ class CardCreator {
if (cnt == 0)
return 0;
return this.pad(Math.floor(ilvl / cnt), 4);
// ilvl division is always out of 13 items
// mainhand counts twice if there's no offhand
// job stones are ignored
return this.pad(Math.floor(ilvl / 13), 4);
}
pad(num, size) {
@ -288,6 +308,11 @@ class CardCreator {
/**
* Creates a character card for a character.
* @param {number | string} charaId The Lodestone ID of the character to generate a card for.
* @param {string | Buffer | null | undefined} customImage Optional parameter providing a custom
* image to be drawn between the background of the character card and the black information boxes.
* The image should be the same resolution as the default image. The default image size can be
* retrieved with {@link CardCreator#canvasSize}. May be a URL, `data: `URI, a local file path,
* or a Buffer instance.
* @example
* const fs = require("fs");
*
@ -302,19 +327,32 @@ class CardCreator {
* });
* @returns {Promise&lt;Buffer>} A promise representating the construction of the card's image data.
*/
async createCard(charaId) {
var response = await fetch(`https://xivapi.com/character/${charaId}?extended=1&amp;data=FC,mimo`);
var data = await response.json();
async createCard(charaId, customImage) {
const characterInfoUrl = `https://xivapi.com/character/${charaId}?extended=1&amp;data=FC,mimo`;
const response = await fetch(characterInfoUrl);
if (!response.ok) {
// Retry once if the request fails
response = await fetch(characterInfoUrl);
}
const canvas = createCanvas(890, 720);
const data = await response.json();
const canvasSize = this.canvasSize;
const canvas = createCanvas(canvasSize.width, canvasSize.height);
const ctx = canvas.getContext("2d");
var portrait = await loadImage(data.Character.Portrait);
const portrait = await loadImage(data.Character.Portrait);
ctx.drawImage(this.bgImage, 0, 0, 890, 722);
ctx.drawImage(this.bgImage, 0, 0, canvasSize.width, canvasSize.height + 2);
ctx.drawImage(portrait, 0, 120, 441, 600);
if (customImage != null) {
const bg = await loadImage(customImage);
ctx.drawImage(bg, 0, 0, canvasSize.width, canvasSize.height);
}
ctx.strokeStyle = white;
ctx.fillStyle = black;
ctx.beginPath();
@ -653,7 +691,7 @@ exports.CardCreator = CardCreator;
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sun May 30 2021 14:07:32 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sat Aug 21 2021 20:16:04 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>

View file

@ -118,7 +118,7 @@ example((err, response) => {
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sun May 30 2021 14:07:32 GMT+0000 (Coordinated Universal Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sat Aug 21 2021 20:16:04 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>