Skip to content

Commit 572df91

Browse files
committed
Интерактивный элемент может содержать собственную озвучку
1 parent 02773fb commit 572df91

10 files changed

Lines changed: 54 additions & 44 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* `0.9.29`
2+
* ✨ Каждая фотография интерактивного элемента может содержать собственную озвучку
23
* ➕ Добавлен biome для лингинга кода и проверки ошибок
34
* `0.9.28`
45
* ✨ Поддержка зума через колесико мыши

src/Models/BackgroundAudio/BackgroundAudioView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ export class BackgroundAudioView {
6464
}
6565

6666
public play() {
67-
this.currentAudioPack && this.currentAudioPack.play(true);
67+
this.currentAudioPack?.play(true);
6868
}
6969

7070
public pause() {
71-
this.currentAudioPack && this.currentAudioPack.pause();
71+
this.currentAudioPack?.pause();
7272
}
7373

7474
public clearSound() {

src/Models/FieldItem.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ export class FieldItem extends LinkToState {
153153
);
154154

155155
if (this.fieldItemInfo.images && this.fieldItemInfo.images.length > 0) {
156+
let audioContent: AudioContent | null = null;
156157
if (audioContentUsedByImageContent) {
157158
// если в фотографиях есть необходимость в аудио - создаем его
158-
createEmptyAudioContent();
159+
audioContent = this.createEmptyAudioContent(backgroundPlane);
159160
}
160161
const imageContent = new ImagesContent(
161162
this.fieldItemInfo.images,
@@ -165,6 +166,7 @@ export class FieldItem extends LinkToState {
165166
this.gui3Dmanager,
166167
this.assetsManager,
167168
this.scene,
169+
audioContent,
168170
);
169171
this.contentList.push(imageContent);
170172
navMenuItems.push("Фотографии");
@@ -219,27 +221,28 @@ export class FieldItem extends LinkToState {
219221
`На элементе ${this.name} есть audio, хотя оно уже занято изображениями, потому пропускается`,
220222
);
221223
} else {
222-
createEmptyAudioContent().setAudioContent(this.fieldItemInfo.audios[0]);
224+
this.createEmptyAudioContent(backgroundPlane).setAudioContent(
225+
this.fieldItemInfo.audios[0],
226+
);
223227
}
224228
}
225229
this.contentBackground = backgroundPlane;
226230
this.changeContent(0);
227-
228-
function createEmptyAudioContent() {
229-
const audioContent = new AudioContent(
230-
backgroundPlane,
231-
FieldItem.containerSize * 1.6,
232-
FieldItem.containerSize / 2,
233-
() => {
234-
this.onPlayMedia();
235-
this.videoContent?.pauseVideo();
236-
},
237-
this.gui3Dmanager,
238-
this.scene,
239-
);
240-
this.contentList.push(audioContent);
241-
return audioContent;
242-
}
231+
}
232+
private createEmptyAudioContent(backgroundPlane: Mesh) {
233+
const audioContent = new AudioContent(
234+
backgroundPlane,
235+
FieldItem.containerSize * 1.6,
236+
FieldItem.containerSize / 2,
237+
() => {
238+
this.onPlayMedia();
239+
this.videoContent?.pauseVideo();
240+
},
241+
this.gui3Dmanager,
242+
this.scene,
243+
);
244+
this.contentList.push(audioContent);
245+
return audioContent;
243246
}
244247

245248
private changeContent(contentIndex: number) {

src/Models/FieldItemContents/AudioContent.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class AudioContent implements FieldItemContent {
3333
private audio: Sound;
3434
private uiLayerPlane: Mesh;
3535

36-
private audioInfo: FieldItemAudioContent | null = null;
36+
private audioInfo?: FieldItemAudioContent | null;
3737

3838
constructor(
3939
private parent: TransformNode,
@@ -184,6 +184,9 @@ export class AudioContent implements FieldItemContent {
184184
}
185185

186186
private getCurrentPositionText(): string {
187+
if (!this.audioInfo) {
188+
return "";
189+
}
187190
return `${this.durationView(this.getCurrentPosition())}/${this.durationView(
188191
this.audioInfo.duration,
189192
)}`;

src/Models/FieldItemContents/ImagesContent.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { GUI3DManager } from "@babylonjs/gui/3D/gui3DManager";
1717
import { CustomHolographicButton } from "../../Stuff/CustomHolographicButton";
1818
import type { FieldItemImageContent } from "../ExcursionModels/FieldItemImageContent";
1919
import { NavigationMenu } from "../NavigationMenu";
20+
import type { AudioContent } from "./AudioContent";
2021
import type { FieldItemContent } from "./FieldItemContent";
2122

2223
export class ImagesContent implements FieldItemContent {
@@ -64,6 +65,7 @@ export class ImagesContent implements FieldItemContent {
6465
private gui3DManager: GUI3DManager,
6566
private assetsManager: AssetsManager,
6667
private scene: Scene,
68+
private parentAudioContent: AudioContent,
6769
) {
6870
if (images.length > 1) {
6971
this.rightButton = this.createButton(">", contentWidth / 2.5);
@@ -148,6 +150,9 @@ export class ImagesContent implements FieldItemContent {
148150
}
149151
}
150152
this.currentImage = index;
153+
if (this.images[index].audio) {
154+
this.parentAudioContent.setAudioContent(this.images[index].audio);
155+
}
151156
}
152157

153158
private loadPictureResources(index: number, url: string): TextureAssetTask {

src/Models/IconBottom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { BottomImageConfiguration } from "../Configuration/Configuration";
77

88
export class IconBottom {
99
constructor(
10-
private _scene: Scene,
10+
_scene: Scene,
1111
config: BottomImageConfiguration,
1212
) {
1313
const bottomPlane = MeshBuilder.CreatePlane(

src/Models/NavigationMenu.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import type { TransformNode } from "@babylonjs/core/Meshes/transformNode";
33
import { TextBlock, TextWrapping } from "@babylonjs/gui/2D/controls/textBlock";
44
import type { GUI3DManager } from "@babylonjs/gui/3D/gui3DManager";
55
import { CustomHolographicButton } from "../Stuff/CustomHolographicButton";
6-
import { ObjectsStackPanelHelper } from "./ObjectsStackPanelHelper";
6+
import { placeAsHorizontalStack } from "./ObjectsStackPanelHelper";
77

88
export class NavigationMenu {
99
private buttons: CustomHolographicButton[] = [];
1010

1111
constructor(
12-
private labels: string[],
13-
private menuWitdh: number,
12+
labels: string[],
13+
menuWitdh: number,
1414
private positionY: number,
15-
private parent: TransformNode,
15+
parent: TransformNode,
1616
private gui3Dmanager: GUI3DManager,
17-
private buttonSizeGetter: (index: number) => {
17+
buttonSizeGetter: (index: number) => {
1818
width: number;
1919
height: number;
2020
},
@@ -26,7 +26,7 @@ export class NavigationMenu {
2626
const button = this.createButton(label, parent, i, width, height);
2727
this.buttons.push(button);
2828
}
29-
ObjectsStackPanelHelper.placeAsHorizontalStack(this.buttons, menuWitdh);
29+
placeAsHorizontalStack(this.buttons, menuWitdh);
3030
}
3131

3232
public setCurrentIndex(index: number) {

src/Models/ObjectsStackPanelHelper.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ interface ItemWithPosition {
44
position: Vector3;
55
}
66

7-
export class ObjectsStackPanelHelper {
8-
public static placeAsHorizontalStack(
9-
objects: ItemWithPosition[],
10-
containerSize: number,
11-
) {
12-
// Stack emulation
13-
const size = containerSize / (objects.length + 1);
14-
for (let i = 0; i < objects.length; i++) {
15-
const currentButton = objects[i];
16-
const position =
17-
-containerSize / 2 + // left point
18-
size * (i + 1); // offset
19-
currentButton.position.x = position;
20-
}
7+
export function placeAsHorizontalStack(
8+
objects: ItemWithPosition[],
9+
containerSize: number,
10+
) {
11+
// Stack emulation
12+
const size = containerSize / (objects.length + 1);
13+
for (let i = 0; i < objects.length; i++) {
14+
const currentButton = objects[i];
15+
const position =
16+
-containerSize / 2 + // left point
17+
size * (i + 1); // offset
18+
currentButton.position.x = position;
2119
}
2220
}

src/StateChangeLoadingScreen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class StateChangeLoadingScreen implements ILoadingScreen {
1010

1111
private textBlock: TextBlock;
1212

13-
constructor(private gui: AdvancedDynamicTexture) {
13+
constructor(gui: AdvancedDynamicTexture) {
1414
this.displayLoadingUI = () => this.displayUIInternal();
1515
this.hideLoadingUI = () => this.hideLoadingUIInternal();
1616

src/Viewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class Viewer {
294294
this.prefetchAudio(targetPicture);
295295
await this.drawImage(
296296
targetPicture,
297-
() => actionBeforeChange && actionBeforeChange(targetPicture),
297+
() => actionBeforeChange?.(targetPicture),
298298
);
299299

300300
this.fullScreenGUI.setFastReturnToFirstStateVisible(

0 commit comments

Comments
 (0)