generated from Labyricorn/labyricorn-project-template
216 lines
6.7 KiB
JavaScript
216 lines
6.7 KiB
JavaScript
/*
|
|
* Planetarium — XZBT Exhibit Contract 5.2 adapter.
|
|
*
|
|
* Declares the catalog, binds targets to real exhibit services, and routes
|
|
* the native UI through the canonical mutation path. No state of its own.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var Core = window.XZBTContractCore;
|
|
|
|
var IDENTITY = {
|
|
product: 'Planetarium',
|
|
version: '1.0.0',
|
|
build: 'reference-exhibit'
|
|
};
|
|
|
|
var DESCRIPTORS = [
|
|
{
|
|
id: 'sky.constellation',
|
|
kind: 'selection',
|
|
label: 'Constellation',
|
|
description: 'Constellation currently tracked and drawn.',
|
|
options: [
|
|
{ value: 'orion', label: 'Orion' },
|
|
{ value: 'cygnus', label: 'Cygnus' },
|
|
{ value: 'scorpius', label: 'Scorpius' },
|
|
{ value: 'ursa-major', label: 'Ursa Major' },
|
|
{ value: 'cassiopeia', label: 'Cassiopeia' },
|
|
{ value: 'lyra', label: 'Lyra' }
|
|
],
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'sky.magnitude-limit',
|
|
kind: 'range',
|
|
label: 'Magnitude limit',
|
|
description: 'Faintest stellar magnitude rendered. Higher values show more stars.',
|
|
min: 1, max: 6, step: 0.1, unit: 'mag',
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'sky.azimuth',
|
|
kind: 'range',
|
|
label: 'Azimuth',
|
|
description: 'Compass bearing of the view, 0 to 1 of a full turn.',
|
|
min: 0, max: 1, step: 0.01,
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'sky.altitude',
|
|
kind: 'range',
|
|
label: 'Altitude',
|
|
description: 'Elevation of the view above the horizon, 0 to 1.',
|
|
min: 0, max: 1, step: 0.01,
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'sky.time-scale',
|
|
kind: 'range',
|
|
label: 'Time scale',
|
|
description: 'Rate at which sky time advances.',
|
|
min: 0, max: 4, step: 0.05, unit: 'x',
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'sky.filter',
|
|
kind: 'selection',
|
|
label: 'Filter',
|
|
description: 'Optical filter applied to the view.',
|
|
options: [
|
|
{ value: 'none', label: 'None' },
|
|
{ value: 'light-pollution', label: 'Light pollution' },
|
|
{ value: 'h-alpha', label: 'H-alpha' },
|
|
{ value: 'oxygen-iii', label: 'Oxygen III' }
|
|
],
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'sky.tracking',
|
|
kind: 'state',
|
|
valueType: 'boolean',
|
|
label: 'Tracking',
|
|
description: 'Whether the mount is tracking the selected constellation.',
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'sky.paused',
|
|
kind: 'state',
|
|
valueType: 'boolean',
|
|
label: 'Sky frozen',
|
|
description: 'Whether sky time is frozen.',
|
|
readable: true, writable: true, restorable: true,
|
|
category: 'sky', requires: []
|
|
},
|
|
{
|
|
id: 'action.advance-time',
|
|
kind: 'impulse',
|
|
label: 'Advance time',
|
|
description: 'Advance sky time. Optional argument: minutes (1 to 240).',
|
|
arguments: [
|
|
{ name: 'minutes', type: 'number', required: false, min: 1, max: 240, default: 10 }
|
|
],
|
|
readable: false, writable: false, restorable: false,
|
|
category: 'action', requires: []
|
|
},
|
|
{
|
|
id: 'action.reset-sky',
|
|
kind: 'impulse',
|
|
label: 'Reset sky',
|
|
description: 'Return sky time to epoch.',
|
|
readable: false, writable: false, restorable: false,
|
|
category: 'action', requires: []
|
|
},
|
|
{
|
|
id: 'action.toggle-tracking',
|
|
kind: 'impulse',
|
|
label: 'Toggle tracking',
|
|
description: 'Engage or disengage the mount.',
|
|
readable: false, writable: false, restorable: false,
|
|
category: 'action', requires: []
|
|
},
|
|
{
|
|
id: 'telemetry.visible-stars',
|
|
kind: 'state',
|
|
valueType: 'number',
|
|
label: 'Visible stars',
|
|
description: 'Stars currently above the magnitude limit.',
|
|
readable: true, writable: false, restorable: false,
|
|
category: 'telemetry', requires: []
|
|
},
|
|
{
|
|
id: 'telemetry.sky-time',
|
|
kind: 'state',
|
|
valueType: 'number',
|
|
unit: 'h',
|
|
label: 'Sky time',
|
|
description: 'Elapsed sky time in hours.',
|
|
readable: true, writable: false, restorable: false,
|
|
category: 'telemetry', requires: []
|
|
},
|
|
{
|
|
id: 'telemetry.moon-phase',
|
|
kind: 'state',
|
|
valueType: 'number',
|
|
label: 'Moon phase',
|
|
description: 'Lunar phase as a fraction of the cycle.',
|
|
readable: true, writable: false, restorable: false,
|
|
category: 'telemetry', requires: []
|
|
}
|
|
];
|
|
|
|
function createPlanetariumContract(exhibit, ui) {
|
|
var catalog = new Core.Catalog(DESCRIPTORS);
|
|
|
|
var capabilities = new Core.CapabilityRegistry();
|
|
capabilities.declare('render', 'ready');
|
|
|
|
var setters = {
|
|
'sky.constellation': function (v) { return exhibit.setConstellation(v); },
|
|
'sky.magnitude-limit': function (v) { return exhibit.setMagnitudeLimit(v); },
|
|
'sky.azimuth': function (v) { return exhibit.setAzimuth(v); },
|
|
'sky.altitude': function (v) { return exhibit.setAltitude(v); },
|
|
'sky.time-scale': function (v) { return exhibit.setTimeScale(v); },
|
|
'sky.filter': function (v) { return exhibit.setFilter(v); },
|
|
'sky.tracking': function (v) { return exhibit.setTracking(v); },
|
|
'sky.paused': function (v) { return exhibit.setPaused(v); }
|
|
};
|
|
|
|
var readers = {};
|
|
var ids = catalog.ids();
|
|
for (var i = 0; i < ids.length; i++) {
|
|
(function (id) {
|
|
readers[id] = function () { return exhibit.read(id); };
|
|
})(ids[i]);
|
|
}
|
|
|
|
var actions = {
|
|
'action.advance-time': function (args) { return exhibit.advanceTime(args); },
|
|
'action.reset-sky': function () { return exhibit.resetSky(); },
|
|
'action.toggle-tracking': function () { return exhibit.toggleTracking(); }
|
|
};
|
|
|
|
var core = new Core.ContractCore({
|
|
identity: IDENTITY,
|
|
catalog: catalog,
|
|
capabilities: capabilities,
|
|
setters: setters,
|
|
readers: readers,
|
|
actions: actions
|
|
});
|
|
|
|
ui.dispatchOverride = function (targetId, value) {
|
|
core.applyMutation(targetId, value, 'ui');
|
|
ui.sync();
|
|
};
|
|
ui.invokeOverride = function (targetId, args) {
|
|
core.invokeAction(targetId, args || {}, 'ui');
|
|
ui.sync();
|
|
};
|
|
|
|
exhibit.onChange = function () { ui.sync(); };
|
|
|
|
return core;
|
|
}
|
|
|
|
window.PlanetariumContract = { create: createPlanetariumContract, IDENTITY: IDENTITY };
|
|
})();
|