## AHAP files (designed patterns as assets)

- Use case: Ship haptic patterns as JSON assets designers can iterate on without recompiling — the standard for game/media haptics.
- Feel: Whatever you design: AHAP expresses the same events, parameters, and curves as code, in a portable file.
- APIs: CHHapticEngine.playPattern(from: URL), AHAP
- Minimum OS: iOS 13+

### Swift (loading)

```swift
import CoreHaptics

func playAHAP(named name: String, engine: CHHapticEngine) {
    guard let url = Bundle.main.url(forResource: name,
                                    withExtension: "ahap") else { return }
    do {
        try engine.start()
        try engine.playPattern(from: url)
    } catch {
        print("Failed to play \(name).ahap: \(error)")
    }
}

// playAHAP(named: "Sparkle", engine: HapticEngine.shared.engine)
```

### Sparkle.ahap

```json
{
  "Version": 1.0,
  "Metadata": {
    "Project": "MyApp",
    "Created": "2026",
    "Description": "Sharp tick followed by a soft fading shimmer"
  },
  "Pattern": [
    {
      "Event": {
        "Time": 0.0,
        "EventType": "HapticTransient",
        "EventParameters": [
          { "ParameterID": "HapticIntensity", "ParameterValue": 0.8 },
          { "ParameterID": "HapticSharpness", "ParameterValue": 1.0 }
        ]
      }
    },
    {
      "Event": {
        "Time": 0.12,
        "EventType": "HapticContinuous",
        "EventDuration": 0.3,
        "EventParameters": [
          { "ParameterID": "HapticIntensity", "ParameterValue": 0.5 },
          { "ParameterID": "HapticSharpness", "ParameterValue": 0.6 }
        ]
      }
    },
    {
      "ParameterCurve": {
        "ParameterID": "HapticIntensityControl",
        "Time": 0.12,
        "ParameterCurveControlPoints": [
          { "Time": 0.0,  "ParameterValue": 1.0 },
          { "Time": 0.3,  "ParameterValue": 0.0 }
        ]
      }
    }
  ]
}
```

### Notes
- AHAP can also carry AudioCustom events that play sound sample-locked to the haptics.
- Tools like Captain AHAP or Lofelt Composer let designers author these visually.
