2022-04-17 22:35:32 -04:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
function generateInclude(outputLocation, headerLocation) {
|
|
|
|
return `#include "${path.relative(path.dirname(outputLocation), headerLocation)}"`
|
|
|
|
}
|
|
|
|
|
2022-05-06 00:49:52 -04:00
|
|
|
const InvalidTokenCharacter = /[^A-Za-z0-9_]/gim;
|
|
|
|
|
2022-07-24 18:03:29 -04:00
|
|
|
function getSegmentName(headerLocation) {
|
|
|
|
const levelName = path.basename(headerLocation);
|
|
|
|
const noExtension = levelName.slice(0, levelName.length - path.extname(levelName).length);
|
|
|
|
|
|
|
|
return noExtension.replace(InvalidTokenCharacter, '_');
|
|
|
|
}
|
|
|
|
|
2022-05-06 00:49:52 -04:00
|
|
|
function generateLevelName(outputLocation, headerLocation) {
|
|
|
|
const relative = path.relative(path.dirname(outputLocation), headerLocation).slice(0, -2);
|
|
|
|
return relative.replace(InvalidTokenCharacter, '_') + '_level';
|
|
|
|
}
|
|
|
|
|
2022-07-24 18:03:29 -04:00
|
|
|
function generateMetadata(outputLocation, headerLocation) {
|
|
|
|
const segmentName = getSegmentName(headerLocation);
|
|
|
|
return ` {
|
|
|
|
&${generateLevelName(outputLocation, headerLocation)},
|
|
|
|
_${segmentName}_geoSegmentRomStart,
|
|
|
|
_${segmentName}_geoSegmentRomEnd,
|
|
|
|
_${segmentName}_geoSegmentStart,
|
|
|
|
},`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateExterns(headerLocation) {
|
|
|
|
const segmentName = getSegmentName(headerLocation);
|
|
|
|
return `
|
|
|
|
extern char _${segmentName}_geoSegmentRomStart[];
|
|
|
|
extern char _${segmentName}_geoSegmentRomEnd[];
|
|
|
|
extern char _${segmentName}_geoSegmentStart[];
|
|
|
|
`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-06 00:49:52 -04:00
|
|
|
function generateLevelList(outputLocation, headerLocations) {
|
2022-07-24 18:03:29 -04:00
|
|
|
return `struct LevelMetadata gLevelList[] = {
|
|
|
|
${headerLocations.map(headerLocation => generateMetadata(outputLocation, headerLocation)).join('\n')}
|
2022-05-06 00:49:52 -04:00
|
|
|
};
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2022-04-17 22:35:32 -04:00
|
|
|
function generateData(outputLocation, headerLocations) {
|
|
|
|
return `#ifndef __BUILD_LEVEL_LIST_H__
|
|
|
|
#define __BUILD_LEVEL_LIST_H__
|
|
|
|
|
2022-07-24 18:03:29 -04:00
|
|
|
#include "levels/level_metadata.h"
|
2022-05-06 00:49:52 -04:00
|
|
|
|
2022-04-17 22:35:32 -04:00
|
|
|
${headerLocations.map(headerLocation => generateInclude(outputLocation, headerLocation)).join('\n')}
|
|
|
|
|
2022-05-06 00:49:52 -04:00
|
|
|
#define LEVEL_COUNT ${headerLocations.length}
|
|
|
|
|
2022-07-24 18:03:29 -04:00
|
|
|
${headerLocations.map(generateExterns).join('\n')}
|
|
|
|
|
2022-05-06 00:49:52 -04:00
|
|
|
${generateLevelList(outputLocation, headerLocations)}
|
|
|
|
|
2022-04-17 22:35:32 -04:00
|
|
|
#endif
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const output = process.argv[2];
|
|
|
|
|
|
|
|
fs.writeFileSync(output, generateData(output, process.argv.slice(3)));
|