Update Healer Man server
This commit is contained in:
1 parent
a64b2cb575
commit
71246e5b75
502 files changed
+4245
-19
No files matched your search
@@ -29,6 +29,7 @@ import {
|
||||
masterAudioOutputEnabled,
|
||||
playCombatAudio,
|
||||
playMasterAudioCue,
|
||||
selectCombatSoundAssets,
|
||||
} from "./combatAudio";
|
||||
|
||||
const fixtureEvent: CombatPresentationEvent = {
|
||||
@@ -56,6 +57,16 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("combat audio output policy", () => {
|
||||
it("plays source cues only on their mapped phase, with instant-cast release support", () => {
|
||||
const cast = { url: "/cast.mp3", phase: "cast-start" as const };
|
||||
const impact = { url: "/impact.mp3", phase: "impact" as const };
|
||||
expect(selectCombatSoundAssets([cast, impact], { phase: "cast-start" })).toEqual([cast]);
|
||||
expect(selectCombatSoundAssets([cast, impact], { phase: "impact" })).toEqual([impact]);
|
||||
expect(selectCombatSoundAssets([cast, impact], { phase: "tick" })).toEqual([]);
|
||||
expect(selectCombatSoundAssets([cast], { phase: "release", instantCast: true })).toEqual([cast]);
|
||||
expect(selectCombatSoundAssets([cast], { phase: "release" })).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not create or fetch audio while the master volume is disabled", async () => {
|
||||
const AudioContextConstructor = vi.fn();
|
||||
const fetch = vi.fn();
|
||||
@@ -151,7 +162,7 @@ describe("combat audio output policy", () => {
|
||||
it.each(["original", "missing-file", "bad-audio"])("uses original audio or a generated fallback for %s", async (scenario) => {
|
||||
vi.resetModules();
|
||||
const audio = await import("./combatAudio");
|
||||
const source = { connect: vi.fn(), disconnect: vi.fn(), start: vi.fn(), stop: vi.fn(), buffer: null, onended: null };
|
||||
const source = { connect: vi.fn(), disconnect: vi.fn(), start: vi.fn(), stop: vi.fn(), buffer: null, loop: false, onended: null };
|
||||
const oscillator = {
|
||||
connect: vi.fn(), disconnect: vi.fn(), start: vi.fn(), stop: vi.fn(),
|
||||
frequency: { setValueAtTime: vi.fn() }, type: "sine", onended: null,
|
||||
@@ -190,9 +201,119 @@ describe("combat audio output policy", () => {
|
||||
|
||||
expect(combatMedia.fetch).toHaveBeenCalledWith("/assets/game/combat-effects/audio/flash-heal.wav");
|
||||
expect(source.start).toHaveBeenCalledTimes(scenario === "original" ? 1 : 0);
|
||||
expect(source.loop).toBe(false);
|
||||
expect(audioContext.createBufferSource).toHaveBeenCalledTimes(scenario === "original" ? 1 : 0);
|
||||
expect(audioContext.createOscillator).toHaveBeenCalledTimes(scenario === "original" ? 0 : 1);
|
||||
expect(oscillator.start).toHaveBeenCalledTimes(scenario === "original" ? 0 : 1);
|
||||
audio.resetCombatAudio();
|
||||
});
|
||||
|
||||
it("loops only a flagged cast sound and stops the matching actor and ability", async () => {
|
||||
vi.resetModules();
|
||||
const audio = await import("./combatAudio");
|
||||
const sources: Array<{
|
||||
connect: ReturnType<typeof vi.fn>; disconnect: ReturnType<typeof vi.fn>;
|
||||
start: ReturnType<typeof vi.fn>; stop: ReturnType<typeof vi.fn>;
|
||||
buffer: null; loop: boolean; onended: null;
|
||||
}> = [];
|
||||
const oscillator = {
|
||||
connect: vi.fn(), disconnect: vi.fn(), start: vi.fn(), stop: vi.fn(),
|
||||
frequency: { setValueAtTime: vi.fn() }, type: "sine", onended: null,
|
||||
};
|
||||
const audioContext = {
|
||||
currentTime: 0, state: "running", destination: {},
|
||||
createGain: () => ({
|
||||
connect: vi.fn(), disconnect: vi.fn(), gain: {
|
||||
setTargetAtTime: vi.fn(), setValueAtTime: vi.fn(),
|
||||
exponentialRampToValueAtTime: vi.fn(), value: 1,
|
||||
},
|
||||
}),
|
||||
createStereoPanner: () => ({ connect: vi.fn(), disconnect: vi.fn() }),
|
||||
createBufferSource: vi.fn(() => {
|
||||
const source = {
|
||||
connect: vi.fn(), disconnect: vi.fn(), start: vi.fn(), stop: vi.fn(),
|
||||
buffer: null, loop: false, onended: null,
|
||||
};
|
||||
sources.push(source);
|
||||
return source;
|
||||
}),
|
||||
createOscillator: vi.fn(() => oscillator),
|
||||
decodeAudioData: vi.fn(async () => ({ duration: 0.2 })),
|
||||
resume: vi.fn(async () => undefined),
|
||||
};
|
||||
vi.stubGlobal("window", { AudioContext: function () { return audioContext; } });
|
||||
combatMedia.ready = true;
|
||||
combatMedia.entry.mockReturnValue({
|
||||
key: "runewaker:491147", source: "runewaker", spellId: 491147,
|
||||
sounds: [{ url: "/assets/game/combat-effects/audio/holy-cast.wav", phase: "cast-start", loopDuringCast: true }],
|
||||
});
|
||||
combatMedia.fetch.mockResolvedValue(new Response(new Uint8Array([1, 2, 3])));
|
||||
audio.configureCombatAudio(DEFAULT_COMBAT_PRESENTATION_SETTINGS, 0.6);
|
||||
const cast = {
|
||||
...fixtureEvent, source: "runewaker" as const, sourceSpellId: 491147,
|
||||
phase: "cast-start" as const, abilityId: "rom-priest-general-0", durationMs: 1_000,
|
||||
};
|
||||
audio.playCombatAudio(cast);
|
||||
audio.playCombatAudio({ ...cast, id: 2, sourceActorId: "second-priest" });
|
||||
audio.playCombatAudio({ ...cast, id: 5, abilityId: "rom-priest-primary-2" });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(sources).toHaveLength(3);
|
||||
expect(sources.every((source) => source.loop && source.start.mock.calls.length === 1)).toBe(true);
|
||||
audio.playCombatAudio({ ...cast, id: 3, phase: "cast-cancel" });
|
||||
expect(sources[0].stop).toHaveBeenCalledTimes(1);
|
||||
expect(sources[1].stop).not.toHaveBeenCalled();
|
||||
expect(sources[2].stop).not.toHaveBeenCalled();
|
||||
audio.playCombatAudio({ ...cast, id: 4, sourceActorId: "second-priest", phase: "release" });
|
||||
expect(sources[1].stop).toHaveBeenCalledTimes(1);
|
||||
expect(sources[2].stop).not.toHaveBeenCalled();
|
||||
audio.playCombatAudio({ ...cast, id: 6, abilityId: "rom-priest-primary-2", phase: "cast-cancel" });
|
||||
expect(sources[2].stop).toHaveBeenCalledTimes(1);
|
||||
audio.resetCombatAudio();
|
||||
});
|
||||
|
||||
it("does not start a loop after cancellation and caps a cast loop at its duration", async () => {
|
||||
vi.resetModules();
|
||||
const audio = await import("./combatAudio");
|
||||
const source = {
|
||||
connect: vi.fn(), disconnect: vi.fn(), start: vi.fn(), stop: vi.fn(),
|
||||
buffer: null, loop: false, onended: null,
|
||||
};
|
||||
const audioContext = {
|
||||
currentTime: 0, state: "running", destination: {},
|
||||
createGain: () => ({ connect: vi.fn(), disconnect: vi.fn(), gain: {
|
||||
setTargetAtTime: vi.fn(), value: 1,
|
||||
} }),
|
||||
createStereoPanner: () => ({ connect: vi.fn(), disconnect: vi.fn() }),
|
||||
createBufferSource: vi.fn(() => source),
|
||||
decodeAudioData: vi.fn(async () => ({ duration: 0.2 })),
|
||||
resume: vi.fn(async () => undefined),
|
||||
};
|
||||
vi.stubGlobal("window", { AudioContext: function () { return audioContext; } });
|
||||
combatMedia.ready = true;
|
||||
combatMedia.entry.mockReturnValue({
|
||||
key: "runewaker:491147", source: "runewaker", spellId: 491147,
|
||||
sounds: [{ url: "/assets/game/combat-effects/audio/holy-cast.wav", phase: "cast-start", loopDuringCast: true }],
|
||||
});
|
||||
let resolveFetch!: (response: Response) => void;
|
||||
combatMedia.fetch.mockImplementation(() => new Promise<Response>((resolve) => { resolveFetch = resolve; }));
|
||||
audio.configureCombatAudio(DEFAULT_COMBAT_PRESENTATION_SETTINGS, 0.6);
|
||||
const cast = {
|
||||
...fixtureEvent, source: "runewaker" as const, sourceSpellId: 491147,
|
||||
phase: "cast-start" as const, abilityId: "rom-priest-general-0", durationMs: 25,
|
||||
};
|
||||
audio.playCombatAudio(cast);
|
||||
audio.playCombatAudio({ ...cast, id: 2, phase: "cast-cancel" });
|
||||
resolveFetch(new Response(new Uint8Array([1, 2, 3])));
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
expect(audioContext.createBufferSource).not.toHaveBeenCalled();
|
||||
|
||||
audio.playCombatAudio({ ...cast, id: 3 });
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
expect(source.loop).toBe(true);
|
||||
expect(source.start).toHaveBeenCalledTimes(1);
|
||||
await new Promise((resolve) => setTimeout(resolve, 40));
|
||||
expect(source.stop).toHaveBeenCalledTimes(1);
|
||||
audio.resetCombatAudio();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user