@@ -16,58 +16,48 @@ module.exports.supportedOflVersion = `7.3.0`;
1616module . exports . export = function exportMillumin ( fixtures , options ) {
1717 // one JSON file for each fixture
1818 const outFiles = fixtures . map ( fixture => {
19- let jsonData = JSON . parse ( JSON . stringify ( fixture . jsonObject ) ) ;
20- jsonData . $schema = `https://raw.githubusercontent.com/OpenLightingProject/open-fixture-library/schema-${ module . exports . supportedOflVersion } /schemas/fixture.json` ;
21-
22- jsonData . fixtureKey = fixture . key ;
23- jsonData . manufacturerKey = fixture . manufacturer . key ;
24- jsonData . oflURL = `https://open-fixture-library.org/${ fixture . manufacturer . key } /${ fixture . key } ` ;
25-
26- jsonData . categories = getDowngradedCategories ( jsonData . categories ) ;
27-
28- if ( jsonData . links ) {
29- if ( jsonData . links . manual ) {
30- // replace links with manual URL in keys array
31- const jsonKeys = Object . keys ( jsonData ) ;
32- jsonKeys [ jsonKeys . indexOf ( `links` ) ] = `manualURL` ;
33- jsonData . manualURL = fixture . getLinksOfType ( `manual` ) [ 0 ] ;
34-
35- // reorder JSON properties in jsonKeys order
36- const reorderedJsonData = { } ;
37- jsonKeys . forEach ( key => {
38- reorderedJsonData [ key ] = jsonData [ key ] ;
39- } ) ;
40- jsonData = reorderedJsonData ;
41- }
42- else {
43- delete jsonData . links ;
44- }
19+ const oflJson = JSON . parse ( JSON . stringify ( fixture . jsonObject ) ) ;
20+ const milluminJson = { } ;
21+
22+ milluminJson . $schema = `https://raw.githubusercontent.com/OpenLightingProject/open-fixture-library/schema-${ module . exports . supportedOflVersion } /schemas/fixture.json` ;
23+ milluminJson . name = oflJson . name ;
24+ addIfValidData ( milluminJson , `shortName` , oflJson . shortName ) ;
25+ milluminJson . categories = getDowngradedCategories ( oflJson . categories ) ;
26+ milluminJson . meta = oflJson . meta ;
27+ addIfValidData ( milluminJson , `comment` , oflJson . comment ) ;
28+
29+ if ( oflJson . links && oflJson . links . manual ) {
30+ milluminJson . manualURL = fixture . getLinksOfType ( `manual` ) [ 0 ] ;
4531 }
4632
47- delete jsonData . wheels ;
33+ addIfValidData ( milluminJson , `helpWanted` , oflJson . helpWanted ) ;
34+ addIfValidData ( milluminJson , `rdm` , oflJson . rdm ) ;
35+ addIfValidData ( milluminJson , `physical` , oflJson . physical ) ;
36+ addIfValidData ( milluminJson , `matrix` , getDowngradedMatrix ( oflJson . matrix , fixture ) ) ;
4837
49- // resolve all pixel key constraints
50- if ( jsonData . matrix && jsonData . matrix . pixelGroups ) {
51- Object . keys ( jsonData . matrix . pixelGroups ) . forEach ( groupKey => {
52- jsonData . matrix . pixelGroups [ groupKey ] = fixture . matrix . pixelGroups [ groupKey ] ;
38+ if ( oflJson . availableChannels ) {
39+ milluminJson . availableChannels = { } ;
40+ Object . entries ( oflJson . availableChannels ) . forEach ( ( [ chKey , jsonChannel ] ) => {
41+ milluminJson . availableChannels [ chKey ] = getDowngradedChannel ( chKey , jsonChannel , fixture ) ;
5342 } ) ;
5443 }
5544
56- if ( jsonData . availableChannels ) {
57- Object . keys ( jsonData . availableChannels ) . forEach (
58- chKey => downgradeChannel ( jsonData . availableChannels , chKey , fixture )
59- ) ;
45+ if ( oflJson . templateChannels ) {
46+ milluminJson . templateChannels = { } ;
47+ Object . entries ( oflJson . templateChannels ) . forEach ( ( [ chKey , jsonChannel ] ) => {
48+ milluminJson . templateChannels [ chKey ] = getDowngradedChannel ( chKey , jsonChannel , fixture ) ;
49+ } ) ;
6050 }
6151
62- if ( jsonData . templateChannels ) {
63- Object . keys ( jsonData . templateChannels ) . forEach (
64- chKey => downgradeChannel ( jsonData . templateChannels , chKey , fixture )
65- ) ;
66- }
52+ milluminJson . modes = oflJson . modes ;
53+
54+ milluminJson . fixtureKey = fixture . key ;
55+ milluminJson . manufacturerKey = fixture . manufacturer . key ;
56+ milluminJson . oflURL = `https://open-fixture-library.org/ ${ fixture . manufacturer . key } / ${ fixture . key } ` ;
6757
6858 return {
6959 name : `${ fixture . manufacturer . key } /${ fixture . key } .json` ,
70- content : fixtureJsonStringify ( jsonData ) ,
60+ content : fixtureJsonStringify ( milluminJson ) ,
7161 mimetype : `application/ofl-fixture` ,
7262 fixtures : [ fixture ]
7363 } ;
@@ -78,7 +68,7 @@ module.exports.export = function exportMillumin(fixtures, options) {
7868
7969/**
8070 * Replaces the fixture's categories array with one that only includes categories
81- * from OFL schema version 7.3.0 .
71+ * from the supported OFL schema version.
8272 * @param {array.<string> } categories The fixture's categories array.
8373 * @returns {array.<string> } A filtered categories array.
8474 */
@@ -97,13 +87,27 @@ function getDowngradedCategories(categories) {
9787}
9888
9989/**
100- * Replaces the specified channel in the specified channels object with a downgraded version for schema 7.1.0.
101- * @param {object } channelObject Either availableChannels or templateChannels.
90+ * @param {object|undefined } jsonMatrix The matrix JSON data (if present) that should be downgraded.
91+ * @param {Fixture } fixture The fixture the matrix belongs to.
92+ * @returns {object } A downgraded version of the specified matrix object.
93+ */
94+ function getDowngradedMatrix ( jsonMatrix , fixture ) {
95+ if ( jsonMatrix && jsonMatrix . pixelGroups ) {
96+ Object . keys ( jsonMatrix . pixelGroups ) . forEach ( groupKey => {
97+ jsonMatrix . pixelGroups [ groupKey ] = fixture . matrix . pixelGroups [ groupKey ] ;
98+ } ) ;
99+ }
100+
101+ return jsonMatrix ;
102+ }
103+
104+ /**
102105 * @param {string } channelKey A key that exists in given channelObject and specifies the channel that should be downgraded.
106+ * @param {object } jsonChannel The channel JSON data that should be downgraded.
103107 * @param {Fixture } fixture The fixture the channel belongs to.
108+ * @returns {object } A downgraded version of the specified channel object.
104109 */
105- function downgradeChannel ( channelObject , channelKey , fixture ) {
106- const jsonChannel = channelObject [ channelKey ] ;
110+ function getDowngradedChannel ( channelKey , jsonChannel , fixture ) {
107111 const channel = new CoarseChannel ( channelKey , jsonChannel , fixture ) ;
108112
109113 const downgradedChannel = { } ;
@@ -119,8 +123,6 @@ function downgradeChannel(channelObject, channelKey, fixture) {
119123 addIfValidData ( downgradedChannel , `crossfade` , channel . canCrossfade ) ;
120124 addIfValidData ( downgradedChannel , `precedence` , jsonChannel . precedence ) ;
121125
122- channelObject [ channelKey ] = downgradedChannel ;
123-
124126 if ( capabilitiesNeeded ( ) ) {
125127 downgradedChannel . capabilities = [ ] ;
126128
@@ -145,6 +147,8 @@ function downgradeChannel(channelObject, channelKey, fixture) {
145147 } ) ;
146148 }
147149
150+ return downgradedChannel ;
151+
148152 /**
149153 * @returns {boolean } Whether or not it is needed to include capabilities in a downgraded version of this channel
150154 */
0 commit comments