UNPKG

cbt-game-generator

Version:

Configuration generator for CBT animation apps

42 lines (35 loc) 1.47 kB
import * as fs from 'fs'; import * as path from 'path'; export class AssetDirectoryGenerator { constructor( private skillName: string, private gameName: string, private targets: { [key: string]: string[] } ) {} generate(): void { const basePath = path.join('public', 'assets', this.skillName.toLowerCase(), this.convertToKebabCase(this.gameName)); // Create textures and videos directories for each sub-lo Object.keys(this.targets).forEach((subLo) => { // Create textures directory const texturesPath = path.join(basePath, 'textures', subLo); fs.mkdirSync(texturesPath, { recursive: true }); // Create videos directory const videosPath = path.join(basePath, 'videos', subLo); fs.mkdirSync(videosPath, { recursive: true }); // Create placeholder files for each target this.targets[subLo].forEach(target => { // Create texture files fs.writeFileSync(path.join(texturesPath, `${target.toLowerCase()}.webp`), ''); fs.writeFileSync(path.join(texturesPath, `${target.toLowerCase()}.json`), ''); // Create video files fs.writeFileSync(path.join(videosPath, `${target.toLowerCase()}.mp4`), ''); fs.writeFileSync(path.join(videosPath, `${target.toLowerCase()}_half.mp4`), ''); }); }); } private convertToKebabCase(str: string): string { return str .replace(/([a-z])([A-Z])/g, '$1-$2') .toLowerCase(); } }