Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Add the auto-generation script for MGLLight.mm
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-guerra committed Jun 13, 2017
1 parent d2153a6 commit eb8032b
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 95 deletions.
15 changes: 8 additions & 7 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ global.testHelperMessage = function (property, layerType, isFunction) {
};

global.propertyDoc = function (propertyName, property, layerType, kind) {
console.log(propertyName + " : " + property + " : " + layerType + " : " + kind)
// Match references to other property names & values.
// Requires the format 'When `foo` is set to `bar`,'.
let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) {
Expand Down Expand Up @@ -257,7 +256,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.';
}
}
Expand Down Expand Up @@ -419,6 +418,7 @@ global.propertyType = function (property) {
return 'NSArray<NSString *> *';
case 'padding':
return 'NSValue *';
case 'position':
case 'offset':
case 'translate':
return 'NSValue *';
Expand Down Expand Up @@ -458,6 +458,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];
Expand Down Expand Up @@ -528,7 +530,7 @@ const lightProperties = Object.keys(spec[`light`]).reduce((memo, name) => {
return memo;
}, []);

console.log(lightProperties);
const lightDoc = spec[`light-cocoa-doc`];

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});
Expand All @@ -539,9 +541,8 @@ const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Til

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});;
fs.writeFileSync(`platform/darwin/src/MGLLight.h`, lightH({ properties: lightProperties, }));
fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, }));

fs.writeFileSync(`platform/darwin/src/MGLLight.h`, duplicatePlatformDecls(lightH({ properties: lightProperties, doc: lightDoc})));
fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, doc: lightDoc}));


const layers = _(spec.layer.type.values).map((value, layerType) => {
Expand All @@ -558,7 +559,7 @@ const layers = _(spec.layer.type.values).map((value, layerType) => {
memo.push(spec[`paint_${layerType}`][name]);
return memo;
}, []);
console.log(spec.layer.type.values[layerType].doc)

return {
doc: spec.layer.type.values[layerType].doc,
type: layerType,
Expand Down
1 change: 1 addition & 0 deletions platform/darwin/scripts/style-spec-overrides-v8.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"light-cocoa-doc": "An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`.",
"layer": {
"type": {
"values": {
Expand Down
113 changes: 89 additions & 24 deletions platform/darwin/src/MGLLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

NS_ASSUME_NONNULL_BEGIN


/** Options to specify extruded geometries are lit relative to the map or viewport. */
/**
Whether extruded geometries are lit relative to the map or viewport.
*/
typedef NS_ENUM(NSUInteger, MGLLightAnchor) {
/** The position of the light source is aligned to the rotation of the map. */
/**
The position of the light source is aligned to the rotation of the map.
*/
MGLLightAnchorMap,
/** The position of the light source is aligned to the rotation of the viewport. */
MGLLightAnchorViewport
/**
The position of the light source is aligned to the rotation of the
viewport.
*/
MGLLightAnchorViewport,
};

/**
Expand Down Expand Up @@ -57,72 +63,131 @@ MGL_EXPORT
@interface MGLLight : NSObject

/**
`anchor` Whether extruded geometries are lit relative to the map or viewport.
Whether extruded geometries are lit relative to the map or viewport.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing `MGLAnchorViewport`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of
`MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-anchor"><code>anchor</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSValue *> *anchor;

/**
Values describing animated transitions to `anchor` property.
*/
@property (nonatomic) MGLTransition anchorTransition;


/**
Position of the light source relative to lit (extruded) geometries.
Position of the light source relative to lit (extruded) geometries, in [r
radial coordinate, a azimuthal angle, p polar angle] where r indicates the
distance from the center of the base of an object to its light, a indicates the
position of the light relative to 0° (0° when `light.anchor` is set to
`MGLLight.anchorViewport` corresponds to the top of the viewport, or 0° when
`light.anchor` is set to `MGLLight.anchorMap` corresponds to due north, and
degrees proceed clockwise), and p indicates the height of the light (from 0°,
directly above, to 180°, directly below).
The default value of this property is an `MGLStyleValue` object containing the
array `1.15`, `210`, `30`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-position"><code>position</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSValue *> *position;

/**
Values describing animated transitions to `position` property.
*/
@property (nonatomic) MGLTransition positionTransiton;
The transition affecting any changes to this layer’s `position` property.
This property corresponds to the `position-transition` property in the style JSON file format.
*/
@property (nonatomic) MGLTransition positionTransition;

#if TARGET_OS_IPHONE
/**
Color tint for lighting extruded geometries.
The default value of this property is an `MGLStyleValue` object containing
`UIColor.whiteColor`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-color"><code>color</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<UIColor *> *color;
#else

/**
Color tint for lighting extruded geometries.
The default value of this property is an `MGLStyleValue` object containing
`NSColor.whiteColor`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-color"><code>color</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSColor *> *color;
#endif

/**
Values describing animated transitions to `color` property.
*/
@property (nonatomic) MGLTransition colorTransiton;
The transition affecting any changes to this layer’s `color` property.
This property corresponds to the `color-transition` property in the style JSON file format.
*/
@property (nonatomic) MGLTransition colorTransition;

/**
Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast.
Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as
more extreme contrast.
The default value of this property is an `MGLStyleValue` object containing an
`NSNumber` object containing the float `0.5`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-intensity"><code>intensity</code></a>
light property in the Mapbox Style Specification.
*/
@property(nonatomic) MGLStyleValue<NSNumber *> *intensity;
@property (nonatomic) MGLStyleValue<NSNumber *> *intensity;

/**
Values describing animated transitions to `intensity` property.
*/
The transition affecting any changes to this layer’s `intensity` property.
This property corresponds to the `intensity-transition` property in the style JSON file format.
*/
@property (nonatomic) MGLTransition intensityTransition;


@end

NS_ASSUME_NONNULL_END
95 changes: 31 additions & 64 deletions platform/darwin/src/MGLLight.h.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@

NS_ASSUME_NONNULL_BEGIN


/** Options to specify extruded geometries are lit relative to the map or viewport. */
typedef NS_ENUM(NSUInteger, MGLLightAnchor) {
/** The position of the light source is aligned to the rotation of the map. */
MGLLightAnchorMap,
/** The position of the light source is aligned to the rotation of the viewport. */
MGLLightAnchorViewport
<% for (const property of properties) { -%>
<% if (property.type == "enum") { -%>
/**
<%- propertyDoc(property.name, property, type, 'enum').wrap(80, 1) %>
*/
typedef NS_ENUM(NSUInteger, MGLLight<%- camelize(property.name) %>) {
<% for (const value in property.values) { -%>
/**
<%- propertyDoc(property.name, property.values[value], type, 'enum').wrap(80, 4+1) %>
*/
MGLLightAnchor<%- camelize(value) %>,
<% } -%>
};
<% } -%>
<% } -%>

/**
A structure containing information about the position of the light source
Expand Down Expand Up @@ -56,77 +63,37 @@ NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CLLocationDistance radia
}

/**
An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`.
<%- doc %>
*/
MGL_EXPORT
@interface MGLLight : NSObject
<% if (properties.length) { -%>
<% for (const property of properties) { -%>
/**
`anchor` Whether extruded geometries are lit relative to the map or viewport.

This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-anchor"><code>anchor</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSValue *> *anchor;

/**
Values describing animated transitions to `anchor` property.
*/
@property (nonatomic) MGLTransition anchorTransition;


/**
Position of the light source relative to lit (extruded) geometries.

This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-position"><code>position</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSValue *> *position;

/**
Values describing animated transitions to `position` property.
*/
@property (nonatomic) MGLTransition positionTransiton;
<%- propertyDoc(property.name, property, type, 'light').wrap(80, 1) %>

#if TARGET_OS_IPHONE
/**
Color tint for lighting extruded geometries.

This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-color"><code>color</code></a>
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-<%- originalPropertyName(property) %>"><code><%- originalPropertyName(property) %></code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<UIColor *> *color;
#else
@property (nonatomic<% if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(property.name) %>;
<% if (property.transition) { -%>
/**
Color tint for lighting extruded geometries.
*/
@property (nonatomic) MGLStyleValue<NSColor *> *color;
#endif
The transition affecting any changes to this layer’s `<%- camelizeWithLeadingLowercase(property.name) %>` property.
/**
Values describing animated transitions to `color` property.
*/
@property (nonatomic) MGLTransition colorTransiton;
This property corresponds to the `<%- originalPropertyName(property) %>-transition` property in the style JSON file format.
*/
@property (nonatomic) MGLTransition <%- camelizeWithLeadingLowercase(property.name) %>Transition;
<% } -%>
<% if (property.original) { -%>
@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead.")));
/**
Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast.

This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-intensity"><code>intensity</code></a>
light property in the Mapbox Style Specification.
*/
@property(nonatomic) MGLStyleValue<NSNumber *> *intensity;

/**
Values describing animated transitions to `intensity` property.
*/
@property (nonatomic) MGLTransition intensityTransition;
<% } -%>
<% } -%>
<% } -%>

@end

Expand Down
Loading

0 comments on commit eb8032b

Please sign in to comment.