diff options
author | Fabian Guerra Soto <fabian.guerra@mapbox.com> | 2017-06-16 06:41:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-16 06:41:51 -0700 |
commit | 67c09b18e491e66e2ba058498b8f3b44e49d0105 (patch) | |
tree | a82b0b79261c352a72a75e0792cf21b327759b03 /platform/darwin/scripts/generate-style-code.js | |
parent | 6cba15f3a964b39184651dae32cccf32c8d706d0 (diff) | |
download | qtlocation-mapboxgl-67c09b18e491e66e2ba058498b8f3b44e49d0105.tar.gz |
MGLLight autogenerate scripts (#9260)
* [ios, macos] Add the MGLLight generation templates
* [ios, macos] Add MGLLight generation script
* [ios, macos] Add the auto-generation script for MGLLight.mm
* [ios, macos] Add the auto-generation script for MGLLightTest.mm
* [core] Add const to Position constructor.
* [ios, macos] Simplify MGLLightTest.mm autogenerate script.
Diffstat (limited to 'platform/darwin/scripts/generate-style-code.js')
-rw-r--r-- | platform/darwin/scripts/generate-style-code.js | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 7efc8d441c..5a4936c0ee 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -149,6 +149,9 @@ global.mbglTestValue = function (property, layerType) { type = 'Alignment'; } let value = camelize(_.last(_.keys(property.values))); + if (property['light-property']) { + return `mbgl::style::Light${type}Type::${value}`; + } return `mbgl::style::${type}Type::${value}`; } case 'color': @@ -225,6 +228,9 @@ global.propertyDoc = function (propertyName, property, layerType, kind) { let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) { let otherProperty = camelizeWithLeadingLowercase(peerPropertyName); let otherValue = objCType(layerType, peerPropertyName) + camelize(propertyValue); + if (property.type == 'array' && kind == 'light') { + otherValue = propertyValue; + } return '`' + `${otherProperty}` + '` is set to `' + `${otherValue}` + '`'; }); // Match references to our own property values. @@ -256,7 +262,7 @@ global.propertyDoc = function (propertyName, property, layerType, kind) { if (kind !== 'enum') { if ('default' in property) { doc += `\n\nThe default value of this property is ${propertyDefault(property, layerType)}.`; - if (!property.required) { + if (!property.required && kind != 'light') { doc += ' Set this property to `nil` to reset it to the default value.'; } } @@ -348,6 +354,8 @@ global.describeValue = function (value, property, layerType) { let objCType = global.objCType(layerType, property.name); return `${conjunction}\`${objCType}${camelize(possibleValue)}\``; }).join(separator); + } else if (property['light-property']) { + displayValue = `\`${prefix}Light${camelize(property.name)}${camelize(value)}\``; } else { let objCType = global.objCType(layerType, property.name); displayValue = `\`${objCType}${camelize(value)}\``; @@ -382,6 +390,8 @@ global.describeValue = function (value, property, layerType) { case 'offset': case 'translate': return 'an `NSValue` object containing a `CGVector` struct set to' + ` ${value[0]}${units} rightward and ${value[1]}${units} downward`; + case 'position': + return 'an `MGLSphericalPosition` struct set to' + ` ${value[0]} radial, ${value[1]} azimuthal and ${value[2]} polar`; default: return 'the array `' + value.join('`, `') + '`'; } @@ -418,6 +428,7 @@ global.propertyType = function (property) { return 'NSArray<NSString *> *'; case 'padding': return 'NSValue *'; + case 'position': case 'offset': case 'translate': return 'NSValue *'; @@ -457,6 +468,8 @@ global.valueTransformerArguments = function (property) { return ['std::vector<std::string>', objCType, 'std::string']; case 'padding': return ['std::array<float, 4>', objCType]; + case 'position': + return ['mbgl::style::Position', objCType]; case 'offset': case 'translate': return ['std::array<float, 2>', objCType]; @@ -478,6 +491,9 @@ global.mbglType = function(property) { return 'std::string'; case 'enum': { let type = camelize(originalPropertyName(property)); + if (property['light-property']) { + return `mbgl::style::Light${type}Type`; + } if (/-translate-anchor$/.test(originalPropertyName(property))) { type = 'TranslateAnchor'; } @@ -499,6 +515,8 @@ global.mbglType = function(property) { case 'offset': case 'translate': return 'std::array<float, 2>'; + case 'position': + return 'mbgl::style::Position'; default: throw new Error(`unknown array type for ${property.name}`); } @@ -519,6 +537,17 @@ global.setSourceLayer = function() { return `_layer->setSourceLayer(sourceLayer.UTF8String);` }; +const lightProperties = Object.keys(spec['light']).reduce((memo, name) => { + var property = spec['light'][name]; + property.name = name; + property['light-property'] = true; + memo.push(property); + return memo; +}, []); + +const lightDoc = spec['light-cocoa-doc']; +const lightType = 'light'; + const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.mm.ejs', 'utf8'), { strict: true}); @@ -526,6 +555,14 @@ const forStyleAuthorsMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guid const ddsGuideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Using Style Functions at Runtime.md.ejs', 'utf8'), { strict: true }); const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Tile URL Templates.md.ejs', 'utf8'), { strict: true }); +const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true}); +const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true}); +const testLight = ejs.compile(fs.readFileSync('platform/darwin/test/MGLLightTest.mm.ejs', 'utf8'), { strict: true}); +fs.writeFileSync(`platform/darwin/src/MGLLight.h`, duplicatePlatformDecls(lightH({ properties: lightProperties, doc: lightDoc, type: lightType }))); +fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, doc: lightDoc, type: lightType })); +fs.writeFileSync(`platform/darwin/test/MGLLightTest.mm`, testLight({ properties: lightProperties, doc: lightDoc, type: lightType })); + + const layers = _(spec.layer.type.values).map((value, layerType) => { const layoutProperties = Object.keys(spec[`layout_${layerType}`]).reduce((memo, name) => { if (name !== 'visibility') { |