import { system, TicksPerSecond } from "@minecraft/server";
import { customWorld } from "./util";
var SoundIds;
(function (SoundIds) {
    SoundIds["Autumn"] = "pu_biomes.oneshot.autumn";
    SoundIds["CrystalCave"] = "pu_biomes.oneshot.crystal_cave";
    SoundIds["Enchanted"] = "pu_biomes.oneshot.enchanted";
    SoundIds["Horror"] = "pu_biomes.oneshot.horror";
    SoundIds["Lavander"] = "pu_biomes.oneshot.lavander";
    SoundIds["Lunar"] = "pu_biomes.oneshot.lunar";
    SoundIds["Mushroom"] = "pu_biomes.oneshot.mushroom";
    SoundIds["SandstoneCave"] = "pu_biomes.oneshot.sandstone_cave";
    SoundIds["Sky"] = "pu_biomes.oneshot.sky";
    SoundIds["Toxic"] = "pu_biomes.oneshot.toxic";
    SoundIds["Volcano"] = "pu_biomes.oneshot.volcano";
    SoundIds["Whisper"] = "pu_biomes.oneshot.whisper";
})(SoundIds || (SoundIds = {}));
const biomeToSoundIdMap = {
    volcano: SoundIds.Volcano,
    autumn: SoundIds.Autumn,
    crystal_caves: SoundIds.CrystalCave,
    sandstone_caves: SoundIds.SandstoneCave,
    enchanted: SoundIds.Enchanted,
    horror: SoundIds.Horror,
    lavander: SoundIds.Lavander,
    lunar: SoundIds.Lunar,
    mushroom: SoundIds.Mushroom,
    sky_islands: SoundIds.Sky,
    toxic: SoundIds.Toxic,
    whisper: SoundIds.Whisper,
};
const cooldownTime = 10;
export class SoundHandler {
    constructor(player, biome) {
        this.player = player;
        this.biome = biome;
        this.processSoundFactory();
    }
    processSoundFactory() {
        if (SoundHandler.soundIndex.has(this.player.id))
            return;
        const biomeName = customWorld.getBiomeName(this.biome);
        if (!biomeName)
            return;
        const selectedSound = biomeToSoundIdMap[biomeName];
        if (!selectedSound)
            return;
        this.player.playSound(selectedSound);
        SoundHandler.soundIndex.add(this.player.id);
        const timeOut = system.runTimeout(() => {
            SoundHandler.soundIndex.delete(this.player.id);
            system.clearRun(timeOut);
        }, (cooldownTime + Math.random() * 30) * TicksPerSecond);
    }
}
SoundHandler.soundIndex = new Set();
