forked from NDLANO/h5p-escape-room
-
Notifications
You must be signed in to change notification settings - Fork 1
/
upgrades.js
132 lines (116 loc) · 5.06 KB
/
upgrades.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var H5PUpgrades = H5PUpgrades || {};
H5PUpgrades['H5P.VirtualTourXR'] = (function () {
return {
0: {
2: function (parameters, finished) {
if (parameters && parameters.context &&
parameters.context.behaviour && parameters.context.behaviour.length) {
// Add wrapper for audio
const audio = parameters.context.behaviour;
parameters.context.behaviour = {
audio: audio
};
}
finished(null, parameters);
},
/**
* @param {{ threeImage: {scenes: Array<SceneParams>}; behaviour?: any; }} parameters
* @param {(param0: any, parameters: any) => void} finished
*/
4: function (parameters, finished) {
if (parameters && parameters.behaviour) {
parameters.behaviour.label = {
showLabel: false,
labelPosition: 'right'
};
}
if (parameters && parameters.threeImage && parameters.threeImage.scenes) {
for (const scene of parameters.threeImage.scenes) {
if (scene.interactions) {
for (const interaction of scene.interactions) {
if (!interaction.label) {
interaction.label = {
labelPosition: 'inherit',
showLabel: 'inherit',
};
}
}
}
}
}
finished(null, parameters);
},
/**
* Move hotspot and password settings out of label group.
* @param {object} parameters Parameters.
* @param {function} finished Callback when finished.
* @param {object} extras Extras such as metadata.
*/
5: (parameters, finished, extras) => {
if (Array.isArray(parameters?.threeImage?.scenes)) {
parameters.threeImage.scenes = parameters.threeImage.scenes.map((scene) => {
if (!Array.isArray(scene.interactions)) {
return scene;
}
scene.interactions = scene.interactions.map((interaction) => {
interaction.passwordSettings = {};
interaction.hotspotSettings = {};
if (interaction.label) {
if (typeof interaction.label.showAsHotspot === 'boolean') {
interaction.showAsHotspot = !!interaction.label.showAsHotspot;
}
if (typeof interaction.label.showAsOpenSceneContent === 'boolean') {
interaction.showAsOpenSceneContent = interaction.label.showAsOpenSceneContent;
}
if (typeof interaction.label.interactionPassword === 'string') {
interaction.passwordSettings.interactionPassword = interaction.label.interactionPassword;
}
if (typeof interaction.label.interactionPasswordHint === 'string') {
interaction.passwordSettings.interactionPasswordHint = interaction.label.interactionPasswordHint;
}
if (typeof interaction.label.showHotspotOnHover === 'boolean') {
interaction.hotspotSettings.showHotspotOnHover = interaction.label.showHotspotOnHover;
}
if (typeof interaction.label.isHotspotTabbable === 'boolean') {
interaction.hotspotSettings.isHotspotTabbable = interaction.label.isHotspotTabbable;
}
if (scene.type === 'static') {
if (typeof interaction.label.hotSpotSizeValues === 'string') {
interaction.hotspotSettings.hotSpotSizeValues = interaction.label.hotSpotSizeValues;
if (interaction.hotspotSettings.hotSpotSizeValues === '256,128') {
interaction.hotspotSettings.hotSpotSizeValues = '25,25'; // Was previously done in view
}
}
else {
interaction.hotspotSettings.hotSpotSizeValues = '25,25'; // Was hardcoded into view
}
}
else {
if (typeof interaction.label.hotSpotSizeValues === 'string') {
interaction.hotspotSettings.hotSpotSizeValues = interaction.label.hotSpotSizeValues;
}
else {
interaction.hotspotSettings.hotSpotSizeValues = '256,128';
}
}
delete interaction.label.showAsHotspot;
delete interaction.label.showAsOpenSceneContent;
delete interaction.label.interactionPassword;
delete interaction.label.interactionPasswordHint;
delete interaction.label.showHotspotOnHover;
delete interaction.label.isHotspotTabbable;
delete interaction.label.hotSpotSizeValues;
}
else {
interaction.label = {}; // Fixes old issue where this upgrade was forgotten
}
return interaction;
});
return scene;
});
}
finished(null, parameters, extras);
}
}
};
})();