Update README

This commit is contained in:
Christian Treffs 2020-07-23 22:47:52 +02:00
parent a0e6f05edc
commit c4de78e6d0
No known key found for this signature in database
GPG Key ID: 49A4B4B460BE3ED4
1 changed files with 23 additions and 1 deletions

View File

@ -34,7 +34,7 @@ import PackageDescription
let package = Package(
name: "YourPackageName",
dependencies: [
.package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.12.2")
.package(url: "https://github.com/fireblade-engine/ecs.git", from: "0.13.0")
],
targets: [
.target(
@ -216,6 +216,28 @@ nexus.family(requires: Position.self)
}
```
### 🔗 Serialization
To serialize/deserialize entities you must conform their assigned components to the `Codable` protocol.
Conforming components can then be serialized per family like this:
```swift
// MyComponent and YourComponent both conform to Component and Codable protocols.
let nexus = Nexus()
let family = nexus.family(requiresAll: MyComponent.self, YourComponent.self)
// JSON encode entities from given family.
var jsonEncoder = JSONEncoder()
let encodedData = try family.encodeMembers(using: &jsonEncoder)
// Decode entities into given family from JSON.
// The decoded entities will be added to the nexus.
var jsonDecoder = JSONDecoder()
let newEntities = try family.decodeMembers(from: jsonData, using: &jsonDecoder)
```
## 🧪 Demo
See the [Fireblade ECS Demo App](https://github.com/fireblade-engine/ecs-demo) to get started.