From 15aabeb6ee961c214053486565d0581e784d61aa Mon Sep 17 00:00:00 2001 From: Didymus Date: Sun, 21 Apr 2024 19:32:06 +0800 Subject: [PATCH 1/2] [ark-render] refactor: add method to canvas interface --- ArkKit/ark-render-kit/canvas/Canvas.swift | 3 +++ ArkKitTests/data-structures-tests/OrderedDictionaryTests.swift | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ArkKit/ark-render-kit/canvas/Canvas.swift b/ArkKit/ark-render-kit/canvas/Canvas.swift index a572f4c..6ed3f0b 100644 --- a/ArkKit/ark-render-kit/canvas/Canvas.swift +++ b/ArkKit/ark-render-kit/canvas/Canvas.swift @@ -22,4 +22,7 @@ protocol Canvas { typealias RenderableComponentType = ObjectIdentifier typealias CanvasElements = [EntityID: [RenderableComponentType: any RenderableComponent]] var canvasElements: CanvasElements { get } + mutating func addEntityRenderableToCanvas(entityId: EntityID, + componentType: RenderableComponentType, + renderableComponent: any RenderableComponent) } diff --git a/ArkKitTests/data-structures-tests/OrderedDictionaryTests.swift b/ArkKitTests/data-structures-tests/OrderedDictionaryTests.swift index ae01ee4..233b21e 100644 --- a/ArkKitTests/data-structures-tests/OrderedDictionaryTests.swift +++ b/ArkKitTests/data-structures-tests/OrderedDictionaryTests.swift @@ -45,7 +45,7 @@ class OrderedDictionaryTests: XCTestCase { iteratedKeys.append(key) } - XCTAssertEqual(iteratedKeys, ["one", "two", "three"], + XCTAssertEqual(iteratedKeys, ["one", "two", "three"], "Keys should be iterated in the order they were inserted.") } From bb3dd6f9b1ffa31ca444f82845978528a74c9980 Mon Sep 17 00:00:00 2001 From: Didymus Date: Sun, 21 Apr 2024 19:39:19 +0800 Subject: [PATCH 2/2] [ark-render] refactor: use more general canvas return type --- ArkKit/ark-render-kit/CanvasContext.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArkKit/ark-render-kit/CanvasContext.swift b/ArkKit/ark-render-kit/CanvasContext.swift index 1f602e8..ad627eb 100644 --- a/ArkKit/ark-render-kit/CanvasContext.swift +++ b/ArkKit/ark-render-kit/CanvasContext.swift @@ -7,7 +7,7 @@ protocol CanvasContext { var arkView: (any ArkView)? { get } var memo: [EntityID: [RenderableComponentType: (any RenderableComponent, any Renderable)]] { get } - func getFlatCanvas() -> ArkFlatCanvas + func getFlatCanvas() -> any Canvas func render(_ canvas: any Canvas, using renderer: any RenderableBuilder) } @@ -62,7 +62,7 @@ class ArkCanvasContext: CanvasContext { } /// Outputs a logical canvas with the relevant entities in the canvas and their renderable components only - func getFlatCanvas() -> ArkFlatCanvas { + func getFlatCanvas() -> any Canvas { var arkCanvas = ArkFlatCanvas() for renderableCompType in ArkCanvasSystem.renderableComponentTypes { let renderableEntities = ecs.getEntities(with: [renderableCompType])