generated from Labyricorn/labyricorn-project-template
146 lines
4.6 KiB
JavaScript
146 lines
4.6 KiB
JavaScript
/*
|
|
* Museum Gallery — XZBT Exhibit Contract 5.3 adapter.
|
|
*
|
|
* Same three responsibilities as every other reference exhibit's adapter
|
|
* (declare the catalog, bind it to the real exhibit, hold no state of its
|
|
* own) plus one addition that only this exhibit needs: declaring the
|
|
* Contract 5.3 `surfaces` catalog (Section 31).
|
|
*
|
|
* This file constructs exactly ONE Exhibit State Core. It is loaded only by
|
|
* control.html — the primary surface — which is the sole owner of the Core
|
|
* this exhibit instance uses. artifact.html and info-wall.html never load
|
|
* this file; they attach to the Core that control.html created, over the
|
|
* exhibit-internal bus in surface-bus.js. See README.md for the full
|
|
* attachment-architecture writeup.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var Core = window.XZBTContractCore;
|
|
var Gallery = window.MuseumGalleryExhibit.Gallery;
|
|
var ARTIFACTS = window.MuseumGalleryExhibit.ARTIFACTS;
|
|
var ARTIFACT_LABELS = window.MuseumGalleryExhibit.ARTIFACT_LABELS;
|
|
|
|
var IDENTITY = {
|
|
product: 'Museum Gallery',
|
|
version: '0.1.0',
|
|
build: 'reference-exhibit'
|
|
};
|
|
|
|
var DESCRIPTORS = [
|
|
{
|
|
id: 'artifact.selected',
|
|
kind: 'selection',
|
|
label: 'Selected Artifact',
|
|
description: 'The artifact currently on display.',
|
|
options: ARTIFACTS.map(function (id) {
|
|
return { value: id, label: ARTIFACT_LABELS[id] };
|
|
}),
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'gallery', requires: []
|
|
},
|
|
{
|
|
id: 'lighting.level',
|
|
kind: 'range',
|
|
label: 'Lighting Level',
|
|
description: 'Gallery lighting, 0 (dark) to 1 (full).',
|
|
min: 0, max: 1, step: 0.01,
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'gallery', requires: []
|
|
},
|
|
{
|
|
id: 'rotation.speed',
|
|
kind: 'range',
|
|
label: 'Rotation Speed',
|
|
description: 'Turntable speed under the displayed artifact.',
|
|
min: 0, max: 2, step: 0.1,
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'gallery', requires: []
|
|
},
|
|
{
|
|
id: 'labels.enabled',
|
|
kind: 'state',
|
|
valueType: 'boolean',
|
|
label: 'Labels Enabled',
|
|
description: 'Whether descriptive labels are shown on the wall and display.',
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'gallery', requires: []
|
|
},
|
|
{
|
|
id: 'action.spotlight-flash',
|
|
kind: 'impulse',
|
|
label: 'Spotlight Flash',
|
|
description: 'Briefly flash a spotlight on the current artifact.',
|
|
readable: false, writable: false, restorable: false,
|
|
category: 'action', requires: [], arguments: []
|
|
}
|
|
];
|
|
|
|
/* Contract 5.3 §31.2 surface descriptors. surface.control is primary. */
|
|
var SURFACES = [
|
|
{
|
|
id: 'surface.control', label: 'Control Room', kind: 'surface',
|
|
primary: true, url: 'control.html', role: 'control'
|
|
},
|
|
{
|
|
id: 'surface.artifact', label: 'Artifact Display', kind: 'surface',
|
|
primary: false, url: 'artifact.html', role: 'ambient'
|
|
},
|
|
{
|
|
id: 'surface.info-wall', label: 'Information Wall', kind: 'surface',
|
|
primary: false, url: 'info-wall.html', role: 'information'
|
|
}
|
|
];
|
|
|
|
function createMuseumGalleryContract(gallery) {
|
|
var catalog = new Core.Catalog(DESCRIPTORS);
|
|
|
|
var capabilities = new Core.CapabilityRegistry();
|
|
capabilities.declare('render', 'ready');
|
|
|
|
var surfaces = new Core.SurfaceCatalog(SURFACES);
|
|
|
|
var setters = {
|
|
'artifact.selected': function (v) { return gallery.setArtifact(v); },
|
|
'lighting.level': function (v) { return gallery.setLightingLevel(v); },
|
|
'rotation.speed': function (v) { return gallery.setRotationSpeed(v); },
|
|
'labels.enabled': function (v) { return gallery.setLabelsEnabled(v); }
|
|
};
|
|
|
|
var readers = {};
|
|
var ids = catalog.ids();
|
|
for (var i = 0; i < ids.length; i++) {
|
|
(function (id) {
|
|
readers[id] = function () { return gallery.read(id); };
|
|
})(ids[i]);
|
|
}
|
|
|
|
var actions = {
|
|
'action.spotlight-flash': function () { return gallery.flashSpotlight(); }
|
|
};
|
|
|
|
var core = new Core.ContractCore({
|
|
identity: IDENTITY,
|
|
catalog: catalog,
|
|
capabilities: capabilities,
|
|
setters: setters,
|
|
readers: readers,
|
|
actions: actions,
|
|
surfaces: surfaces,
|
|
/* Contract 5.3 adoption is per-instance; every other reference exhibit
|
|
* keeps the shared core's Contract 5.2 defaults untouched. */
|
|
contractMinor: 3,
|
|
xzbtVersion: '5.3'
|
|
});
|
|
|
|
return core;
|
|
}
|
|
|
|
window.MuseumGalleryContract = {
|
|
create: createMuseumGalleryContract,
|
|
IDENTITY: IDENTITY,
|
|
DESCRIPTORS: DESCRIPTORS,
|
|
SURFACES: SURFACES
|
|
};
|
|
})();
|