From 4ef2cd6597ed12e3ae74eab5ba9647c9dd4e33ed Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 9 Apr 2023 22:22:54 +0900 Subject: [PATCH 1/5] =?UTF-8?q?clean=20Widget=20list=20=E7=94=A8=E3=81=AE?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80=E3=82=92=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/Commons/{ => WidgetList}/WidgetList.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Sources/GameWidget/Commons/{ => WidgetList}/WidgetList.swift (100%) diff --git a/Sources/GameWidget/Commons/WidgetList.swift b/Sources/GameWidget/Commons/WidgetList/WidgetList.swift similarity index 100% rename from Sources/GameWidget/Commons/WidgetList.swift rename to Sources/GameWidget/Commons/WidgetList/WidgetList.swift From b618206ed292c044b6bc137ed0b452d68bf7fef3 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 9 Apr 2023 22:25:27 +0900 Subject: [PATCH 2/5] =?UTF-8?q?clean=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WidgetList/{WidgetList.swift => WidgetListBuilder.swift} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Sources/GameWidget/Commons/WidgetList/{WidgetList.swift => WidgetListBuilder.swift} (99%) diff --git a/Sources/GameWidget/Commons/WidgetList/WidgetList.swift b/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift similarity index 99% rename from Sources/GameWidget/Commons/WidgetList/WidgetList.swift rename to Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift index 7f2dc6f..937c1d4 100644 --- a/Sources/GameWidget/Commons/WidgetList/WidgetList.swift +++ b/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift @@ -1,5 +1,5 @@ // -// Group.swift +// WidgetListBuilder.swift // // // Created by rrbox on 2022/07/24. From de02092ba197d96983eaa3f3bc653a417b37ea23 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 9 Apr 2023 22:27:04 +0900 Subject: [PATCH 3/5] =?UTF-8?q?add=20=E6=96=B0=E3=81=9F=E3=81=AB=20WidgetL?= =?UTF-8?q?ist.swift=20=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `WidgetList2` ... `WidgetList10` をこのファイルに作成します. --- Sources/GameWidget/Commons/WidgetList/WidgetList.swift | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Sources/GameWidget/Commons/WidgetList/WidgetList.swift diff --git a/Sources/GameWidget/Commons/WidgetList/WidgetList.swift b/Sources/GameWidget/Commons/WidgetList/WidgetList.swift new file mode 100644 index 0000000..196d618 --- /dev/null +++ b/Sources/GameWidget/Commons/WidgetList/WidgetList.swift @@ -0,0 +1,8 @@ +// +// WidgetList.swift +// +// +// Created by rrbox on 2023/04/09. +// + +import Foundation From 6fb451585b864249d941c807bb8232a5dace81f7 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 9 Apr 2023 22:29:13 +0900 Subject: [PATCH 4/5] =?UTF-8?q?rename=20protocol=20WidgetList=20=E3=82=92?= =?UTF-8?q?=20`WidgetListProtocol`=20=E3=81=AB=E5=A4=89=E6=9B=B4=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/Commons/Display.swift | 14 +++++----- .../Commons/StructuringTools/Extension.swift | 2 +- .../NodeWidget/NodeWidget.swift | 2 +- .../WidgetList/WidgetListBuilder.swift | 26 +++++++++---------- Tests/GameWidgetTests/GroupTests.swift | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Sources/GameWidget/Commons/Display.swift b/Sources/GameWidget/Commons/Display.swift index fc96ff1..20093eb 100644 --- a/Sources/GameWidget/Commons/Display.swift +++ b/Sources/GameWidget/Commons/Display.swift @@ -13,26 +13,26 @@ public struct Display { public init() {} /// ``Display/Single`` の ``Display/Single/place(block:)`` により生成され, 二つの ``WidgetList`` を保持します. - public struct Link { + public struct Link { let value: (T, U) } /// 一つの widget から ``Display/Link`` を生成するためのラッパー. /// ``Display`` の ``Display/place(block:)`` により生成され, 一つの ``WidgetList`` を保持します. - public struct Single { + public struct Single { let value: T } } public extension Display { - func place(@GroupBuilder block: () -> T) -> Display.Single { + func place(@GroupBuilder block: () -> T) -> Display.Single { .init(value: block()) } } -extension Display.Link: Widget, WidgetList { - public func place(@GroupBuilder block: () -> V) -> Display.Link { +extension Display.Link: Widget, WidgetListProtocol { + public func place(@GroupBuilder block: () -> V) -> Display.Link { .init(value: (self, block())) } @@ -51,8 +51,8 @@ extension Display.Link: Widget, WidgetList { } } -extension Display.Single: Widget, WidgetList { - public func place(@GroupBuilder block: () -> U) -> Display.Link { +extension Display.Single: Widget, WidgetListProtocol { + public func place(@GroupBuilder block: () -> U) -> Display.Link { .init(value: (self, block())) } diff --git a/Sources/GameWidget/Commons/StructuringTools/Extension.swift b/Sources/GameWidget/Commons/StructuringTools/Extension.swift index e3b2e50..3b02d41 100644 --- a/Sources/GameWidget/Commons/StructuringTools/Extension.swift +++ b/Sources/GameWidget/Commons/StructuringTools/Extension.swift @@ -9,7 +9,7 @@ import SpriteKit /// widget 数を増やす際に使用します. 10 個以下の widget を内包することができます. /// - note: モディファイアはありませんが, メモリのオーバーヘッドがありません. -public struct Extension: WidgetListElementType { +public struct Extension: WidgetListElementType { var content: Content diff --git a/Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeWidget.swift b/Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeWidget.swift index 4bd1632..6dc8183 100644 --- a/Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeWidget.swift @@ -8,7 +8,7 @@ import SpriteKit /// 10 個以下の widget を一つの widget としてまとめます. 座標, スケール, 回転を内包するコンテンツと共に調整することができます. -public struct NodeWidget: Widget, ContextPresentPlugIn { +public struct NodeWidget: Widget, ContextPresentPlugIn { public typealias Context = NodeContext public var content: Content diff --git a/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift b/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift index 937c1d4..d2617a3 100644 --- a/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift +++ b/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift @@ -10,19 +10,19 @@ import SpriteKit @resultBuilder public struct GroupBuilder { - public static func buildBlock(_ c0: C0) -> some WidgetList { + public static func buildBlock(_ c0: C0) -> some WidgetListProtocol { Single(widget: c0) } public static func buildBlock(_ c0: C0, _ c1: C1) -> some WidgetList { + C1: WidgetListElementType>(_ c0: C0, _ c1: C1) -> some WidgetListProtocol { Single(widget: c0) .append(c1) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2) -> some WidgetList { + C2: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -31,7 +31,7 @@ import SpriteKit public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3) -> some WidgetList { + C3: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -42,7 +42,7 @@ import SpriteKit C1: WidgetListElementType, C2: WidgetListElementType, C3: WidgetListElementType, - C4: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4) -> some WidgetList { + C4: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -55,7 +55,7 @@ import SpriteKit C2: WidgetListElementType, C3: WidgetListElementType, C4: WidgetListElementType, - C5: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5) -> some WidgetList { + C5: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -70,7 +70,7 @@ import SpriteKit C3: WidgetListElementType, C4: WidgetListElementType, C5: WidgetListElementType, - C6: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6) -> some WidgetList { + C6: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -87,7 +87,7 @@ import SpriteKit C4: WidgetListElementType, C5: WidgetListElementType, C6: WidgetListElementType, - C7: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7) -> some WidgetList { + C7: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -106,7 +106,7 @@ import SpriteKit C5: WidgetListElementType, C6: WidgetListElementType, C7: WidgetListElementType, - C8: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8) -> some WidgetList { + C8: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -127,7 +127,7 @@ import SpriteKit C6: WidgetListElementType, C7: WidgetListElementType, C8: WidgetListElementType, - C9: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8, _ c9: C9) -> some WidgetList { + C9: WidgetListElementType>(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8, _ c9: C9) -> some WidgetListProtocol { Single(widget: c0) .append(c1) .append(c2) @@ -142,12 +142,12 @@ import SpriteKit } -public protocol WidgetList { +public protocol WidgetListProtocol { func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] } /// 再帰可能. widget のペアです. オーバーヘッドはありません. -public struct RecursiveGroup: WidgetList { +public struct RecursiveGroup: WidgetListProtocol { var first: T var second: U @@ -165,7 +165,7 @@ public struct RecursiveGroup: WidgetLis } // 一つの widget から RecursiveGroup を生成するためのラッパー. -struct Single: WidgetList { +struct Single: WidgetListProtocol { var widget: T diff --git a/Tests/GameWidgetTests/GroupTests.swift b/Tests/GameWidgetTests/GroupTests.swift index d66b013..917253b 100644 --- a/Tests/GameWidgetTests/GroupTests.swift +++ b/Tests/GameWidgetTests/GroupTests.swift @@ -10,7 +10,7 @@ import SpriteKit import GameWidget final class GroupTest: XCTestCase { - func generateNodesNameReduced(@GroupBuilder _ list: () -> T) -> String { + func generateNodesNameReduced(@GroupBuilder _ list: () -> T) -> String { list().widgetNodes(center: WidgetNotificationSystem()).reduce(into: "") { partialResult, node in guard let name = node.name else { XCTFail() From ac2a4bb2307796d41a81344296ceb00b2d75059c Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Mon, 10 Apr 2023 02:48:26 +0900 Subject: [PATCH 5/5] =?UTF-8?q?change=20WidgetList=20=E3=81=AE=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=82=92=E5=85=A8=E3=81=A6=20SIMD=20like=20=E3=81=AA?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=E3=81=AB=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commons/WidgetList/WidgetList.swift | 190 +++++++++++++++++- .../WidgetList/WidgetListBuilder.swift | 98 +-------- 2 files changed, 198 insertions(+), 90 deletions(-) diff --git a/Sources/GameWidget/Commons/WidgetList/WidgetList.swift b/Sources/GameWidget/Commons/WidgetList/WidgetList.swift index 196d618..5924b75 100644 --- a/Sources/GameWidget/Commons/WidgetList/WidgetList.swift +++ b/Sources/GameWidget/Commons/WidgetList/WidgetList.swift @@ -5,4 +5,192 @@ // Created by rrbox on 2023/04/09. // -import Foundation +import SpriteKit + +// 一つの widget から RecursiveGroup を生成するためのラッパー. +struct Single: WidgetListProtocol { + + var widget: T + + func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widget.addTo(buffer: &result, center: center) + return result + } + +} + +public struct WidgetList2: WidgetListProtocol { + let widgets: (C0, C1) + + public init(_ c0: C0, _ c1: C1) { + self.widgets = (c0, c1) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + return result + } + +} + +public struct WidgetList3: WidgetListProtocol { + let widgets: (C0, C1, C2) + + public init(_ c0: C0, _ c1: C1, _ c2: C2) { + self.widgets = (c0, c1, c2) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + return result + } + +} + +public struct WidgetList4: WidgetListProtocol { + let widgets: (C0, C1, C2, C3) + + public init(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3) { + self.widgets = (c0, c1, c2, c3) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + self.widgets.3.addTo(buffer: &result, center: center) + return result + } + +} + +public struct WidgetList5: WidgetListProtocol { + let widgets: (C0, C1, C2, C3, C4) + + public init(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4) { + self.widgets = (c0, c1, c2, c3, c4) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + self.widgets.3.addTo(buffer: &result, center: center) + self.widgets.4.addTo(buffer: &result, center: center) + return result + } + +} + +public struct WidgetList6: WidgetListProtocol { + let widgets: (C0, C1, C2, C3, C4, C5) + + public init(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5) { + self.widgets = (c0, c1, c2, c3, c4, c5) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + self.widgets.3.addTo(buffer: &result, center: center) + self.widgets.4.addTo(buffer: &result, center: center) + self.widgets.5.addTo(buffer: &result, center: center) + return result + } +} + +public struct WidgetList7: WidgetListProtocol { + let widgets: (C0, C1, C2, C3, C4, C5, C6) + + public init(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6) { + self.widgets = (c0, c1, c2, c3, c4, c5, c6) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + self.widgets.3.addTo(buffer: &result, center: center) + self.widgets.4.addTo(buffer: &result, center: center) + self.widgets.5.addTo(buffer: &result, center: center) + self.widgets.6.addTo(buffer: &result, center: center) + return result + } +} + +public struct WidgetList8: WidgetListProtocol { + let widgets: (C0, C1, C2, C3, C4, C5, C6, C7) + + public init(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7) { + self.widgets = (c0, c1, c2, c3, c4, c5, c6, c7) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + self.widgets.3.addTo(buffer: &result, center: center) + self.widgets.4.addTo(buffer: &result, center: center) + self.widgets.5.addTo(buffer: &result, center: center) + self.widgets.6.addTo(buffer: &result, center: center) + self.widgets.7.addTo(buffer: &result, center: center) + return result + } +} + +public struct WidgetList9: WidgetListProtocol { + let widgets: (C0, C1, C2, C3, C4, C5, C6, C7, C8) + + public init(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8) { + self.widgets = (c0, c1, c2, c3, c4, c5, c6, c7, c8) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + self.widgets.3.addTo(buffer: &result, center: center) + self.widgets.4.addTo(buffer: &result, center: center) + self.widgets.5.addTo(buffer: &result, center: center) + self.widgets.6.addTo(buffer: &result, center: center) + self.widgets.7.addTo(buffer: &result, center: center) + self.widgets.8.addTo(buffer: &result, center: center) + return result + } +} + +public struct WidgetList10: WidgetListProtocol { + let widgets: (C0, C1, C2, C3, C4, C5, C6, C7, C8, C9) + + public init(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8, _ c9: C9) { + self.widgets = (c0, c1, c2, c3, c4, c5, c6, c7, c8, c9) + } + + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { + var result = [SKNode]() + self.widgets.0.addTo(buffer: &result, center: center) + self.widgets.1.addTo(buffer: &result, center: center) + self.widgets.2.addTo(buffer: &result, center: center) + self.widgets.3.addTo(buffer: &result, center: center) + self.widgets.4.addTo(buffer: &result, center: center) + self.widgets.5.addTo(buffer: &result, center: center) + self.widgets.6.addTo(buffer: &result, center: center) + self.widgets.7.addTo(buffer: &result, center: center) + self.widgets.8.addTo(buffer: &result, center: center) + self.widgets.9.addTo(buffer: &result, center: center) + return result + } +} diff --git a/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift b/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift index d2617a3..d24415f 100644 --- a/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift +++ b/Sources/GameWidget/Commons/WidgetList/WidgetListBuilder.swift @@ -16,26 +16,20 @@ import SpriteKit public static func buildBlock(_ c0: C0, _ c1: C1) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) + WidgetList2(c0, c1) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) + WidgetList3(c0, c1, c2) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) - .append(c3) + WidgetList4(c0, c1, c2, c3) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) - .append(c3) - .append(c4) + WidgetList5(c0, c1, c2, c3, c4) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) - .append(c3) - .append(c4) - .append(c5) + WidgetList6(c0, c1, c2, c3, c4, c5) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) - .append(c3) - .append(c4) - .append(c5) - .append(c6) + WidgetList7(c0, c1, c2, c3, c4, c5, c6) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) - .append(c3) - .append(c4) - .append(c5) - .append(c6) - .append(c7) + WidgetList8(c0, c1, c2, c3, c4, c5, c6, c7) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) - .append(c3) - .append(c4) - .append(c5) - .append(c6) - .append(c7) - .append(c8) + WidgetList9(c0, c1, c2, c3, c4, c5, c6, c7, c8) } public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8, _ c9: C9) -> some WidgetListProtocol { - Single(widget: c0) - .append(c1) - .append(c2) - .append(c3) - .append(c4) - .append(c5) - .append(c6) - .append(c7) - .append(c8) - .append(c9) + WidgetList10(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9) } } @@ -145,38 +100,3 @@ import SpriteKit public protocol WidgetListProtocol { func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] } - -/// 再帰可能. widget のペアです. オーバーヘッドはありません. -public struct RecursiveGroup: WidgetListProtocol { - - var first: T - var second: U - - func append(_ newWidget: V) -> RecursiveGroup { - .init(first: self, second: newWidget) - } - - public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { - var result = self.first.widgetNodes(center: center) - self.second.addTo(buffer: &result, center: center) - return result - } - -} - -// 一つの widget から RecursiveGroup を生成するためのラッパー. -struct Single: WidgetListProtocol { - - var widget: T - - func append(_ newWidget: U) -> RecursiveGroup { - .init(first: self, second: newWidget) - } - - func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { - var result = [SKNode]() - self.widget.addTo(buffer: &result, center: center) - return result - } - -}