mirror of
https://github.com/javl/image2cpp.git
synced 2026-09-11 09:03:04 +00:00
Reuse method for glyphcomment instead of duplicate lines per section
This commit is contained in:
+11
-7
@@ -884,6 +884,13 @@ function getIdentifier() {
|
|||||||
return (vn && vn.value.length) ? vn.value : identifier;
|
return (vn && vn.value.length) ? vn.value : identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Builds the "// 'glyph', WxHpx" comment line placed before each image's
|
||||||
|
// byte array, or '' when comments are disabled. Indent is prefixed when given.
|
||||||
|
function glyphComment(image, indent = '') {
|
||||||
|
if (!settings.outputComments) return '';
|
||||||
|
return `${indent}// '${image.glyph}', ${image.canvas.width}x${image.canvas.height}px\n`;
|
||||||
|
}
|
||||||
|
|
||||||
// Output the image string to the textfield
|
// Output the image string to the textfield
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
function generateOutputString() {
|
function generateOutputString() {
|
||||||
@@ -905,7 +912,7 @@ function generateOutputString() {
|
|||||||
|
|
||||||
code = `\t${code.split('\n').join('\n\t')}\n`;
|
code = `\t${code.split('\n').join('\n\t')}\n`;
|
||||||
// const variableCount = images.length() > 1 ? count++ : '';
|
// const variableCount = images.length() > 1 ? count++ : '';
|
||||||
const comment = settings.outputComments ? `// '${image.glyph}', ${image.canvas.width}x${image.canvas.height}px\n` : '';
|
const comment = glyphComment(image);
|
||||||
bytesUsed += code.split('\n').length * 16; // 16 bytes per line.
|
bytesUsed += code.split('\n').length * 16; // 16 bytes per line.
|
||||||
|
|
||||||
const varname = getIdentifier() + (image.glyph ? image.glyph.replace(/[^a-zA-Z0-9]/g, '_') : '');
|
const varname = getIdentifier() + (image.glyph ? image.glyph.replace(/[^a-zA-Z0-9]/g, '_') : '');
|
||||||
@@ -931,7 +938,7 @@ function generateOutputString() {
|
|||||||
images.each((image) => {
|
images.each((image) => {
|
||||||
code = imageToString(image);
|
code = imageToString(image);
|
||||||
code = `\t${code.split('\n').join('\n\t')}\n`;
|
code = `\t${code.split('\n').join('\n\t')}\n`;
|
||||||
comment = settings.outputComments ? `\t// '${image.glyph}, ${image.canvas.width}x${image.canvas.height}px\n` : '';
|
comment = glyphComment(image, '\t');
|
||||||
outputString += comment + code;
|
outputString += comment + code;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -950,7 +957,7 @@ function generateOutputString() {
|
|||||||
images.each((image) => {
|
images.each((image) => {
|
||||||
code = imageToString(image);
|
code = imageToString(image);
|
||||||
code = `\t${code.split('\n').join('\n\t')}\n`;
|
code = `\t${code.split('\n').join('\n\t')}\n`;
|
||||||
comment = settings.outputComments ? `\t// '${image.glyph}', ${image.canvas.width}x${image.canvas.height}px\n` : '';
|
comment = glyphComment(image, '\t');
|
||||||
outputString += comment + code;
|
outputString += comment + code;
|
||||||
if (image.glyph.length === 1) {
|
if (image.glyph.length === 1) {
|
||||||
useGlyphs++;
|
useGlyphs++;
|
||||||
@@ -1008,10 +1015,7 @@ function generateOutputString() {
|
|||||||
default: { // plain
|
default: { // plain
|
||||||
images.each((image) => {
|
images.each((image) => {
|
||||||
code = imageToString(image);
|
code = imageToString(image);
|
||||||
let comment = '';
|
let comment = image.glyph ? glyphComment(image) : '';
|
||||||
if (image.glyph && settings.outputComments) {
|
|
||||||
comment = (`// '${image.glyph}', ${image.canvas.width}x${image.canvas.height}px\n`);
|
|
||||||
}
|
|
||||||
if (image.img !== images.first().img) {
|
if (image.img !== images.first().img) {
|
||||||
comment = `\n${comment}`;
|
comment = `\n${comment}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user