-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mai/directional and ambient light (#1305)
* Add codegen template for Lights * Update codegen - add experimental flags for 3D lights
- Loading branch information
Showing
5 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<% | ||
const properties = locals.properties | ||
const lightName = locals.name | ||
-%> | ||
// This file is generated. | ||
import Foundation | ||
|
||
/// Represents 3D <%- camelizeWithLeadingLowercase(lightName) %> light. | ||
/// - SeeAlso: [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#light) | ||
<% if (locals.experimental) { -%>@_spi(Experimental) <% } -%>public struct <%- camelizeWithUndercoreRemoved(lightName) %>Light: Light3DProtocol { | ||
public let lightType: Light3DType | ||
<%_ for (const property of properties) { -%> | ||
/// <%- markdownFriendlyDoc(property) %> | ||
<%_ if (property.name === 'id') { _%> | ||
<% if (property.experimental) { -%>@_spi(Experimental) <% } -%>public let <%- camelizeWithLeadingLowercase(property.name) %>: <%- propertySwiftElementType(property) %> | ||
<%_ } else { _%> | ||
<% if (property.experimental) { -%>@_spi(Experimental) <% } -%>public var <%- camelizeWithLeadingLowercase(property.name) %>: <%- propertySwiftValueType(property) %>? | ||
<%_ } _%> | ||
<%_ if (property.transition) { -%> | ||
/// Transition property for `<%- camelizeWithLeadingLowercase(property.name) %>` | ||
<% if (property.experimental) { -%>@_spi(Experimental) <% } -%>public var <%- camelizeWithLeadingLowercase(property.name) %>Transition: StyleTransition? | ||
<%_ } -%> | ||
<%_ } -%> | ||
public init(id: String) { | ||
self.id = id | ||
self.lightType = .<%- camelizeWithLeadingLowercase(lightName) %> | ||
} | ||
enum CodingKeys: String, CodingKey { | ||
case lightType = "type" | ||
<%_ for (const property of properties) { -%> | ||
case <%- camelizeWithLeadingLowercase(property.name) %> = "<%- property.name %>" | ||
<%_ if (property.transition) { -%> | ||
case <%- camelizeWithLeadingLowercase(property.name) %>Transition = "<%- property.name %>-transition" | ||
<%_ } -%> | ||
<%_ } -%> | ||
} | ||
} | ||
// End of generated file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<% | ||
const properties = locals.properties | ||
const lightName = locals.name | ||
const containsExperimentalApi = properties.some((property) => property.experimental === true) || locals.experimental | ||
-%> | ||
// This file is generated | ||
import XCTest | ||
<%if (containsExperimentalApi) { -%>@_spi(Experimental) <% } -%>@testable import MapboxMaps | ||
|
||
final class <%- camelizeWithUndercoreRemoved(lightName) %>LightTests: XCTestCase { | ||
|
||
func testLightEncodingAndDecoding() throws { | ||
let lightID = UUID().uuidString | ||
var light = <%- camelizeWithUndercoreRemoved(lightName) %>Light(id: lightID) | ||
<%_ for (const property of properties) { -%> | ||
<%_ if (property.name !== 'id') { _%> | ||
light.<%- camelizeWithLeadingLowercase(property.name) %> = <%- propertySwiftValueType(property) %>.testConstantValue() | ||
<%_ if (property.transition) { -%> | ||
light.<%- camelizeWithLeadingLowercase(property.name) %>Transition = StyleTransition(duration: 10.0, delay: 10.0) | ||
<%_ } -%> | ||
<%_ } _%> | ||
<%_ } -%> | ||
|
||
let data = try JSONEncoder().encode(light) | ||
XCTAssertFalse(data.isEmpty) | ||
|
||
let decodedLight = try JSONDecoder().decode(<%- camelizeWithUndercoreRemoved(lightName) %>Light.self, from: data) | ||
|
||
XCTAssertEqual(decodedLight.lightType, Light3DType.<%- camelizeWithLeadingLowercase(lightName) %>) | ||
<%_ for (const property of properties) { -%> | ||
<%_ if (property.name === 'id') { _%> | ||
XCTAssertEqual(decodedLight.id, lightID) | ||
<%_ } else { _%> | ||
XCTAssertEqual(decodedLight.<%- camelizeWithLeadingLowercase(property.name) %>, <%- propertySwiftValueType(property) %>.testConstantValue()) | ||
<%_ if (property.transition) { -%> | ||
XCTAssertEqual(decodedLight.<%- camelizeWithLeadingLowercase(property.name) %>Transition?.duration, 10) | ||
XCTAssertEqual(decodedLight.<%- camelizeWithLeadingLowercase(property.name) %>Transition?.delay, 10) | ||
<%_ } -%> | ||
<%_ } -%> | ||
<%_ } -%> | ||
} | ||
} | ||
// End of generated file |
Submodule mapbox-maps-stylegen
updated
from 917e65 to 3fad60
Submodule mapbox-maps-ios-private
updated
from 9abe78 to 1e2c3c