UNPKG

arx-level-generator

Version:
101 lines 3.36 kB
import path from 'node:path'; import { toArxLocale } from './Translations.js'; export class Audio { static replacements = {}; filename; isNative; sourcePath; type; isInternalAsset; constructor(props) { this.filename = props.filename; if (!this.filename.toLowerCase().endsWith('.wav')) { this.filename += '.wav'; } this.isNative = props.isNative ?? true; this.sourcePath = props.sourcePath; this.type = props.type ?? 'sfx'; this.isInternalAsset = props.isInternalAsset ?? false; } clone() { return new Audio({ filename: this.filename, isNative: this.isNative, sourcePath: this.sourcePath, type: this.type, isInternalAsset: this.isInternalAsset, }); } static fromCustomFile(props) { return new Audio({ ...props, isNative: false, }); } exportSourceAndTarget(settings) { if (this.isNative) { throw new Error('trying to export a native Audio'); } const targetPath = this.type === 'sfx' ? 'sfx' : 'speech/' + toArxLocale(this.type.split('/')[1]); const source = path.resolve(this.isInternalAsset ? settings.internalAssetsDir : settings.assetsDir, this.sourcePath ?? targetPath, this.filename); const target = path.resolve(settings.outputDir, targetPath, this.filename); return [source, target]; } static replace(from, to) { if (!from.isNative) { throw new Error('you can only replace native audio files'); } if (to.isNative) { throw new Error('you can only replace audio files with custom audio files'); } this.replacements[from.filename] = to; } static mute(sound) { this.replace(sound, Audio.fromCustomFile({ filename: 'no-sound.wav', sourcePath: 'reset', isInternalAsset: true, })); } static exportReplacements(settings, type = 'sfx') { const pairs = {}; for (const key in this.replacements) { const [source] = this.replacements[key].exportSourceAndTarget(settings); const target = path.resolve(settings.outputDir, type, key); pairs[target] = source; } return pairs; } // ---------------- static get spiderStep3() { return new Audio({ filename: 'spider_step3' }); } static get metalOnWood2() { return new Audio({ filename: 'metal_on_wood_2' }); } static get sausageJump() { return new Audio({ filename: 'sausage_jump' }); } static get footstepShoeMetalStep() { return new Audio({ filename: 'footstep_shoe_metal_step' }); } static get interfaceInvstd() { return new Audio({ filename: 'interface_invstd' }); } static get clothOnCloth1() { return new Audio({ filename: 'cloth_on_cloth_1' }); } static get lever() { return new Audio({ filename: 'lever' }); } static get system() { return new Audio({ filename: 'system' }); } static get system2() { return new Audio({ filename: 'system2' }); } static get system3() { return new Audio({ filename: 'system3' }); } } //# sourceMappingURL=Audio.js.map