@remvst/asset-catalog 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/lib/generate-image-catalog.js +4 -2
- package/lib/generate-sound-catalog.js +1 -1
- package/package.json +1 -1
- package/src/generate-image-catalog.ts +5 -3
- package/src/generate-sound-catalog.ts +18 -18
- package/src/utils.ts +1 -2
- package/testOut/images.ts +38 -0
- package/testOut/sounds.ts +45 -0
- package/testData/directions/left.png +0 -0
- package/testData/directions/up.png +0 -0
- package/testData/fire.png +0 -0
- package/testData/sounds/click/UI_Click_Metallic_mono.mp3 +0 -0
- package/testData/sounds/click/UI_Click_Metallic_mono.ogg +0 -0
- package/testData/sounds/jump/jump2.ogg +0 -0
- package/testData/sounds/jump/xhGkA9Px.mp3 +0 -0
package/README.md
CHANGED
|
@@ -30,7 +30,8 @@ function generatedTemplateInterface(tree, name, indent = '') {
|
|
|
30
30
|
generated += indent + ` ${(0, utils_1.lowerCamelize)(subname)}: ${generatedSub}`;
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
|
|
33
|
+
const withoutExt = (0, path_1.basename)(subname, (0, path_1.extname)(subname));
|
|
34
|
+
generated += indent + ` ${(0, utils_1.lowerCamelize)(withoutExt)}: T,\n`;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
generated += indent + '}\n';
|
|
@@ -47,7 +48,8 @@ async function generatedCreateCatalogFunction(assetDir, tree) {
|
|
|
47
48
|
else {
|
|
48
49
|
const dimensions = (0, image_size_1.default)(item);
|
|
49
50
|
const stats = await fs_1.promises.stat(item);
|
|
50
|
-
|
|
51
|
+
const withoutExt = (0, path_1.basename)(subname, (0, path_1.extname)(subname));
|
|
52
|
+
generated += indent + ` ${(0, utils_1.lowerCamelize)(withoutExt)}: createItem({
|
|
51
53
|
path: ${importName(assetDir, item)},
|
|
52
54
|
width: ${dimensions.width},
|
|
53
55
|
height: ${dimensions.height},
|
|
@@ -95,7 +95,7 @@ async function main() {
|
|
|
95
95
|
let totalFileSize = 0;
|
|
96
96
|
for (const soundFile of files) {
|
|
97
97
|
const importName = (0, utils_1.sanitize)(soundFile);
|
|
98
|
-
imports.push(`import ${importName} from '${(0, path_1.relative)((0, path_1.dirname)(argv.outFile), soundFile)}';`);
|
|
98
|
+
imports.push(`import ${importName} from '${(0, path_1.relative)((0, path_1.dirname)(argv.outFile), soundFile).replace(/\\/g, '/')}';`);
|
|
99
99
|
func += ` ${importName},\n`;
|
|
100
100
|
const stats = await fs_1.promises.stat(soundFile);
|
|
101
101
|
totalFileSize += stats.size;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { promises as fs } from 'fs';
|
|
4
4
|
import sizeOf from 'image-size';
|
|
5
5
|
import { sanitize, allFiles, lowerCamelize } from './utils';
|
|
6
|
-
import { resolve, relative, dirname, extname } from 'path';
|
|
6
|
+
import { resolve, relative, dirname, extname, basename } from 'path';
|
|
7
7
|
import yargs from 'yargs/yargs';
|
|
8
8
|
import { hideBin } from 'yargs/helpers';
|
|
9
9
|
import { Tree, generateTree } from './tree';
|
|
@@ -29,7 +29,8 @@ function generatedTemplateInterface(tree: Tree, name: string, indent: string = '
|
|
|
29
29
|
const generatedSub = generatedTemplateInterface(item, subname, indent + ' ');
|
|
30
30
|
generated += indent + ` ${lowerCamelize(subname)}: ${generatedSub}`;
|
|
31
31
|
} else {
|
|
32
|
-
|
|
32
|
+
const withoutExt = basename(subname, extname(subname));
|
|
33
|
+
generated += indent + ` ${lowerCamelize(withoutExt)}: T,\n`;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
generated += indent + '}\n';
|
|
@@ -46,7 +47,8 @@ async function generatedCreateCatalogFunction(assetDir: string, tree: Tree): Pro
|
|
|
46
47
|
} else {
|
|
47
48
|
const dimensions = sizeOf(item);
|
|
48
49
|
const stats = await fs.stat(item);
|
|
49
|
-
|
|
50
|
+
const withoutExt = basename(subname, extname(subname));
|
|
51
|
+
generated += indent + ` ${lowerCamelize(withoutExt)}: createItem({
|
|
50
52
|
path: ${importName(assetDir, item)},
|
|
51
53
|
width: ${dimensions.width},
|
|
52
54
|
height: ${dimensions.height},
|
|
@@ -9,31 +9,31 @@ import { dirname, extname, basename, relative } from 'path';
|
|
|
9
9
|
async function main() {
|
|
10
10
|
const argv = await yargs(hideBin(process.argv))
|
|
11
11
|
.options({
|
|
12
|
-
'outFile': {
|
|
13
|
-
type: 'string',
|
|
14
|
-
default: '.',
|
|
15
|
-
alias: 'o',
|
|
12
|
+
'outFile': {
|
|
13
|
+
type: 'string',
|
|
14
|
+
default: '.',
|
|
15
|
+
alias: 'o',
|
|
16
16
|
describe: 'Directory to generate the files into',
|
|
17
17
|
},
|
|
18
|
-
'assetDir': {
|
|
19
|
-
type: 'string',
|
|
20
|
-
default: './package.json',
|
|
21
|
-
alias: 'a',
|
|
18
|
+
'assetDir': {
|
|
19
|
+
type: 'string',
|
|
20
|
+
default: './package.json',
|
|
21
|
+
alias: 'a',
|
|
22
22
|
describe: 'package.json file to use for the version',
|
|
23
23
|
},
|
|
24
|
-
'wav': {
|
|
25
|
-
type: 'boolean',
|
|
26
|
-
default: false,
|
|
24
|
+
'wav': {
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
default: false,
|
|
27
27
|
describe: 'Include .wav files',
|
|
28
28
|
},
|
|
29
|
-
'ogg': {
|
|
30
|
-
type: 'boolean',
|
|
31
|
-
default: true,
|
|
29
|
+
'ogg': {
|
|
30
|
+
type: 'boolean',
|
|
31
|
+
default: true,
|
|
32
32
|
describe: 'Include .ogg files',
|
|
33
33
|
},
|
|
34
|
-
'mp3': {
|
|
35
|
-
type: 'boolean',
|
|
36
|
-
default: true,
|
|
34
|
+
'mp3': {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
default: true,
|
|
37
37
|
describe: 'Include .mp3 files',
|
|
38
38
|
},
|
|
39
39
|
})
|
|
@@ -103,7 +103,7 @@ async function main() {
|
|
|
103
103
|
let totalFileSize = 0;
|
|
104
104
|
for (const soundFile of files) {
|
|
105
105
|
const importName = sanitize(soundFile);
|
|
106
|
-
imports.push(`import ${importName} from '${relative(dirname(argv.outFile), soundFile)}';`);
|
|
106
|
+
imports.push(`import ${importName} from '${relative(dirname(argv.outFile), soundFile).replace(/\\/g, '/')}';`);
|
|
107
107
|
func += ` ${importName},\n`;
|
|
108
108
|
const stats = await fs.stat(soundFile);
|
|
109
109
|
totalFileSize += stats.size;
|
package/src/utils.ts
CHANGED
|
@@ -22,7 +22,7 @@ export async function allFiles(path: string): Promise<string[]> {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function sanitize(string: string): string {
|
|
25
|
-
return string.replace(/[^a-zA-Z0-9]/g, '_');
|
|
25
|
+
return string.replace(/[^a-zA-Z0-9]/g, '_');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function camelize(str: string) {
|
|
@@ -34,7 +34,6 @@ export function lowerCamelize(str: string): string {
|
|
|
34
34
|
return camelized.slice(0, 1).toLowerCase() + camelized.slice(1);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
37
|
export function categoryPath(assetDir: string, png: string): string[] {
|
|
39
38
|
const dir = dirname(png);
|
|
40
39
|
const trimmedDir = relative(assetDir, dir);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _directions_left_png from './../testData/directions/left.png';
|
|
2
|
+
import _directions_up_png from './../testData/directions/up.png';
|
|
3
|
+
import _fire_png from './../testData/fire.png';
|
|
4
|
+
|
|
5
|
+
export type TextureCatalog<T> = {
|
|
6
|
+
directions: {
|
|
7
|
+
left: T,
|
|
8
|
+
up: T,
|
|
9
|
+
}
|
|
10
|
+
fire: T,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export function createTextureCatalog<T>(createItem: (opts: {path: string, width: number, height: number, size: number}) => T): TextureCatalog<T> {
|
|
16
|
+
return {
|
|
17
|
+
directions: {
|
|
18
|
+
left: createItem({
|
|
19
|
+
path: _directions_left_png,
|
|
20
|
+
width: 100,
|
|
21
|
+
height: 100,
|
|
22
|
+
size: 4424,
|
|
23
|
+
}),
|
|
24
|
+
up: createItem({
|
|
25
|
+
path: _directions_up_png,
|
|
26
|
+
width: 100,
|
|
27
|
+
height: 100,
|
|
28
|
+
size: 601,
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
fire: createItem({
|
|
32
|
+
path: _fire_png,
|
|
33
|
+
width: 384,
|
|
34
|
+
height: 384,
|
|
35
|
+
size: 10908,
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import __testData_sounds_click_UI_Click_Metallic_mono_ogg from '../testData/sounds/click/UI_Click_Metallic_mono.ogg';
|
|
2
|
+
import __testData_sounds_click_UI_Click_Metallic_mono_mp3 from '../testData/sounds/click/UI_Click_Metallic_mono.mp3';
|
|
3
|
+
import __testData_sounds_jump_jump2_ogg from '../testData/sounds/jump/jump2.ogg';
|
|
4
|
+
import __testData_sounds_jump_xhGkA9Px_mp3 from '../testData/sounds/jump/xhGkA9Px.mp3';
|
|
5
|
+
|
|
6
|
+
export class SoundDefinition {
|
|
7
|
+
constructor(
|
|
8
|
+
readonly basename: string,
|
|
9
|
+
readonly files: string[],
|
|
10
|
+
readonly averageFileSize: number,
|
|
11
|
+
) {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export function sound_click(): SoundDefinition[] {
|
|
16
|
+
return [
|
|
17
|
+
new SoundDefinition(
|
|
18
|
+
'UI_Click_Metallic_mono',
|
|
19
|
+
[
|
|
20
|
+
__testData_sounds_click_UI_Click_Metallic_mono_ogg,
|
|
21
|
+
__testData_sounds_click_UI_Click_Metallic_mono_mp3,
|
|
22
|
+
],
|
|
23
|
+
2836,
|
|
24
|
+
),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function sound_jump(): SoundDefinition[] {
|
|
29
|
+
return [
|
|
30
|
+
new SoundDefinition(
|
|
31
|
+
'jump2',
|
|
32
|
+
[
|
|
33
|
+
__testData_sounds_jump_jump2_ogg,
|
|
34
|
+
],
|
|
35
|
+
5631,
|
|
36
|
+
),
|
|
37
|
+
new SoundDefinition(
|
|
38
|
+
'xhGkA9Px',
|
|
39
|
+
[
|
|
40
|
+
__testData_sounds_jump_xhGkA9Px_mp3,
|
|
41
|
+
],
|
|
42
|
+
2106,
|
|
43
|
+
),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
Binary file
|
|
Binary file
|
package/testData/fire.png
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|