arx-level-generator
Version:
A tool for creating Arx Fatalis maps
69 lines • 1.95 kB
JavaScript
export var SoundFlags;
(function (SoundFlags) {
SoundFlags[SoundFlags["None"] = 0] = "None";
SoundFlags[SoundFlags["EmitFromPlayer"] = 1] = "EmitFromPlayer";
SoundFlags[SoundFlags["Loop"] = 2] = "Loop";
SoundFlags[SoundFlags["Unique"] = 4] = "Unique";
SoundFlags[SoundFlags["VaryPitch"] = 8] = "VaryPitch";
})(SoundFlags || (SoundFlags = {}));
export class Sound {
filename;
flags;
/**
* Don't forget to add the audio to an entity's otherDependencies if you are
* using custom files
*/
constructor(filename, flags = SoundFlags.None) {
this.filename = filename;
this.flags = flags;
}
play() {
const flags = this.stringifyFlags();
const filename = this.getFilename();
return `play ${flags} ${filename}`;
}
/**
* only works if the sound has the unique flag
* @see SoundFlags.Unique
*/
stop() {
const flags = '-s';
const filename = this.getFilename();
return `play ${flags} ${filename}`;
}
getFilename() {
if (typeof this.filename === 'string') {
return '"' + this.filename + '"';
}
else {
return this.filename.name;
}
}
/**
* [o] = emit from player
* [l] = loop
* [i] = unique
* [p] = variable pitch
* [s] = stop (only if unique)
*/
stringifyFlags() {
let letters = '';
if (this.flags & SoundFlags.EmitFromPlayer) {
letters += 'o';
}
if (this.flags & SoundFlags.Loop) {
letters += 'l';
}
if (this.flags & SoundFlags.Unique) {
letters += 'i';
}
if (this.flags & SoundFlags.VaryPitch) {
letters += 'p';
}
return (letters === '' ? '' : '-') + letters;
}
isStoppable() {
return (this.flags & SoundFlags.Unique) !== 0;
}
}
//# sourceMappingURL=Sound.js.map