Skip to content

Commit

Permalink
Merge pull request #56 from Rallista/fix/apple/public-config-init
Browse files Browse the repository at this point in the history
Added public to valhalla config inits
  • Loading branch information
Archdoog authored Jan 26, 2025
2 parents 2bb139e + 233b329 commit d747a29
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "14.3.1"
xcode-version: "15.4.0"

- name: Setup VCPKG
run: |
Expand All @@ -51,7 +51,7 @@ jobs:

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "14.3.1"
xcode-version: "15.4.0"

- name: Download all artifacts
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -84,15 +84,15 @@ jobs:
strategy:
matrix:
scheme: [ValhallaMobile]
destination: ["platform=iOS Simulator,name=iPhone 14,OS=16.4"]
destination: ["platform=iOS Simulator,name=iPhone 15,OS=17.5"]

steps:
- name: Checkout Valhalla
uses: actions/checkout@v4

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "14.3.1"
xcode-version: "15.4.0"

- name: Download xcframework artifact
uses: actions/download-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "14.3.1"
xcode-version: "15.4.0"

- name: Setup VCPKG
run: |
Expand All @@ -55,7 +55,7 @@ jobs:

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "14.3.1"
xcode-version: "15.4.0"

- name: Download all artifacts
uses: actions/download-artifact@v4
Expand Down
55 changes: 47 additions & 8 deletions apple/Sources/Valhalla/Extensions/ValhallaConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,54 @@ import ValhallaConfigModels

extension ValhallaConfig {

init(data: Data) throws {
/// Initialize ValhallaConfig directly from JSON Data.
///
/// Important! Using this method, you must have functional valhalla config json with
/// the correct local path to a tiles folder or tar inside the json.
///
/// The ``init(tileExtractTar:)`` or ``init(tilesDir:)`` automate this process
/// by setting the path in the default valhalla json config (as produced by the valhalla build scripts).
///
/// - Parameter data: A data representation of the valhalla config json.
public init(data: Data) throws {
self = try JSONDecoder().decode(ValhallaConfig.self, from: data)
}

init(_ json: String, using encoding: String.Encoding = .utf8) throws {
/// Initialize ValhallaConfig directly from a JSON string.
///
/// Important! Using this method, you must have functional valhalla config json with
/// the correct local path to a tiles folder or tar inside the json.
///
/// The ``init(tileExtractTar:)`` or ``init(tilesDir:)`` automate this process
/// by setting the path in the default valhalla json config (as produced by the valhalla build scripts).
///
/// - Parameters:
/// - json: The valhalla config json string.
/// - encoding: The json's encoding. Default's to utf8
public init(_ json: String, using encoding: String.Encoding = .utf8) throws {
guard let data = json.data(using: encoding) else {
throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
}
try self.init(data: data)
}

init(fromURL url: URL) throws {

/// Initialize ValhallaConfig from a local file url.
///
/// Important! Using this method, the file path must point to a functional valhalla config json with
/// the correct local path to a tiles folder or tar inside the json.
///
/// The ``init(tileExtractTar:)`` or ``init(tilesDir:)`` automate this process
/// by setting the path in the default valhalla json config (as produced by the valhalla build scripts).
///
/// - Parameter url: The path of the valhalla config json file.
public init(fromURL url: URL) throws {
try self.init(data: try Data(contentsOf: url))
}

/// Generate a ValhallaConfig using the defaults provided by the valhalla build scripts.
/// Initialize ValhallaConfig using the defaults provided by the valhalla build scripts.
///
/// This can be used to manipulate select values as a var.
init() {
public init() {
guard let configJsonURL = Bundle.module.url(forResource: "default", withExtension: "json") else {
fatalError("ValhallaConfig default.json config resource not found in module bundle.")
}
Expand All @@ -33,7 +62,12 @@ extension ValhallaConfig {
}
}

init(tileExtractTar: URL) throws {
/// Initialize ValhallaConfig for a specific tar file.
///
/// This injects a tile tarball file path into the default valhalla config.
///
/// - Parameter tileExtractTar: The local file path URL for the tiles tar file.
public init(tileExtractTar: URL) throws {
let defaultConfig = ValhallaConfig.loadDefault()

var mjolnir = defaultConfig.mjolnir
Expand All @@ -50,7 +84,12 @@ extension ValhallaConfig {
thor: defaultConfig.thor)
}

init(tilesDir: URL) throws {
/// Initialize ValhallaConfig for a specific tiles directory.
///
/// This injects a tile folder path into the default valhalla config.
///
/// - Parameter tileExtractTar: The local folder path URL for the tiles directory.
public init(tilesDir: URL) throws {
let defaultConfig = ValhallaConfig.loadDefault()

var mjolnir = defaultConfig.mjolnir
Expand Down

0 comments on commit d747a29

Please sign in to comment.