summaryrefslogtreecommitdiff
path: root/scripts/generate-style-code.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/generate-style-code.js')
-rw-r--r--scripts/generate-style-code.js45
1 files changed, 40 insertions, 5 deletions
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js
index d090dff872..de68c33ceb 100644
--- a/scripts/generate-style-code.js
+++ b/scripts/generate-style-code.js
@@ -14,7 +14,11 @@ function parseCSSColor(str) {
];
}
-global.propertyType = function (property) {
+global.isDataDriven = function (property) {
+ return property['property-function'] === true;
+};
+
+global.evaluatedType = function (property) {
if (/-translate-anchor$/.test(property.name)) {
return 'TranslateAnchorType';
}
@@ -34,14 +38,45 @@ global.propertyType = function (property) {
return `Color`;
case 'array':
if (property.length) {
- return `std::array<${propertyType({type: property.value})}, ${property.length}>`;
+ return `std::array<${evaluatedType({type: property.value})}, ${property.length}>`;
} else {
- return `std::vector<${propertyType({type: property.value})}>`;
+ return `std::vector<${evaluatedType({type: property.value})}>`;
}
default: throw new Error(`unknown type for ${property.name}`)
}
};
+function attributeType(property, type) {
+ const name = property.name.replace(type + '-', '').replace('-', '_');
+ return `attributes::a_${name}${name === 'offset' ? '<1>' : ''}`;
+}
+
+global.layoutPropertyType = function (property) {
+ if (isDataDriven(property)) {
+ return `DataDrivenLayoutProperty<${evaluatedType(property)}>`;
+ } else {
+ return `LayoutProperty<${evaluatedType(property)}>`;
+ }
+};
+
+global.paintPropertyType = function (property, type) {
+ if (isDataDriven(property)) {
+ return `DataDrivenPaintProperty<${evaluatedType(property)}, ${attributeType(property, type)}>`;
+ } else if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') {
+ return `CrossFadedPaintProperty<${evaluatedType(property)}>`;
+ } else {
+ return `PaintProperty<${evaluatedType(property)}>`;
+ }
+};
+
+global.propertyValueType = function (property) {
+ if (isDataDriven(property)) {
+ return `DataDrivenPropertyValue<${evaluatedType(property)}>`;
+ } else {
+ return `PropertyValue<${evaluatedType(property)}>`;
+ }
+};
+
global.defaultValue = function (property) {
// https://github.com/mapbox/mapbox-gl-native/issues/5258
if (property.name === 'line-round-limit') {
@@ -59,9 +94,9 @@ global.defaultValue = function (property) {
return JSON.stringify(property.default || "");
case 'enum':
if (property.default === undefined) {
- return `${propertyType(property)}::Undefined`;
+ return `${evaluatedType(property)}::Undefined`;
} else {
- return `${propertyType(property)}::${camelize(property.default)}`;
+ return `${evaluatedType(property)}::${camelize(property.default)}`;
}
case 'color':
const color = parseCSSColor(property.default).join(', ');