Skip to content

Commit

Permalink
Fix bug that happened when the background filenames had special chars.
Browse files Browse the repository at this point in the history
This fixes #87 
Merge pull request #108 from haroldo-ok/special-chars-on-filenams
  • Loading branch information
haroldo-ok authored Mar 6, 2023
2 parents b248f41 + 95a7e33 commit 62d7e33
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions generator/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ const addResource = (map, fileName, generator) => {
if (map[fileName]) return map[fileName].variable;

// No; add to the map
const variable = fileName.trim().replace(/\W+/g, '_');

const suffix = fileName.trim().replace(/\W+/g, '_');
const variable = /^[^A-Za-z_]/.test(suffix) ? '_' + suffix : suffix;

map[fileName] = {
variable,
content: generator(variable)
Expand All @@ -118,11 +121,10 @@ const generateResource = map => Object.values(map).map(({ content }) => content)
const generateImageCommand = (functionName, entity, context, mapOption = 'ALL', generatedFlags='') => {
const imageFileName = getFileNameConstant(entity, entity.params.positional.fileName, context, 'Image filename');

const endsWithPng = /\.png$/i;
const targetFileName = endsWithPng.test(imageFileName) ? imageFileName : imageFileName + '.png';

const imageVariable = addResource(context.res.gfx, imageFileName, imageVariable =>
`IMAGE ${imageVariable} "${targetFileName}" APLIB ${mapOption}`);
`IMAGE ${imageVariable} "${imageVariable}.png" APLIB ${mapOption}`);

const targetFileName = `${imageVariable}.png`;

if (!context.images[imageFileName]) {
context.images[imageFileName] = { entity, imageFileName, targetFileName };
Expand Down
4 changes: 2 additions & 2 deletions generator/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ const convertImages = async (result, projectFolder, commandLine) => {
const isCorrectSize = entity.command !== 'background' || width === 320 && height === 224;

if (isCorrectFormat && isCorrectPalette && isCorrectSize) {
console.log(`Copying "${imageFile}"...`);
console.log(`Copying "${imageFile}" to ${targetFileName}...`);
await copy(sourceFile, destFile);
} else {
console.log(`Converting "${imageFile}"...`);
console.log(`Converting "${imageFile}" to ${targetFileName}...`);

let params = [];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "choice4genesis",
"version": "0.14.0",
"version": "0.14.1",
"description": "A ChoiceScript clone that generates SGDK-compatible C source for the Sega Genesis ",
"main": "index.js",
"targets": {
Expand Down

0 comments on commit 62d7e33

Please sign in to comment.