Skip to content

Commit

Permalink
Initial TypeScript/async port.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed May 6, 2016
1 parent 526153c commit 95cd48b
Show file tree
Hide file tree
Showing 54 changed files with 5,487 additions and 2,559 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.ntvs_analysis.dat
/.ntvs_analysis.dat.tmp
/.idea/workspace.xml
/*.js.map
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"name": "Launch",
"type": "node",
"request": "launch",
"program": "khamake.js",
"program": "${workspaceRoot}/khamake.js",
"stopOnEntry": false,
"args": ["html5"],
"cwd": "../../..",
"cwd": "${workspaceRoot}/../../..",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
Expand Down
10 changes: 10 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
5 changes: 5 additions & 0 deletions Asset.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Asset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Color} from './Color';

export class Asset {
name: string;
scale: number;
background: Color;
original_width: number;
original_height: number;
}
5 changes: 5 additions & 0 deletions Color.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class Color {
red: number;
green: number;
blue: number;
}
81 changes: 44 additions & 37 deletions Converter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions Converter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";

import * as child_process from 'child_process';
import * as fs from 'fs';
import * as log from './log';

export function convert(inFilename: string, outFilename: string, encoder: string, args: Array<string> = null): Promise<boolean> {
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]);
}

let process = child_process.spawn(exe, options);
process.on('close', (code) => {
resolve(code === 0);
});
})
};
72 changes: 27 additions & 45 deletions Exporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions Exporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use strict";

import * as fs from 'fs-extra';
import * as path from 'path';

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 = new Buffer(tabs + line + '\n');
fs.writeSync(this.out, data, 0, data.length, null);
}

copyFile(from: string, to: string) {
fs.copySync(from, to, { clobber: true });
}

copyDirectory(from: string, to: string) {
fs.copySync(from, to, { clobber: true });
}

createDirectory(dir: string) {
fs.ensureDirSync(dir);
}
}
20 changes: 10 additions & 10 deletions GraphicsApi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions GraphicsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

export var GraphicsApi = {
OpenGL: 'opengl',
OpenGL2: 'opengl2',
Direct3D9: 'direct3d9',
Direct3D11: 'direct3d11',
Direct3D12: 'direct3d12',
Metal: 'metal',
Vulkan: 'vulkan'
};
Loading

0 comments on commit 95cd48b

Please sign in to comment.