Skip to content

Commit

Permalink
🐛 Hotfix: fix font import issues on Windows, as well as fix potential…
Browse files Browse the repository at this point in the history
… similar issues for other asset types
  • Loading branch information
CosmoMyzrailGorynych committed Aug 29, 2020
1 parent 57d8bd8 commit c9a3ef5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* Fix overflow issues and wrong initial values for bitmap font generator.
* Fix regression from v1.4 with blurry particle editor and room view when pixelart rendering was enabled.
* Fix `user-select` CSS parameter on modules' docs panel.
* Hotfix: fix font import issues on Windows, as well as fix potential similar issues for other asset types

### 🍱 Demos, Dependencies and Stuff

Expand Down
10 changes: 5 additions & 5 deletions src/node_requires/resources/fonts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const getPathToTtf = function getPathToTtf(font, fs) {
if (fs) {
return path.join(global.projdir, 'fonts', font.origname);
}
return `file://${global.projdir}/fonts/${font.origname}`;
return `file://${global.projdir.replace(/\\/g, '/')}/fonts/${font.origname}`;
};

/**
Expand All @@ -21,7 +21,7 @@ const getFontPreview = function getFontPreview(font, fs) {
if (fs) {
return path.join(global.projdir, 'fonts', `${font.origname}_prev.png`);
}
return `file://${global.projdir}/fonts/${font.origname}_prev.png?cache=${font.lastmod}`;
return `file://${global.projdir.replace(/\\/g, '/')}/fonts/${font.origname}_prev.png?cache=${font.lastmod}`;
};

const fontGenPreview = async function fontGenPreview(font) {
Expand Down Expand Up @@ -52,7 +52,7 @@ const fontGenPreview = async function fontGenPreview(font) {
c.x.clearRect(0, 0, 64, 64);
c.x.font = `${font.italic ? 'italic ' : ''}${font.weight} ${Math.floor(64 * 0.75)}px "${loaded.family}"`;
c.x.fillStyle = '#000';
c.x.fillText('Aa', 64 * 0.05, 64 * 0.75);
c.x.fillText('Ab', 64 * 0.05, 64 * 0.75);

// strip off the data:image url prefix to get just the base64-encoded bytes
const dataURL = c.toDataURL();
Expand All @@ -64,14 +64,14 @@ const fontGenPreview = async function fontGenPreview(font) {
const importTtfToFont = async function importTtfToFont(src) {
const fs = require('fs-extra'),
path = require('path');
if (path.extname(src) !== '.ttf') {
if (path.extname(src).toLowerCase() !== '.ttf') {
throw new Error(`[resources/fonts] Rejecting a file as it does not have a .ttf extension: ${src}`);
}
const generateGUID = require('./../../generateGUID');
const uid = generateGUID();
await fs.copy(src, path.join(global.projdir, '/fonts/f' + uid + '.ttf'));
const obj = {
typefaceName: path.basename(src).replace('.ttf', ''),
typefaceName: path.basename(src).replace(/\.ttf$/i, ''),
weight: 400,
italic: false,
origname: `f${uid}.ttf`,
Expand Down
2 changes: 1 addition & 1 deletion src/node_requires/resources/skeletons.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getSkeletonPreview = function getSkeletonPreview(skeleton, fs) {
if (fs) {
return path.join(global.projdir, 'img', `${skeleton.origname}_prev.png`);
}
return `file://${global.projdir}/img/${skeleton.origname}_prev.png`;
return `file://${global.projdir.replace(/\\/g, '/')}/img/${skeleton.origname}_prev.png`;
};

/**
Expand Down
8 changes: 4 additions & 4 deletions src/node_requires/resources/textures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getTexturePreview = function (texture, x2, fs) {
if (fs) {
return `${global.projdir}/img/${texture.origname}_prev${x2 ? '@2' : ''}.png`;
}
return `file://${global.projdir}/img/${texture.origname}_prev${x2 ? '@2' : ''}.png?cache=${texture.lastmod}`;
return `file://${global.projdir.replace(/\\/g, '/')}/img/${texture.origname}_prev${x2 ? '@2' : ''}.png?cache=${texture.lastmod}`;
};

/**
Expand All @@ -47,14 +47,14 @@ const getTextureOrig = function (texture, fs) {
if (fs) {
return `${global.projdir}/img/${texture.origname}`;
}
return `file://${global.projdir}/img/${texture.origname}?cache=${texture.lastmod}`;
return `file://${global.projdir.replace(/\\/g, '/')}/img/${texture.origname}?cache=${texture.lastmod}`;
};

const baseTextureFromTexture = texture => new Promise((resolve, reject) => {
const textureLoader = new PIXI.Loader();
const {resources} = textureLoader;

const path = 'file://' + global.projdir + '/img/' + texture.origname + '?' + texture.lastmod;
const path = 'file://' + global.projdir.replace(/\\/g, '/') + '/img/' + texture.origname + '?' + texture.lastmod;

textureLoader.add(texture.uid, path);
textureLoader.onError.add(reject);
Expand Down Expand Up @@ -111,7 +111,7 @@ const getDOMImage = function (texture, deflt) {
if (typeof texture === 'string') {
texture = getTextureFromId(texture);
}
path = 'file://' + global.projdir + '/img/' + texture.origname + '?' + texture.lastmod;
path = 'file://' + global.projdir.replace(/\\/g, '/') + '/img/' + texture.origname + '?' + texture.lastmod;
}
img.src = path;
return new Promise((resolve, reject) => {
Expand Down

0 comments on commit c9a3ef5

Please sign in to comment.