[core] generated accessor methods on light

This commit is contained in:
Ivo van Dongen
2017-05-04 17:26:42 +03:00
committed by Ivo van Dongen
parent 20810f988a
commit feae5e22ee
11 changed files with 332 additions and 69 deletions

View File

@@ -18,6 +18,10 @@ global.isDataDriven = function (property) {
return property['property-function'] === true;
};
global.isLightProperty = function (property) {
return property['light-property'] === true;
};
global.evaluatedType = function (property) {
if (/-translate-anchor$/.test(property.name)) {
return 'TranslateAnchorType';
@@ -25,6 +29,9 @@ global.evaluatedType = function (property) {
if (/-(rotation|pitch|illumination)-alignment$/.test(property.name)) {
return 'AlignmentType';
}
if (/position/.test(property.name)) {
return 'Position';
}
switch (property.type) {
case 'boolean':
return 'bool';
@@ -33,7 +40,7 @@ global.evaluatedType = function (property) {
case 'string':
return 'std::string';
case 'enum':
return `${camelize(property.name)}Type`;
return (isLightProperty(property) ? 'Light' : '') + `${camelize(property.name)}Type`;
case 'color':
return `Color`;
case 'array':
@@ -177,3 +184,17 @@ for (const layer of layers) {
const propertySettersHpp = ejs.compile(fs.readFileSync('include/mbgl/style/conversion/make_property_setters.hpp.ejs', 'utf8'), {strict: true});
writeIfModified('include/mbgl/style/conversion/make_property_setters.hpp', propertySettersHpp({layers: layers}));
// Light
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 lightHpp = ejs.compile(fs.readFileSync('include/mbgl/style/light.hpp.ejs', 'utf8'), {strict: true});
const lightCpp = ejs.compile(fs.readFileSync('src/mbgl/style/light.cpp.ejs', 'utf8'), {strict: true});
writeIfModified(`include/mbgl/style/light.hpp`, lightHpp({properties: lightProperties}));
writeIfModified(`src/mbgl/style/light.cpp`, lightCpp({properties: lightProperties}));