Skip to content

Commit

Permalink
original_width, original_height for image assets
Browse files Browse the repository at this point in the history
  • Loading branch information
romamik committed Aug 2, 2016
1 parent 6c38c56 commit 7cf8ded
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
18 changes: 9 additions & 9 deletions AssetConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AssetConverter {
else return fileinfo.name;
}

watch(watch: boolean, match: string, options: any): Promise<{ name: string, from: string, type: string, files: string[] }[]> {
watch(watch: boolean, match: string, options: any): Promise<{ name: string, from: string, type: string, files: string[], original_width:number, original_height:number }[]> {
return new Promise<{ from: string, type: string, files: string[] }[]>((resolve, reject) => {
if (!options) options = {};
let ready = false;
Expand All @@ -64,7 +64,7 @@ export class AssetConverter {

this.watcher.on('ready', async () => {
ready = true;
let parsedFiles: { name: string, from: string, type: string, files: string[] }[] = [];
let parsedFiles: { name: string, from: string, type: string, files: string[], original_width:number, original_height:number }[] = [];
let index = 0;
for (let file of files) {
let fileinfo = path.parse(file);
Expand All @@ -76,19 +76,19 @@ export class AssetConverter {
case '.hdr': {
let name = this.createName(fileinfo, false, options, this.exporter.options.from);
let images = await this.exporter.copyImage(this.platform, file, name, options);
parsedFiles.push({ name: name, from: file, type: 'image', files: images });
parsedFiles.push({ name: name, from: file, type: 'image', files: images, original_width:options.original_width, original_height:options.original_height });
break;
}
case '.wav': {
let name = this.createName(fileinfo, false, options, this.exporter.options.from);
let sounds = await this.exporter.copySound(this.platform, file, name);
parsedFiles.push({ name: name, from: file, type: 'sound', files: sounds });
parsedFiles.push({ name: name, from: file, type: 'sound', files: sounds, original_width:undefined, original_height:undefined });
break;
}
case '.ttf': {
let name = this.createName(fileinfo, false, options, this.exporter.options.from);
let fonts = await this.exporter.copyFont(this.platform, file, name);
parsedFiles.push({ name: name, from: file, type: 'font', files: fonts });
parsedFiles.push({ name: name, from: file, type: 'font', files: fonts, original_width:undefined, original_height:undefined });
break;
}
case '.mp4':
Expand All @@ -97,13 +97,13 @@ export class AssetConverter {
case '.avi': {
let name = this.createName(fileinfo, false, options, this.exporter.options.from);
let videos = await this.exporter.copyVideo(this.platform, file, name);
parsedFiles.push({ name: name, from: file, type: 'video', files: videos });
parsedFiles.push({ name: name, from: file, type: 'video', files: videos, original_width:undefined, original_height:undefined });
break;
}
default: {
let name = this.createName(fileinfo, true, options, this.exporter.options.from);
let blobs = await this.exporter.copyBlob(this.platform, file, name);
parsedFiles.push({ name: name, from: file, type: 'blob', files: blobs });
parsedFiles.push({ name: name, from: file, type: 'blob', files: blobs, original_width:undefined, original_height:undefined });
break;
}
}
Expand All @@ -114,8 +114,8 @@ export class AssetConverter {
});
}

async run(watch: boolean): Promise<{ name: string, from: string, type: string, files: string[] }[]> {
let files: { name: string, from: string, type: string, files: string[] }[] = [];
async run(watch: boolean): Promise<{ name: string, from: string, type: string, files: string[], original_width:number, original_height:number }[]> {
let files: { name: string, from: string, type: string, files: string[], original_width:number, original_height:number }[] = [];
for (let matcher of this.assetMatchers) {
files = files.concat(await this.watch(watch, matcher.match, matcher.options));
}
Expand Down
9 changes: 7 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,16 @@ async function exportKhaProject(options: Options): Promise<string> {

let files = [];
for (let asset of assets) {
files.push({
let file:any = {
name: fixName(asset.name),
files: asset.files,
type: asset.type
});
};
if(file.type == "image") {
file.original_width = asset.original_width;
file.original_height = asset.original_height;
}
files.push(file);
}
for (let shader of exportedShaders) {
files.push({
Expand Down
10 changes: 5 additions & 5 deletions out/AssetConverter.js

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

9 changes: 7 additions & 2 deletions out/main.js

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

0 comments on commit 7cf8ded

Please sign in to comment.