Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Architecture = void 0;
exports.Architecture = {
Default: 'default',
Arm7: 'arm7',
Arm8: 'arm8',
X86: 'x86',
X86_64: 'x86_64'
};
//# sourceMappingURL=Architecture.js.map

View File

@ -0,0 +1,255 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssetConverter = void 0;
const ProjectFile_1 = require("./ProjectFile");
const fs = require("fs-extra");
const path = require("path");
const log = require("./log");
const chokidar = require("chokidar");
const crypto = require("crypto");
const Throttle = require("promise-parallel-throttle");
class AssetConverter {
constructor(exporter, options, assetMatchers) {
this.exporter = exporter;
this.options = options;
this.platform = options.target;
this.assetMatchers = assetMatchers;
}
close() {
if (this.watcher)
this.watcher.close();
}
static replacePattern(pattern, name, fileinfo, options, from) {
let basePath = options.nameBaseDir ? path.join(from, options.nameBaseDir) : from;
let dirValue = path.relative(basePath, fileinfo.dir);
if (basePath.length > 0 && basePath[basePath.length - 1] === path.sep
&& dirValue.length > 0 && dirValue[dirValue.length - 1] !== path.sep) {
dirValue += path.sep;
}
if (options.namePathSeparator) {
dirValue = dirValue.split(path.sep).join(options.namePathSeparator);
}
const dirRegex = dirValue === ''
? /{dir}\//g
: /{dir}/g;
return pattern.replace(/{name}/g, name).replace(/{ext}/g, fileinfo.ext).replace(dirRegex, dirValue);
}
static createExportInfo(fileinfo, keepextension, options, from) {
let nameValue = fileinfo.name;
let destination = fileinfo.name;
if (options.md5sum) {
let data = fs.readFileSync(path.join(fileinfo.dir, fileinfo.base));
let md5sum = crypto.createHash('md5').update(data).digest('hex'); // TODO yield generateMd5Sum(file);
destination += '_' + md5sum;
}
if ((keepextension || options.noprocessing) && (!options.destination || options.destination.indexOf('{ext}') < 0)) {
destination += fileinfo.ext;
}
if (options.destination) {
destination = AssetConverter.replacePattern(options.destination, destination, fileinfo, options, from);
}
if (options.destinationCallback) {
destination = options.destinationCallback(destination);
}
if (keepextension && (!options.name || options.name.indexOf('{ext}') < 0)) {
nameValue += fileinfo.ext;
}
if (options.name) {
nameValue = AssetConverter.replacePattern(options.name, nameValue, fileinfo, options, from);
}
return { name: nameValue, destination: destination };
}
watch(watch, match, temp, options) {
return new Promise((resolve, reject) => {
let ready = false;
let files = [];
this.watcher = chokidar.watch(match, { ignored: /[\/\\]\.(svn|git|DS_Store)/, persistent: watch, followSymlinks: false });
const onFileChange = async (file) => {
const fileinfo = path.parse(file);
let outPath = fileinfo.name;
// with subfolders
if (options.destination) {
const from = path.resolve(options.baseDir, '..');
outPath = AssetConverter.replacePattern(options.destination, fileinfo.name, fileinfo, options, from);
}
log.info('Reexporting ' + outPath + fileinfo.ext);
switch (fileinfo.ext) {
case '.png':
case '.jpg':
case '.jpeg':
case '.hdr':
{ }
await this.exporter.copyImage(this.platform, file, outPath, {}, {});
break;
case '.ogg':
case '.mp3':
case '.flac':
case '.wav': {
await this.exporter.copySound(this.platform, file, outPath, {});
break;
}
case '.mp4':
case '.webm':
case '.mov':
case '.wmv':
case '.avi': {
await this.exporter.copyVideo(this.platform, file, outPath, {});
break;
}
case '.ttf':
await this.exporter.copyFont(this.platform, file, outPath, {});
break;
default:
await this.exporter.copyBlob(this.platform, file, outPath + fileinfo.ext, {});
}
for (let callback of ProjectFile_1.Callbacks.postAssetReexporting) {
callback(outPath + fileinfo.ext);
}
};
this.watcher.on('add', (file) => {
if (ready) {
onFileChange(file);
}
else {
files.push(file);
}
});
if (watch) {
this.watcher.on('change', (file) => {
if (ready) {
onFileChange(file);
}
});
}
this.watcher.on('ready', async () => {
ready = true;
let parsedFiles = [];
let cache = {};
let cachePath = path.join(temp, 'cache.json');
if (fs.existsSync(cachePath)) {
cache = JSON.parse(fs.readFileSync(cachePath, 'utf8'));
}
const self = this;
async function convertAsset(file, index) {
let fileinfo = path.parse(file);
log.info('Exporting asset ' + (index + 1) + ' of ' + files.length + ' (' + fileinfo.base + ').');
const ext = fileinfo.ext.toLowerCase();
switch (ext) {
case '.png':
case '.jpg':
case '.jpeg':
case '.hdr': {
let exportInfo = AssetConverter.createExportInfo(fileinfo, false, options, self.exporter.options.from);
let images;
if (options.noprocessing) {
images = await self.exporter.copyBlob(self.platform, file, exportInfo.destination, options);
}
else {
images = await self.exporter.copyImage(self.platform, file, exportInfo.destination, options, cache);
}
if (!options.notinlist) {
parsedFiles.push({ name: exportInfo.name, from: file, type: 'image', files: images.files, file_sizes: images.sizes, original_width: options.original_width, original_height: options.original_height, readable: options.readable });
}
break;
}
case '.ogg':
case '.mp3':
case '.flac':
case '.wav': {
let exportInfo = AssetConverter.createExportInfo(fileinfo, false, options, self.exporter.options.from);
let sounds;
if (options.noprocessing) {
sounds = await self.exporter.copyBlob(self.platform, file, exportInfo.destination, options);
}
else {
sounds = await self.exporter.copySound(self.platform, file, exportInfo.destination, options);
}
if (sounds.files.length === 0) {
throw 'Audio file ' + file + ' could not be exported, you have to specify a path to ffmpeg.';
}
if (!options.notinlist) {
parsedFiles.push({ name: exportInfo.name, from: file, type: 'sound', files: sounds.files, file_sizes: sounds.sizes, original_width: undefined, original_height: undefined, readable: undefined });
}
break;
}
case '.ttf': {
let exportInfo = AssetConverter.createExportInfo(fileinfo, false, options, self.exporter.options.from);
let fonts;
if (options.noprocessing) {
fonts = await self.exporter.copyBlob(self.platform, file, exportInfo.destination, options);
}
else {
fonts = await self.exporter.copyFont(self.platform, file, exportInfo.destination, options);
}
if (!options.notinlist) {
parsedFiles.push({ name: exportInfo.name, from: file, type: 'font', files: fonts.files, file_sizes: fonts.sizes, original_width: undefined, original_height: undefined, readable: undefined });
}
break;
}
case '.mp4':
case '.webm':
case '.mov':
case '.wmv':
case '.avi': {
let exportInfo = AssetConverter.createExportInfo(fileinfo, false, options, self.exporter.options.from);
let videos;
if (options.noprocessing) {
videos = await self.exporter.copyBlob(self.platform, file, exportInfo.destination, options);
}
else {
videos = await self.exporter.copyVideo(self.platform, file, exportInfo.destination, options);
}
if (videos.files.length === 0) {
log.error('Video file ' + file + ' could not be exported, you have to specify a path to ffmpeg.');
}
if (!options.notinlist) {
parsedFiles.push({ name: exportInfo.name, from: file, type: 'video', files: videos.files, file_sizes: videos.sizes, original_width: undefined, original_height: undefined, readable: undefined });
}
break;
}
default: {
let exportInfo = AssetConverter.createExportInfo(fileinfo, true, options, self.exporter.options.from);
let blobs = await self.exporter.copyBlob(self.platform, file, exportInfo.destination, options);
if (!options.notinlist) {
parsedFiles.push({ name: exportInfo.name, from: file, type: 'blob', files: blobs.files, file_sizes: blobs.sizes, original_width: undefined, original_height: undefined, readable: undefined });
}
break;
}
}
}
if (this.options.parallelAssetConversion !== 0) {
let todo = files.map((file, index) => {
return async () => {
await convertAsset(file, index);
};
});
let processes = this.options.parallelAssetConversion === -1
? require('os').cpus().length - 1
: this.options.parallelAssetConversion;
await Throttle.all(todo, {
maxInProgress: processes,
});
}
else {
let index = 0;
for (let file of files) {
await convertAsset(file, index);
index += 1;
}
}
fs.ensureDirSync(temp);
fs.writeFileSync(cachePath, JSON.stringify(cache), { encoding: 'utf8' });
resolve(parsedFiles);
});
});
}
async run(watch, temp) {
let files = [];
for (let matcher of this.assetMatchers) {
files = files.concat(await this.watch(watch, matcher.match, temp, matcher.options));
}
return files;
}
}
exports.AssetConverter = AssetConverter;
//# sourceMappingURL=AssetConverter.js.map

View File

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AudioApi = void 0;
exports.AudioApi = {
Default: 'default',
DirectSound: 'directsound',
WASAPI: 'wasapi'
};
//# sourceMappingURL=AudioApi.js.map

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Color = void 0;
class Color {
}
exports.Color = Color;
//# sourceMappingURL=Color.js.map

View File

@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convert = void 0;
const child_process = require("child_process");
const fs = require("fs");
function convert(inFilename, outFilename, encoder, args = null) {
return new Promise((resolve, reject) => {
if (fs.existsSync(outFilename.toString()) && fs.statSync(outFilename.toString()).mtime.getTime() > fs.statSync(inFilename.toString()).mtime.getTime()) {
resolve(true);
return;
}
if (!encoder) {
resolve(false);
return;
}
let dirend = Math.max(encoder.lastIndexOf('/'), encoder.lastIndexOf('\\'));
let firstspace = encoder.indexOf(' ', dirend);
let exe = encoder.substr(0, firstspace);
let parts = encoder.substr(firstspace + 1).split(' ');
let options = [];
for (let i = 0; i < parts.length; ++i) {
let foundarg = false;
if (args !== null) {
for (let arg in args) {
if (parts[i] === '{' + arg + '}') {
options.push(args[arg]);
foundarg = true;
break;
}
}
}
if (foundarg)
continue;
if (parts[i] === '{in}')
options.push(inFilename.toString());
else if (parts[i] === '{out}')
options.push(outFilename.toString());
else
options.push(parts[i]);
}
// About stdio ignore: https://stackoverflow.com/a/20792428
let process = child_process.spawn(exe, options, { stdio: 'ignore' });
process.on('close', (code) => {
resolve(code === 0);
});
});
}
exports.convert = convert;
//# sourceMappingURL=Converter.js.map

View File

@ -0,0 +1,156 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AndroidExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const ImageTool_1 = require("../ImageTool");
const exec_1 = require("../exec");
function findIcon(from, options) {
if (fs.existsSync(path.join(from, 'icon.png')))
return path.join(from, 'icon.png');
else
return path.join(options.kha, 'Kinc', 'Tools', (0, exec_1.sysdir)(), 'icon.png');
}
class AndroidExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
}
backend() {
return 'Android';
}
haxeOptions(name, targetOptions, defines) {
const safename = name.replace(/ /g, '-');
defines.push('no-compilation');
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('kha_java');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_java');
defines.push('kha_opengl');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('android');
return {
from: this.options.from,
to: path.join(this.sysdir(), safename),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'java',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
if (this.projectFiles) {
this.exportAndroidStudioProject(name, targetOptions, this.options.from);
}
}
exportAndroidStudioProject(name, _targetOptions, from) {
let safename = name.replace(/ /g, '-');
this.safename = safename;
let targetOptions = {
package: 'tech.kode.kha',
installLocation: 'internalOnly',
screenOrientation: 'sensor',
permissions: new Array()
};
if (_targetOptions != null && _targetOptions.android != null) {
let userOptions = _targetOptions.android;
if (userOptions.package != null)
targetOptions.package = userOptions.package;
if (userOptions.installLocation != null)
targetOptions.installLocation = userOptions.installLocation;
if (userOptions.screenOrientation != null)
targetOptions.screenOrientation = userOptions.screenOrientation;
if (userOptions.permissions != null)
targetOptions.permissions = userOptions.permissions;
}
let indir = path.join(__dirname, '..', '..', 'Data', 'android');
let outdir = path.join(this.options.to, this.sysdir(), safename);
fs.copySync(path.join(indir, 'gitignore'), path.join(outdir, '.gitignore'));
fs.copySync(path.join(indir, 'build.gradle'), path.join(outdir, 'build.gradle'));
fs.copySync(path.join(indir, 'gradle.properties'), path.join(outdir, 'gradle.properties'));
fs.copySync(path.join(indir, 'gradlew'), path.join(outdir, 'gradlew'));
fs.copySync(path.join(indir, 'gradlew.bat'), path.join(outdir, 'gradlew.bat'));
fs.copySync(path.join(indir, 'settings.gradle'), path.join(outdir, 'settings.gradle'));
fs.copySync(path.join(indir, 'app', 'gitignore'), path.join(outdir, 'app', '.gitignore'));
let gradle = fs.readFileSync(path.join(indir, 'app', 'build.gradle'), { encoding: 'utf8' });
gradle = gradle.replace(/{package}/g, targetOptions.package);
fs.writeFileSync(path.join(outdir, 'app', 'build.gradle'), gradle, { encoding: 'utf8' });
fs.copySync(path.join(indir, 'app', 'proguard-rules.pro'), path.join(outdir, 'app', 'proguard-rules.pro'));
fs.ensureDirSync(path.join(outdir, 'app', 'src'));
// fs.emptyDirSync(path.join(outdir, 'app', 'src'));
let manifest = fs.readFileSync(path.join(indir, 'main', 'AndroidManifest.xml'), { encoding: 'utf8' });
manifest = manifest.replace(/{package}/g, targetOptions.package);
manifest = manifest.replace(/{installLocation}/g, targetOptions.installLocation);
manifest = manifest.replace(/{screenOrientation}/g, targetOptions.screenOrientation);
manifest = manifest.replace(/{permissions}/g, targetOptions.permissions.map(function (p) { return '\n\t<uses-permission android:name="' + p + '"/>'; }).join(''));
fs.ensureDirSync(path.join(outdir, 'app', 'src', 'main'));
fs.writeFileSync(path.join(outdir, 'app', 'src', 'main', 'AndroidManifest.xml'), manifest, { encoding: 'utf8' });
fs.ensureDirSync(path.join(outdir, 'app', 'src', 'main', 'res', 'values'));
let strings = fs.readFileSync(path.join(indir, 'main', 'res', 'values', 'strings.xml'), { encoding: 'utf8' });
strings = strings.replace(/{name}/g, name);
fs.writeFileSync(path.join(outdir, 'app', 'src', 'main', 'res', 'values', 'strings.xml'), strings, { encoding: 'utf8' });
fs.ensureDirSync(path.join(outdir, 'app', 'src', 'main', 'res', 'mipmap-hdpi'));
(0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, findIcon(from, this.options), path.join(this.options.to, this.sysdir(), safename, 'app', 'src', 'main', 'res', 'mipmap-hdpi', 'ic_launcher'), { width: 72, height: 72 }, 'png', false, false, {});
fs.ensureDirSync(path.join(outdir, 'app', 'src', 'main', 'res', 'mipmap-mdpi'));
(0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, findIcon(from, this.options), path.join(this.options.to, this.sysdir(), safename, 'app', 'src', 'main', 'res', 'mipmap-mdpi', 'ic_launcher'), { width: 48, height: 48 }, 'png', false, false, {});
fs.ensureDirSync(path.join(outdir, 'app', 'src', 'main', 'res', 'mipmap-xhdpi'));
(0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, findIcon(from, this.options), path.join(this.options.to, this.sysdir(), safename, 'app', 'src', 'main', 'res', 'mipmap-xhdpi', 'ic_launcher'), { width: 96, height: 96 }, 'png', false, false, {});
fs.ensureDirSync(path.join(outdir, 'app', 'src', 'main', 'res', 'mipmap-xxhdpi'));
(0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, findIcon(from, this.options), path.join(this.options.to, this.sysdir(), safename, 'app', 'src', 'main', 'res', 'mipmap-xxhdpi', 'ic_launcher'), { width: 144, height: 144 }, 'png', false, false, {});
fs.ensureDirSync(path.join(outdir, 'app', 'src', 'main', 'res', 'mipmap-xxxhdpi'));
(0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, findIcon(from, this.options), path.join(this.options.to, this.sysdir(), safename, 'app', 'src', 'main', 'res', 'mipmap-xxxhdpi', 'ic_launcher'), { width: 192, height: 192 }, 'png', false, false, {});
fs.copySync(path.join(indir, 'gradle', 'wrapper', 'gradle-wrapper.jar'), path.join(outdir, 'gradle', 'wrapper', 'gradle-wrapper.jar'));
fs.copySync(path.join(indir, 'gradle', 'wrapper', 'gradle-wrapper.properties'), path.join(outdir, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
fs.copySync(path.join(indir, 'idea', 'gradle.xml'), path.join(outdir, '.idea', 'gradle.xml'));
fs.copySync(path.join(indir, 'idea', 'misc.xml'), path.join(outdir, '.idea', 'misc.xml'));
fs.copySync(path.join(indir, 'idea', 'runConfigurations.xml'), path.join(outdir, '.idea', 'runConfigurations.xml'));
fs.copySync(path.join(indir, 'idea', 'codeStyles', 'Project.xml'), path.join(outdir, '.idea', 'codeStyles', 'Project.xml'));
}
/*copyMusic(platform, from, to, encoders, callback) {
Files.createDirectories(this.directory.resolve(this.sysdir()).resolve(to).parent());
Converter.convert(from, this.directory.resolve(Paths.get(this.sysdir(), this.safename, 'app', 'src', 'main', 'assets', to + '.ogg')), encoders.oggEncoder, function (success) {
callback([to + '.ogg']);
});
}*/
async copySound(platform, from, to, options) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), this.safename, 'app', 'src', 'main', 'assets', path.dirname(to)));
let ogg = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), this.safename, 'app', 'src', 'main', 'assets', to + '.ogg'), this.options.ogg);
return { files: [to + '.ogg'], sizes: [1] };
}
else {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), this.safename, 'app', 'src', 'main', 'assets', to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
}
async copyImage(platform, from, to, asset, cache) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), this.safename, 'app', 'src', 'main', 'assets', to), asset, undefined, false, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), this.safename, 'app', 'src', 'main', 'assets', to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
return { files: [to], sizes: [1] };
}
}
exports.AndroidExporter = AndroidExporter;
//# sourceMappingURL=AndroidExporter.js.map

View File

@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CSharpExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const KhaExporter_1 = require("./KhaExporter");
const ImageTool_1 = require("../ImageTool");
const uuid = require('uuid');
class CSharpExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
fs.removeSync(path.join(this.options.to, this.sysdir() + '-build', 'Sources'));
}
includeFiles(dir, baseDir) {
if (!dir || !fs.existsSync(dir))
return;
let files = fs.readdirSync(dir);
for (let f in files) {
let file = path.join(dir, files[f]);
if (fs.existsSync(file) && fs.statSync(file).isDirectory())
this.includeFiles(file, baseDir);
else if (file.endsWith('.cs')) {
this.p('<Compile Include="' + path.relative(baseDir, file).replace(/\//g, '\\') + '" />', 2);
}
}
}
haxeOptions(name, targetOptions, defines) {
defines.push('no-root');
defines.push('no-compilation');
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_a1');
defines.push('kha_cs');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_cs');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_a1');
return {
from: this.options.from,
to: path.join(this.sysdir() + '-build', 'Sources'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'cs',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
if (this.projectFiles) {
const projectUuid = uuid.v4();
this.exportSLN(projectUuid);
this.exportCsProj(projectUuid);
this.exportResources();
}
}
exportSLN(projectUuid) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir() + '-build'));
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Project.sln'));
const solutionUuid = uuid.v4();
this.p('Microsoft Visual Studio Solution File, Format Version 11.00');
this.p('# Visual Studio 2010');
this.p('Project("{' + solutionUuid.toString().toUpperCase() + '}") = "HaxeProject", "Project.csproj", "{' + projectUuid.toString().toUpperCase() + '}"');
this.p('EndProject');
this.p('Global');
this.p('GlobalSection(SolutionConfigurationPlatforms) = preSolution', 1);
this.p('Debug|x86 = Debug|x86', 2);
this.p('Release|x86 = Release|x86', 2);
this.p('EndGlobalSection', 1);
this.p('GlobalSection(ProjectConfigurationPlatforms) = postSolution', 1);
this.p('{' + projectUuid.toString().toUpperCase() + '}.Debug|x86.ActiveCfg = Debug|x86', 2);
this.p('{' + projectUuid.toString().toUpperCase() + '}.Debug|x86.Build.0 = Debug|x86', 2);
this.p('{' + projectUuid.toString().toUpperCase() + '}.Release|x86.ActiveCfg = Release|x86', 2);
this.p('{' + projectUuid.toString().toUpperCase() + '}.Release|x86.Build.0 = Release|x86', 2);
this.p('EndGlobalSection', 1);
this.p('GlobalSection(SolutionProperties) = preSolution', 1);
this.p('HideSolutionNode = FALSE', 2);
this.p('EndGlobalSection', 1);
this.p('EndGlobal');
this.closeFile();
}
async copySound(platform, from, to) {
return { files: [to], sizes: [1] };
}
async copyImage(platform, from, to, asset, cache) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), asset, undefined, false, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
async copyBlob(platform, from, to) {
fs.copySync(from, path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
return { files: [to], sizes: [1] };
}
}
exports.CSharpExporter = CSharpExporter;
//# sourceMappingURL=CSharpExporter.js.map

View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugHtml5Exporter = void 0;
const Html5Exporter_1 = require("./Html5Exporter");
class DebugHtml5Exporter extends Html5Exporter_1.Html5Exporter {
constructor(options) {
super(options);
this.isDebug = true;
}
}
exports.DebugHtml5Exporter = DebugHtml5Exporter;
//# sourceMappingURL=DebugHtml5Exporter.js.map

View File

@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmptyExporter = void 0;
const child_process = require("child_process");
const fs = require("fs-extra");
const path = require("path");
const KhaExporter_1 = require("./KhaExporter");
const Haxe_1 = require("../Haxe");
const log = require("../log");
class EmptyExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
}
backend() {
return 'Empty';
}
haxeOptions(name, targetOptions, defines) {
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('kha_a2');
return {
from: this.options.from,
to: path.join(this.sysdir(), 'docs.xml'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'xml',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, _targetOptions, haxeOptions) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir()));
try {
// Remove any @:export first
await (0, Haxe_1.executeHaxe)(this.options.to, this.options.haxe, ['project-' + this.sysdir() + '.hxml']);
let doxresult = child_process.spawnSync('haxelib', ['run', 'dox', '-in', 'kha.*', '-i', path.join(this.sysdir(), 'docs.xml')], { env: process.env, cwd: path.normalize(this.options.to) });
if (doxresult.stdout.toString() !== '') {
log.info(doxresult.stdout.toString());
}
if (doxresult.stderr.toString() !== '') {
log.error(doxresult.stderr.toString());
}
}
catch (error) {
}
}
async copySound(platform, from, to) {
return { files: [''], sizes: [0] };
}
async copyImage(platform, from, to, asset) {
return { files: [''], sizes: [0] };
}
async copyBlob(platform, from, to) {
return { files: [''], sizes: [0] };
}
async copyVideo(platform, from, to) {
return { files: [''], sizes: [0] };
}
}
exports.EmptyExporter = EmptyExporter;
//# sourceMappingURL=EmptyExporter.js.map

View File

@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Exporter = void 0;
const fs = require("fs-extra");
class Exporter {
constructor() {
}
writeFile(file) {
this.out = fs.openSync(file, 'w');
}
closeFile() {
fs.closeSync(this.out);
}
p(line = '', indent = 0) {
let tabs = '';
for (let i = 0; i < indent; ++i)
tabs += '\t';
let data = Buffer.from(tabs + line + '\n');
fs.writeSync(this.out, data, 0, data.length, null);
}
copyFile(from, to) {
fs.copySync(from, to, { overwrite: true });
}
copyDirectory(from, to) {
fs.copySync(from, to, { overwrite: true });
}
createDirectory(dir) {
fs.ensureDirSync(dir);
}
}
exports.Exporter = Exporter;
//# sourceMappingURL=Exporter.js.map

View File

@ -0,0 +1,126 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlashExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const ImageTool_1 = require("../ImageTool");
function adjustFilename(filename) {
filename = filename.replace(/\./g, '_');
filename = filename.replace(/-/g, '_');
filename = filename.replace(/\//g, '_');
return filename;
}
class FlashExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
this.images = [];
this.sounds = [];
this.blobs = [];
}
backend() {
return 'Flash';
}
haxeOptions(name, targetOptions, defines) {
defines.push('swf-script-timeout=60');
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_' + this.options.target);
defines.push('kha_stage3d');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('kha_a2');
if (this.options.embedflashassets)
defines.push('KHA_EMBEDDED_ASSETS');
let defaultFlashOptions = {
framerate: 60,
stageBackground: 'ffffff',
swfVersion: '16.0'
};
let flashOptions = targetOptions ? (targetOptions.flash ? targetOptions.flash : defaultFlashOptions) : defaultFlashOptions;
return {
from: this.options.from,
to: path.join(this.sysdir(), 'kha.swf'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'as',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
framerate: 'framerate' in flashOptions ? flashOptions.framerate : defaultFlashOptions.framerate,
stageBackground: 'stageBackground' in flashOptions ? flashOptions.stageBackground : defaultFlashOptions.stageBackground,
swfVersion: 'swfVersion' in flashOptions ? flashOptions.swfVersion : defaultFlashOptions.swfVersion,
};
}
async export(name, targetOptions, haxeOptions) {
if (this.options.embedflashassets) {
this.writeFile(path.join(this.options.to, '..', 'Sources', 'Assets.hx'));
this.p('package;');
this.p();
this.p('import flash.display.BitmapData;');
this.p('import flash.media.Sound;');
this.p('import flash.utils.ByteArray;');
this.p();
for (let image of this.images) {
this.p('@:bitmap("flash/' + image + '") class Assets_' + adjustFilename(image) + ' extends BitmapData { }');
}
this.p();
for (let sound of this.sounds) {
this.p('@:file("flash/' + sound + '") class Assets_' + adjustFilename(sound) + ' extends ByteArray { }');
}
this.p();
for (let blob of this.blobs) {
this.p('@:file("flash/' + blob + '") class Assets_' + adjustFilename(blob) + ' extends ByteArray { }');
}
this.p();
this.p('class Assets {');
this.p('public static function visit(): Void {', 1);
this.p('', 2);
this.p('}', 1);
this.p('}');
this.closeFile();
}
}
async copySound(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.mp3'), this.options.mp3);
return { files: [to + '.mp3'], sizes: [1] };
}
async copyImage(platform, from, to, asset, cache) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), asset, undefined, false, false, cache);
if (this.options.embedflashassets)
this.images.push(to + '.' + format);
return { files: [to + '.' + format], sizes: [1] };
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
if (this.options.embedflashassets)
this.blobs.push(to);
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
addShader(shader) {
if (this.options.embedflashassets)
this.blobs.push(shader);
}
}
exports.FlashExporter = FlashExporter;
//# sourceMappingURL=FlashExporter.js.map

View File

@ -0,0 +1,252 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Html5Exporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const ImageTool_1 = require("../ImageTool");
const VrApi_1 = require("../VrApi");
class Html5Exporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
}
backend() {
return 'HTML5';
}
isADebugTarget() {
return this.isDebug;
}
isDebugHtml5() {
return this.sysdir() === 'debug-html5';
}
isNode() {
return false;
}
isHtml5Worker() {
return this.sysdir() === 'html5worker';
}
haxeOptions(name, targetOptions, defines) {
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_js');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_a1');
defines.push('kha_a2');
if (targetOptions.html5.noKeyboard) {
defines.push('kha_no_keyboard');
}
if (targetOptions.html5.disableContextMenu) {
defines.push('kha_disable_context_menu');
}
if (this.options.vr === VrApi_1.VrApi.WebVR) {
defines.push('kha_webvr');
}
let canvasId = targetOptions.html5.canvasId == null ? 'khanvas' : targetOptions.html5.canvasId;
defines.push('canvas_id=' + canvasId);
let scriptName = this.isHtml5Worker() ? 'khaworker' : 'kha';
if (targetOptions.html5.scriptName != null && !(this.isNode() || this.isDebugHtml5())) {
scriptName = targetOptions.html5.scriptName;
}
defines.push('script_name=' + scriptName);
let webgl = targetOptions.html5.webgl == null ? true : targetOptions.html5.webgl;
if (webgl) {
defines.push('sys_g4');
defines.push('kha_g4');
defines.push('kha_webgl');
}
else {
defines.push('kha_html5_canvas');
}
if (this.isNode()) {
defines.push('nodejs');
defines.push('sys_node');
defines.push('sys_server');
defines.push('kha_node');
defines.push('kha_server');
}
else {
defines.push('sys_' + this.options.target);
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_js');
defines.push('sys_html5');
defines.push('kha_html5');
defines.push('kha_html5_js');
}
if (this.isADebugTarget()) {
this.parameters.push('-debug');
defines.push('sys_debug_html5');
defines.push('kha_debug_html5');
defines.push('kha_html5');
}
if (this.isHtml5Worker()) {
defines.push('js-classic');
}
return {
from: this.options.from.toString(),
to: path.join(this.sysdir(), scriptName + '.js'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'js',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, _targetOptions, haxeOptions) {
let targetOptions = {
canvasId: 'khanvas',
scriptName: this.isHtml5Worker() ? 'khaworker' : 'kha',
unsafeEval: false,
expose: ''
};
if (_targetOptions != null && _targetOptions.html5 != null) {
let userOptions = _targetOptions.html5;
if (userOptions.canvasId != null)
targetOptions.canvasId = userOptions.canvasId;
if (userOptions.scriptName != null)
targetOptions.scriptName = userOptions.scriptName;
if (userOptions.unsafeEval != null)
targetOptions.unsafeEval = userOptions.unsafeEval;
if (userOptions.expose != null)
targetOptions.expose = userOptions.expose;
}
fs.ensureDirSync(path.join(this.options.to, this.sysdir()));
if (this.isADebugTarget()) { // support custom debug-html5 based targets
let electron = path.join(this.options.to, this.sysdir(), 'electron.js');
let protoelectron = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'debug-html5', 'electron.js'), { encoding: 'utf8' });
protoelectron = protoelectron.replace(/{Width}/g, '' + this.width);
protoelectron = protoelectron.replace(/{Height}/g, '' + this.height);
protoelectron = protoelectron.replace(/{ext}/g, process.platform === 'win32' ? '\'.ico\'' : '\'.png\'');
fs.writeFileSync(electron.toString(), protoelectron);
let pack = path.join(this.options.to, this.sysdir(), 'package.json');
let protopackage = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'debug-html5', 'package.json'), { encoding: 'utf8' });
protopackage = protopackage.replace(/{Name}/g, name);
fs.writeFileSync(pack.toString(), protopackage);
let index = path.join(this.options.to, this.sysdir(), 'index.html');
let protoindex = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'debug-html5', 'index.html'), { encoding: 'utf8' });
protoindex = protoindex.replace(/{Name}/g, name);
protoindex = protoindex.replace(/{Width}/g, '' + this.width);
protoindex = protoindex.replace(/{Height}/g, '' + this.height);
protoindex = protoindex.replace(/{CanvasId}/g, '' + targetOptions.canvasId);
protoindex = protoindex.replace(/{ScriptName}/g, '' + targetOptions.scriptName);
protoindex = protoindex.replace(/{UnsafeEval}/g, targetOptions.unsafeEval ? '\'unsafe-eval\'' : '');
fs.writeFileSync(index.toString(), protoindex);
let preload = path.join(this.options.to, this.sysdir(), 'preload.js');
let protopreload = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'debug-html5', 'preload.js'), { encoding: 'utf8' });
protopreload = protopreload.replace(/{Expose}/g, targetOptions.expose);
fs.writeFileSync(preload.toString(), protopreload);
}
else if (this.isNode()) {
let pack = path.join(this.options.to, this.sysdir(), 'package.json');
let protopackage = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'node', 'package.json'), 'utf8');
protopackage = protopackage.replace(/{Name}/g, name);
fs.writeFileSync(pack, protopackage);
let protoserver = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'node', 'server.js'), 'utf8');
fs.writeFileSync(path.join(this.options.to, this.sysdir(), 'server.js'), protoserver);
}
else if (!this.isHtml5Worker()) {
let index = path.join(this.options.to, this.sysdir(), 'index.html');
if (!fs.existsSync(index)) {
let protoindex = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'html5', 'index.html'), { encoding: 'utf8' });
protoindex = protoindex.replace(/{Name}/g, name);
protoindex = protoindex.replace(/{Width}/g, '' + this.width);
protoindex = protoindex.replace(/{Height}/g, '' + this.height);
protoindex = protoindex.replace(/{CanvasId}/g, '' + targetOptions.canvasId);
protoindex = protoindex.replace(/{ScriptName}/g, '' + targetOptions.scriptName);
fs.writeFileSync(index.toString(), protoindex);
}
}
}
/*copyMusic(platform, from, to, encoders, callback) {
Files.createDirectories(this.directory.resolve(this.sysdir()).resolve(to).parent());
Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + '.ogg'), encoders.oggEncoder, (ogg) => {
Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + '.mp4'), encoders.aacEncoder, (mp4) => {
var files = [];
if (ogg) files.push(to + '.ogg');
if (mp4) files.push(to + '.mp4');
callback(files);
});
});
}*/
async copySound(platform, from, to, options) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let ogg = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ogg'), this.options.ogg);
let ogg_size = (await fs.stat(path.join(this.options.to, this.sysdir(), to + '.ogg'))).size;
let mp4 = false;
let mp4_size = 0;
let mp3 = false;
let mp3_size = 0;
if (!this.isDebugHtml5()) {
mp4 = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.aac);
if (mp4) {
mp4_size = (await fs.stat(path.join(this.options.to, this.sysdir(), to + '.mp4'))).size;
}
if (!mp4) {
mp3 = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.mp3'), this.options.mp3);
mp3_size = (await fs.stat(path.join(this.options.to, this.sysdir(), to + '.mp3'))).size;
}
}
let files = [];
let sizes = [];
if (ogg) {
files.push(to + '.ogg');
sizes.push(ogg_size);
}
if (mp4) {
files.push(to + '.mp4');
sizes.push(mp4_size);
}
if (mp3) {
files.push(to + '.mp3');
sizes.push(mp3_size);
}
return { files: files, sizes: sizes };
}
async copyImage(platform, from, to, options, cache) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, undefined, false, false, cache);
let stat = await fs.stat(path.join(this.options.to, this.sysdir(), to + '.' + format));
let size = stat.size;
return { files: [to + '.' + format], sizes: [size] };
}
async copyBlob(platform, from, to, options) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true, dereference: true });
let stat = await fs.stat(path.join(this.options.to, this.sysdir(), to));
let size = stat.size;
return { files: [to], sizes: [size] };
}
async copyVideo(platform, from, to, options) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let mp4 = false;
let mp4_size = 0;
if (!this.isDebugHtml5()) {
mp4 = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
mp4_size = (await fs.stat(path.join(this.options.to, this.sysdir(), to + '.mp4'))).size;
}
let webm = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.webm'), this.options.webm);
let webm_size = (await fs.stat(path.join(this.options.to, this.sysdir(), to + '.webm'))).size;
let files = [];
let sizes = [];
if (mp4) {
files.push(to + '.mp4');
sizes.push(mp4_size);
}
if (webm) {
files.push(to + '.webm');
sizes.push(webm_size);
}
return { files: files, sizes: sizes };
}
}
exports.Html5Exporter = Html5Exporter;
//# sourceMappingURL=Html5Exporter.js.map

View File

@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Html5WorkerExporter = void 0;
const Html5Exporter_1 = require("./Html5Exporter");
class Html5WorkerExporter extends Html5Exporter_1.Html5Exporter {
constructor(options) {
super(options);
}
backend() {
return 'HTML5-Worker';
}
}
exports.Html5WorkerExporter = Html5WorkerExporter;
//# sourceMappingURL=Html5WorkerExporter.js.map

View File

@ -0,0 +1,103 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JavaExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const KhaExporter_1 = require("./KhaExporter");
const ImageTool_1 = require("../ImageTool");
class JavaExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
}
haxeOptions(name, targetOptions, defines) {
const sources = path.join(this.options.to, this.sysdir(), 'Sources');
if (fs.existsSync(sources)) {
fs.removeSync(sources);
}
defines.push('no-compilation');
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_a1');
defines.push('kha_' + this.options.target);
if (this.options.target !== 'java') {
defines.push('kha_java');
defines.push('kha_' + this.options.target + '_java');
}
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_a1');
return {
from: this.options.from,
to: path.join(this.sysdir(), 'Sources'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'java',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir()));
this.exportEclipseProject();
}
backend() {
return 'Java';
}
exportEclipseProject() {
this.writeFile(path.join(this.options.to, this.sysdir(), '.classpath'));
this.p('<?xml version="1.0" encoding="UTF-8"?>');
this.p('<classpath>');
this.p('\t<classpathentry kind="src" path="Sources/src"/>');
this.p('\t<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>');
this.p('\t<classpathentry kind="output" path="bin"/>');
this.p('</classpath>');
this.closeFile();
this.writeFile(path.join(this.options.to, this.sysdir(), '.project'));
this.p('<?xml version="1.0" encoding="UTF-8"?>');
this.p('<projectDescription>');
this.p('\t<name>' + path.parse(this.options.to).name + '</name>');
this.p('\t<comment></comment>');
this.p('\t<projects>');
this.p('\t</projects>');
this.p('\t<buildSpec>');
this.p('\t\t<buildCommand>');
this.p('\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>');
this.p('\t\t\t<arguments>');
this.p('\t\t\t</arguments>');
this.p('\t\t</buildCommand>');
this.p('\t</buildSpec>');
this.p('\t<natures>');
this.p('\t\t<nature>org.eclipse.jdt.core.javanature</nature>');
this.p('\t</natures>');
this.p('</projectDescription>');
this.closeFile();
}
/*copyMusic(platform, from, to, encoders) {
this.copyFile(from, this.directory.resolve(this.sysdir()).resolve(to + '.wav'));
callback([to + '.wav']);
}*/
async copySound(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
async copyImage(platform, from, to, asset, cache) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), asset, undefined, false, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
return { files: [to], sizes: [1] };
}
}
exports.JavaExporter = JavaExporter;
//# sourceMappingURL=JavaExporter.js.map

View File

@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KhaExporter = void 0;
const path = require("path");
const Exporter_1 = require("./Exporter");
class KhaExporter extends Exporter_1.Exporter {
constructor(options) {
super();
this.options = options;
this.width = 640;
this.height = 480;
this.sources = [];
this.libraries = [];
this.addSourceDirectory(path.join(options.kha, 'Sources'));
this.projectFiles = !options.noproject;
this.parameters = [];
// this.parameters = ['--macro kha.internal.GraphicsBuilder.build("' + this.backend().toLowerCase() + '")'];
this.addSourceDirectory(path.join(options.kha, 'Backends', this.backend()));
}
sysdir() {
return this.systemDirectory;
}
async export(name, targetOptions, haxeOptions) {
return new Promise((resolve, reject) => {
reject('Called an abstract function');
});
}
setWidthAndHeight(width, height) {
this.width = width;
this.height = height;
}
setName(name) {
this.name = name;
this.safename = name.replace(/ /g, '-');
}
setSystemDirectory(systemDirectory) {
this.systemDirectory = systemDirectory;
}
addShader(shader) {
}
addSourceDirectory(path) {
this.sources.push(path);
}
addLibrary(library) {
this.libraries.push(library);
}
removeSourceDirectory(path) {
for (let i = 0; i < this.sources.length; ++i) {
if (this.sources[i] === path) {
this.sources.splice(i, 1);
return;
}
}
}
async copyImage(platform, from, to, options, cache) {
return { files: [], sizes: [] };
}
async copySound(platform, from, to, options) {
return { files: [], sizes: [] };
}
async copyVideo(platform, from, to, options) {
return { files: [], sizes: [] };
}
async copyBlob(platform, from, to, options) {
return { files: [], sizes: [] };
}
async copyFont(platform, from, to, options) {
return await this.copyBlob(platform, from, to + '.ttf', options);
}
}
exports.KhaExporter = KhaExporter;
//# sourceMappingURL=KhaExporter.js.map

View File

@ -0,0 +1,137 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KincExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const defaults = require("../defaults");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const GraphicsApi_1 = require("../GraphicsApi");
const Platform_1 = require("../Platform");
const ImageTool_1 = require("../ImageTool");
class KincExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
this.slowgc = options.slowgc;
// Files.removeDirectory(this.directory.resolve(Paths.get(this.sysdir() + "-build", "Sources")));
}
backend() {
return 'Kinc-hxcpp';
}
haxeOptions(name, targetOptions, defines) {
defines.push('no-compilation');
defines.push('include-prefix=hxinc');
if (!this.slowgc) {
defines.push('HXCPP_GC_GENERATIONAL');
}
defines.push('sys_' + this.options.target);
defines.push('sys_kore');
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_cpp');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_native');
defines.push('kha_' + this.options.target + '_cpp');
let graphics = this.options.graphics;
if (graphics === GraphicsApi_1.GraphicsApi.Default) {
graphics = defaults.graphicsApi(this.options.target);
}
defines.push('kha_' + graphics);
defines.push('kha_kore');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('kha_a2');
if (this.options.vr === 'gearvr') {
defines.push('vr_gearvr');
}
else if (this.options.vr === 'cardboard') {
defines.push('vr_cardboard');
}
else if (this.options.vr === 'rift') {
defines.push('vr_rift');
}
if (this.options.raytrace === 'dxr') {
defines.push('kha_dxr');
}
return {
from: this.options.from,
to: path.join(this.sysdir() + '-build', 'Sources'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'cpp',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
}
async copySound(platform, from, to, options) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ogg'), this.options.ogg);
return { files: [to + '.ogg'], sizes: [1] };
}
else {
if (from.endsWith('.wav')) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
}
else {
throw 'Can not convert ' + from + ' to wav format.';
}
return { files: [to + '.wav'], sizes: [1] };
}
}
async copyImage(platform, from, to, options, cache) {
if (platform === Platform_1.Platform.iOS && options.quality < 1) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, 'pvr', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else if (platform === Platform_1.Platform.Windows && options.quality < 1 && (this.options.graphics === GraphicsApi_1.GraphicsApi.OpenGL || this.options.graphics === GraphicsApi_1.GraphicsApi.Vulkan)) {
// let format = await exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'ASTC', true, false, cache);
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, 'DXT5', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, 'lz4', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
if (platform === Platform_1.Platform.Windows) {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.avi'), this.options.h264);
return { files: [to + '.avi'], sizes: [1] };
}
else if (platform === Platform_1.Platform.iOS || platform === Platform_1.Platform.OSX) {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
else if (platform === Platform_1.Platform.Android) {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ts'), this.options.h264);
return { files: [to + '.ts'], sizes: [1] };
}
else {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ogv'), this.options.theora);
return { files: [to + '.ogv'], sizes: [1] };
}
}
}
exports.KincExporter = KincExporter;
//# sourceMappingURL=KincExporter.js.map

View File

@ -0,0 +1,124 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KincHLExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const defaults = require("../defaults");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const GraphicsApi_1 = require("../GraphicsApi");
const Platform_1 = require("../Platform");
const ImageTool_1 = require("../ImageTool");
class KincHLExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
// Files.removeDirectory(this.directory.resolve(Paths.get(this.sysdir() + "-build", "Sources")));
}
backend() {
return 'Kinc-HL';
}
haxeOptions(name, targetOptions, defines) {
defines.push('no-compilation');
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_hl');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_hl');
let graphics = this.options.graphics;
if (graphics === GraphicsApi_1.GraphicsApi.Default) {
graphics = defaults.graphicsApi(this.options.target);
}
defines.push('kha_' + graphics);
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('kha_a2');
if (this.options.vr === 'gearvr') {
defines.push('vr_gearvr');
}
else if (this.options.vr === 'cardboard') {
defines.push('vr_cardboard');
}
else if (this.options.vr === 'rift') {
defines.push('vr_rift');
}
if (this.options.raytrace === 'dxr') {
defines.push('kha_dxr');
}
return {
from: this.options.from,
to: path.join(this.sysdir() + '-build', 'sources.c'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'hl',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
}
async copySound(platform, from, to, options) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let ogg = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ogg'), this.options.ogg);
return { files: [to + '.ogg'], sizes: [1] };
}
else {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
}
async copyImage(platform, from, to, options, cache) {
if (platform === Platform_1.Platform.iOS && options.quality < 1) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, 'pvr', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else if (platform === Platform_1.Platform.Windows && options.quality < 1 && (this.options.graphics === GraphicsApi_1.GraphicsApi.OpenGL || this.options.graphics === GraphicsApi_1.GraphicsApi.Vulkan)) {
// let format = await exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'ASTC', true, false, cache);
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, 'DXT5', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, 'lz4', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to).toString(), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
if (platform === Platform_1.Platform.Windows) {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.avi'), this.options.h264);
return { files: [to + '.avi'], sizes: [1] };
}
else if (platform === Platform_1.Platform.iOS || platform === Platform_1.Platform.OSX) {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
else if (platform === Platform_1.Platform.Android) {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ts'), this.options.h264);
return { files: [to + '.ts'], sizes: [1] };
}
else {
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ogv'), this.options.theora);
return { files: [to + '.ogv'], sizes: [1] };
}
}
}
exports.KincHLExporter = KincHLExporter;
//# sourceMappingURL=KincHLExporter.js.map

View File

@ -0,0 +1,136 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs-extra");
const path = require("path");
const defaults = require("../defaults");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const GraphicsApi_1 = require("../GraphicsApi");
const Platform_1 = require("../Platform");
const ImageTool_1 = require("../ImageTool");
class KoreExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
this.slowgc = options.slowgc;
// Files.removeDirectory(this.directory.resolve(Paths.get(this.sysdir() + "-build", "Sources")));
}
backend() {
return 'Kore';
}
haxeOptions(name, targetOptions, defines) {
defines.push('no-compilation');
defines.push('include-prefix=hxinc');
if (!this.slowgc) {
defines.push('HXCPP_GC_GENERATIONAL');
}
defines.push('sys_' + this.options.target);
defines.push('sys_kore');
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_cpp');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_native');
defines.push('kha_' + this.options.target + '_cpp');
let graphics = this.options.graphics;
if (graphics === GraphicsApi_1.GraphicsApi.Default) {
graphics = defaults.graphicsApi(this.options.target);
}
defines.push('kha_' + graphics);
defines.push('kha_kore');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('kha_a2');
if (this.options.vr === 'gearvr') {
defines.push('vr_gearvr');
}
else if (this.options.vr === 'cardboard') {
defines.push('vr_cardboard');
}
else if (this.options.vr === 'rift') {
defines.push('vr_rift');
}
if (this.options.raytrace === 'dxr') {
defines.push('kha_dxr');
}
return {
from: this.options.from,
to: path.join(this.sysdir() + '-build', 'Sources'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'cpp',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
}
async copySound(platform, from, to, options) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.ogg'), this.options.ogg);
return { files: [to + '.ogg'], sizes: [1] };
}
else {
if (from.endsWith('.wav')) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
}
else {
throw 'Can not convert ' + from + ' to wav format.';
}
return { files: [to + '.wav'], sizes: [1] };
}
}
async copyImage(platform, from, to, options, cache) {
if (platform === Platform_1.Platform.iOS && options.quality < 1) {
let format = await ImageTool_1.exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'pvr', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else if (platform === Platform_1.Platform.Windows && options.quality < 1 && (this.options.graphics === GraphicsApi_1.GraphicsApi.OpenGL || this.options.graphics === GraphicsApi_1.GraphicsApi.Vulkan)) {
// let format = await exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'ASTC', true, false, cache);
let format = await ImageTool_1.exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'DXT5', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else {
let format = await ImageTool_1.exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'lz4', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
if (platform === Platform_1.Platform.Windows) {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.avi'), this.options.h264);
return { files: [to + '.avi'], sizes: [1] };
}
else if (platform === Platform_1.Platform.iOS || platform === Platform_1.Platform.OSX) {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
else if (platform === Platform_1.Platform.Android) {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.ts'), this.options.h264);
return { files: [to + '.ts'], sizes: [1] };
}
else {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.ogv'), this.options.theora);
return { files: [to + '.ogv'], sizes: [1] };
}
}
}
exports.KoreExporter = KoreExporter;
//# sourceMappingURL=KoreExporter.js.map

View File

@ -0,0 +1,123 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs-extra");
const path = require("path");
const defaults = require("../defaults");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const GraphicsApi_1 = require("../GraphicsApi");
const Platform_1 = require("../Platform");
const ImageTool_1 = require("../ImageTool");
class KoreHLExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
// Files.removeDirectory(this.directory.resolve(Paths.get(this.sysdir() + "-build", "Sources")));
}
backend() {
return 'KoreHL';
}
haxeOptions(name, targetOptions, defines) {
defines.push('no-compilation');
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_hl');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_hl');
let graphics = this.options.graphics;
if (graphics === GraphicsApi_1.GraphicsApi.Default) {
graphics = defaults.graphicsApi(this.options.target);
}
defines.push('kha_' + graphics);
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('kha_a2');
if (this.options.vr === 'gearvr') {
defines.push('vr_gearvr');
}
else if (this.options.vr === 'cardboard') {
defines.push('vr_cardboard');
}
else if (this.options.vr === 'rift') {
defines.push('vr_rift');
}
if (this.options.raytrace === 'dxr') {
defines.push('kha_dxr');
}
return {
from: this.options.from,
to: path.join(this.sysdir() + '-build', 'sources.c'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'hl',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
}
async copySound(platform, from, to, options) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let ogg = await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.ogg'), this.options.ogg);
return { files: [to + '.ogg'], sizes: [1] };
}
else {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
}
async copyImage(platform, from, to, options, cache) {
if (platform === Platform_1.Platform.iOS && options.quality < 1) {
let format = await ImageTool_1.exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'pvr', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else if (platform === Platform_1.Platform.Windows && options.quality < 1 && (this.options.graphics === GraphicsApi_1.GraphicsApi.OpenGL || this.options.graphics === GraphicsApi_1.GraphicsApi.Vulkan)) {
// let format = await exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'ASTC', true, false, cache);
let format = await ImageTool_1.exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'DXT5', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
else {
let format = await ImageTool_1.exportImage(this.options.kha, from, path.join(this.options.to, this.sysdir(), to), options, 'lz4', true, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to).toString(), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
if (platform === Platform_1.Platform.Windows) {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.avi'), this.options.h264);
return { files: [to + '.avi'], sizes: [1] };
}
else if (platform === Platform_1.Platform.iOS || platform === Platform_1.Platform.OSX) {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
else if (platform === Platform_1.Platform.Android) {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.ts'), this.options.h264);
return { files: [to + '.ts'], sizes: [1] };
}
else {
await Converter_1.convert(from, path.join(this.options.to, this.sysdir(), to + '.ogv'), this.options.theora);
return { files: [to + '.ogv'], sizes: [1] };
}
}
}
exports.KoreHLExporter = KoreHLExporter;
//# sourceMappingURL=KoreHLExporter.js.map

View File

@ -0,0 +1,96 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KromExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const defaults = require("../defaults");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const GraphicsApi_1 = require("../GraphicsApi");
const ImageTool_1 = require("../ImageTool");
class KromExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
}
backend() {
return 'Krom';
}
haxeOptions(name, targetOptions, defines) {
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('sys_a2');
defines.push('kha_js');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_js');
let graphics = this.options.graphics;
if (graphics === GraphicsApi_1.GraphicsApi.Default) {
graphics = defaults.graphicsApi(this.options.target);
}
defines.push('kha_' + graphics);
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
defines.push('kha_a2');
if (this.options.debug) {
this.parameters.push('-debug');
defines.push('js-classic');
}
return {
from: this.options.from.toString(),
to: path.join(this.sysdir(), 'krom.js.temp'),
realto: path.join(this.sysdir(), 'krom.js'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'js',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir()));
}
async copySound(platform, from, to, options) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let ogg = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.ogg'), this.options.ogg);
return { files: [to + '.ogg'], sizes: [1] };
}
else {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
}
async copyImage(platform, from, to, options, cache) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), options, undefined, false, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let webm = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.webm'), this.options.webm);
let files = [];
let sizes = [];
if (webm) {
files.push(to + '.webm');
sizes.push(1);
}
return { files: files, sizes: sizes };
}
}
exports.KromExporter = KromExporter;
//# sourceMappingURL=KromExporter.js.map

View File

@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeExporter = void 0;
const Html5Exporter_1 = require("./Html5Exporter");
class NodeExporter extends Html5Exporter_1.Html5Exporter {
constructor(options) {
super(options);
}
backend() {
return 'Node';
}
isNode() {
return true;
}
}
exports.NodeExporter = NodeExporter;
//# sourceMappingURL=NodeExporter.js.map

View File

@ -0,0 +1,146 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlayStationMobileExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const CSharpExporter_1 = require("./CSharpExporter");
const ImageTool_1 = require("../ImageTool");
const uuid = require('uuid');
class PlayStationMobileExporter extends CSharpExporter_1.CSharpExporter {
constructor(options) {
super(options);
this.files = [];
}
backend() {
return 'PSM';
}
exportSLN(projectUuid) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir() + '-build'));
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Project.sln'));
const solutionUuid = uuid.v4();
this.p('Microsoft Visual Studio Solution File, Format Version 11.00');
this.p('# Visual Studio 2010');
this.p('Project("{' + solutionUuid.toString().toUpperCase() + '}") = "HaxeProject", "Project.csproj", "{' + projectUuid.toString().toUpperCase() + '}"');
this.p('EndProject');
this.p('Global');
this.p('GlobalSection(SolutionConfigurationPlatforms) = preSolution', 1);
this.p('Debug|Any CPU = Debug|Any CPU', 2);
this.p('Release|Any CPU = Release|Any CPU', 2);
this.p('EndGlobalSection', 1);
this.p('GlobalSection(ProjectConfigurationPlatforms) = postSolution', 1);
this.p('{" + projectUuid.toString().toUpperCase() + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU', 2);
this.p('{" + projectUuid.toString().toUpperCase() + "}.Debug|Any CPU.Build.0 = Debug|Any CPU', 2);
this.p('{" + projectUuid.toString().toUpperCase() + "}.Release|Any CPU.ActiveCfg = Release|Any CPU', 2);
this.p('{" + projectUuid.toString().toUpperCase() + "}.Release|Any CPU.Build.0 = Release|Any CPU', 2);
this.p('EndGlobalSection', 1);
this.p('GlobalSection(MonoDevelopProperties) = preSolution', 1);
this.p('StartupItem = Project.csproj', 2);
this.p('EndGlobalSection', 1);
this.p('EndGlobal');
this.closeFile();
}
exportResources() {
this.createDirectory(path.join(this.options.to, this.sysdir() + '-build', 'shaders'));
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Simple.fcg'), 'void main(float4 out Color : COLOR, uniform float4 MaterialColor) {\n'
+ '\tColor = MaterialColor;\n'
+ '}\n');
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Simple.vcg'), 'void main(float4 in a_Position : POSITION, float4 out v_Position : POSITION, uniform float4x4 WorldViewProj) {\n'
+ '\tv_Position = mul(a_Position, WorldViewProj);\n'
+ '}\n');
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Texture.fcg'), 'void main(float2 in v_TexCoord : TEXCOORD0, float4 out Color : COLOR, uniform sampler2D Texture0 : TEXUNIT0) {\n'
+ '\tColor = tex2D(Texture0, v_TexCoord);\n'
+ '}\n');
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Texture.vcg'), 'void main(float4 in a_Position : POSITION, float2 in a_TexCoord : TEXCOORD0, float4 out v_Position : POSITION, float2 out v_TexCoord : TEXCOORD0, uniform float4x4 WorldViewProj) {\n'
+ '\tv_Position = mul(a_Position, WorldViewProj);\n'
+ '\tv_TexCoord = a_TexCoord;\n'
+ '}\n');
let appxml = path.join(this.options.to, this.sysdir() + '-build', 'app.xml');
if (!fs.existsSync(appxml)) {
let appxmltext = fs.readFileSync(path.join(__dirname, 'Data', 'psm', 'app.xml'), { encoding: 'utf8' });
fs.writeFileSync(appxml.toString(), appxmltext);
}
}
exportCsProj(projectUuid) {
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Project.csproj'));
this.p('<?xml version="1.0" encoding="utf-8"?>');
this.p('<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">');
this.p('<PropertyGroup>', 1);
this.p('<Configuration Condition=" \'$(Configuration)\' == \'\' ">Debug</Configuration>', 2);
this.p('<Platform Condition=" \'$(Platform)\' == \'\' ">AnyCPU</Platform>', 2);
this.p('<ProductVersion>10.0.0</ProductVersion>', 2);
this.p('<SchemaVersion>2.0</SchemaVersion>', 2);
this.p('<ProjectGuid>{' + projectUuid.toString().toUpperCase() + '}</ProjectGuid>', 2);
this.p('<ProjectTypeGuids>{69878862-DA7D-4DC6-B0A1-50D8FAB4242F};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>', 2);
this.p('<OutputType>Exe</OutputType>', 2);
this.p('<RootNamespace>PSTest</RootNamespace>', 2);
this.p('<AssemblyName>PSTest</AssemblyName>', 2);
this.p('</PropertyGroup>', 1);
this.p('<PropertyGroup Condition=" \'$(Configuration)|$(Platform)\' == \'Debug|AnyCPU\' ">', 1);
this.p('<DebugSymbols>true</DebugSymbols>', 2);
this.p('<DebugType>full</DebugType>', 2);
this.p('<Optimize>false</Optimize>', 2);
this.p('<OutputPath>bin\\Debug</OutputPath>', 2);
this.p('<DefineConstants>DEBUG;</DefineConstants>', 2);
this.p('<ErrorReport>prompt</ErrorReport>', 2);
this.p('<WarningLevel>4</WarningLevel>', 2);
this.p('<ConsolePause>false</ConsolePause>', 2);
this.p('</PropertyGroup>', 1);
this.p('<PropertyGroup Condition=" \'$(Configuration)|$(Platform)\' == \'Release|AnyCPU\' ">', 1);
this.p('<DebugType>none</DebugType>', 2);
this.p('<Optimize>true</Optimize>', 2);
this.p('<OutputPath>bin\\Release</OutputPath>', 2);
this.p('<ErrorReport>prompt</ErrorReport>', 2);
this.p('<WarningLevel>4</WarningLevel>', 2);
this.p('<ConsolePause>false</ConsolePause>', 2);
this.p('</PropertyGroup>', 1);
this.p('<ItemGroup>', 1);
this.p('<Reference Include="System" />', 2);
this.p('<Reference Include="System.Xml" />', 2);
this.p('<Reference Include="System.Core" />', 2);
this.p('<Reference Include="Sce.PlayStation.Core" />', 2);
this.p('</ItemGroup>', 1);
this.p('<ItemGroup>', 1);
this.includeFiles(path.join(this.options.to, this.sysdir() + '-build', 'Sources', 'src'), path.join(this.options.to, this.sysdir() + '-build'));
this.p('</ItemGroup>', 1);
this.p('<ItemGroup>', 1);
this.p('<ShaderProgram Include="shaders\\Simple.fcg" />', 2);
this.p('<ShaderProgram Include="shaders\\Simple.vcg" />', 2);
this.p('<ShaderProgram Include="shaders\\Texture.fcg" />', 2);
this.p('<ShaderProgram Include="shaders\\Texture.vcg" />', 2);
this.p('</ItemGroup>', 1);
this.p('<ItemGroup>', 1);
this.p('<Folder Include="resources\\" />', 2);
this.p('</ItemGroup>', 1);
this.p('<ItemGroup>', 1);
for (let file of this.files) {
this.p('<Content Include="..\\' + this.sysdir() + '\\' + file.toString() + '">', 2);
this.p('<Link>resources\\' + file.toString() + '</Link>', 3);
this.p('</Content>', 2);
}
this.p('</ItemGroup>', 1);
this.p('<Import Project="$(MSBuildExtensionsPath)\\Sce\\Sce.Psm.CSharp.targets" />', 1);
this.p('</Project>');
this.closeFile();
}
/*copyMusic(platform, from, to, encoders, callback) {
callback();
}*/
async copySound(platform, from, to) {
return { files: [''], sizes: [1] };
}
async copyImage(platform, from, to, asset, cache) {
this.files.push(asset['file']);
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), to), asset, undefined, false, false, cache);
return { files: [to + '.' + format], sizes: [1] };
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
this.files.push(to);
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
return { files: [''], sizes: [1] };
}
}
exports.PlayStationMobileExporter = PlayStationMobileExporter;
//# sourceMappingURL=PlayStationMobileExporter.js.map

View File

@ -0,0 +1,87 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnityExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const KhaExporter_1 = require("./KhaExporter");
const Converter_1 = require("../Converter");
const ImageTool_1 = require("../ImageTool");
const uuid = require('uuid');
class UnityExporter extends KhaExporter_1.KhaExporter {
constructor(options) {
super(options);
}
backend() {
return 'Unity';
}
haxeOptions(name, targetOptions, defines) {
const sources = path.join(this.options.to, this.sysdir(), 'Assets', 'Sources');
if (fs.existsSync(sources)) {
fs.removeSync(sources);
}
defines.push('no-root');
defines.push('no-compilation');
defines.push('sys_' + this.options.target);
defines.push('sys_g1');
defines.push('sys_g2');
defines.push('sys_g3');
defines.push('sys_g4');
defines.push('sys_a1');
defines.push('kha_cs');
defines.push('kha_' + this.options.target);
defines.push('kha_' + this.options.target + '_cs');
defines.push('kha_g1');
defines.push('kha_g2');
defines.push('kha_g3');
defines.push('kha_g4');
defines.push('kha_a1');
return {
from: this.options.from,
to: path.join(this.sysdir(), 'Assets', 'Sources'),
sources: this.sources,
libraries: this.libraries,
defines: defines,
parameters: this.parameters,
haxeDirectory: this.options.haxe,
system: this.sysdir(),
language: 'cs',
width: this.width,
height: this.height,
name: name,
main: this.options.main,
};
}
async export(name, targetOptions, haxeOptions) {
let copyDirectory = (from, to) => {
let files = fs.readdirSync(path.join(__dirname, '..', '..', 'Data', 'unity', from));
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), to));
for (let file of files) {
let text = fs.readFileSync(path.join(__dirname, '..', '..', 'Data', 'unity', from, file), 'utf8');
fs.writeFileSync(path.join(this.options.to, this.sysdir(), to, file), text);
}
};
copyDirectory('Assets', 'Assets');
copyDirectory('Editor', 'Assets/Editor');
copyDirectory('ProjectSettings', 'ProjectSettings');
}
/*copyMusic(platform, from, to, encoders, callback) {
callback([to]);
}*/
async copySound(platform, from, to) {
let ogg = await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), 'Assets', 'Resources', 'Sounds', to + '.ogg'), this.options.ogg);
return { files: [to + '.ogg'], sizes: [1] };
}
async copyImage(platform, from, to, asset, cache) {
let format = await (0, ImageTool_1.exportImage)(this.options.kha, this.options.kraffiti, from, path.join(this.options.to, this.sysdir(), 'Assets', 'Resources', 'Images', to), asset, undefined, false, true, cache);
return { files: [to + '.' + format], sizes: [1] };
}
async copyBlob(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), 'Assets', 'Resources', 'Blobs', to + '.bytes'), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform, from, to) {
return { files: [to], sizes: [1] };
}
}
exports.UnityExporter = UnityExporter;
//# sourceMappingURL=UnityExporter.js.map

View File

@ -0,0 +1,277 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WpfExporter = void 0;
const fs = require("fs-extra");
const path = require("path");
const CSharpExporter_1 = require("./CSharpExporter");
const Converter_1 = require("../Converter");
const uuid = require('uuid');
class WpfExporter extends CSharpExporter_1.CSharpExporter {
constructor(options) {
super(options);
}
backend() {
return 'WPF';
}
exportResources() {
fs.ensureDirSync(path.join(this.options.to, this.sysdir() + '-build', 'Properties'));
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Properties', 'AssemblyInfo.cs'));
this.p('using System.Reflection;');
this.p('using System.Resources;');
this.p('using System.Runtime.CompilerServices;');
this.p('using System.Runtime.InteropServices;');
this.p('using System.Windows;');
this.p();
this.p('[assembly: AssemblyTitle("HaxeProject")]');
this.p('[assembly: AssemblyDescription("")]');
this.p('[assembly: AssemblyConfiguration("")]');
this.p('[assembly: AssemblyCompany("Kha Development Team")]');
this.p('[assembly: AssemblyProduct("HaxeProject")]');
this.p('[assembly: AssemblyCopyright("Copyright ? Kha Development Team 2018")]');
this.p('[assembly: AssemblyTrademark("")]');
this.p('[assembly: AssemblyCulture("")]');
this.p();
this.p('[assembly: ComVisible(false)]');
this.p();
this.p('//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]');
this.p();
this.p('[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]');
this.p();
this.p('// [assembly: AssemblyVersion("1.0.*")]');
this.p('[assembly: AssemblyVersion("1.0.0.0")]');
this.p('[assembly: AssemblyFileVersion("1.0.0.0")]');
this.closeFile();
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Properties', 'Resources.Designer.cs'));
this.p('namespace WpfApplication1.Properties {');
this.p('[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]', 1);
this.p('[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]', 1);
this.p('[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]', 1);
this.p('internal class Resources', 1);
this.p('{', 1);
this.p('private static global::System.Resources.ResourceManager resourceMan;', 2);
this.p('private static global::System.Globalization.CultureInfo resourceCulture;', 2);
this.p();
this.p('[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]', 2);
this.p('internal Resources() { }', 2);
this.p();
this.p('[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]', 2);
this.p('internal static global::System.Resources.ResourceManager ResourceManager', 2);
this.p('{', 2);
this.p('get', 3);
this.p('{', 3);
this.p('if ((resourceMan == null))', 4);
this.p('{', 4);
this.p('global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfApplication1.Properties.Resources", typeof(Resources).Assembly);', 5);
this.p('resourceMan = temp;', 5);
this.p('}', 4);
this.p('return resourceMan;', 4);
this.p('}', 3);
this.p('}', 2);
this.p();
this.p('[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]', 2);
this.p('internal static global::System.Globalization.CultureInfo Culture', 2);
this.p('{', 2);
this.p('get', 3);
this.p('{', 3);
this.p('return resourceCulture;', 4);
this.p('}', 3);
this.p('set', 3);
this.p('{', 3);
this.p('resourceCulture = value;', 4);
this.p('}', 3);
this.p('}', 2);
this.p('}', 1);
this.p('}');
this.closeFile();
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Properties', 'Resources.resx'));
this.p('<?xml version="1.0" encoding="utf-8"?>');
this.p('<root>');
this.p('<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">');
this.p('<xsd:element name="root" msdata:IsDataSet="true">');
this.p('<xsd:complexType>');
this.p('<xsd:choice maxOccurs="unbounded">');
this.p('<xsd:element name="metadata">');
this.p('<xsd:complexType>');
this.p('<xsd:sequence>');
this.p('<xsd:element name="value" type="xsd:string" minOccurs="0" />');
this.p('</xsd:sequence>');
this.p('<xsd:attribute name="name" type="xsd:string" />');
this.p('<xsd:attribute name="type" type="xsd:string" />');
this.p('<xsd:attribute name="mimetype" type="xsd:string" />');
this.p('</xsd:complexType>');
this.p('</xsd:element>');
this.p('<xsd:element name="assembly">');
this.p('<xsd:complexType>');
this.p('<xsd:attribute name="alias" type="xsd:string" />');
this.p('<xsd:attribute name="name" type="xsd:string" />');
this.p('</xsd:complexType>');
this.p('</xsd:element>');
this.p('<xsd:element name="data">');
this.p('<xsd:complexType>');
this.p('<xsd:sequence>');
this.p('<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />');
this.p('<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />');
this.p('</xsd:sequence>');
this.p('<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />');
this.p('<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />');
this.p('<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />');
this.p('</xsd:complexType>');
this.p('</xsd:element>');
this.p('<xsd:element name="resheader">');
this.p('<xsd:complexType>');
this.p('<xsd:sequence>');
this.p('<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />');
this.p('</xsd:sequence>');
this.p('<xsd:attribute name="name" type="xsd:string" use="required" />');
this.p('</xsd:complexType>');
this.p('</xsd:element>');
this.p('</xsd:choice>');
this.p('</xsd:complexType>');
this.p('</xsd:element>');
this.p('</xsd:schema>');
this.p('<resheader name="resmimetype">');
this.p('<value>text/microsoft-resx</value>');
this.p('</resheader>');
this.p('<resheader name="version">');
this.p('<value>2.0</value>');
this.p('</resheader>');
this.p('<resheader name="reader">');
this.p('<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>');
this.p('</resheader>');
this.p('<resheader name="writer">');
this.p('<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>');
this.p('</resheader>');
this.p('</root>');
this.closeFile();
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Properties', 'Settings.Designer.cs'));
this.p('namespace WpfApplication1.Properties');
this.p('{');
this.p('[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]', 1);
this.p('[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]', 1);
this.p('internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase', 1);
this.p('{', 1);
this.p('private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));', 2);
this.p();
this.p('public static Settings Default', 2);
this.p('{', 2);
this.p('get', 3);
this.p('{', 3);
this.p('return defaultInstance;', 4);
this.p('}', 3);
this.p('}', 2);
this.p('}', 1);
this.p('}');
this.closeFile();
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Properties', 'Settings.settings'));
this.p('<?xml version="1.0" encoding="utf-8"?>');
this.p('<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">');
this.p('<Profiles>');
this.p('<Profile Name="(Default)" />');
this.p('</Profiles>');
this.p('<Settings />');
this.p('</SettingsFile>');
this.closeFile();
}
exportCsProj(projectUuid) {
this.writeFile(path.join(this.options.to, this.sysdir() + '-build', 'Project.csproj'));
this.p('<?xml version="1.0" encoding="utf-8"?>');
this.p('<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">');
this.p('<PropertyGroup>', 1);
this.p('<Configuration Condition=" \'$(Configuration)\' == \'\' ">Debug</Configuration>', 2);
this.p('<Platform Condition=" \'$(Platform)\' == \'\' ">x86</Platform>', 2);
this.p('<ProductVersion>8.0.30703</ProductVersion>', 2);
this.p('<SchemaVersion>2.0</SchemaVersion>', 2);
this.p('<ProjectGuid>{' + projectUuid.toString().toUpperCase() + '}</ProjectGuid>', 2);
this.p('<OutputType>Library</OutputType>', 2);
this.p('<AppDesignerFolder>Properties</AppDesignerFolder>', 2);
this.p('<RootNamespace>WpfApplication1</RootNamespace>', 2);
this.p('<AssemblyName>WpfApplication1</AssemblyName>', 2);
this.p('<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>', 2);
this.p('<TargetFrameworkProfile>Client</TargetFrameworkProfile>', 2);
this.p('<FileAlignment>512</FileAlignment>', 2);
this.p('<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>', 2);
this.p('<WarningLevel>4</WarningLevel>', 2);
this.p('</PropertyGroup>', 1);
this.p('<PropertyGroup Condition=" \'$(Configuration)|$(Platform)\' == \'Debug|x86\' ">', 1);
this.p('<PlatformTarget>x86</PlatformTarget>', 2);
this.p('<DebugSymbols>true</DebugSymbols>', 2);
this.p('<DebugType>full</DebugType>', 2);
this.p('<Optimize>false</Optimize>', 2);
this.p('<OutputPath>bin\\Debug\\</OutputPath>', 2);
this.p('<DefineConstants>DEBUG;TRACE</DefineConstants>', 2);
this.p('<ErrorReport>prompt</ErrorReport>', 2);
this.p('<WarningLevel>4</WarningLevel>', 2);
this.p('</PropertyGroup>', 1);
this.p('<PropertyGroup Condition=" \'$(Configuration)|$(Platform)\' == \'Release|x86\' ">', 1);
this.p('<PlatformTarget>x86</PlatformTarget>', 2);
this.p('<DebugType>pdbonly</DebugType>', 2);
this.p('<Optimize>true</Optimize>', 2);
this.p('<OutputPath>bin\\Release\\</OutputPath>', 2);
this.p('<DefineConstants>TRACE</DefineConstants>', 2);
this.p('<ErrorReport>prompt</ErrorReport>', 2);
this.p('<WarningLevel>4</WarningLevel>', 2);
this.p('</PropertyGroup>', 1);
this.p('<ItemGroup>', 1);
this.p('<Reference Include="System" />', 2);
this.p('<Reference Include="System.Data" />', 2);
this.p('<Reference Include="System.Xml" />', 2);
this.p('<Reference Include="Microsoft.CSharp" />', 2);
this.p('<Reference Include="System.Core" />', 2);
this.p('<Reference Include="System.Xml.Linq" />', 2);
this.p('<Reference Include="System.Data.DataSetExtensions" />', 2);
this.p('<Reference Include="System.Xaml">', 2);
this.p('<RequiredTargetFramework>4.0</RequiredTargetFramework>', 3);
this.p('</Reference>', 2);
this.p('<Reference Include="WindowsBase" />', 2);
this.p('<Reference Include="PresentationCore" />', 2);
this.p('<Reference Include="PresentationFramework" />', 2);
this.p('</ItemGroup>', 1);
this.p('<ItemGroup>', 1);
this.includeFiles(path.join(this.options.to, this.sysdir() + '-build', 'Sources', 'src'), path.join(this.options.to, this.sysdir() + '-build'));
this.p('</ItemGroup>', 1);
this.p('<ItemGroup>', 1);
this.p('<Compile Include="Properties\\AssemblyInfo.cs">', 2);
this.p('<SubType>Code</SubType>', 3);
this.p('</Compile>', 2);
this.p('<Compile Include="Properties\\Resources.Designer.cs">', 2);
this.p('<AutoGen>True</AutoGen>', 3);
this.p('<DesignTime>True</DesignTime>', 3);
this.p('<DependentUpon>Resources.resx</DependentUpon>', 3);
this.p('</Compile>', 2);
this.p('<Compile Include="Properties\\Settings.Designer.cs">', 2);
this.p('<AutoGen>True</AutoGen>', 3);
this.p('<DependentUpon>Settings.settings</DependentUpon>', 3);
this.p('<DesignTimeSharedInput>True</DesignTimeSharedInput>', 3);
this.p('</Compile>', 2);
this.p('<EmbeddedResource Include="Properties\\Resources.resx">', 2);
this.p('<Generator>ResXFileCodeGenerator</Generator>', 3);
this.p('<LastGenOutput>Resources.Designer.cs</LastGenOutput>', 3);
this.p('</EmbeddedResource>', 2);
this.p('<None Include="Properties\\Settings.settings">', 2);
this.p('<Generator>SettingsSingleFileGenerator</Generator>', 3);
this.p('<LastGenOutput>Settings.Designer.cs</LastGenOutput>', 3);
this.p('</None>', 2);
this.p('<AppDesigner Include="Properties\\" />', 2);
this.p('</ItemGroup>', 1);
this.p('<Import Project="$(MSBuildToolsPath)\\Microsoft.CSharp.targets" />', 1);
this.p('</Project>');
this.closeFile();
}
/*copyMusic(platform, from, to, encoders, callback) {
Files.createDirectories(this.directory.resolve(this.sysdir()).resolve(to).parent());
Converter.convert(from, this.directory.resolve(this.sysdir()).resolve(to + '.mp4'), encoders.aacEncoder, () => {
callback([to + '.mp4']);
});
}*/
async copySound(platform, from, to) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
async copyVideo(platform, from, to) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await (0, Converter_1.convert)(from, path.join(this.options.to, this.sysdir(), to + '.wmv'), this.options.wmv);
return { files: [to + '.wmv'], sizes: [1] };
}
}
exports.WpfExporter = WpfExporter;
//# sourceMappingURL=WpfExporter.js.map

View File

@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphicsApi = void 0;
exports.GraphicsApi = {
Default: 'default',
OpenGL: 'opengl',
OpenGL1: 'opengl1',
Direct3D9: 'direct3d9',
Direct3D11: 'direct3d11',
Direct3D12: 'direct3d12',
Metal: 'metal',
Vulkan: 'vulkan'
};
//# sourceMappingURL=GraphicsApi.js.map

View File

@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeHaxe = void 0;
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const log = require("./log");
const exec_1 = require("./exec");
function executeHaxe(from, haxeDirectory, options) {
return new Promise((resolve, reject) => {
let exe = 'haxe';
let env = process.env;
if (fs.existsSync(haxeDirectory) && fs.statSync(haxeDirectory).isDirectory()) {
let localexe = path.resolve(haxeDirectory, 'haxe' + (0, exec_1.sys)());
if (!fs.existsSync(localexe))
localexe = path.resolve(haxeDirectory, 'haxe');
if (fs.existsSync(localexe))
exe = localexe;
const stddir = path.resolve(haxeDirectory, 'std');
if (fs.existsSync(stddir) && fs.statSync(stddir).isDirectory()) {
env.HAXE_STD_PATH = stddir;
}
}
let haxe = child_process.spawn(exe, options, { env: env, cwd: path.normalize(from) });
haxe.stdout.on('data', (data) => {
log.info(data.toString());
});
haxe.stderr.on('data', (data) => {
log.error(data.toString());
});
haxe.on('close', (code) => {
if (code === 0) {
resolve();
}
else
reject('Haxe compiler error.');
});
});
}
exports.executeHaxe = executeHaxe;
//# sourceMappingURL=Haxe.js.map

View File

@ -0,0 +1,229 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HaxeCompiler = void 0;
const ProjectFile_1 = require("./ProjectFile");
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const chokidar = require("chokidar");
const log = require("./log");
const exec_1 = require("./exec");
const ws_1 = require("ws");
class HaxeCompiler {
constructor(from, temp, to, resourceDir, haxeDirectory, hxml, sourceDirectories, sysdir, port, isLiveReload, httpPort) {
this.ready = true;
this.todo = false;
this.port = '7000';
this.isLiveReload = false;
this.wsClients = [];
this.from = from;
this.temp = temp;
this.to = to;
this.resourceDir = resourceDir;
this.haxeDirectory = haxeDirectory;
this.hxml = hxml;
this.sysdir = sysdir;
this.port = port;
this.isLiveReload = isLiveReload;
this.sourceMatchers = [];
for (let dir of sourceDirectories) {
this.sourceMatchers.push(path.join(dir, '**').replace(/\\/g, '/'));
}
if (isLiveReload) {
this.wss = new ws_1.WebSocketServer({
port: parseInt(httpPort) + 1
});
this.wss.on('connection', (client) => {
if (this.wsClients.includes(client))
return;
this.wsClients.push(client);
});
}
}
close() {
if (this.watcher)
this.watcher.close();
if (this.compilationServer)
this.compilationServer.kill();
if (this.isLiveReload)
this.wss.close();
}
async run(watch) {
if (watch) {
this.watcher = chokidar.watch(this.sourceMatchers, { ignored: /[\/\\]\.(git|DS_Store)/, persistent: true, ignoreInitial: true });
this.watcher.on('add', (file) => {
this.scheduleCompile();
});
this.watcher.on('change', (file) => {
this.scheduleCompile();
});
this.watcher.on('unlink', (file) => {
this.scheduleCompile();
});
this.startCompilationServer();
this.triggerCompilationServer();
}
else {
try {
await this.compile();
}
catch (error) {
return Promise.reject(error);
}
}
return Promise.resolve();
}
scheduleCompile() {
if (this.ready) {
this.triggerCompilationServer();
}
else {
this.todo = true;
}
}
runHaxeAgain(parameters, onClose) {
let exe = 'haxe';
let env = process.env;
if (fs.existsSync(this.haxeDirectory) && fs.statSync(this.haxeDirectory).isDirectory()) {
let localexe = path.resolve(this.haxeDirectory, 'haxe' + (0, exec_1.sys)());
if (!fs.existsSync(localexe))
localexe = path.resolve(this.haxeDirectory, 'haxe');
if (fs.existsSync(localexe))
exe = localexe;
const stddir = path.resolve(this.haxeDirectory, 'std');
if (fs.existsSync(stddir) && fs.statSync(stddir).isDirectory()) {
env.HAXE_STD_PATH = stddir;
}
}
let haxe = child_process.spawn(exe, parameters, { env: env, cwd: path.normalize(this.from) });
haxe.stdout.on('data', (data) => {
log.info(data.toString());
});
haxe.stderr.on('data', (data) => {
log.error(data.toString());
});
haxe.on('close', onClose);
return haxe;
}
runHaxeAgainAndWait(parameters) {
return new Promise((resolve, reject) => {
this.runHaxeAgain(parameters, (code, signal) => {
if (code === 0) {
resolve();
}
else {
reject();
}
});
});
}
static cleanHxml(hxml) {
let params = [];
let ignoreNext = false;
let parameters = hxml.split('\n');
for (let parameter of parameters) {
if (!parameter.startsWith('-main') && !parameter.startsWith('-js')) {
params.push(parameter);
}
}
return params.join('\n');
}
runHaxe(parameters, onClose) {
if (fs.existsSync(path.join(this.resourceDir, 'workers.txt'))) {
fs.unlinkSync(path.join(this.resourceDir, 'workers.txt'));
}
let haxe = this.runHaxeAgain(parameters, async (code, signal) => {
if (fs.existsSync(path.join(this.resourceDir, 'workers.txt'))) {
let hxml = fs.readFileSync(path.join(this.from, parameters[0]), { encoding: 'utf8' });
let workers = fs.readFileSync(path.join(this.resourceDir, 'workers.txt'), { encoding: 'utf8' });
let lines = workers.split('\n');
for (let line of lines) {
if (line.trim() === '')
continue;
log.info('Creating ' + line + ' worker.');
let newhxml = HaxeCompiler.cleanHxml(hxml);
newhxml += '-main ' + line.trim() + '\n';
newhxml += '-js ' + path.join(this.sysdir, line.trim()) + '.js\n';
newhxml += '-D kha_in_worker\n';
fs.writeFileSync(path.join(this.from, 'temp.hxml'), newhxml, { encoding: 'utf8' });
await this.runHaxeAgainAndWait(['temp.hxml']);
}
onClose(code, signal);
}
else {
onClose(code, signal);
}
});
return haxe;
}
startCompilationServer() {
this.compilationServer = this.runHaxe(['--wait', this.port], (code) => {
log.info('Haxe compilation server stopped.');
});
}
triggerCompilationServer() {
process.stdout.write('\x1Bc');
log.info('Haxe compilation...');
this.ready = false;
this.todo = false;
return new Promise((resolve, reject) => {
this.runHaxe(['--connect', this.port, this.hxml], (code) => {
if (this.to && fs.existsSync(path.join(this.from, this.temp))) {
fs.renameSync(path.join(this.from, this.temp), path.join(this.from, this.to));
}
this.ready = true;
if (code === 0) {
process.stdout.write('\x1Bc');
log.info('Haxe compile end.');
if (this.isLiveReload) {
this.wsClients.forEach(client => {
client.send(JSON.stringify({}));
});
}
for (let callback of ProjectFile_1.Callbacks.postHaxeRecompilation) {
callback();
}
}
else {
log.info('Haxe compile error.');
}
if (code === 0) {
resolve();
}
// (node:3630) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,
// promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
// else reject('Haxe compiler error.');
if (this.todo) {
this.scheduleCompile();
}
});
});
}
compile() {
return new Promise((resolve, reject) => {
this.runHaxe([this.hxml], (code) => {
if (code === 0) {
if (this.to && fs.existsSync(path.join(this.from, this.temp))) {
fs.renameSync(path.join(this.from, this.temp), path.join(this.from, this.to));
}
resolve();
}
else {
process.exitCode = 1;
log.error('Haxe compiler error.');
reject();
}
});
});
}
static spinRename(from, to) {
for (;;) {
if (fs.existsSync(from)) {
fs.renameSync(from, to);
return;
}
}
}
}
exports.HaxeCompiler = HaxeCompiler;
//# sourceMappingURL=HaxeCompiler.js.map

View File

@ -0,0 +1,414 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeHaxeProject = void 0;
const fs = require("fs-extra");
const path = require("path");
const XmlWriter_1 = require("./XmlWriter");
function copyAndReplace(from, to, names, values) {
let data = fs.readFileSync(from, { encoding: 'utf8' });
for (let i = 0; i < names.length; ++i) {
data = data.replace(new RegExp(names[i], 'g'), values[i]);
}
fs.writeFileSync(to, data, { encoding: 'utf8' });
}
function escapeXml(s) {
return s.replace(/[<>&'"]/g, c => {
switch (c) {
case '<': return '&lt;';
case '>': return '&gt;';
case '&': return '&amp;';
case '\'': return '&apos;';
case '"': return '&quot;';
default: throw 'unreachable code';
}
});
}
function IntelliJ(projectdir, options) {
let indir = path.join(__dirname, '..', 'Data', 'intellij');
let outdir = path.join(projectdir, options.safeName + '-' + options.system + '-intellij');
let sources = '';
for (let i = 0; i < options.sources.length; ++i) {
if (path.isAbsolute(options.sources[i])) {
sources += ' <sourceFolder url="file://' + options.sources[i] + '" isTestSource="false" />\n';
}
else {
sources += ' <sourceFolder url="file://$MODULE_DIR$/' + path.relative(outdir, path.resolve(options.from, options.sources[i])).replace(/\\/g, '/') + '" isTestSource="false" />\n';
}
}
let libraries = '';
for (let i = 0; i < options.libraries.length; ++i) {
if (path.isAbsolute(options.libraries[i].libpath)) {
libraries += ' <content url="file://' + options.libraries[i].libroot + '">\n';
libraries += ' <sourceFolder url="file://' + options.libraries[i].libpath + '" isTestSource="false" />\n';
}
else {
libraries += ' <content url="file://$MODULE_DIR$/' + path.relative(outdir, path.resolve(options.from, options.libraries[i].libroot)).replace(/\\/g, '/') + '">\n';
libraries += ' <sourceFolder url="file://$MODULE_DIR$/' + path.relative(outdir, path.resolve(options.from, options.libraries[i].libpath)).replace(/\\/g, '/') + '" isTestSource="false" />\n';
}
libraries += ' </content>\n';
}
let args = '';
let defines = '';
for (let i = 0; i < options.defines.length; ++i) {
defines += options.defines[i];
if (i < options.defines.length - 1)
defines += ',';
}
for (let param of options.parameters) {
defines += param + ',';
}
let target;
switch (options.language) {
case 'hl':
case 'cpp':
target = 'C++';
break;
case 'as':
target = 'Flash';
args = '-swf-version 16.0';
break;
case 'cs':
target = 'C#';
if (fs.existsSync(options.haxeDirectory) && fs.statSync(options.haxeDirectory).isDirectory() && fs.existsSync(path.join(options.haxeDirectory, 'netlib'))) {
args = '-net-std ' + path.relative(outdir, path.join(options.haxeDirectory, 'netlib'));
}
break;
case 'java':
target = 'Java';
if (fs.existsSync(options.haxeDirectory) && fs.statSync(options.haxeDirectory).isDirectory() && fs.existsSync(path.join(options.haxeDirectory, 'hxjava', 'hxjava-std.jar'))) {
args = '-java-lib ' + path.relative(outdir, path.join(options.haxeDirectory, 'hxjava', 'hxjava-std.jar'));
}
break;
case 'js':
target = 'JavaScript';
break;
}
fs.copySync(path.join(indir, 'name.iml'), path.join(outdir, options.name + '.iml'), { overwrite: true });
copyAndReplace(path.join(indir, 'name.iml'), path.join(outdir, options.name + '.iml'), ['{name}', '{sources}', '{libraries}', '{target}', '{system}', '{args}'], [options.safeName, sources, libraries, target, options.system, args]);
fs.copySync(path.join(indir, 'idea', 'compiler.xml'), path.join(outdir, '.idea', 'compiler.xml'), { overwrite: true });
copyAndReplace(path.join(indir, 'idea', 'haxe.xml'), path.join(outdir, '.idea', 'haxe.xml'), ['{defines}'], [defines]);
fs.copySync(path.join(indir, 'idea', 'misc.xml'), path.join(outdir, '.idea', 'misc.xml'), { overwrite: true });
copyAndReplace(path.join(indir, 'idea', 'modules.xml'), path.join(outdir, '.idea', 'modules.xml'), ['{name}'], [options.name]);
fs.copySync(path.join(indir, 'idea', 'vcs.xml'), path.join(outdir, '.idea', 'vcs.xml'), { overwrite: true });
copyAndReplace(path.join(indir, 'idea', 'name'), path.join(outdir, '.idea', '.name'), ['{name}'], [options.name]);
fs.copySync(path.join(indir, 'idea', 'copyright', 'profiles_settings.xml'), path.join(outdir, '.idea', 'copyright', 'profiles_settings.xml'), { overwrite: true });
}
function hxml(projectdir, options) {
let data = '';
let lines = [];
// returns only unique lines and '' otherwise
function unique(line) {
if (lines.indexOf(line) === -1) {
lines.push(line);
return line;
}
return '';
}
for (let i = 0; i < options.sources.length; ++i) {
if (path.isAbsolute(options.sources[i])) {
data += unique('-cp ' + options.sources[i] + '\n');
}
else {
data += unique('-cp ' + path.relative(projectdir, path.resolve(options.from, options.sources[i])) + '\n'); // from.resolve('build').relativize(from.resolve(this.sources[i])).toString());
}
}
for (let i = 0; i < options.libraries.length; ++i) {
if (path.isAbsolute(options.libraries[i].libpath)) {
data += unique('-cp ' + options.libraries[i].libpath + '\n');
}
else {
data += unique('-cp ' + path.relative(projectdir, path.resolve(options.from, options.libraries[i].libpath)) + '\n'); // from.resolve('build').relativize(from.resolve(this.sources[i])).toString());
}
}
for (let d in options.defines) {
let define = options.defines[d];
data += unique('-D ' + define + '\n');
}
if (options.language === 'cpp') {
data += unique('-cpp ' + path.normalize(options.to) + '\n');
}
else if (options.language === 'cs') {
data += unique('-cs ' + path.normalize(options.to) + '\n');
if (fs.existsSync(options.haxeDirectory) && fs.statSync(options.haxeDirectory).isDirectory() && fs.existsSync(path.join(options.haxeDirectory, 'netlib'))) {
data += unique('-net-std ' + path.relative(projectdir, path.join(options.haxeDirectory, 'netlib')) + '\n');
}
}
else if (options.language === 'java') {
data += unique('-java ' + path.normalize(options.to) + '\n');
if (fs.existsSync(options.haxeDirectory) && fs.statSync(options.haxeDirectory).isDirectory() && fs.existsSync(path.join(options.haxeDirectory, 'hxjava', 'hxjava-std.jar'))) {
data += unique('-java-lib ' + path.relative(projectdir, path.join(options.haxeDirectory, 'hxjava', 'hxjava-std.jar')) + '\n');
}
}
else if (options.language === 'js') {
data += unique('-js ' + path.normalize(options.to) + '\n');
}
else if (options.language === 'as') {
data += unique('-swf ' + path.normalize(options.to) + '\n');
data += unique('-swf-version ' + options.swfVersion + '\n');
data += unique('-swf-header ' + options.width + ':' + options.height + ':' + options.framerate + ':' + options.stageBackground + '\n');
}
else if (options.language === 'xml') {
data += unique('-xml ' + path.normalize(options.to) + '\n');
data += unique('--macro include(\'kha\')\n');
}
else if (options.language === 'hl') {
data += unique('-hl ' + path.normalize(options.to) + '\n');
}
for (let param of options.parameters) {
data += unique(param + '\n');
}
if (!options.parameters.some((param) => param.includes('-main '))) {
const entrypoint = options ? options.main ? options.main : 'Main' : 'Main';
data += unique('-main ' + entrypoint + '\n');
}
fs.outputFileSync(path.join(projectdir, 'project-' + options.system + '.hxml'), data);
}
function FlashDevelop(projectdir, options) {
let platform;
switch (options.language) {
case 'hl':
case 'cpp':
platform = 'C++';
break;
case 'as':
platform = 'Flash Player';
break;
case 'cs':
platform = 'C#';
break;
case 'java':
platform = 'Java';
break;
case 'js':
platform = 'JavaScript';
break;
}
options.swfVersion = 'swfVersion' in options ? options.swfVersion : 16.0;
options.stageBackground = 'stageBackground' in options ? options.stageBackground : 'ffffff';
options.framerate = 'framerate' in options ? options.framerate : 30;
let swfVersion = parseFloat(options.swfVersion).toFixed(1).split('.');
let output = {
n: 'output',
e: [
{
n: 'movie',
outputType: 'Application'
},
{
n: 'movie',
input: ''
},
{
n: 'movie',
path: path.normalize(options.to)
},
{
n: 'movie',
fps: options.framerate
},
{
n: 'movie',
width: options.width
},
{
n: 'movie',
height: options.height
},
{
n: 'movie',
version: swfVersion[0]
},
{
n: 'movie',
minorVersion: swfVersion[1]
},
{
n: 'movie',
platform: platform
},
{
n: 'movie',
background: '#' + options.stageBackground
}
]
};
if (fs.existsSync(options.haxeDirectory) && fs.statSync(options.haxeDirectory).isDirectory()) {
output.e.push({
n: 'movie',
preferredSDK: path.relative(projectdir, options.haxeDirectory)
});
}
let classpaths = [];
for (let i = 0; i < options.sources.length; ++i) {
classpaths.push(path.relative(projectdir, path.resolve(options.from, options.sources[i])));
}
for (let i = 0; i < options.libraries.length; ++i) {
classpaths.push(path.relative(projectdir, path.resolve(options.from, options.libraries[i].libpath)));
}
let otheroptions = [
{
n: 'option',
showHiddenPaths: 'False'
}
];
if (options.language === 'cpp' || options.system === 'krom') {
otheroptions.push({
n: 'option',
testMovie: 'Custom'
});
otheroptions.push({
n: 'option',
testMovieCommand: 'run_' + options.system + '.bat'
});
}
else if (options.language === 'cs' || options.language === 'java') {
otheroptions.push({
n: 'option',
testMovie: 'OpenDocument'
});
otheroptions.push({
n: 'option',
testMovieCommand: ''
});
}
else if (options.language === 'js') {
otheroptions.push({
n: 'option',
testMovie: 'Webserver'
});
otheroptions.push({
n: 'option',
testMovieCommand: path.join(path.parse(options.to).dir, 'index.html')
});
}
else {
otheroptions.push({
n: 'option',
testMovie: 'Default'
});
}
let def = '';
for (let d of options.defines) {
def += '-D ' + d + '&#xA;';
}
if (options.language === 'java' && fs.existsSync(options.haxeDirectory) && fs.statSync(options.haxeDirectory).isDirectory() && fs.existsSync(path.join(options.haxeDirectory, 'hxjava', 'hxjava-std.jar'))) {
def += '-java-lib ' + path.relative(projectdir, path.join(options.haxeDirectory, 'hxjava', 'hxjava-std.jar')) + '&#xA;';
}
if (options.language === 'cs' && fs.existsSync(options.haxeDirectory) && fs.statSync(options.haxeDirectory).isDirectory() && fs.existsSync(path.join(options.haxeDirectory, 'netlib'))) {
def += '-net-std ' + path.relative(projectdir, path.join(options.haxeDirectory, 'netlib')) + '&#xA;';
}
def += '-D kha_output=&quot;' + path.resolve(path.join(projectdir, options.to)) + '&quot;&#xA;';
let mainClass = 'Main';
for (let param of options.parameters) {
const mainRe = /-main\s+([^\s]+)/.exec(param);
if (mainRe) {
mainClass = mainRe[1];
}
else {
def += escapeXml(param) + '&#xA;';
}
}
let project = {
n: 'project',
version: '2',
e: [
'Output SWF options',
output,
'Other classes to be compiled into your SWF',
{
n: 'classpaths',
e: classpaths
.reduce((a, b) => {
if (a.indexOf(b) < 0)
a.push(b);
return a;
}, [])
.map((e) => {
return { n: 'class', path: e };
})
},
'Build options',
{
n: 'build',
e: [
{
n: 'option',
directives: ''
},
{
n: 'option',
flashStrict: 'False'
},
{
n: 'option',
noInlineOnDebug: 'False'
},
{
n: 'option',
mainClass: mainClass
},
{
n: 'option',
enabledebug: options.language === 'as' ? 'True' : 'False'
},
{
n: 'option',
additional: def
}
]
},
'haxelib libraries',
{
n: 'haxelib',
e: [
'example: <library name="..." />'
]
},
'Class files to compile (other referenced classes will automatically be included)',
{
n: 'compileTargets',
e: [
{
n: 'compile',
path: '..\\Sources\\Main.hx'
}
]
},
'Paths to exclude from the Project Explorer tree',
{
n: 'hiddenPaths',
e: [
'example: <hidden path="..." />'
]
},
'Executed before build',
{
n: 'preBuildCommand'
},
'Executed after build',
{
n: 'postBuildCommand',
alwaysRun: 'False'
},
'Other project options',
{
n: 'options',
e: otheroptions
},
'Plugin storage',
{
n: 'storage'
}
]
};
(0, XmlWriter_1.writeXml)(project, path.join(projectdir, options.safeName + '-' + options.system + '.hxproj'));
}
function writeHaxeProject(projectdir, projectFiles, options) {
hxml(projectdir, options);
if (projectFiles) {
FlashDevelop(projectdir, options);
IntelliJ(projectdir, options);
}
}
exports.writeHaxeProject = writeHaxeProject;
//# sourceMappingURL=HaxeProject.js.map

View File

@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.exportBmp = exports.exportPng24 = exports.exportPng = exports.exportIcns = exports.exportIco = void 0;
const cp = require("child_process");
const fs = require("fs");
const path = require("path");
const log = require("./log");
const exec = require("./exec");
function run(exe, from, to, width, height, format, background, transparent, callback) {
let params = ['from=' + from, 'to=' + to, 'format=' + format, 'keepaspect'];
if (width > 0)
params.push('width=' + width);
if (height > 0)
params.push('height=' + height);
if (background !== undefined && !transparent)
params.push('background=' + background.toString(16));
if (transparent)
params.push('transparent=' + background.toString(16));
let child = cp.spawn(exe, params);
child.stdout.on('data', (data) => {
// log.info('kraffiti stdout: ' + data);
});
child.stderr.on('data', (data) => {
log.error('kraffiti stderr: ' + data);
});
child.on('error', (err) => {
log.error('kraffiti error: ' + err);
});
child.on('close', (code) => {
if (code !== 0)
log.error('kraffiti exited with code ' + code);
callback();
});
}
function findIcon(icon, from, options) {
if (icon && fs.existsSync(path.join(from, icon)))
return path.join(from, icon);
if (fs.existsSync(path.join(from, 'icon.png')))
return path.join(from, 'icon.png');
else
return path.join(options.kha, 'Kinc', 'Tools', exec.sysdir(), 'icon.png');
}
function exportIco(icon, to, from, options) {
run(options.kraffiti, findIcon(icon, from.toString(), options), to.toString(), 0, 0, 'ico', undefined, false, function () { });
}
exports.exportIco = exportIco;
function exportIcns(icon, to, from, options) {
run(options.kraffiti, findIcon(icon, from.toString(), options), to.toString(), 0, 0, 'icns', undefined, false, function () { });
}
exports.exportIcns = exportIcns;
function exportPng(icon, to, width, height, background, transparent, from, options) {
run(options.kraffiti, findIcon(icon, from.toString(), options), to.toString(), width, height, 'png', background, transparent, function () { });
}
exports.exportPng = exportPng;
function exportPng24(icon, to, width, height, background, transparent, from, options) {
run(options.kraffiti, findIcon(icon, from.toString(), options), to.toString(), width, height, 'png24', background, transparent, function () { });
}
exports.exportPng24 = exportPng24;
function exportBmp(icon, to, width, height, background, from, options) {
run(options.kraffiti, findIcon(icon, from.toString(), options), to.toString(), width, height, 'bmp', background, false, function () { });
}
exports.exportBmp = exportBmp;
//# sourceMappingURL=Icon.js.map

View File

@ -0,0 +1,159 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.exportImage = void 0;
const child_process = require("child_process");
const fs = require("fs-extra");
const path = require("path");
const log = require("./log");
function getWidthAndHeight(kha, exe, from, to, options, format, prealpha) {
return new Promise((resolve, reject) => {
let params = ['from=' + from, 'to=' + to, 'format=' + format, 'donothing'];
if (options.scale !== undefined && options.scale !== 1) {
params.push('scale=' + options.scale);
}
let process = child_process.spawn(exe, params);
let output = '';
process.stdout.on('data', (data) => {
output += data.toString();
});
process.stderr.on('data', (data) => {
});
process.on('close', (code) => {
if (code !== 0) {
log.error('kraffiti process exited with code ' + code + ' when trying to get size of ' + path.parse(from).name);
resolve({ w: 0, h: 0 });
return;
}
const lines = output.split('\n');
for (let line of lines) {
if (line.startsWith('#')) {
let numbers = line.substring(1).split('x');
resolve({ w: parseInt(numbers[0]), h: parseInt(numbers[1]) });
return;
}
}
resolve({ w: 0, h: 0 });
});
});
}
function convertImage(from, temp, to, kha, exe, params, options, cache) {
return new Promise((resolve, reject) => {
let process = child_process.spawn(exe, params);
let output = '';
process.stdout.on('data', (data) => {
output += data.toString();
});
process.stderr.on('data', (data) => {
});
process.on('close', (code) => {
if (code !== 0) {
log.error('kraffiti process exited with code ' + code + ' when trying to convert ' + path.parse(from).name);
resolve();
return;
}
fs.renameSync(temp, to);
const lines = output.split('\n');
for (let line of lines) {
if (line.startsWith('#')) {
let numbers = line.substring(1).split('x');
cache[to] = {};
cache[to].original_width = options.original_width = parseInt(numbers[0]);
cache[to].original_height = options.original_height = parseInt(numbers[1]);
resolve();
return;
}
}
resolve();
});
});
}
async function exportImage(kha, exe, from, to, options, format, prealpha, poweroftwo, cache) {
if (format === undefined) {
if (from.toString().endsWith('.png'))
format = 'png';
else if (from.toString().endsWith('.hdr'))
format = 'hdr';
else
format = 'jpg';
}
if (format === 'jpg' && (options.scale === undefined || options.scale === 1) && options.background === undefined) {
to = to + '.jpg';
}
else if (format === 'pvr') {
to = to + '.pvr';
}
else if (format === 'ASTC') {
to = to + '.astc.k';
}
else if (format === 'DXT5') {
to = to + '.dxt5.k';
}
else if (format === 'hdr') {
to = to + '.hdr';
}
else if (format === 'lz4') {
to += '.k';
}
else {
format = 'png';
if (prealpha)
to = to + '.kng';
else
to = to + '.png';
}
let temp = to + '.temp';
let outputformat = format;
if (format === 'png' && prealpha) {
outputformat = 'kng';
}
if (format === 'lz4') {
outputformat = 'k';
}
if (format === 'ASTC') {
outputformat = 'astc.k';
}
if (format === 'DXT5') {
outputformat = 'dxt5.k';
}
if (fs.existsSync(to) && fs.statSync(to).mtime.getTime() > fs.statSync(from.toString()).mtime.getTime()) {
if (cache[to] !== undefined) {
const cachedOptions = cache[to];
options.original_width = cachedOptions.original_width;
options.original_height = cachedOptions.original_height;
return outputformat;
}
let wh = await getWidthAndHeight(kha, exe, from, to, options, format, prealpha);
cache[to] = {};
cache[to].original_width = options.original_width = wh.w;
cache[to].original_height = options.original_height = wh.h;
return outputformat;
}
fs.ensureDirSync(path.dirname(to));
if (format === 'jpg' || format === 'hdr') {
fs.copySync(from, temp, { overwrite: true });
fs.renameSync(temp, to);
let wh = await getWidthAndHeight(kha, exe, from, to, options, format, prealpha);
options.original_width = wh.w;
options.original_height = wh.h;
return outputformat;
}
let params = ['from=' + from, 'to=' + temp, 'format=' + format];
if (!poweroftwo) {
params.push('filter=nearest');
}
if (prealpha)
params.push('prealpha');
if (options.scale !== undefined && options.scale !== 1) {
params.push('scale=' + options.scale);
}
if (options.background !== undefined) {
params.push('transparent=' + ((options.background.red << 24) | (options.background.green << 16) | (options.background.blue << 8) | 0xff).toString(16));
}
if (poweroftwo) {
params.push('poweroftwo');
}
await convertImage(from, temp, to, kha, exe, params, options, cache);
return outputformat;
}
exports.exportImage = exportImage;
//# sourceMappingURL=ImageTool.js.map

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Options = void 0;
class Options {
}
exports.Options = Options;
//# sourceMappingURL=Options.js.map

View File

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Platform = void 0;
exports.Platform = {
Krom: 'krom',
Windows: 'windows',
WindowsApp: 'windowsapp',
PlayStation3: 'ps3',
iOS: 'ios',
OSX: 'osx',
Android: 'android',
Xbox360: 'xbox360',
Linux: 'linux',
HTML5: 'html5',
HTML5Worker: 'html5worker',
Flash: 'flash',
WPF: 'wpf',
Java: 'java',
PlayStationMobile: 'psm',
Node: 'node',
DebugHTML5: 'debug-html5',
Empty: 'empty',
Pi: 'pi',
tvOS: 'tvos',
FreeBSD: 'freebsd',
Emscripten: 'emscripten'
};
//# sourceMappingURL=Platform.js.map

View File

@ -0,0 +1,292 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Project = exports.Target = exports.Library = void 0;
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const log = require("./log");
const ProjectFile_1 = require("./ProjectFile");
class Library {
}
exports.Library = Library;
class Target {
constructor(baseTarget, backends) {
this.baseTarget = baseTarget;
this.backends = backends;
}
}
exports.Target = Target;
function contains(main, sub) {
main = path.resolve(main);
sub = path.resolve(sub);
if (process.platform === 'win32') {
main = main.toLowerCase();
sub = sub.toLowerCase();
}
return sub.indexOf(main) === 0 && sub.slice(main.length)[0] === path.sep;
}
class Project {
constructor(name) {
this.icon = null;
this.name = name;
this.safeName = name.replace(/[^A-z0-9\-\_]/g, '-');
this.version = '1.0';
this.sources = [];
this.defines = ['hxcpp_smart_strings'];
this.cdefines = [];
this.cflags = [];
this.cppflags = [];
this.parameters = [];
this.scriptdir = Project.scriptdir;
this.libraries = [];
this.localLibraryPath = 'Libraries';
this.assetMatchers = [];
this.shaderMatchers = [];
this.customTargets = new Map();
this.stackSize = 0;
this.windowOptions = {};
this.targetOptions = {
html5: {},
flash: {},
android: {},
android_native: {},
ios: {},
xboxOne: {},
playStation4: {},
switch: {},
xboxSeriesXS: {},
playStation5: {},
stadia: {}
};
}
getSafeName() {
return this.safeName;
}
async addProject(projectDir) {
if (!path.isAbsolute(projectDir)) {
projectDir = path.join(this.scriptdir, projectDir);
}
if (!fs.existsSync(path.join(projectDir, 'khafile.js')) && (fs.existsSync(path.join(projectDir, 'kincfile.js')) || fs.existsSync(path.join(projectDir, 'korefile.js')) || fs.existsSync(path.join(projectDir, 'kfile.js')))) {
this.libraries.push({
libpath: projectDir,
libroot: projectDir
});
}
else {
let project = await (0, ProjectFile_1.loadProject)(projectDir, 'khafile.js', Project.platform);
this.assetMatchers = this.assetMatchers.concat(project.assetMatchers);
this.sources = this.sources.concat(project.sources);
this.shaderMatchers = this.shaderMatchers.concat(project.shaderMatchers);
this.defines = this.defines.concat(project.defines);
this.cdefines = this.cdefines.concat(project.cdefines);
this.cflags = this.cflags.concat(project.cflags);
this.cppflags = this.cppflags.concat(project.cppflags);
this.parameters = this.parameters.concat(project.parameters);
this.libraries = this.libraries.concat(project.libraries);
if (this.icon === null && project.icon !== null)
this.icon = path.join(projectDir, project.icon);
for (let customTarget of project.customTargets.keys()) {
this.customTargets.set(customTarget, project.customTargets.get(customTarget));
}
// windowOptions and targetOptions are ignored
}
}
unglob(str) {
const globChars = ['\\@', '\\!', '\\+', '\\*', '\\?', '\\(', '\\[', '\\{', '\\)', '\\]', '\\}'];
str = str.replace(/\\/g, '/');
for (const char of globChars) {
str = str.replace(new RegExp(char, 'g'), char);
}
return str;
}
getBaseDir(str) {
// replace \\ to / if next char is not glob
str = str.replace(/\\([^@!+*?{}()[\]]|$)/g, '/$1');
// find non-globby path part
const globby = /[^\\][@!+*?{}()[\]]/;
while (globby.test(str)) {
str = path.posix.dirname(str);
}
str = this.removeGlobEscaping(str);
if (!str.endsWith('/'))
str += '/';
return str;
}
removeGlobEscaping(str) {
return str.replace(/\\([@!+*?{}()[\]]|$)/g, '$1');
}
/**
* Add all assets matching the match glob relative to the directory containing the current khafile.
* Asset types are infered from the file suffix.
* Glob syntax is very simple, the most important patterns are * for anything and ** for anything across directories.
*/
addAssets(match, options) {
if (!options)
options = {};
if (!path.isAbsolute(match)) {
let base = this.unglob(path.resolve(this.scriptdir));
if (!base.endsWith('/'))
base += '/';
// if there is no nameBaseDir: extract relative assets path from match
const baseName = options.nameBaseDir == null ? this.getBaseDir(match) : options.nameBaseDir;
match = path.posix.join(base, match.replace(/\\/g, '/'));
options.baseDir = path.posix.join(this.removeGlobEscaping(base), baseName);
}
else {
options.baseDir = this.getBaseDir(match);
}
this.assetMatchers.push({ match: match, options: options });
}
addSources(source) {
this.sources.push(path.resolve(path.join(this.scriptdir, source)));
}
/**
* Add all shaders matching the match glob relative to the directory containing the current khafile.
* Glob syntax is very simple, the most important patterns are * for anything and ** for anything across directories.
*/
addShaders(match, options) {
if (!options)
options = {};
if (!path.isAbsolute(match)) {
let base = this.unglob(path.resolve(this.scriptdir));
if (!base.endsWith('/')) {
base += '/';
}
match = base + match.replace(/\\/g, '/');
}
this.shaderMatchers.push({ match: match, options: options });
}
addDefine(define) {
this.defines.push(define);
}
addCDefine(define) {
this.cdefines.push(define);
}
addCFlag(flag) {
this.cflags.push(flag);
}
addCppFlag(flag) {
this.cppflags.push(flag);
}
addParameter(parameter) {
this.parameters.push(parameter);
}
addTarget(name, baseTarget, backends) {
this.customTargets.set(name, new Target(baseTarget, backends));
}
addLibrary(library) {
this.addDefine(library);
let self = this;
function findLibraryDirectory(name) {
if (path.isAbsolute(name)) {
return { libpath: name, libroot: name };
}
// Tries to load the default library from inside the kha project.
// e.g. 'Libraries/wyngine'
let libpath = path.join(self.scriptdir, self.localLibraryPath, name);
if (fs.existsSync(libpath) && fs.statSync(libpath).isDirectory()) {
let dir = path.resolve(libpath);
return { libpath: dir, libroot: dir };
}
// If the library couldn't be found in Libraries folder, try
// looking in the haxelib folders.
// e.g. addLibrary('hxcpp') => '/usr/lib/haxelib/hxcpp/3,2,193'
try {
libpath = path.join(child_process.execSync('haxelib config', { encoding: 'utf8' }).trim(), name.replace(/\./g, ','));
}
catch (error) {
if (process.env.HAXEPATH) {
libpath = path.join(process.env.HAXEPATH, 'lib', name.toLowerCase());
}
}
if (fs.existsSync(libpath) && fs.statSync(libpath).isDirectory()) {
if (fs.existsSync(path.join(libpath, '.dev'))) {
libpath = fs.readFileSync(path.join(libpath, '.dev'), 'utf8');
if (!path.isAbsolute(libpath)) {
libpath = path.resolve(libpath);
}
return { libpath: libpath, libroot: libpath };
}
else if (fs.existsSync(path.join(libpath, '.current'))) {
// Get the latest version of the haxelib path,
// e.g. for 'hxcpp', latest version '3,2,193'
let current = fs.readFileSync(path.join(libpath, '.current'), 'utf8');
return { libpath: path.join(libpath, current.replace(/\./g, ',')), libroot: libpath };
}
}
// check relative path
if (fs.existsSync(path.resolve(name))) {
let libpath = path.resolve(name);
return { libpath: libpath, libroot: libpath };
}
// Show error if library isn't found in Libraries or haxelib folder
log.error('Error: Library ' + name + ' not found.');
log.error('Add it to the \'Libraries\' subdirectory of your project. You may also install it via haxelib but that\'s less cool.');
throw 'Library ' + name + ' not found.';
}
let libInfo = findLibraryDirectory(library);
let dir = libInfo.libpath;
if (dir !== '') {
for (let elem of this.libraries) {
if (elem.libroot === libInfo.libroot)
return '';
}
this.libraries.push({
libpath: dir,
libroot: libInfo.libroot
});
// If this is a haxelib library, there must be a haxelib.json
if (fs.existsSync(path.join(dir, 'haxelib.json'))) {
let options = JSON.parse(fs.readFileSync(path.join(dir, 'haxelib.json'), 'utf8'));
// If there is a classPath value, add that directory to be loaded.
// Otherwise, just load the current path.
if (options.classPath) {
// TODO find an example haxelib that has a classPath value
this.sources.push(path.join(dir, options.classPath));
}
else {
// e.g. '/usr/lib/haxelib/hxcpp/3,2,193'
this.sources.push(dir);
}
// If this haxelib has other library dependencies, add them too
if (options.dependencies) {
for (let dependency in options.dependencies) {
if (dependency.toLowerCase() !== 'kha') {
this.addLibrary(dependency);
}
}
}
}
else {
// If there is no haxelib.json file, then just load the library
// by the Sources folder.
// e.g. Libraries/wyngine/Sources
if (!fs.existsSync(path.join(dir, 'Sources'))) {
log.info('Warning: No haxelib.json and no Sources directory found in library ' + library + '.');
}
this.sources.push(path.join(dir, 'Sources'));
}
if (fs.existsSync(path.join(dir, 'extraParams.hxml'))) {
let params = fs.readFileSync(path.join(dir, 'extraParams.hxml'), 'utf8');
for (let parameter of params.split('\n')) {
let param = parameter.trim();
if (param !== '') {
if (param.startsWith('-lib')) {
// (DK)
// - '-lib xxx' is for linking a library via haxe, it forces the use of the haxelib version
// - this should be handled by khamake though, as it tracks the dependencies better (local folder or haxelib)
log.info('Ignoring ' + dir + '/extraParams.hxml "' + param + '"');
}
else {
this.addParameter(param);
}
}
}
}
this.addShaders(dir + '/Sources/Shaders/**', {});
}
return dir;
}
}
exports.Project = Project;
//# sourceMappingURL=Project.js.map

View File

@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadProject = exports.Callbacks = void 0;
const fs = require("fs");
const path = require("path");
const Platform_1 = require("./Platform");
const Project_1 = require("./Project");
exports.Callbacks = {
preAssetConversion: [() => { }],
preShaderCompilation: [() => { }],
preHaxeCompilation: [() => { }],
postHaxeCompilation: [() => { }],
postHaxeRecompilation: [() => { }],
postCppCompilation: [() => { }],
postAssetReexporting: [(filePath) => { }],
postBuild: [() => { }],
onFailure: [(error) => { }]
};
async function loadProject(from, projectfile, platform) {
return new Promise((resolve, reject) => {
fs.readFile(path.join(from, projectfile), 'utf8', (err, data) => {
if (err) {
throw new Error('Error reading ' + projectfile + ' from ' + from + '.');
}
let resolved = false;
let callbacks = {
preAssetConversion: () => { },
preShaderCompilation: () => { },
preHaxeCompilation: () => { },
postHaxeCompilation: () => { },
postHaxeRecompilation: () => { },
postCppCompilation: () => { },
postAssetReexporting: (filePath) => { },
postBuild: () => { },
onFailure: (error) => { }
};
let resolver = (project) => {
resolved = true;
exports.Callbacks.preAssetConversion.push(callbacks.preAssetConversion);
exports.Callbacks.preShaderCompilation.push(callbacks.preShaderCompilation);
exports.Callbacks.preHaxeCompilation.push(callbacks.preHaxeCompilation);
exports.Callbacks.postHaxeCompilation.push(callbacks.postHaxeCompilation);
exports.Callbacks.postHaxeRecompilation.push(callbacks.postHaxeRecompilation);
exports.Callbacks.postCppCompilation.push(callbacks.postCppCompilation);
exports.Callbacks.postAssetReexporting.push(callbacks.postAssetReexporting);
exports.Callbacks.postBuild.push(callbacks.postBuild);
exports.Callbacks.onFailure.push(callbacks.onFailure);
resolve(project);
};
process.on('exit', (code) => {
if (!resolved) {
console.error('Error: khafile.js did not call resolve, no project created.');
}
});
Project_1.Project.platform = platform;
Project_1.Project.scriptdir = from;
try {
let AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
new AsyncFunction('Project', 'Platform', 'platform', 'require', '__dirname', 'process', 'resolve', 'reject', 'callbacks', data)(Project_1.Project, Platform_1.Platform, platform, require, path.resolve(from), process, resolver, reject, callbacks);
}
catch (error) {
reject(error);
}
});
});
}
exports.loadProject = loadProject;
//# sourceMappingURL=ProjectFile.js.map

View File

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RayTraceApi = void 0;
exports.RayTraceApi = {
DXR: 'dxr',
None: 'none'
};
//# sourceMappingURL=RayTraceApi.js.map

View File

@ -0,0 +1,459 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShaderCompiler = exports.CompiledShader = void 0;
const child_process = require("child_process");
const fs = require("fs-extra");
const os = require("os");
const path = require("path");
const chokidar = require("chokidar");
const Throttle = require("promise-parallel-throttle");
const GraphicsApi_1 = require("./GraphicsApi");
const Platform_1 = require("./Platform");
const AssetConverter_1 = require("./AssetConverter");
const log = require("./log");
class CompiledShader {
constructor() {
this.files = [];
this.inputs = [];
this.outputs = [];
this.uniforms = [];
this.types = [];
this.noembed = false;
}
}
exports.CompiledShader = CompiledShader;
class ShaderCompiler {
constructor(exporter, platform, compiler, to, temp, builddir, options, shaderMatchers) {
this.exporter = exporter;
if (platform.endsWith('-native'))
platform = platform.substr(0, platform.length - '-native'.length);
if (platform.endsWith('-hl'))
platform = platform.substr(0, platform.length - '-hl'.length);
this.platform = platform;
this.compiler = compiler;
this.type = ShaderCompiler.findType(platform, options);
this.options = options;
this.to = to;
this.temp = temp;
this.builddir = builddir;
this.shaderMatchers = shaderMatchers;
}
close() {
if (this.watcher)
this.watcher.close();
}
static findType(platform, options) {
switch (platform) {
case Platform_1.Platform.Empty:
case Platform_1.Platform.Node:
return 'glsl';
case Platform_1.Platform.Flash:
return 'agal';
case Platform_1.Platform.Android:
if (options.graphics === GraphicsApi_1.GraphicsApi.Vulkan || options.graphics === GraphicsApi_1.GraphicsApi.Default) {
return 'spirv';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.OpenGL) {
return 'essl';
}
else {
throw new Error('Unsupported shader language.');
}
case Platform_1.Platform.HTML5:
case Platform_1.Platform.DebugHTML5:
case Platform_1.Platform.HTML5Worker:
case Platform_1.Platform.Pi:
return 'essl';
case Platform_1.Platform.tvOS:
case Platform_1.Platform.iOS:
if (options.graphics === GraphicsApi_1.GraphicsApi.Metal || options.graphics === GraphicsApi_1.GraphicsApi.Default) {
return 'metal';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.OpenGL) {
return 'essl';
}
else {
throw new Error('Unsupported shader language.');
}
case Platform_1.Platform.Windows:
if (options.graphics === GraphicsApi_1.GraphicsApi.Vulkan) {
return 'spirv';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.OpenGL) {
return 'glsl';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.Direct3D11 || options.graphics === GraphicsApi_1.GraphicsApi.Direct3D12 || options.graphics === GraphicsApi_1.GraphicsApi.Default) {
return 'd3d11';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.Direct3D9) {
return 'd3d9';
}
else {
throw new Error('Unsupported shader language.');
}
case Platform_1.Platform.WindowsApp:
return 'd3d11';
case Platform_1.Platform.Xbox360:
case Platform_1.Platform.PlayStation3:
return 'd3d9';
case Platform_1.Platform.Linux:
if (options.graphics === GraphicsApi_1.GraphicsApi.Vulkan || options.graphics === GraphicsApi_1.GraphicsApi.Default) {
return 'spirv';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.OpenGL) {
return 'glsl';
}
else {
throw new Error('Unsupported shader language.');
}
case Platform_1.Platform.OSX:
if (options.graphics === GraphicsApi_1.GraphicsApi.Metal || options.graphics === GraphicsApi_1.GraphicsApi.Default) {
return 'metal';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.OpenGL) {
return 'glsl';
}
else {
throw new Error('Unsupported shader language.');
}
case Platform_1.Platform.Krom:
if (options.graphics === GraphicsApi_1.GraphicsApi.Default) {
if (process.platform === 'win32') {
return 'd3d11';
}
else if (process.platform === 'darwin') {
return 'metal';
}
else {
return 'glsl';
}
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.Vulkan) {
return 'spirv';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.Metal) {
return 'metal';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.OpenGL) {
return 'glsl';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.Direct3D11 || options.graphics === GraphicsApi_1.GraphicsApi.Direct3D12) {
return 'd3d11';
}
else if (options.graphics === GraphicsApi_1.GraphicsApi.Direct3D9) {
return 'd3d9';
}
else {
throw new Error('Unsupported shader language.');
}
case Platform_1.Platform.FreeBSD:
return 'glsl';
default:
return platform;
}
}
watch(watch, match, options, recompileAll) {
return new Promise((resolve, reject) => {
let shaders = [];
let ready = false;
this.watcher = chokidar.watch(match, { ignored: /[\/\\]\.(git|DS_Store)/, persistent: watch });
this.watcher.on('add', (filepath) => {
let file = path.parse(filepath);
if (ready) {
switch (file.ext) {
case '.glsl':
if (!file.name.endsWith('.inc') && this.isSupported(file.name)) {
log.info('Compiling ' + file.name);
this.compileShader(filepath, options, recompileAll);
}
break;
}
}
else {
switch (file.ext) {
case '.glsl':
if (!file.name.endsWith('.inc')) {
shaders.push(filepath);
}
break;
}
}
});
if (watch) {
this.watcher.on('change', (filepath) => {
let file = path.parse(filepath);
switch (file.ext) {
case '.glsl':
if (!file.name.endsWith('.inc') && this.isSupported(file.name)) {
log.info('Recompiling ' + file.name);
this.compileShader(filepath, options, recompileAll);
}
break;
}
});
}
this.watcher.on('unlink', (file) => {
});
this.watcher.on('ready', async () => {
ready = true;
let compiledShaders = [];
const self = this;
async function compile(shader, index) {
let parsed = path.parse(shader);
if (self.isSupported(shader)) {
log.info('Compiling shader ' + (index + 1) + ' of ' + shaders.length + ' (' + parsed.base + ').');
let compiledShader = null;
try {
compiledShader = await self.compileShader(shader, options, recompileAll);
}
catch (error) {
log.error('Compiling shader ' + (index + 1) + ' of ' + shaders.length + ' (' + parsed.base + ') failed:');
log.error(error);
return Promise.reject(error);
}
if (compiledShader === null) {
compiledShader = new CompiledShader();
compiledShader.noembed = options.noembed;
// mark variables as invalid, so they are loaded from previous compilation
compiledShader.files = null;
compiledShader.inputs = null;
compiledShader.outputs = null;
compiledShader.uniforms = null;
compiledShader.types = null;
}
if (compiledShader.files != null && compiledShader.files.length === 0) {
// TODO: Remove when krafix has been recompiled everywhere
compiledShader.files.push(parsed.name + '.' + self.type);
}
compiledShader.name = AssetConverter_1.AssetConverter.createExportInfo(parsed, false, options, self.exporter.options.from).name;
compiledShaders.push(compiledShader);
}
else {
log.info('Skipping shader ' + (index + 1) + ' of ' + shaders.length + ' (' + parsed.base + ').');
}
++index;
return Promise.resolve();
}
if (this.options.parallelAssetConversion !== 0) {
let todo = shaders.map((shader, index) => {
return async () => {
await compile(shader, index);
};
});
let processes = this.options.parallelAssetConversion === -1
? require('os').cpus().length - 1
: this.options.parallelAssetConversion;
await Throttle.all(todo, {
maxInProgress: processes,
});
}
else {
let index = 0;
for (let shader of shaders) {
try {
await compile(shader, index);
}
catch (err) {
reject();
return;
}
index += 1;
}
}
resolve(compiledShaders);
return;
});
});
}
async run(watch, recompileAll) {
let shaders = [];
for (let matcher of this.shaderMatchers) {
shaders = shaders.concat(await this.watch(watch, matcher.match, matcher.options, recompileAll));
}
return shaders;
}
isSupported(file) {
if (file.endsWith('.frag.glsl') || file.endsWith('.vert.glsl')) {
return true;
}
return this.type !== 'essl' && this.type !== 'agal';
}
compileShader(file, options, recompile) {
return new Promise((resolve, reject) => {
if (!this.compiler)
reject('No shader compiler found.');
if (this.type === 'none') {
resolve(new CompiledShader());
return;
}
let fileinfo = path.parse(file);
let from = file;
let to = path.join(this.to, fileinfo.name + '.' + this.type);
let temp = to + '.temp';
fs.stat(from, (fromErr, fromStats) => {
fs.stat(to, (toErr, toStats) => {
if (options.noprocessing) {
if (!toStats || toStats.mtime.getTime() < fromStats.mtime.getTime()) {
fs.copySync(from, to, { overwrite: true });
}
let compiledShader = new CompiledShader();
compiledShader.noembed = options.noembed;
resolve(compiledShader);
return;
}
fs.stat(this.compiler, (compErr, compStats) => {
if (!recompile && (fromErr || (!toErr && toStats.mtime.getTime() > fromStats.mtime.getTime() && toStats.mtime.getTime() > compStats.mtime.getTime()))) {
if (fromErr)
log.error('Shader compiler error: ' + fromErr);
resolve(null);
}
else {
if (this.type === 'metal' && this.platform !== Platform_1.Platform.Krom) {
fs.ensureDirSync(path.join(this.builddir, 'Sources'));
let funcname = fileinfo.name;
funcname = funcname.replace(/-/g, '_');
funcname = funcname.replace(/\./g, '_');
funcname += '_main';
fs.writeFileSync(to, '>' + funcname, 'utf8');
to = path.join(this.builddir, 'Sources', fileinfo.name + '.' + this.type);
temp = to;
}
let parameters = [this.type === 'hlsl' ? 'd3d9' : this.type, from, temp, this.temp, this.platform];
if (this.options.shaderversion) {
parameters.push('--version');
parameters.push(this.options.shaderversion);
}
else if (this.platform === Platform_1.Platform.Krom && os.platform() === 'linux') {
parameters.push('--version');
parameters.push('110');
}
if (this.options.glsl2) {
parameters.push('--glsl2');
}
if (this.options.debug) {
parameters.push('--debug');
}
if (options.defines) {
for (let define of options.defines) {
parameters.push('-D' + define);
}
}
if (this.platform === Platform_1.Platform.HTML5 || this.platform === Platform_1.Platform.HTML5Worker || this.platform === Platform_1.Platform.Android) {
parameters.push('--relax');
}
parameters[1] = path.resolve(parameters[1]);
parameters[2] = path.resolve(parameters[2]);
parameters[3] = path.resolve(parameters[3]);
let child = child_process.spawn(this.compiler, parameters);
let errorLine = '';
let newErrorLine = true;
let errorData = false;
let compiledShader = new CompiledShader();
compiledShader.noembed = options.noembed;
function parseData(data) {
data = data.replace(':\\', '#\\'); // Filter out absolute paths on Windows
let parts = data.split(':');
if (parts.length >= 3) {
if (parts[0] === 'uniform') {
compiledShader.uniforms.push({ name: parts[1], type: parts[2] });
}
else if (parts[0] === 'input') {
compiledShader.inputs.push({ name: parts[1], type: parts[2] });
}
else if (parts[0] === 'output') {
compiledShader.outputs.push({ name: parts[1], type: parts[2] });
}
else if (parts[0] === 'type') {
let type = data.substring(data.indexOf(':') + 1);
let name = type.substring(0, type.indexOf(':'));
let typedata = type.substring(type.indexOf(':') + 2);
typedata = typedata.substr(0, typedata.length - 1);
let members = typedata.split(',');
let memberdecls = [];
for (let member of members) {
let memberparts = member.split(':');
memberdecls.push({ type: memberparts[1], name: memberparts[0] });
}
compiledShader.types.push({ name: name, members: memberdecls });
}
}
else if (parts.length >= 2) {
if (parts[0] === 'file') {
const parsed = path.parse(parts[1].replace('#\\', ':\\'));
let name = parsed.name;
if (parsed.ext !== '.temp')
name += parsed.ext;
compiledShader.files.push(name);
}
}
}
let stdOutString = '';
child.stdout.on('data', (data) => {
stdOutString += data.toString();
});
child.stderr.on('data', (data) => {
let str = data.toString();
for (let char of str) {
if (char === '\n') {
if (errorData) {
parseData(errorLine.trim());
}
else {
log.error(errorLine.trim());
}
errorLine = '';
newErrorLine = true;
errorData = false;
}
else if (newErrorLine && char === '#') {
errorData = true;
newErrorLine = false;
}
else {
errorLine += char;
newErrorLine = false;
}
}
});
child.on('close', (code) => {
if (stdOutString) {
if (code === 0) {
log.info(stdOutString);
}
else {
log.error(stdOutString);
}
}
if (errorLine.trim().length > 0) {
if (errorData) {
parseData(errorLine.trim());
}
else {
log.error(errorLine.trim());
}
}
if (code === 0) {
if (this.type !== 'metal' || this.platform === Platform_1.Platform.Krom) {
if (compiledShader.files === null || compiledShader.files.length === 0) {
fs.renameSync(temp, to);
}
for (let file of compiledShader.files) {
fs.renameSync(path.join(this.to, file + '.temp'), path.join(this.to, file));
}
}
resolve(compiledShader);
}
else {
process.exitCode = 1;
reject('Shader compiler error.');
}
});
}
});
});
});
});
}
}
exports.ShaderCompiler = ShaderCompiler;
//# sourceMappingURL=ShaderCompiler.js.map

View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VisualStudioVersion = void 0;
exports.VisualStudioVersion = {
VS2010: 'vs2010',
VS2012: 'vs2012',
VS2013: 'vs2013',
VS2015: 'vs2015',
VS2017: 'vs2017',
VS2019: 'vs2019',
VS2022: 'vs2022'
};
//# sourceMappingURL=VisualStudioVersion.js.map

View File

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VrApi = void 0;
exports.VrApi = {
GearVr: 'gearvr',
Cardboard: 'cardboard',
Oculus: 'oculus',
WebVR: 'webvr',
None: 'none'
};
//# sourceMappingURL=VrApi.js.map

View File

@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeXml = void 0;
const fs = require("fs-extra");
function printElement(elem, data, indents) {
for (let i = 0; i < indents; ++i)
data += '\t';
if (typeof elem === 'string') {
data += '<!-- ' + elem + ' -->\n';
return data;
}
data += '<' + elem.n;
for (let a in elem) {
if (a === 'n')
continue;
if (a === 'e')
continue;
data += ' ' + a + '="' + elem[a] + '"';
}
if (elem.e === undefined || elem.e.length === 0) {
data += ' />\n';
}
else {
data += '>\n';
for (let e of elem.e) {
data = printElement(e, data, indents + 1);
}
for (let i = 0; i < indents; ++i)
data += '\t';
data += '</' + elem.n + '>\n';
}
return data;
}
function writeXml(xml, path) {
let data = '';
data += '<?xml version="1.0" encoding="utf-8"?>\n';
data += '<' + xml.n;
for (let a in xml) {
if (a === 'n')
continue;
if (a === 'e')
continue;
data += ' ' + a + '="' + xml[a] + '"';
}
data += '>\n';
for (let e of xml.e) {
data = printElement(e, data, 1);
}
data += '</' + xml.n + '>\n';
fs.outputFileSync(path, data);
}
exports.writeXml = writeXml;
//# sourceMappingURL=XmlWriter.js.map

View File

@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.graphicsApi = void 0;
const GraphicsApi_1 = require("./GraphicsApi");
const Platform_1 = require("./Platform");
function graphicsApi(platform) {
switch (platform) {
case Platform_1.Platform.Empty:
case Platform_1.Platform.Node:
case Platform_1.Platform.Android:
case Platform_1.Platform.HTML5:
case Platform_1.Platform.DebugHTML5:
case Platform_1.Platform.HTML5Worker:
case Platform_1.Platform.Pi:
case Platform_1.Platform.Linux:
return GraphicsApi_1.GraphicsApi.OpenGL;
case Platform_1.Platform.tvOS:
case Platform_1.Platform.iOS:
case Platform_1.Platform.OSX:
return GraphicsApi_1.GraphicsApi.Metal;
case Platform_1.Platform.Windows:
case Platform_1.Platform.WindowsApp:
return GraphicsApi_1.GraphicsApi.Direct3D11;
case Platform_1.Platform.Krom:
if (process.platform === 'win32') {
return GraphicsApi_1.GraphicsApi.Direct3D11;
}
else if (process.platform === 'darwin') {
return GraphicsApi_1.GraphicsApi.Metal;
}
else {
return GraphicsApi_1.GraphicsApi.OpenGL;
}
case Platform_1.Platform.FreeBSD:
return GraphicsApi_1.GraphicsApi.OpenGL;
default:
return platform;
}
}
exports.graphicsApi = graphicsApi;
//# sourceMappingURL=defaults.js.map

View File

@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sysdir = exports.sys = void 0;
const os = require("os");
function sys() {
if (os.platform() === 'win32') {
return '.exe';
}
else {
return '';
}
}
exports.sys = sys;
function sysdir() {
if (os.platform() === 'linux') {
if (os.arch() === 'arm')
return 'linux_arm';
if (os.arch() === 'arm64')
return 'linux_arm64';
else if (os.arch() === 'x64')
return 'linux_x64';
else
throw 'Unsupported CPU';
}
else if (os.platform() === 'win32') {
return 'windows_x64';
}
else if (os.platform() === 'freebsd') {
return 'freebsd_x64';
}
else {
return 'macos';
}
}
exports.sysdir = sysdir;
//# sourceMappingURL=exec.js.map

View File

@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const fs = require("fs");
const path = require("path");
function run(name, from, projectfile) {
if (!fs.existsSync(path.join(from, projectfile))) {
fs.writeFileSync(path.join(from, projectfile), 'let project = new Project(\'New Project\');\n'
+ 'project.addAssets(\'Assets/**\');\n'
+ 'project.addShaders(\'Shaders/**\');\n'
+ 'project.addSources(\'Sources\');\n'
+ 'resolve(project);\n', { encoding: 'utf8' });
}
if (!fs.existsSync(path.join(from, 'Assets')))
fs.mkdirSync(path.join(from, 'Assets'));
if (!fs.existsSync(path.join(from, 'Shaders')))
fs.mkdirSync(path.join(from, 'Shaders'));
if (!fs.existsSync(path.join(from, 'Sources')))
fs.mkdirSync(path.join(from, 'Sources'));
let friendlyName = name;
friendlyName = friendlyName.replace(/ /g, '_');
friendlyName = friendlyName.replace(/-/g, '_');
if (!fs.existsSync(path.join(from, 'Sources', 'Main.hx'))) {
let mainsource = 'package;\n\n'
+ 'import kha.Assets;\n'
+ 'import kha.Color;\n'
+ 'import kha.Framebuffer;\n'
+ 'import kha.Scheduler;\n'
+ 'import kha.System;\n\n'
+ 'class Main {\n'
+ '\tstatic var logo = ["1 1 1 1 111", "11 111 111", "1 1 1 1 1 1"];\n\n'
+ '\tstatic function update(): Void {\n'
+ '\t}\n\n'
+ '\tstatic function render(frames: Array<Framebuffer>): Void {\n'
+ '\t\t// As we are using only 1 window, grab the first framebuffer\n'
+ '\t\tfinal fb = frames[0];\n'
+ '\t\t// Now get the `g2` graphics object so we can draw\n'
+ '\t\tfinal g2 = fb.g2;\n'
+ '\t\t// Start drawing, and clear the framebuffer to `petrol`\n'
+ '\t\tg2.begin(true, Color.fromBytes(0, 95, 106));\n'
+ '\t\t// Offset all following drawing operations from the top-left a bit\n'
+ '\t\tg2.pushTranslation(64, 64);\n'
+ '\t\t// Fill the following rects with red\n'
+ '\t\tg2.color = Color.Red;\n\n'
+ '\t\t// Loop over the logo (Array<String>) and draw a rect for each "1"\n'
+ '\t\tfor (rowIndex in 0...logo.length) {\n'
+ '\t\t final row = logo[rowIndex];\n\n'
+ '\t\t for (colIndex in 0...row.length) {\n'
+ '\t\t switch row.charAt(colIndex) {\n'
+ '\t\t case "1": g2.fillRect(colIndex * 16, rowIndex * 16, 16, 16);\n'
+ '\t\t case _:\n'
+ '\t\t }\n'
+ '\t\t }\n'
+ '\t\t}\n\n'
+ '\t\t// Pop the pushed translation so it will not accumulate over multiple frames\n'
+ '\t\tg2.popTransformation();\n'
+ '\t\t// Finish the drawing operations\n'
+ '\t\tg2.end();\n'
+ '\t}\n\n'
+ '\tpublic static function main() {\n'
+ '\t\tSystem.start({title: "' + name + '", width: 1024, height: 768}, function (_) {\n'
+ '\t\t\t// Just loading everything is ok for small projects\n'
+ '\t\t\tAssets.loadEverything(function () {\n'
+ '\t\t\t\t// Avoid passing update/render directly,\n'
+ '\t\t\t\t// so replacing them via code injection works\n'
+ '\t\t\t\tScheduler.addTimeTask(function () { update(); }, 0, 1 / 60);\n'
+ '\t\t\t\tSystem.notifyOnFrames(function (frames) { render(frames); });\n'
+ '\t\t\t});\n'
+ '\t\t});\n'
+ '\t}\n'
+ '}\n';
fs.writeFileSync(path.join(from, 'Sources', 'Main.hx'), mainsource, { encoding: 'utf8' });
}
}
exports.run = run;
//# sourceMappingURL=init.js.map

View File

@ -0,0 +1,427 @@
"use strict";
// Called from entry point, e.g. Kha/make.js
// This is where options are processed:
// e.g. '-t html5 --server'
Object.defineProperty(exports, "__esModule", { value: true });
const os = require("os");
const path = require("path");
const GraphicsApi_1 = require("./GraphicsApi");
const Architecture_1 = require("./Architecture");
const AudioApi_1 = require("./AudioApi");
const VrApi_1 = require("./VrApi");
const RayTraceApi_1 = require("./RayTraceApi");
const Options_1 = require("./Options");
const Platform_1 = require("./Platform");
const VisualStudioVersion_1 = require("./VisualStudioVersion");
let defaultTarget;
if (os.platform() === 'linux') {
defaultTarget = Platform_1.Platform.Linux;
}
else if (os.platform() === 'win32') {
defaultTarget = Platform_1.Platform.Windows;
}
else if (os.platform() === 'freebsd') {
defaultTarget = Platform_1.Platform.FreeBSD;
}
else {
defaultTarget = Platform_1.Platform.OSX;
}
let options = [
{
full: 'from',
value: true,
description: 'Location of your project',
default: '.'
},
{
full: 'to',
value: true,
description: 'Build location',
default: 'build'
},
{
full: 'projectfile',
value: true,
description: 'Name of your project file, defaults to "khafile.js"',
default: 'khafile.js'
},
{
full: 'target',
short: 't',
value: true,
description: 'Target platform',
default: defaultTarget
},
{
full: 'vr',
value: true,
description: 'Target VR device',
default: VrApi_1.VrApi.None
},
{
full: 'raytrace',
value: true,
description: 'Target raytracing api',
default: RayTraceApi_1.RayTraceApi.None
},
{
full: 'main',
value: true,
description: 'Entrypoint for the haxe code (-main argument), defaults to "Main".',
default: 'Main'
},
{
full: 'intermediate',
description: 'Intermediate location for object files.',
value: true,
default: '',
hidden: true
},
{
full: 'graphics',
short: 'g',
description: 'Graphics api to use. Possible parameters are direct3d9, direct3d11, direct3d12, metal, vulkan and opengl.',
value: true,
default: GraphicsApi_1.GraphicsApi.Default
},
{
full: 'arch',
description: 'Target architecture to use. Possible parameters are arm7, arm8, x86, x86_64.',
value: true,
default: Architecture_1.Architecture.Default
},
{
full: 'audio',
short: 'a',
description: 'Audio api to use. Possible parameters are directsound and wasapi.',
value: true,
default: AudioApi_1.AudioApi.Default
},
{
full: 'visualstudio',
short: 'v',
description: 'Version of Visual Studio to use. Possible parameters are vs2010, vs2012, vs2013, vs2015, vs2017, vs2019 and vs2022.',
value: true,
default: VisualStudioVersion_1.VisualStudioVersion.VS2022
},
{
full: 'kha',
short: 'k',
description: 'Location of Kha directory',
value: true,
default: ''
},
{
full: 'haxe',
description: 'Location of Haxe directory',
value: true,
default: ''
},
{
full: 'nohaxe',
description: 'Do not compile Haxe sources',
value: false,
},
{
full: 'ffmpeg',
description: 'Location of ffmpeg executable',
value: true,
default: ''
},
{
full: 'ogg',
description: 'Commandline for running the ogg encoder',
value: true,
default: ''
},
{
full: 'mp3',
description: 'Commandline for running the mp3 encoder',
value: true,
default: ''
},
{
full: 'aac',
description: 'Commandline for running the ffmpeg executable',
value: true,
default: ''
},
{
full: 'krafix',
description: 'Location of krafix shader compiler',
value: true,
default: ''
},
{
full: 'kraffiti',
description: 'Location of kraffiti image processing tool',
value: true,
default: ''
},
{
full: 'noshaders',
description: 'Do not compile shaders',
value: false
},
{
full: 'noproject',
description: 'Only source files. Don\'t generate project files.',
value: false,
},
{
full: 'onlydata',
description: 'Only assets/data. Don\'t generate project files.',
value: false,
},
{
full: 'embedflashassets',
description: 'Embed assets in swf for flash target',
value: false
},
{
full: 'compile',
description: 'Compile executable',
value: false
},
{
full: 'run',
description: 'Run executable',
value: false
},
{
full: 'init',
description: 'Init a Kha project inside the current directory',
value: false
},
{
full: 'name',
description: 'Project name to use when initializing a project',
value: true,
default: 'Project'
},
{
full: 'server',
description: 'Run local http server for html5 target',
value: false
},
{
full: 'port',
description: 'Running port for the server',
value: true,
default: 8080
},
{
full: 'debug',
description: 'Compile in debug mode.',
value: false
},
{
full: 'silent',
description: 'Silent mode.',
value: false
},
{
full: 'quiet',
description: 'Quiet mode. Like silent mode but prints error messages.',
value: false
},
{
full: 'watch',
short: 'w',
description: 'Watch files and recompile on change.',
value: false
},
{
full: 'watchport',
short: 'wp',
description: 'Port for the compilation server (default value is 7000).',
value: true,
default: '7000',
},
{
full: 'livereload',
description: 'Reload http server page on watch mode recompilations.',
value: false
},
{
full: 'glsl2',
description: 'Use experimental SPIRV-Cross glsl mode.',
value: false
},
{
full: 'shaderversion',
description: 'Set target shader version manually.',
value: true,
default: null
},
{
full: 'parallelAssetConversion',
description: 'Experimental - Spawn multiple processes during asset and shader conversion. Possible values:\n 0: disabled (default value)\n -1: choose number of processes automatically\n N: specify number of processes manually',
value: true,
default: 0
},
{
full: 'slowgc',
description: 'Disables generational garbage collection.',
value: false
},
{
full: 'nosigning',
value: false,
description: 'Disable code signing for iOS'
}
];
let parsedOptions = new Options_1.Options();
function printHelpLine(options, description) {
let helpLine = options;
while (helpLine.length < 30) {
helpLine += ' ';
}
helpLine += '' + description;
console.log(helpLine);
console.log();
}
function printHelp() {
console.log('khamake options:\n');
for (let option of options) {
if (option.hidden) {
continue;
}
if (option.short) {
printHelpLine('-' + option.short + ' ' + '--' + option.full, option.description);
}
else {
printHelpLine('--' + option.full, option.description);
}
}
}
function isTarget(target) {
if (target.trim().length < 1)
return false;
return true;
}
for (let option of options) {
if (option.value) {
parsedOptions[option.full] = option.default;
}
else {
parsedOptions[option.full] = false;
}
}
let targetIsDefault = true;
let args = process.argv;
for (let i = 2; i < args.length; ++i) {
let arg = args[i];
if (arg === '--')
break;
if (arg[0] === '-') {
if (arg[1] === '-') {
if (arg.substr(2) === 'help') {
printHelp();
process.exit(0);
}
for (let option of options) {
if (arg.substr(2) === option.full) {
if (option.value) {
++i;
parsedOptions[option.full] = args[i];
if (option.full === 'target') {
targetIsDefault = false;
}
else if (option.full === 'parallelAssetConversion') {
parsedOptions[option.full] = parseInt(parsedOptions[option.full]);
}
}
else {
parsedOptions[option.full] = true;
}
}
}
}
else {
if (arg[1] === 'h') {
printHelp();
process.exit(0);
}
for (let option of options) {
if (option.short && arg[1] === option.short) {
if (option.value) {
++i;
parsedOptions[option.full] = args[i];
if (option.full === 'target') {
targetIsDefault = false;
}
}
else {
parsedOptions[option.full] = true;
}
}
}
}
}
else {
if (isTarget(arg)) {
parsedOptions.target = arg.toLowerCase();
targetIsDefault = false;
}
}
}
if (parsedOptions.run) {
parsedOptions.compile = true;
}
async function runKhamake() {
try {
let logInfo = function (text, newline) {
if (newline) {
console.log(text);
}
else {
process.stdout.write(text);
}
};
let logError = function (text, newline) {
if (newline) {
console.error(text);
}
else {
process.stderr.write(text);
}
};
await require('./main.js').run(parsedOptions, { info: logInfo, error: logError });
}
catch (error) {
if (error) {
console.log(error);
}
process.exit(1);
}
}
if (parsedOptions.init) {
console.log('Initializing Kha project.\n');
require('./init').run(parsedOptions.name, parsedOptions.from, parsedOptions.projectfile);
console.log('If you want to use the git version of Kha, execute "git init" and "git submodule add https://github.com/Kode/Kha.git".');
}
else if (parsedOptions.server) {
console.log('Running server on ' + parsedOptions.port);
let nstatic = require('node-static');
let fileServer = new nstatic.Server(path.join(parsedOptions.from, 'build', targetIsDefault ? 'html5' : parsedOptions.target), { cache: 0 });
let server = require('http').createServer(function (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response);
}).resume();
});
server.on('error', function (e) {
if (e.code === 'EADDRINUSE') {
console.log('Error: Port ' + parsedOptions.port + ' is already in use.');
console.log('Please close the competing program (maybe another instance of khamake?)');
console.log('or switch to a different port using the --port argument.');
}
});
server.listen(parsedOptions.port);
if (parsedOptions.watch)
runKhamake();
}
else {
runKhamake();
}
//# sourceMappingURL=khamake.js.map

View File

@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.get = exports.init = void 0;
const path = require("path");
const exec_1 = require("./exec");
let korepath = path.join(__dirname, '..', '..', '..', 'Kinc', 'Tools', (0, exec_1.sysdir)());
function init(options) {
korepath = path.join(options.kha, 'Kinc', 'Tools', (0, exec_1.sysdir)());
}
exports.init = init;
function get() {
return korepath;
}
exports.get = get;
//# sourceMappingURL=korepath.js.map

View File

@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.error = exports.info = exports.silent = exports.set = void 0;
let myInfo = function (text, newline) {
if (newline) {
console.log(text);
}
else {
process.stdout.write(text);
}
};
let myError = function (text, newline) {
if (newline) {
console.error(text);
}
else {
process.stderr.write(text);
}
};
function set(log) {
myInfo = log.info;
myError = log.error;
}
exports.set = set;
function silent(showErrors = false) {
myInfo = function () { };
if (!showErrors) {
myError = function () { };
}
}
exports.silent = silent;
function info(text, newline = true) {
myInfo(text, newline);
}
exports.info = info;
function error(text, newline = true) {
myError(text, newline);
}
exports.error = error;
//# sourceMappingURL=log.js.map

View File

@ -0,0 +1,706 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.close = exports.run = exports.api = void 0;
const child_process = require("child_process");
const fs = require("fs-extra");
const path = require("path");
const exec_1 = require("./exec");
const korepath = require("./korepath");
const log = require("./log");
const Platform_1 = require("./Platform");
const ProjectFile_1 = require("./ProjectFile");
const AssetConverter_1 = require("./AssetConverter");
const HaxeCompiler_1 = require("./HaxeCompiler");
const ShaderCompiler_1 = require("./ShaderCompiler");
const DebugHtml5Exporter_1 = require("./Exporters/DebugHtml5Exporter");
const EmptyExporter_1 = require("./Exporters/EmptyExporter");
const FlashExporter_1 = require("./Exporters/FlashExporter");
const Html5Exporter_1 = require("./Exporters/Html5Exporter");
const Html5WorkerExporter_1 = require("./Exporters/Html5WorkerExporter");
const JavaExporter_1 = require("./Exporters/JavaExporter");
const KincExporter_1 = require("./Exporters/KincExporter");
const KincHLExporter_1 = require("./Exporters/KincHLExporter");
const KromExporter_1 = require("./Exporters/KromExporter");
const NodeExporter_1 = require("./Exporters/NodeExporter");
const PlayStationMobileExporter_1 = require("./Exporters/PlayStationMobileExporter");
const WpfExporter_1 = require("./Exporters/WpfExporter");
const HaxeProject_1 = require("./HaxeProject");
const Icon = require("./Icon");
let lastAssetConverter;
let lastShaderCompiler;
let lastHaxeCompiler;
function fixName(name) {
name = name.replace(/[-@\ \.\/\\]/g, '_');
if (name[0] === '0' || name[0] === '1' || name[0] === '2' || name[0] === '3' || name[0] === '4'
|| name[0] === '5' || name[0] === '6' || name[0] === '7' || name[0] === '8' || name[0] === '9') {
name = '_' + name;
}
return name;
}
function safeName(name) {
return name.replace(/[^A-z0-9\-\_]/g, '-');
}
function createKorefile(name, exporter, options, targetOptions, libraries, cdefines, cflags, cppflags, stackSize, version, id, korehl, icon) {
let out = '';
out += 'let fs = require(\'fs\');\n';
out += 'let path = require(\'path\');\n';
out += 'let project = new Project(\'' + name + '\');\n';
if (version) {
out += 'project.version = \'' + version + '\';\n';
}
if (id) {
out += 'project.id = \'' + id + '\';\n';
}
if (icon != null)
out += 'project.icon = \'' + icon + '\';\n';
for (let cdefine of cdefines) {
out += 'project.addDefine(\'' + cdefine + '\');\n';
}
for (let cppflag of cppflags) {
out += 'project.addCppFlag(\'' + cppflag + '\');\n';
}
for (let cflag of cflags) {
out += 'project.addCFlag(\'' + cflag + '\');\n';
}
out += 'project.addDefine(\'HXCPP_API_LEVEL=400\');\n';
out += 'project.addDefine(\'HXCPP_DEBUG\', \'Debug\');\n';
if (!options.slowgc) {
out += 'project.addDefine(\'HXCPP_GC_GENERATIONAL\');\n';
}
if (targetOptions) {
let koreTargetOptions = {};
for (let option in targetOptions) {
koreTargetOptions[option] = targetOptions[option];
}
out += 'project.targetOptions = ' + JSON.stringify(koreTargetOptions) + ';\n';
}
out += 'project.setDebugDir(\'' + path.relative(options.from, path.join(options.to, exporter.sysdir())).replace(/\\/g, '/') + '\');\n';
let buildpath = path.relative(options.from, path.join(options.to, exporter.sysdir() + '-build')).replace(/\\/g, '/');
if (buildpath.startsWith('..'))
buildpath = path.resolve(path.join(options.from.toString(), buildpath));
out += 'await project.addProject(\'' + path.join(options.kha, 'Kinc').replace(/\\/g, '/') + '\');\n';
out += 'await project.addProject(\'' + buildpath.replace(/\\/g, '/') + '\');\n';
if (korehl)
out += 'await project.addProject(\'' + path.join(options.kha, 'Backends', 'Kinc-HL').replace(/\\/g, '/') + '\');\n';
else
out += 'await project.addProject(\'' + path.join(options.kha, 'Backends', 'Kinc-hxcpp').replace(/\\/g, '/') + '\');\n';
for (let lib of libraries) {
let libPath = lib.libpath.replace(/\\/g, '/');
out += 'if (fs.existsSync(path.join(\'' + libPath + '\', \'kfile.js\')) || fs.existsSync(path.join(\'' + libPath + '\', \'kincfile.js\')) || fs.existsSync(path.join(\'' + libPath + '\', \'korefile.js\'))) {\n';
out += '\tawait project.addProject(\'' + libPath + '\');\n';
out += '}\n';
}
if (stackSize) {
out += 'project.stackSize = ' + stackSize + ';\n';
}
out += 'project.flatten();\n';
out += 'resolve(project);\n';
return out;
}
function runKmake(options) {
return new Promise((resolve, reject) => {
const child = child_process.spawn(path.join(korepath.get(), 'kmake' + (0, exec_1.sys)()), options);
child.stdout.on('data', (data) => {
const str = data.toString();
log.info(str, false);
});
child.stderr.on('data', (data) => {
const str = data.toString();
log.error(str, false);
});
child.on('error', (err) => {
log.error('Could not start kmake.');
reject();
});
child.on('close', (code) => {
if (code === 0) {
resolve();
}
else {
reject();
}
});
});
}
async function exportProjectFiles(name, resourceDir, options, exporter, kore, korehl, icon, libraries, targetOptions, defines, cdefines, cflags, cppflags, stackSize, version, id) {
if (options.haxe !== '') {
let haxeOptions = exporter.haxeOptions(name, targetOptions, defines);
haxeOptions.defines.push('kha');
haxeOptions.defines.push('kha_version=1810');
haxeOptions.safeName = safeName(haxeOptions.name);
haxeOptions.defines.push('kha_project_name=' + haxeOptions.name);
if (options.livereload)
haxeOptions.defines.push('kha_live_reload');
if (options.debug && haxeOptions.parameters.indexOf('-debug') < 0) {
haxeOptions.parameters.push('-debug');
}
(0, HaxeProject_1.writeHaxeProject)(options.to, !options.noproject, haxeOptions);
if (!options.nohaxe) {
let compiler = new HaxeCompiler_1.HaxeCompiler(options.to, haxeOptions.to, haxeOptions.realto, resourceDir, options.haxe, 'project-' + exporter.sysdir() + '.hxml', haxeOptions.sources, exporter.sysdir(), options.watchport, options.livereload, options.port);
lastHaxeCompiler = compiler;
try {
await compiler.run(options.watch);
}
catch (error) {
return Promise.reject(error);
}
}
for (let callback of ProjectFile_1.Callbacks.postHaxeCompilation) {
callback();
}
await exporter.export(name, targetOptions, haxeOptions);
}
let buildDir = path.join(options.to, exporter.sysdir() + '-build');
if (options.haxe !== '' && kore && !options.noproject) {
// If target is a Kore project, generate additional project folders here.
// generate the kincfile.js
fs.copySync(path.join(__dirname, '..', 'Data', 'hxcpp', 'kfile.js'), path.join(buildDir, 'kfile.js'), { overwrite: true });
fs.writeFileSync(path.join(options.to, 'kfile.js'), createKorefile(name, exporter, options, targetOptions, libraries, cdefines, cflags, cppflags, stackSize, version, id, false, icon));
// Similar to khamake.js -> main.js -> run(...)
// We now do kincmake.js -> main.js -> run(...)
// This will create additional project folders for the target,
// e.g. 'build/pi-build'
try {
const kmakeOptions = ['--from', options.from, '--to', buildDir, '--kfile', path.resolve(options.to, 'kfile.js'), '-t', koreplatform(options.target), '--noshaders',
'--graphics', options.graphics, '--arch', options.arch, '--audio', options.audio, '--vr', options.vr, '-v', options.visualstudio
];
if (options.nosigning) {
kmakeOptions.push('--nosigning');
}
if (options.debug) {
kmakeOptions.push('--debug');
}
if (options.run) {
kmakeOptions.push('--run');
}
if (options.compile) {
kmakeOptions.push('--compile');
}
await runKmake(kmakeOptions);
for (let callback of ProjectFile_1.Callbacks.postCppCompilation) {
callback();
}
log.info('Done.');
return name;
}
catch (error) {
if (error) {
log.error('Error: ' + error);
}
else {
log.error('Error.');
}
process.exit(1);
return name;
}
}
else if (options.haxe !== '' && korehl && !options.noproject) {
fs.copySync(path.join(__dirname, '..', 'Data', 'hl', 'kore_sources.c'), path.join(buildDir, 'kore_sources.c'), { overwrite: true });
fs.copySync(path.join(__dirname, '..', 'Data', 'hl', 'kfile.js'), path.join(buildDir, 'kfile.js'), { overwrite: true });
fs.writeFileSync(path.join(options.to, 'kfile.js'), createKorefile(name, exporter, options, targetOptions, libraries, cdefines, cflags, cppflags, stackSize, version, id, korehl, icon));
try {
const kmakeOptions = ['--from', options.from, '--to', buildDir, '--kfile', path.resolve(options.to, 'kfile.js'), '-t', koreplatform(options.target), '--noshaders',
'--graphics', options.graphics, '--arch', options.arch, '--audio', options.audio, '--vr', options.vr, '-v', options.visualstudio
];
if (options.nosigning) {
kmakeOptions.push('--nosigning');
}
if (options.debug) {
kmakeOptions.push('--debug');
}
if (options.run) {
kmakeOptions.push('--run');
}
if (options.compile) {
kmakeOptions.push('--compile');
}
await runKmake(kmakeOptions);
for (let callback of ProjectFile_1.Callbacks.postCppCompilation) {
callback();
}
log.info('Done.');
return name;
}
catch (error) {
if (error) {
log.error('Error: ' + error);
}
else {
log.error('Error.');
}
process.exit(1);
return name;
}
}
else {
// If target is not a Kore project, e.g. HTML5, finish building here.
log.info('Done.');
return name;
}
}
function checkKorePlatform(platform) {
return platform === 'windows'
|| platform === 'windowsapp'
|| platform === 'ios'
|| platform === 'osx'
|| platform === 'android'
|| platform === 'linux'
|| platform === 'emscripten'
|| platform === 'pi'
|| platform === 'tvos'
|| platform === 'ps4'
|| platform === 'xboxone'
|| platform === 'switch'
|| platform === 'xboxscarlett'
|| platform === 'ps5'
|| platform === 'freebsd';
}
function koreplatform(platform) {
if (platform.endsWith('-hl'))
return platform.substr(0, platform.length - '-hl'.length);
else
return platform;
}
let kore = false;
let korehl = false;
async function exportKhaProject(options) {
log.info('Creating Kha project.');
let project = null;
let foundProjectFile = false;
// get the khafile.js and load the config code,
// then create the project config object, which contains stuff
// like project name, assets paths, sources path, library path...
if (fs.existsSync(path.join(options.from, options.projectfile))) {
try {
project = await (0, ProjectFile_1.loadProject)(options.from, options.projectfile, options.target);
}
catch (x) {
log.error(x);
throw 'Loading the projectfile failed.';
}
foundProjectFile = true;
}
if (!foundProjectFile) {
throw 'No khafile found.';
}
let temp = path.join(options.to, 'temp');
fs.ensureDirSync(temp);
let exporter = null;
let target = options.target.toLowerCase();
let baseTarget = target;
let customTarget = null;
if (project.customTargets.get(options.target)) {
customTarget = project.customTargets.get(options.target);
baseTarget = customTarget.baseTarget;
}
switch (baseTarget) {
case Platform_1.Platform.Krom:
exporter = new KromExporter_1.KromExporter(options);
break;
case Platform_1.Platform.Flash:
exporter = new FlashExporter_1.FlashExporter(options);
break;
case Platform_1.Platform.HTML5:
exporter = new Html5Exporter_1.Html5Exporter(options);
break;
case Platform_1.Platform.HTML5Worker:
exporter = new Html5WorkerExporter_1.Html5WorkerExporter(options);
break;
case Platform_1.Platform.DebugHTML5:
exporter = new DebugHtml5Exporter_1.DebugHtml5Exporter(options);
break;
case Platform_1.Platform.WPF:
exporter = new WpfExporter_1.WpfExporter(options);
break;
case Platform_1.Platform.Java:
exporter = new JavaExporter_1.JavaExporter(options);
break;
case Platform_1.Platform.PlayStationMobile:
exporter = new PlayStationMobileExporter_1.PlayStationMobileExporter(options);
break;
case Platform_1.Platform.Node:
exporter = new NodeExporter_1.NodeExporter(options);
break;
case Platform_1.Platform.Empty:
exporter = new EmptyExporter_1.EmptyExporter(options);
break;
default:
if (baseTarget.endsWith('-hl')) {
korehl = true;
options.target = koreplatform(baseTarget);
if (!checkKorePlatform(options.target)) {
log.error(`Unknown platform: ${target} (baseTarget=$${baseTarget})`);
return Promise.reject('');
}
exporter = new KincHLExporter_1.KincHLExporter(options);
}
else {
kore = true;
options.target = koreplatform(baseTarget);
if (!checkKorePlatform(options.target)) {
log.error(`Unknown platform: ${target} (baseTarget=$${baseTarget})`);
return Promise.reject('');
}
exporter = new KincExporter_1.KincExporter(options);
}
break;
}
exporter.setSystemDirectory(target);
let buildDir = path.join(options.to, exporter.sysdir() + '-build');
// Create the target build folder
// e.g. 'build/pi'
fs.ensureDirSync(path.join(options.to, exporter.sysdir()));
let defaultWindowOptions = {
width: 800,
height: 600
};
let windowOptions = project.windowOptions ? project.windowOptions : defaultWindowOptions;
exporter.setName(project.name);
exporter.setWidthAndHeight('width' in windowOptions ? windowOptions.width : defaultWindowOptions.width, 'height' in windowOptions ? windowOptions.height : defaultWindowOptions.height);
for (let source of project.sources) {
exporter.addSourceDirectory(source);
}
for (let library of project.libraries) {
exporter.addLibrary(library);
}
exporter.parameters = exporter.parameters.concat(project.parameters);
project.scriptdir = options.kha;
if (baseTarget !== Platform_1.Platform.Java && baseTarget !== Platform_1.Platform.WPF) {
project.addShaders('Sources/Shaders/**', {});
}
for (let callback of ProjectFile_1.Callbacks.preAssetConversion) {
callback();
}
let assetConverter = new AssetConverter_1.AssetConverter(exporter, options, project.assetMatchers);
lastAssetConverter = assetConverter;
let assets = await assetConverter.run(options.watch, temp);
if ((target === Platform_1.Platform.DebugHTML5 && process.platform === 'win32') || target === Platform_1.Platform.HTML5) {
Icon.exportIco(project.icon, path.join(options.to, exporter.sysdir(), 'favicon.ico'), options.from, options);
}
else if (target === Platform_1.Platform.DebugHTML5) {
Icon.exportPng(project.icon, path.join(options.to, exporter.sysdir(), 'favicon.png'), 256, 256, 0xffffffff, true, options.from, options);
}
let shaderDir = path.join(options.to, exporter.sysdir() + '-resources');
for (let callback of ProjectFile_1.Callbacks.preShaderCompilation) {
callback();
}
fs.ensureDirSync(shaderDir);
let oldResources = null;
let recompileAllShaders = false;
try {
oldResources = JSON.parse(fs.readFileSync(path.join(options.to, exporter.sysdir() + '-resources', 'files.json'), 'utf8'));
for (let file of oldResources.files) {
if (file.type === 'shader') {
if (!file.files || file.files.length === 0) {
recompileAllShaders = true;
break;
}
}
}
}
catch (error) {
}
let exportedShaders = [];
if (!options.noshaders) {
if (fs.existsSync(path.join(options.from, 'Backends'))) {
let libdirs = fs.readdirSync(path.join(options.from, 'Backends'));
for (let ld in libdirs) {
let libdir = path.join(options.from, 'Backends', libdirs[ld]);
if (fs.statSync(libdir).isDirectory()) {
let exe = path.join(libdir, 'krafix', 'krafix-' + options.target + '.exe');
if (fs.existsSync(exe)) {
options.krafix = exe;
}
}
}
}
let shaderCompiler = new ShaderCompiler_1.ShaderCompiler(exporter, baseTarget, options.krafix, shaderDir, temp, buildDir, options, project.shaderMatchers);
lastShaderCompiler = shaderCompiler;
try {
if (baseTarget !== Platform_1.Platform.Java && baseTarget !== Platform_1.Platform.WPF) {
exportedShaders = await shaderCompiler.run(options.watch, recompileAllShaders);
}
}
catch (err) {
return Promise.reject(err);
}
}
function findShader(name) {
let fallback = {};
fallback.files = [];
fallback.inputs = [];
fallback.outputs = [];
fallback.uniforms = [];
fallback.types = [];
try {
for (let file of oldResources.files) {
if (file.type === 'shader' && file.name === fixName(name)) {
return file;
}
}
}
catch (error) {
return fallback;
}
return fallback;
}
let files = [];
for (let asset of assets) {
let file = {
name: fixName(asset.name),
files: asset.files,
file_sizes: asset.file_sizes,
type: asset.type
};
if (file.type === 'image') {
file.original_width = asset.original_width;
file.original_height = asset.original_height;
if (asset.readable)
file.readable = asset.readable;
}
files.push(file);
}
for (let shader of exportedShaders) {
if (shader.noembed)
continue;
let oldShader = findShader(shader.name);
files.push({
name: fixName(shader.name),
files: shader.files === null ? oldShader.files : shader.files,
file_sizes: [1],
type: 'shader',
inputs: shader.inputs === null ? oldShader.inputs : shader.inputs,
outputs: shader.outputs === null ? oldShader.outputs : shader.outputs,
uniforms: shader.uniforms === null ? oldShader.uniforms : shader.uniforms,
types: shader.types === null ? oldShader.types : shader.types
});
}
// Sort to prevent files.json from changing between makes when no files have changed.
files.sort(function (a, b) {
if (a.name > b.name)
return 1;
if (a.name < b.name)
return -1;
return 0;
});
function secondPass() {
// First pass is for main project files. Second pass is for shaders.
// Will try to look for the folder, e.g. 'build/Shaders'.
// if it exists, export files similar to other a
let hxslDir = path.join('build', 'Shaders');
/** if (fs.existsSync(hxslDir) && fs.readdirSync(hxslDir).length > 0) {
addShaders(exporter, platform, project, from, to.resolve(exporter.sysdir() + '-resources'), temp, from.resolve(Paths.get(hxslDir)), krafix);
if (foundProjectFile) {
fs.outputFileSync(to.resolve(Paths.get(exporter.sysdir() + '-resources', 'files.json')).toString(), JSON.stringify({ files: files }, null, '\t'), { encoding: 'utf8' });
log.info('Assets done.');
exportProjectFiles(name, from, to, options, exporter, platform, khaDirectory, haxeDirectory, kore, project.libraries, project.targetOptions, callback);
}
else {
exportProjectFiles(name, from, to, options, exporter, platform, khaDirectory, haxeDirectory, kore, project.libraries, project.targetOptions, callback);
}
}*/
}
if (foundProjectFile) {
fs.outputFileSync(path.join(options.to, exporter.sysdir() + '-resources', 'files.json'), JSON.stringify({ files: files }, null, '\t'));
}
for (let callback of ProjectFile_1.Callbacks.preHaxeCompilation) {
callback();
}
return await exportProjectFiles(project.name, path.join(options.to, exporter.sysdir() + '-resources'), options, exporter, kore, korehl, project.icon, project.libraries, project.targetOptions, project.defines, project.cdefines, project.cflags, project.cppflags, project.stackSize, project.version, project.id);
}
function isKhaProject(directory, projectfile) {
return fs.existsSync(path.join(directory, 'Kha')) || fs.existsSync(path.join(directory, projectfile));
}
async function exportProject(options) {
if (isKhaProject(options.from, options.projectfile)) {
return await exportKhaProject(options);
}
else {
log.error('Neither Kha directory nor project file (' + options.projectfile + ') found.');
return 'Unknown';
}
}
function runProject(options, name) {
return new Promise((resolve, reject) => {
log.info('Running...');
let run = child_process.spawn(path.join(process.cwd(), options.to, 'linux-build', name), [], { cwd: path.join(process.cwd(), options.to, 'linux') });
run.stdout.on('data', function (data) {
log.info(data.toString());
});
run.stderr.on('data', function (data) {
log.error(data.toString());
});
run.on('close', function (code) {
resolve();
});
});
}
exports.api = 2;
function findKhaVersion(dir) {
let p = path.join(dir, '.git');
let hasGitInfo = false;
if (fs.existsSync(p)) {
let stat = fs.statSync(p);
hasGitInfo = stat.isDirectory();
// otherwise git might not utilize an in-place directory
if (!hasGitInfo) {
let contents = fs.readFileSync(p).toString('utf8', 0, 7);
hasGitInfo = contents === 'gitdir:';
}
}
if (hasGitInfo) {
let gitVersion = 'git-error';
try {
const output = child_process.spawnSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8', cwd: dir }).output;
for (const str of output) {
if (str != null && str.length > 0) {
gitVersion = str.substr(0, 8);
break;
}
}
}
catch (error) {
}
let gitStatus = 'git-error';
try {
const output = child_process.spawnSync('git', ['status', '--porcelain'], { encoding: 'utf8', cwd: dir }).output;
gitStatus = '';
for (const str of output) {
if (str != null && str.length > 0) {
gitStatus = str.trim();
break;
}
}
}
catch (error) {
}
if (gitStatus) {
return gitVersion + ', ' + gitStatus.replace(/\n/g, ',');
}
else {
return gitVersion;
}
}
else {
return '¯\\_(ツ)_/¯';
}
}
async function run(options, loglog) {
if (options.silent) {
log.silent();
}
else {
log.set(loglog);
}
if (options.quiet) {
log.silent(true);
}
if (!options.kha) {
let p = path.join(__dirname, '..', '..', '..');
if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {
options.kha = p;
}
}
else {
options.kha = path.resolve(options.kha);
}
log.info('Using Kha (' + findKhaVersion(options.kha) + ') from ' + options.kha);
if (options.parallelAssetConversion === undefined) {
options.parallelAssetConversion = 0;
}
if (!options.haxe) {
let haxepath = path.join(options.kha, 'Tools', (0, exec_1.sysdir)());
if (fs.existsSync(haxepath) && fs.statSync(haxepath).isDirectory())
options.haxe = haxepath;
}
if (!options.krafix) {
let krafixpath = path.join(options.kha, 'Kinc', 'Tools', (0, exec_1.sysdir)(), 'krafix' + (0, exec_1.sys)());
if (fs.existsSync(krafixpath))
options.krafix = krafixpath;
}
if (!options.kraffiti) {
const kraffitipath = path.join(options.kha, 'Kinc', 'Tools', (0, exec_1.sysdir)(), 'kraffiti' + (0, exec_1.sys)());
if (fs.existsSync(kraffitipath))
options.kraffiti = kraffitipath;
}
else {
log.info('Using kraffiti from ' + options.kraffiti);
}
if (!options.ogg && options.ffmpeg) {
options.ogg = options.ffmpeg + ' -nostdin -i {in} {out} -y';
}
if (!options.mp3 && options.ffmpeg) {
options.mp3 = options.ffmpeg + ' -nostdin -i {in} {out}';
}
if (!options.ogg) {
let oggpath = path.join(options.kha, 'Tools', (0, exec_1.sysdir)(), 'oggenc' + (0, exec_1.sys)());
if (fs.existsSync(oggpath))
options.ogg = oggpath + ' {in} -o {out} --quiet';
}
if (!options.mp3) {
let lamepath = path.join(options.kha, 'Tools', (0, exec_1.sysdir)(), 'lame' + (0, exec_1.sys)());
if (fs.existsSync(lamepath))
options.mp3 = lamepath + ' {in} {out}';
}
// if (!options.kravur) {
// let kravurpath = path.join(options.kha, 'Tools', 'kravur', 'kravur' + sys());
// if (fs.existsSync(kravurpath)) options.kravur = kravurpath + ' {in} {size} {out}';
// }
if (!options.aac && options.ffmpeg) {
options.aac = options.ffmpeg + ' -nostdin -i {in} {out}';
}
if (!options.h264 && options.ffmpeg) {
options.h264 = options.ffmpeg + ' -nostdin -i {in} {out}';
}
if (!options.webm && options.ffmpeg) {
options.webm = options.ffmpeg + ' -nostdin -i {in} {out}';
}
if (!options.wmv && options.ffmpeg) {
options.wmv = options.ffmpeg + ' -nostdin -i {in} {out}';
}
if (!options.theora && options.ffmpeg) {
options.theora = options.ffmpeg + ' -nostdin -i {in} {out}';
}
if (options.target === 'emscripten') {
console.log();
console.log('Please note that the html5 target\n'
+ 'is usually a better choice.\n'
+ 'In particular the html5 target usually runs faster\n'
+ 'than the emscripten target. That is because\n'
+ 'Haxe and JavaScript are similar in many ways and\n'
+ 'therefore the html5 target can make direct use of\n'
+ 'all of the optimizations in modern JavaScript\n'
+ 'runtimes. The emscripten target on the other hand\n'
+ 'has to provide its own garbage collector and many\n'
+ 'other performance critical pieces of infrastructure.');
console.log();
}
let name = '';
try {
name = await exportProject(options);
}
catch (err) {
for (let callback of ProjectFile_1.Callbacks.onFailure) {
callback(err);
}
throw err;
}
for (let callback of ProjectFile_1.Callbacks.postBuild) {
callback();
}
if ((options.target === Platform_1.Platform.Linux || options.target === Platform_1.Platform.FreeBSD) && options.run) {
await runProject(options, name);
}
return name;
}
exports.run = run;
function close() {
if (lastAssetConverter)
lastAssetConverter.close();
if (lastShaderCompiler)
lastShaderCompiler.close();
if (lastHaxeCompiler)
lastHaxeCompiler.close();
}
exports.close = close;
//# sourceMappingURL=main.js.map

View File

@ -0,0 +1,9 @@
{
"name": "khamake",
"dependencies": {},
"globalDependencies": {
"chokidar": "registry:dt/chokidar#1.4.3+20160316155526",
"fs-extra": "registry:dt/fs-extra#0.0.0+20160517121359",
"node": "registry:dt/node#6.0.0+20160728152422"
}
}