diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-09-25 12:37:45 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-10-17 11:47:22 -0700 |
commit | 9652028915af6602626939e0b0075333c34bfbfe (patch) | |
tree | 0b299507c1339dcb1f947a496dcd375095f9bc4b /platform/darwin/scripts | |
parent | 0c8a3feffa94a9594bcaa77fdc18d11a3c482ff5 (diff) | |
download | qtlocation-mapboxgl-9652028915af6602626939e0b0075333c34bfbfe.tar.gz |
[ios, macos] Expand changes to entire API
Diffstat (limited to 'platform/darwin/scripts')
-rw-r--r-- | platform/darwin/scripts/generate-style-code.js | 141 |
1 files changed, 63 insertions, 78 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 0c8b704e91..4bcfe54d32 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -44,7 +44,8 @@ global.testGetterImplementation = function (property, layerType, isFunction) { if (isFunction) { return `XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`; } - return `XCTAssert([(NSValue *)gLayer.${objCName(property)} isEqualToValue:${value}], @"%@ is not equal to %@", gLayer.${objCName(property)}, ${value});`; + return `XCTAssert([gLayer.${objCName(property)} isKindOfClass:[MGLStyleConstantValue class]]); + XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`; } return `XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`; } @@ -129,7 +130,7 @@ global.propertyReqs = function (property, layoutPropertiesByName, type) { return '`' + camelizeWithLeadingLowercase(req['!']) + '` is set to `nil`'; } else { let name = Object.keys(req)[0]; - return '`' + camelizeWithLeadingLowercase(name) + '` is set to ' + describeValue(req[name], layoutPropertiesByName[name], type); + return '`' + camelizeWithLeadingLowercase(name) + '` is set to an `MGLStyleValue` object containing ' + describeValue(req[name], layoutPropertiesByName[name], type); } }).join(', and ') + '. Otherwise, it is ignored.'; }; @@ -204,109 +205,93 @@ global.describeValue = function (value, property, layerType) { }; global.propertyDefault = function (property, layerType) { - return describeValue(property.default, property, layerType); + return 'an `MGLStyleValue` object containing ' + describeValue(property.default, property, layerType); }; -global.propertyType = function (property, _private) { - return _private ? `id <MGLStyleAttributeValue, MGLStyleAttributeValue_Private>` : `id <MGLStyleAttributeValue>`; -}; - -global.initLayer = function (layerType) { - if (layerType == "background") { - return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String);` - } else { - return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String, source.identifier.UTF8String);` - } -} - -global.setSourceLayer = function() { - return `_layer->setSourceLayer(sourceLayer.UTF8String);` -} - -global.setterImplementation = function(property, layerType) { - let implementation = ''; +global.propertyType = function (property) { switch (property.type) { case 'boolean': - implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_boolPropertyValue);`; - break; + return 'NSNumber *'; case 'number': - implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_floatPropertyValue);`; - break; + return 'NSNumber *'; case 'string': - implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_stringPropertyValue);`; - break; + return 'NSString *'; case 'enum': - let objCType = global.objCType(layerType, property.name); - implementation = `MGLSetEnumProperty(${objCName(property)}, ${camelize(property.name)}, ${mbglType(property)}, ${objCType});`; - break; + return 'NSValue *'; case 'color': - implementation = `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_colorPropertyValue);`; - break; + return 'MGLColor *'; case 'array': - implementation = arraySetterImplementation(property); - break; - default: throw new Error(`unknown type for ${property.name}`) - } - return implementation; -} - -global.mbglType = function(property) { - let mbglType = camelize(property.name) + 'Type'; - if (/-translate-anchor$/.test(property.name)) { - mbglType = 'TranslateAnchorType'; - } - if (/-(rotation|pitch)-alignment$/.test(property.name)) { - mbglType = 'AlignmentType'; + switch (arrayType(property)) { + case 'dasharray': + return 'NSArray<NSNumber *> *'; + case 'font': + return 'NSArray<NSString *> *'; + case 'padding': + return 'NSValue *'; + case 'offset': + case 'translate': + return 'NSValue *'; + default: + throw new Error(`unknown array type for ${property.name}`); + } + default: + throw new Error(`unknown type for ${property.name}`); } - return mbglType; -} - -global.arraySetterImplementation = function(property) { - return `self.layer->set${camelize(property.name)}(${objCName(property)}.mbgl_${convertedType(property)}PropertyValue);`; -} +}; -global.styleAttributeFactory = function (property, layerType) { +global.valueTransformerArguments = function (property) { + let objCType = propertyType(property); switch (property.type) { case 'boolean': - return 'mbgl_boolWithPropertyValueBool'; + return ['bool', objCType]; case 'number': - return 'mbgl_numberWithPropertyValueNumber'; + return ['float', objCType]; case 'string': - return 'mbgl_stringWithPropertyValueString'; + return ['std::string', objCType]; case 'enum': - throw new Error('Use MGLGetEnumProperty() for enums.'); + return [`mbgl::style::${mbglType(property)}`, objCType]; case 'color': - return 'mbgl_colorWithPropertyValueColor'; + return ['mbgl::Color', objCType]; case 'array': - return `mbgl_${convertedType(property)}WithPropertyValue${camelize(convertedType(property))}`; + switch (arrayType(property)) { + case 'dasharray': + return ['std::vector<float>', objCType, 'float']; + case 'font': + return ['std::vector<std::string>', objCType, 'std::string']; + case 'padding': + return ['std::array<float, 4>', objCType]; + case 'offset': + case 'translate': + return ['std::array<float, 2>', objCType]; + default: + throw new Error(`unknown array type for ${property.name}`); + } default: throw new Error(`unknown type for ${property.name}`); } }; -global.getterImplementation = function(property, layerType) { - if (property.type === 'enum') { - let objCType = global.objCType(layerType, property.name); - return `MGLGetEnumProperty(${camelize(property.name)}, ${mbglType(property)}, ${objCType});`; +global.initLayer = function (layerType) { + if (layerType == "background") { + return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String);` + } else { + return `_layer = new mbgl::style::${camelize(layerType)}Layer(identifier.UTF8String, source.identifier.UTF8String);` } - let rawValue = `self.layer->get${camelize(property.name)}() ?: self.layer->getDefault${camelize(property.name)}()`; - return `return [MGLStyleAttribute ${styleAttributeFactory(property, layerType)}:${rawValue}];`; } -global.convertedType = function(property) { - switch (arrayType(property)) { - case 'dasharray': - return 'numberArray'; - case 'font': - return 'stringArray'; - case 'padding': - return 'padding'; - case 'offset': - case 'translate': - return 'offset'; - default: - throw new Error(`unknown array type for ${property.name}`); +global.setSourceLayer = function() { + return `_layer->setSourceLayer(sourceLayer.UTF8String);` +} + +global.mbglType = function(property) { + let mbglType = camelize(property.name) + 'Type'; + if (/-translate-anchor$/.test(property.name)) { + mbglType = 'TranslateAnchorType'; } + if (/-(rotation|pitch)-alignment$/.test(property.name)) { + mbglType = 'AlignmentType'; + } + return mbglType; } const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); |