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,121 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
import {Library} from '../Project';
const uuid = require('uuid');
export abstract class CSharpExporter extends KhaExporter {
constructor(options: Options) {
super(options);
fs.removeSync(path.join(this.options.to, this.sysdir() + '-build', 'Sources'));
}
includeFiles(dir: string, baseDir: string) {
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: string, targetOptions: any, defines: Array<string>) {
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: string, targetOptions: any, haxeOptions: any): Promise<void> {
if (this.projectFiles) {
const projectUuid: string = uuid.v4();
this.exportSLN(projectUuid);
this.exportCsProj(projectUuid);
this.exportResources();
}
}
exportSLN(projectUuid: string) {
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();
}
abstract backend(): string;
abstract exportCsProj(projectUuid: string): void;
abstract exportResources(): void;
async copySound(platform: string, from: string, to: string) {
return { files: [to], sizes: [1] };
}
async copyImage(platform: string, from: string, to: string, asset: any, cache: any) {
let format = await 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: string, from: string, to: string) {
fs.copySync(from, path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform: string, from: string, to: string) {
return { files: [to], sizes: [1] };
}
}

View File

@ -0,0 +1,9 @@
import {Html5Exporter} from './Html5Exporter';
import {Options} from '../Options';
export class DebugHtml5Exporter extends Html5Exporter {
constructor(options: Options) {
super(options);
this.isDebug = true;
}
}

View File

@ -0,0 +1,88 @@
import * as child_process from 'child_process';
import * as fs from 'fs-extra';
import * as path from 'path';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
import * as log from '../log';
import {Library} from '../Project';
export class EmptyExporter extends KhaExporter {
constructor(options: Options) {
super(options);
}
backend(): string {
return 'Empty';
}
haxeOptions(name: string, targetOptions: any, defines: Array<string>) {
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: string, _targetOptions: any, haxeOptions: any): Promise<void> {
fs.ensureDirSync(path.join(this.options.to, this.sysdir()));
try {
// Remove any @:export first
await 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: string, from: string, to: string) {
return { files: [''], sizes: [0] };
}
async copyImage(platform: string, from: string, to: string, asset: any) {
return { files: [''], sizes: [0] };
}
async copyBlob(platform: string, from: string, to: string) {
return { files: [''], sizes: [0] };
}
async copyVideo(platform: string, from: string, to: string) {
return { files: [''], sizes: [0] };
}
}

View File

@ -0,0 +1,36 @@
import * as fs from 'fs-extra';
export class Exporter {
out: number;
constructor() {
}
writeFile(file: string) {
this.out = fs.openSync(file, 'w');
}
closeFile() {
fs.closeSync(this.out);
}
p(line: string = '', indent: number = 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: string, to: string) {
fs.copySync(from, to, { overwrite: true });
}
copyDirectory(from: string, to: string) {
fs.copySync(from, to, { overwrite: true });
}
createDirectory(dir: string) {
fs.ensureDirSync(dir);
}
}

View File

@ -0,0 +1,148 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
import {Library} from '../Project';
function adjustFilename(filename: string): string {
filename = filename.replace(/\./g, '_');
filename = filename.replace(/-/g, '_');
filename = filename.replace(/\//g, '_');
return filename;
}
export class FlashExporter extends KhaExporter {
images: Array<string>;
sounds: Array<string>;
blobs: Array<string>;
constructor(options: Options) {
super(options);
this.images = [];
this.sounds = [];
this.blobs = [];
}
backend(): string {
return 'Flash';
}
haxeOptions(name: string, targetOptions: any, defines: Array<string>) {
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: string, targetOptions: any, haxeOptions: any): Promise<void> {
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: string, from: string, to: string) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await convert(from, path.join(this.options.to, this.sysdir(), to + '.mp3'), this.options.mp3);
return { files: [to + '.mp3'], sizes: [1] };
}
async copyImage(platform: string, from: string, to: string, asset: any, cache: any) {
let format = await 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: string, from: string, to: string) {
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: string, from: string, to: string) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await convert(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
addShader(shader: string) {
if (this.options.embedflashassets) this.blobs.push(shader);
}
}

View File

@ -0,0 +1,274 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
import {Library} from '../Project';
import {VrApi} from '../VrApi';
export class Html5Exporter extends KhaExporter {
width: number;
height: number;
isDebug: boolean;
constructor(options: Options) {
super(options);
}
backend(): string {
return 'HTML5';
}
isADebugTarget() {
return this.isDebug;
}
isDebugHtml5() {
return this.sysdir() === 'debug-html5';
}
isNode() {
return false;
}
isHtml5Worker() {
return this.sysdir() === 'html5worker';
}
haxeOptions(name: string, targetOptions: any, defines: Array<string>) {
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.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: string, _targetOptions: any, haxeOptions: any): Promise<void> {
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: string, from: string, to: string, options: any) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let ogg = await 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 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 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: string[] = [];
let sizes: number[] = [];
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: string, from: string, to: string, options: any, cache: any) {
let format = await 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: string, from: string, to: string, options: any) {
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: string, from: string, to: string, options: any) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let mp4 = false;
let mp4_size = 0;
if (!this.isDebugHtml5()) {
mp4 = await 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 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: string[] = [];
let sizes: number[] = [];
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 };
}
}

View File

@ -0,0 +1,13 @@
import * as path from 'path';
import {Html5Exporter} from './Html5Exporter';
import {Options} from '../Options';
export class Html5WorkerExporter extends Html5Exporter {
constructor(options: Options) {
super(options);
}
backend(): string {
return 'HTML5-Worker';
}
}

View File

@ -0,0 +1,117 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
import {Library} from '../Project';
export class JavaExporter extends KhaExporter {
constructor(options: Options) {
super(options);
}
haxeOptions(name: string, targetOptions: any, defines: Array<string>) {
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: string, targetOptions: any, haxeOptions: any): Promise<void> {
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: string, from: string, to: string) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
async copyImage(platform: string, from: string, to: string, asset: any, cache: any) {
let format = await 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: string, from: string, to: string) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform: string, from: string, to: string) {
return { files: [to], sizes: [1] };
}
}

View File

@ -0,0 +1,101 @@
import * as path from 'path';
import {convert} from '../Converter';
import {Exporter} from './Exporter';
import {Options} from '../Options';
import {Library} from '../Project';
export abstract class KhaExporter extends Exporter {
width: number;
height: number;
sources: string[];
libraries: Library[];
name: string;
safename: string;
options: Options;
projectFiles: boolean;
parameters: string[];
systemDirectory: string;
constructor(options: 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(): string {
return this.systemDirectory;
}
abstract backend(): string;
abstract haxeOptions(name: string, targetOptions: any, defines: Array<string>): any;
async export(name: string, targetOptions: any, haxeOptions: any): Promise<void> {
return new Promise<void>((resolve, reject) => {
reject('Called an abstract function');
});
}
setWidthAndHeight(width: number, height: number): void {
this.width = width;
this.height = height;
}
setName(name: string): void {
this.name = name;
this.safename = name.replace(/ /g, '-');
}
setSystemDirectory(systemDirectory: string): void {
this.systemDirectory = systemDirectory;
}
addShader(shader: string): void {
}
addSourceDirectory(path: string): void {
this.sources.push(path);
}
addLibrary(library: Library): void {
this.libraries.push(library);
}
removeSourceDirectory(path: string): void {
for (let i = 0; i < this.sources.length; ++i) {
if (this.sources[i] === path) {
this.sources.splice(i, 1);
return;
}
}
}
async copyImage(platform: string, from: string, to: string, options: any, cache: any): Promise<{ files: Array<string>, sizes: Array<number>}> {
return {files: [], sizes: []};
}
async copySound(platform: string, from: string, to: string, options: any): Promise<{ files: Array<string>, sizes: Array<number>}> {
return {files: [], sizes: []};
}
async copyVideo(platform: string, from: string, to: string, options: any): Promise<{ files: Array<string>, sizes: Array<number>}> {
return {files: [], sizes: []};
}
async copyBlob(platform: string, from: string, to: string, options: any): Promise<{ files: Array<string>, sizes: Array<number>}> {
return {files: [], sizes: []};
}
async copyFont(platform: string, from: string, to: string, options: any): Promise<{ files: Array<string>, sizes: Array<number>}> {
return await this.copyBlob(platform, from, to + '.ttf', options);
}
}

View File

@ -0,0 +1,152 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import * as defaults from '../defaults';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {GraphicsApi} from '../GraphicsApi';
import {Platform} from '../Platform';
import {exportImage} from '../ImageTool';
import {Options} from '../Options';
import {Library} from '../Project';
export class KincExporter extends KhaExporter {
slowgc: boolean;
constructor(options: Options) {
super(options);
this.slowgc = options.slowgc;
// Files.removeDirectory(this.directory.resolve(Paths.get(this.sysdir() + "-build", "Sources")));
}
backend(): string {
return 'Kinc-hxcpp';
}
haxeOptions(name: string, targetOptions: any, defines: Array<string>) {
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.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: string, targetOptions: any, haxeOptions: any): Promise<void> {
}
async copySound(platform: string, from: string, to: string, options: any) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await 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: string, from: string, to: string, options: any, cache: any) {
if (platform === Platform.iOS && options.quality < 1) {
let format = await 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.Windows && options.quality < 1 && (this.options.graphics === GraphicsApi.OpenGL || this.options.graphics === 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 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 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: string, from: string, to: string) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform: string, from: string, to: string) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
if (platform === Platform.Windows) {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.avi'), this.options.h264);
return { files: [to + '.avi'], sizes: [1] };
}
else if (platform === Platform.iOS || platform === Platform.OSX) {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
else if (platform === Platform.Android) {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.ts'), this.options.h264);
return { files: [to + '.ts'], sizes: [1] };
}
else {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.ogv'), this.options.theora);
return { files: [to + '.ogv'], sizes: [1] };
}
}
}

View File

@ -0,0 +1,136 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import * as defaults from '../defaults';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {GraphicsApi} from '../GraphicsApi';
import {Platform} from '../Platform';
import {exportImage} from '../ImageTool';
import {Options} from '../Options';
import {Library} from '../Project';
export class KincHLExporter extends KhaExporter {
constructor(options: Options) {
super(options);
// Files.removeDirectory(this.directory.resolve(Paths.get(this.sysdir() + "-build", "Sources")));
}
backend(): string {
return 'Kinc-HL';
}
haxeOptions(name: string, targetOptions: any, defines: Array<string>) {
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.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: string, targetOptions: any, haxeOptions: any): Promise<void> {
}
async copySound(platform: string, from: string, to: string, options: any) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let ogg = await 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: string, from: string, to: string, options: any, cache: any) {
if (platform === Platform.iOS && options.quality < 1) {
let format = await 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.Windows && options.quality < 1 && (this.options.graphics === GraphicsApi.OpenGL || this.options.graphics === 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 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 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: string, from: string, to: string) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to).toString(), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform: string, from: string, to: string) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
if (platform === Platform.Windows) {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.avi'), this.options.h264);
return { files: [to + '.avi'], sizes: [1] };
}
else if (platform === Platform.iOS || platform === Platform.OSX) {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.mp4'), this.options.h264);
return { files: [to + '.mp4'], sizes: [1] };
}
else if (platform === Platform.Android) {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.ts'), this.options.h264);
return { files: [to + '.ts'], sizes: [1] };
}
else {
await convert(from, path.join(this.options.to, this.sysdir(), to + '.ogv'), this.options.theora);
return { files: [to + '.ogv'], sizes: [1] };
}
}
}

View File

@ -0,0 +1,105 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import * as defaults from '../defaults';
import {KhaExporter} from './KhaExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {GraphicsApi} from '../GraphicsApi';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
import {Library} from '../Project';
export class KromExporter extends KhaExporter {
width: number;
height: number;
constructor(options: Options) {
super(options);
}
backend(): string {
return 'Krom';
}
haxeOptions(name: string, targetOptions: any, defines: Array<string>) {
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.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: string, targetOptions: any, haxeOptions: any): Promise<void> {
fs.ensureDirSync(path.join(this.options.to, this.sysdir()));
}
async copySound(platform: string, from: string, to: string, options: any) {
if (options.quality < 1) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let ogg = await 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: string, from: string, to: string, options: any, cache: any) {
let format = await 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: string, from: string, to: string) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to), { overwrite: true });
return { files: [to], sizes: [1] };
}
async copyVideo(platform: string, from: string, to: string) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
let webm = await convert(from, path.join(this.options.to, this.sysdir(), to + '.webm'), this.options.webm);
let files: string[] = [];
let sizes: number[] = [];
if (webm) { files.push(to + '.webm'); sizes.push(1); }
return { files: files, sizes: sizes };
}
}

View File

@ -0,0 +1,17 @@
import * as path from 'path';
import {Html5Exporter} from './Html5Exporter';
import {Options} from '../Options';
export class NodeExporter extends Html5Exporter {
constructor(options: Options) {
super(options);
}
backend(): string {
return 'Node';
}
isNode() {
return true;
}
}

View File

@ -0,0 +1,165 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import {CSharpExporter} from './CSharpExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
const uuid = require('uuid');
export class PlayStationMobileExporter extends CSharpExporter {
files: Array<string>;
constructor(options: Options) {
super(options);
this.files = [];
}
backend() {
return 'PSM';
}
exportSLN(projectUuid: string) {
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: string) {
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: string, from: string, to: string) {
return { files: [''], sizes: [1] };
}
async copyImage(platform: string, from: string, to: string, asset: any, cache: any) {
this.files.push(asset['file']);
let format = await 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: string, from: string, to: string) {
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: string, from: string, to: string) {
return { files: [''], sizes: [1] };
}
}

View File

@ -0,0 +1,287 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import {CSharpExporter} from './CSharpExporter';
import {convert} from '../Converter';
import {executeHaxe} from '../Haxe';
import {Options} from '../Options';
import {exportImage} from '../ImageTool';
const uuid = require('uuid');
export class WpfExporter extends CSharpExporter {
constructor(options: 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: string) {
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: string, from: string, to: string) {
fs.copySync(from.toString(), path.join(this.options.to, this.sysdir(), to + '.wav'), { overwrite: true });
return { files: [to + '.wav'], sizes: [1] };
}
async copyVideo(platform: string, from: string, to: string) {
fs.ensureDirSync(path.join(this.options.to, this.sysdir(), path.dirname(to)));
await convert(from, path.join(this.options.to, this.sysdir(), to + '.wmv'), this.options.wmv);
return { files: [to + '.wmv'], sizes: [1] };
}
}