From 5a2a935629b6aaa05611da1623feabdad99352a2 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 2 Dec 2022 00:29:07 +0900 Subject: [PATCH 01/57] add GroupTests.swift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 複数の Widget から node 配列を作成する Group のテストファイルです. --- Tests/GameWidgetTests/GroupTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Tests/GameWidgetTests/GroupTests.swift diff --git a/Tests/GameWidgetTests/GroupTests.swift b/Tests/GameWidgetTests/GroupTests.swift new file mode 100644 index 0000000..c1f361c --- /dev/null +++ b/Tests/GameWidgetTests/GroupTests.swift @@ -0,0 +1,12 @@ +// +// GroupTests.swift +// +// +// Created by rrbox on 2022/12/02. +// + +import XCTest + +final class GroupTest: XCTestCase { + +} From 1384ec2c6b69db8b03f79478d503361da4800005 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 2 Dec 2022 00:43:52 +0900 Subject: [PATCH 02/57] =?UTF-8?q?update=20Group=20=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E4=BD=9C=E6=88=90=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Group に正しい順番で widget がセットされるかチェックします. --- Tests/GameWidgetTests/GroupTests.swift | 104 +++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/Tests/GameWidgetTests/GroupTests.swift b/Tests/GameWidgetTests/GroupTests.swift index c1f361c..acdb210 100644 --- a/Tests/GameWidgetTests/GroupTests.swift +++ b/Tests/GameWidgetTests/GroupTests.swift @@ -6,7 +6,111 @@ // import XCTest +import SpriteKit +import GameWidget + +struct TextNode: Widget { + let value: String + + typealias Context = Never + func node(context: Never) -> SKNode { + + } + + func node() -> SKNode { + let node = SKNode() + node.name = self.value + return node + } +} final class GroupTest: XCTestCase { + func generateNodesNameReduced(list: Extension) -> String { + list.widgetNodes().reduce(into: "") { partialResult, node in + guard let name = node.name else { + XCTFail() + return + } + partialResult += name + } + } + // group に widget が正しい順番で追加されているかチェックします. + func testNodeArrayGenerate() { + XCTAssertEqual("0", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + })) + XCTAssertEqual("01", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + })) + XCTAssertEqual("012", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + })) + XCTAssertEqual("0123", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + TextNode(value: "3") + })) + XCTAssertEqual("01234", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + TextNode(value: "3") + TextNode(value: "4") + })) + XCTAssertEqual("012345", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + TextNode(value: "3") + TextNode(value: "4") + TextNode(value: "5") + })) + XCTAssertEqual("0123456", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + TextNode(value: "3") + TextNode(value: "4") + TextNode(value: "5") + TextNode(value: "6") + })) + XCTAssertEqual("01234567", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + TextNode(value: "3") + TextNode(value: "4") + TextNode(value: "5") + TextNode(value: "6") + TextNode(value: "7") + })) + XCTAssertEqual("012345678", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + TextNode(value: "3") + TextNode(value: "4") + TextNode(value: "5") + TextNode(value: "6") + TextNode(value: "7") + TextNode(value: "8") + })) + XCTAssertEqual("0123456789", self.generateNodesNameReduced(list: Extension { + TextNode(value: "0") + TextNode(value: "1") + TextNode(value: "2") + TextNode(value: "3") + TextNode(value: "4") + TextNode(value: "5") + TextNode(value: "6") + TextNode(value: "7") + TextNode(value: "8") + TextNode(value: "9") + })) + } } From bca9d6d16d86054284570a0a691f78af35abcd49 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 2 Dec 2022 01:03:42 +0900 Subject: [PATCH 03/57] =?UTF-8?q?update=20Extension=20=E3=81=AB=E4=BE=9D?= =?UTF-8?q?=E5=AD=98=E3=81=97=E3=81=AA=E3=81=84=20test=20=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=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 --- Tests/GameWidgetTests/GroupTests.swift | 44 +++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Tests/GameWidgetTests/GroupTests.swift b/Tests/GameWidgetTests/GroupTests.swift index acdb210..5ae1120 100644 --- a/Tests/GameWidgetTests/GroupTests.swift +++ b/Tests/GameWidgetTests/GroupTests.swift @@ -25,8 +25,8 @@ struct TextNode: Widget { } final class GroupTest: XCTestCase { - func generateNodesNameReduced(list: Extension) -> String { - list.widgetNodes().reduce(into: "") { partialResult, node in + func generateNodesNameReduced(@GroupBuilder _ list: () -> T) -> String { + list().widgetNodes().reduce(into: "") { partialResult, node in guard let name = node.name else { XCTFail() return @@ -37,40 +37,40 @@ final class GroupTest: XCTestCase { // group に widget が正しい順番で追加されているかチェックします. func testNodeArrayGenerate() { - XCTAssertEqual("0", self.generateNodesNameReduced(list: Extension { + XCTAssertEqual("0", self.generateNodesNameReduced { TextNode(value: "0") - })) - XCTAssertEqual("01", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("01", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") - })) - XCTAssertEqual("012", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("012", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") - })) - XCTAssertEqual("0123", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("0123", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") TextNode(value: "3") - })) - XCTAssertEqual("01234", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("01234", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") TextNode(value: "3") TextNode(value: "4") - })) - XCTAssertEqual("012345", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("012345", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") TextNode(value: "3") TextNode(value: "4") TextNode(value: "5") - })) - XCTAssertEqual("0123456", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("0123456", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") @@ -78,8 +78,8 @@ final class GroupTest: XCTestCase { TextNode(value: "4") TextNode(value: "5") TextNode(value: "6") - })) - XCTAssertEqual("01234567", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("01234567", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") @@ -88,8 +88,8 @@ final class GroupTest: XCTestCase { TextNode(value: "5") TextNode(value: "6") TextNode(value: "7") - })) - XCTAssertEqual("012345678", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("012345678", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") @@ -99,8 +99,8 @@ final class GroupTest: XCTestCase { TextNode(value: "6") TextNode(value: "7") TextNode(value: "8") - })) - XCTAssertEqual("0123456789", self.generateNodesNameReduced(list: Extension { + }) + XCTAssertEqual("0123456789", self.generateNodesNameReduced { TextNode(value: "0") TextNode(value: "1") TextNode(value: "2") @@ -111,6 +111,6 @@ final class GroupTest: XCTestCase { TextNode(value: "7") TextNode(value: "8") TextNode(value: "9") - })) + }) } } From 806165a9851db94a27b0e23da51e8310111f9d4d Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 2 Dec 2022 19:39:54 +0900 Subject: [PATCH 04/57] =?UTF-8?q?clean=20=E4=BD=99=E5=88=86=E3=81=AA?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E3=82=92=E5=89=8A=E9=99=A4=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 --- Sources/GameWidget/Commons/Group.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/Group.swift index 018a141..bab9c42 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/Group.swift @@ -14,7 +14,7 @@ import SpriteKit Single(widget: c0) } - public static func buildBlock(_ c0: C0, _ c1: C1) -> some WidgetList{ + public static func buildBlock(_ c0: C0, _ c1: C1) -> some WidgetList { Single(widget: c0) .append(c1) } From dab9613c1264fe4771f737e2bdfe1a6d9a4b7e1f Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 19:27:16 +0900 Subject: [PATCH 05/57] =?UTF-8?q?add=20DisplayTests.swift=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=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 --- Tests/GameWidgetTests/DisplayTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Tests/GameWidgetTests/DisplayTests.swift diff --git a/Tests/GameWidgetTests/DisplayTests.swift b/Tests/GameWidgetTests/DisplayTests.swift new file mode 100644 index 0000000..5247490 --- /dev/null +++ b/Tests/GameWidgetTests/DisplayTests.swift @@ -0,0 +1,12 @@ +// +// DisplayTests.swift +// +// +// Created by rrbox on 2022/12/03. +// + +import XCTest + +final class DisplayTests: XCTestCase { + +} From 75448a1ddc9932cb0015349acdcfce2dafc83452 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 19:34:20 +0900 Subject: [PATCH 06/57] =?UTF-8?q?move=20Test=20=E7=94=A8=E3=81=AB=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E3=81=97=E3=81=9F=E3=82=B5=E3=83=B3=E3=83=97=E3=83=AB?= =?UTF-8?q?=E6=A7=8B=E9=80=A0=E4=BD=93=E3=82=92=E7=A7=BB=E5=8B=95=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 --- .../xcschemes/GameWidgetTests.xcscheme | 52 +++++++++++++++++++ Tests/GameWidgetTests/DisplayTests.swift | 5 +- Tests/GameWidgetTests/GroupTests.swift | 15 ------ Tests/GameWidgetTests/WidgetSample.swift | 25 +++++++++ 4 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/GameWidgetTests.xcscheme create mode 100644 Tests/GameWidgetTests/WidgetSample.swift diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/GameWidgetTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/GameWidgetTests.xcscheme new file mode 100644 index 0000000..c1901b6 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/GameWidgetTests.xcscheme @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/GameWidgetTests/DisplayTests.swift b/Tests/GameWidgetTests/DisplayTests.swift index 5247490..04726be 100644 --- a/Tests/GameWidgetTests/DisplayTests.swift +++ b/Tests/GameWidgetTests/DisplayTests.swift @@ -6,7 +6,10 @@ // import XCTest +import GameWidget final class DisplayTests: XCTestCase { - + func testDisplayGenerate() { + + } } diff --git a/Tests/GameWidgetTests/GroupTests.swift b/Tests/GameWidgetTests/GroupTests.swift index 5ae1120..37bb6d0 100644 --- a/Tests/GameWidgetTests/GroupTests.swift +++ b/Tests/GameWidgetTests/GroupTests.swift @@ -9,21 +9,6 @@ import XCTest import SpriteKit import GameWidget -struct TextNode: Widget { - let value: String - - typealias Context = Never - func node(context: Never) -> SKNode { - - } - - func node() -> SKNode { - let node = SKNode() - node.name = self.value - return node - } -} - final class GroupTest: XCTestCase { func generateNodesNameReduced(@GroupBuilder _ list: () -> T) -> String { list().widgetNodes().reduce(into: "") { partialResult, node in diff --git a/Tests/GameWidgetTests/WidgetSample.swift b/Tests/GameWidgetTests/WidgetSample.swift new file mode 100644 index 0000000..a9fcc21 --- /dev/null +++ b/Tests/GameWidgetTests/WidgetSample.swift @@ -0,0 +1,25 @@ +// +// WidgetSample.swift +// +// +// Created by rrbox on 2022/12/03. +// + +import SpriteKit +import GameWidget + +struct TextNode: Widget { + let value: String + + typealias Context = Never + func node(context: Never) -> SKNode { + + } + + func node() -> SKNode { + let node = SKNode() + node.name = self.value + return node + } +} + From b08d420b2d2e8f45ff7b19596078be8b15fa0465 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 19:39:11 +0900 Subject: [PATCH 07/57] =?UTF-8?q?add=20Display=20=E7=94=A8=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=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 --- Tests/GameWidgetTests/DisplayTests.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/GameWidgetTests/DisplayTests.swift b/Tests/GameWidgetTests/DisplayTests.swift index 04726be..ae99901 100644 --- a/Tests/GameWidgetTests/DisplayTests.swift +++ b/Tests/GameWidgetTests/DisplayTests.swift @@ -10,6 +10,20 @@ import GameWidget final class DisplayTests: XCTestCase { func testDisplayGenerate() { + let displayNode = Display() + .place { + TextNode(value: "0") + TextNode(value: "1") + } + .place { + TextNode(value: "2") + TextNode(value: "3") + } + .node() + XCTAssertEqual(displayNode.children.count, 4) + XCTAssertEqual(displayNode.children.reduce(into: "", { partialResult, node in + partialResult += node.name! + }), "0123") } } From 187e21d244dea6f6a4f171ebdc810ffe2eb6e8cc Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 19:55:47 +0900 Subject: [PATCH 08/57] =?UTF-8?q?update=20Widget=20=E3=82=923=E3=81=A4?= =?UTF-8?q?=E3=81=AE=E3=83=97=E3=83=AD=E3=83=88=E3=82=B3=E3=83=AB=E3=81=AB?= =?UTF-8?q?=E5=88=86=E9=9B=A2=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 - WidgetListElementType - VoidNodeGenerator - ContextNodeGenerator --- Sources/GameWidget/Commons/Widget.swift | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Sources/GameWidget/Commons/Widget.swift b/Sources/GameWidget/Commons/Widget.swift index e3dfe7d..b0c11b2 100644 --- a/Sources/GameWidget/Commons/Widget.swift +++ b/Sources/GameWidget/Commons/Widget.swift @@ -9,19 +9,31 @@ import SpriteKit import GameplayKit -public protocol Widget { +public protocol ContextNodeGenerator { + associatedtype Context: ContextProtocol func node(context: Context) -> SKNode +} + +public protocol VoidNodeGenerator { func node() -> SKNode +} + +public protocol WidgetListElementType { func addTo(parent list: inout [SKNode]) +} + +public protocol Widget: ContextNodeGenerator, VoidNodeGenerator, WidgetListElementType { - associatedtype Context: ContextProtocol } -public extension Widget { + +public extension WidgetListElementType where Self: VoidNodeGenerator { func addTo(parent list: inout [SKNode]) { list.append(self.node()) } - +} + +public extension VoidNodeGenerator where Self: ContextNodeGenerator { func node() -> SKNode { self.node(context: Context()) } From c47a6af64ff1c13888f27251f17d81990b40b31b Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 20:07:17 +0900 Subject: [PATCH 09/57] =?UTF-8?q?change=20GroupBuilder=20=E3=81=AE?= =?UTF-8?q?=E9=80=A3=E7=B5=90=E3=83=AA=E3=82=B9=E3=83=88=E3=81=AE=E8=A6=81?= =?UTF-8?q?=E7=B4=A0=E3=82=92=20WidgetListElementType=20=E3=81=A7=E5=88=B6?= =?UTF-8?q?=E7=B4=84=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/Group.swift | 84 ++++++++++++++++++-------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/Group.swift index bab9c42..989b710 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/Group.swift @@ -10,29 +10,39 @@ import SpriteKit @resultBuilder public struct GroupBuilder { - public static func buildBlock(_ c0: C0) -> some WidgetList { + public static func buildBlock(_ c0: C0) -> some WidgetList { Single(widget: c0) } - public static func buildBlock(_ c0: C0, _ c1: C1) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1) -> some WidgetList { Single(widget: c0) .append(c1) } - public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2) -> some WidgetList { Single(widget: c0) .append(c1) .append(c2) } - public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3) -> some WidgetList { Single(widget: c0) .append(c1) .append(c2) .append(c3) } - public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4) -> some WidgetList { Single(widget: c0) .append(c1) .append(c2) @@ -40,7 +50,12 @@ import SpriteKit .append(c4) } - public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5) -> some WidgetList { Single(widget: c0) .append(c1) .append(c2) @@ -49,7 +64,13 @@ import SpriteKit .append(c5) } - public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6) -> some WidgetList { Single(widget: c0) .append(c1) .append(c2) @@ -59,7 +80,14 @@ import SpriteKit .append(c6) } - public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7) -> some WidgetList { Single(widget: c0) .append(c1) .append(c2) @@ -70,7 +98,15 @@ import SpriteKit .append(c7) } - public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8) -> some WidgetList { + public static func buildBlock(_ c0: C0, _ c1: C1, _ c2: C2, _ c3: C3, _ c4: C4, _ c5: C5, _ c6: C6, _ c7: C7, _ c8: C8) -> some WidgetList { Single(widget: c0) .append(c1) .append(c2) @@ -82,7 +118,16 @@ import SpriteKit .append(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 WidgetList { + 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 WidgetList { Single(widget: c0) .append(c1) .append(c2) @@ -102,12 +147,12 @@ public protocol WidgetList { } /// 再帰可能. widget のペアです. オーバーヘッドはありません. -public struct RecursiveGroup: WidgetList { +public struct RecursiveGroup: WidgetList { var first: T var second: U - func append(_ newWidget: V) -> RecursiveGroup { + func append(_ newWidget: V) -> RecursiveGroup { .init(first: self, second: newWidget) } @@ -120,11 +165,11 @@ public struct RecursiveGroup: WidgetList { } // 一つの widget から RecursiveGroup を生成するためのラッパー. -struct Single: WidgetList { +struct Single: WidgetList { var widget: T - func append(_ newWidget: U) -> RecursiveGroup { + func append(_ newWidget: U) -> RecursiveGroup { .init(first: self, second: newWidget) } @@ -138,8 +183,7 @@ struct Single: WidgetList { /// widget 数を増やす際に使用します. 10 個以下の widget を内包することができます. /// - note: モディファイアはありませんが, メモリのオーバーヘッドがありません. -public struct Extension: Widget, WidgetList { - public typealias Context = Never +public struct Extension: WidgetListElementType, WidgetList { var content: Content @@ -151,14 +195,6 @@ public struct Extension: Widget, WidgetList { self.content.widgetNodes() } - public func node(context: Never) -> SKNode { - - } - - public func node() -> SKNode { - fatalError("Extension は node を生成しません.") - } - public func addTo(parent list: inout [SKNode]) { for node in self.content.widgetNodes() { list.append(node) From 12d2acfd7df50c1ab69b2e36026b8dd9b66b71f4 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 20:26:52 +0900 Subject: [PATCH 10/57] =?UTF-8?q?change=20`modifiable`=20=E3=81=AE?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=E3=82=92=E9=99=90=E5=AE=9A=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 --- Sources/GameWidget/Commons/ModifiableWidget.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index 28b763a..38e67ab 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -7,7 +7,7 @@ import SpriteKit -public struct ModifiableWidget: Widget where Body.Context == Builder.Mod.Context { +public struct ModifiableWidget: Widget where Body.Context == Builder.Mod.Context { public func node(context: Body.Context) -> SKNode { fatalError("\(context)") } @@ -36,7 +36,7 @@ public struct Empty: Modifier { } -public extension Widget { +public extension ContextNodeGenerator { typealias Modifiable = ModifiableWidget>> var modifiable: Modifiable { From 8c00d41df6d09a500d5d9910b476a2090cf9dc3c Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 20:30:57 +0900 Subject: [PATCH 11/57] =?UTF-8?q?change=20`ModifiableWidget`=20=E3=81=8B?= =?UTF-8?q?=E3=82=89=20`node(context:)=20`=20=E3=82=92=E5=89=8A=E9=99=A4?= =?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/ModifiableWidget.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index 38e67ab..221c628 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -7,10 +7,7 @@ import SpriteKit -public struct ModifiableWidget: Widget where Body.Context == Builder.Mod.Context { - public func node(context: Body.Context) -> SKNode { - fatalError("\(context)") - } +public struct ModifiableWidget: WidgetListElementType, VoidNodeGenerator where Body.Context == Builder.Mod.Context { public func node() -> SKNode { var context = Context() From f97ee9e098585ba2eb8a85af5250a8a94de84d00 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 21:01:17 +0900 Subject: [PATCH 12/57] =?UTF-8?q?change=20Display=20=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9=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 Widget では無くなりました. --- Sources/GameWidget/Commons/Display.swift | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Sources/GameWidget/Commons/Display.swift b/Sources/GameWidget/Commons/Display.swift index 72717cc..4b96c64 100644 --- a/Sources/GameWidget/Commons/Display.swift +++ b/Sources/GameWidget/Commons/Display.swift @@ -1,5 +1,5 @@ // -// File.swift +// Display.swift // // // Created by rrbox on 2022/07/24. @@ -69,22 +69,12 @@ public struct SingleWidgetDisplay: Widget, WidgetList { /// Widget のレイアウトの起点. place メソッドチェーンで無制限に Widget を配置できます. /// - note: 一回の place メソッドで配置可能な widget の数は 10 個までです. -public struct Display: Widget { - public typealias Context = Never - +public struct Display { public init() {} public func place(@GroupBuilder block: () -> T) -> SingleWidgetDisplay { SingleWidgetDisplay(widgetList: block()) } - public func node(context: Never) -> SKNode { - - } - - public func node() -> SKNode { - fatalError("display has no widget") - } - } From 4b417ad517b7f9168645f1ac45be325c3372d1fa Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 21:02:22 +0900 Subject: [PATCH 13/57] =?UTF-8?q?change=20Extension=20=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9=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 --- Sources/GameWidget/Commons/Group.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/Group.swift index 989b710..617cc4a 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/Group.swift @@ -1,5 +1,5 @@ // -// File.swift +// Group.swift // // // Created by rrbox on 2022/07/24. @@ -183,7 +183,7 @@ struct Single: WidgetList { /// widget 数を増やす際に使用します. 10 個以下の widget を内包することができます. /// - note: モディファイアはありませんが, メモリのオーバーヘッドがありません. -public struct Extension: WidgetListElementType, WidgetList { +public struct Extension: WidgetListElementType { var content: Content @@ -191,10 +191,6 @@ public struct Extension: WidgetListElementType, WidgetList self.content = content() } - public func widgetNodes() -> [SKNode] { - self.content.widgetNodes() - } - public func addTo(parent list: inout [SKNode]) { for node in self.content.widgetNodes() { list.append(node) From 1c6a8db5c9817ac3615e992b10b7e4790a02b6dd Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 3 Dec 2022 21:02:47 +0900 Subject: [PATCH 14/57] =?UTF-8?q?fix=20=E3=83=98=E3=83=83=E3=83=80?= =?UTF-8?q?=E3=83=BC=E9=83=A8=E5=88=86=E3=82=92=E4=BF=AE=E6=AD=A3=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/Entity.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/GameWidget/Commons/Entity.swift b/Sources/GameWidget/Commons/Entity.swift index b9cc10a..5dca957 100644 --- a/Sources/GameWidget/Commons/Entity.swift +++ b/Sources/GameWidget/Commons/Entity.swift @@ -1,6 +1,6 @@ // -// File.swift -// +// Entity.swift +// // // Created by rrbox on 2022/06/18. // From b5ef4fd5c65bb811934d77ea17facaa15e713f49 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Wed, 4 Jan 2023 18:45:18 +0900 Subject: [PATCH 15/57] =?UTF-8?q?change=20protocol=20=E3=81=AE=E5=9E=8B?= =?UTF-8?q?=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/Commons/Context/Context.swift | 16 +++++++++++----- .../GameWidget/Commons/ModifiableWidget.swift | 4 ++-- Sources/GameWidget/Commons/Widget.swift | 15 ++++++--------- Sources/GameWidget/NodeWidget/NodeWidget.swift | 3 +-- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Sources/GameWidget/Commons/Context/Context.swift b/Sources/GameWidget/Commons/Context/Context.swift index 4242e1c..6101656 100644 --- a/Sources/GameWidget/Commons/Context/Context.swift +++ b/Sources/GameWidget/Commons/Context/Context.swift @@ -5,12 +5,18 @@ // Created by rrbox on 2022/10/29. // -public protocol ContextProtocol { +public protocol WidgetContextType { + +} + +public protocol ParameterLessGeneratable { init() } -extension Never: ContextProtocol { - public init() { - fatalError() - } +public protocol ContextProtocol: WidgetContextType, ParameterLessGeneratable { + +} + +extension Never: WidgetContextType { + } diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index 221c628..41bec1a 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -7,7 +7,7 @@ import SpriteKit -public struct ModifiableWidget: WidgetListElementType, VoidNodeGenerator where Body.Context == Builder.Mod.Context { +public struct ModifiableWidget: WidgetListElementType, ParameterLessNodeGenerator where Body.Context == Builder.Mod.Context { public func node() -> SKNode { var context = Context() @@ -33,7 +33,7 @@ public struct Empty: Modifier { } -public extension ContextNodeGenerator { +public extension Widget where Context: ContextProtocol { typealias Modifiable = ModifiableWidget>> var modifiable: Modifiable { diff --git a/Sources/GameWidget/Commons/Widget.swift b/Sources/GameWidget/Commons/Widget.swift index b0c11b2..4c7db41 100644 --- a/Sources/GameWidget/Commons/Widget.swift +++ b/Sources/GameWidget/Commons/Widget.swift @@ -5,16 +5,14 @@ // Created by rrbox on 2022/03/10. // - import SpriteKit -import GameplayKit -public protocol ContextNodeGenerator { - associatedtype Context: ContextProtocol +public protocol ContextPresenter { + associatedtype Context: WidgetContextType func node(context: Context) -> SKNode } -public protocol VoidNodeGenerator { +public protocol ParameterLessNodeGenerator { func node() -> SKNode } @@ -22,18 +20,17 @@ public protocol WidgetListElementType { func addTo(parent list: inout [SKNode]) } -public protocol Widget: ContextNodeGenerator, VoidNodeGenerator, WidgetListElementType { +public protocol Widget: ContextPresenter, ParameterLessNodeGenerator, WidgetListElementType { } - -public extension WidgetListElementType where Self: VoidNodeGenerator { +public extension WidgetListElementType where Self: ParameterLessNodeGenerator { func addTo(parent list: inout [SKNode]) { list.append(self.node()) } } -public extension VoidNodeGenerator where Self: ContextNodeGenerator { +public extension ParameterLessNodeGenerator where Self: ContextPresenter, Context: ParameterLessGeneratable { func node() -> SKNode { self.node(context: Context()) } diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index 3a19584..4a64e86 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -11,8 +11,7 @@ import SpriteKit /// - note: 数値をもつため, 40バイトのメモリを必要とします. public struct Node: Widget, WidgetList { public typealias Context = NodeContext - public - var content: Content + public var content: Content public init(@GroupBuilder _ content: () -> Content) { self.content = content() From 17d0ca16d6e5bbc910517dc4b4a4e4dbbca7d861 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Wed, 4 Jan 2023 21:47:43 +0900 Subject: [PATCH 16/57] =?UTF-8?q?change=20Widget=20=E3=81=AE=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9=E3=82=92=20ParameterLessNodeGenerato=20r+=20WidgetLis?= =?UTF-8?q?tElementType=20=E3=81=AB=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 --- Sources/GameWidget/Commons/Widget.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/GameWidget/Commons/Widget.swift b/Sources/GameWidget/Commons/Widget.swift index 4c7db41..ccdd6a4 100644 --- a/Sources/GameWidget/Commons/Widget.swift +++ b/Sources/GameWidget/Commons/Widget.swift @@ -20,7 +20,7 @@ public protocol WidgetListElementType { func addTo(parent list: inout [SKNode]) } -public protocol Widget: ContextPresenter, ParameterLessNodeGenerator, WidgetListElementType { +public protocol Widget: ParameterLessNodeGenerator, WidgetListElementType { } From 1c42447e8f5e6d054e4f9678e61dd1a6c77a4748 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Wed, 4 Jan 2023 21:50:00 +0900 Subject: [PATCH 17/57] =?UTF-8?q?change=20=E5=AE=9A=E7=BE=A9=E6=B8=88?= =?UTF-8?q?=E3=81=BF=20Widget=20=E3=81=AE=E3=81=86=E3=81=A1,=20Modifiable?= =?UTF-8?q?=20=E3=81=AA=E3=82=82=E3=81=AE=E3=81=AE=E3=81=BF=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E3=81=97,=20ContextPresenter=20=E3=81=AB=E6=BA=96?= =?UTF-8?q?=E6=8B=A0=E3=81=95=E3=81=9B=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/BarChart/BarChart.swift | 2 +- Sources/GameWidget/Button/Button.swift | 2 +- Sources/GameWidget/Controller/Controller.swift | 2 +- Sources/GameWidget/NodeWidget/NodeWidget.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/GameWidget/BarChart/BarChart.swift b/Sources/GameWidget/BarChart/BarChart.swift index db1d4e0..5f46dbf 100644 --- a/Sources/GameWidget/BarChart/BarChart.swift +++ b/Sources/GameWidget/BarChart/BarChart.swift @@ -36,7 +36,7 @@ public struct HorizontalSingleBarChart { } -extension HorizontalSingleBarChart: Widget { +extension HorizontalSingleBarChart: Widget, ContextPresenter { public typealias Context = HorizontalSingleBarChartContext public func node(context: HorizontalSingleBarChartContext) -> SKNode { diff --git a/Sources/GameWidget/Button/Button.swift b/Sources/GameWidget/Button/Button.swift index 3eb206e..0ba535e 100644 --- a/Sources/GameWidget/Button/Button.swift +++ b/Sources/GameWidget/Button/Button.swift @@ -25,7 +25,7 @@ public struct Button { } -extension Button: Widget { +extension Button: Widget, ContextPresenter { public typealias Context = ButtonContext public func node(context: ButtonContext) -> SKNode { diff --git a/Sources/GameWidget/Controller/Controller.swift b/Sources/GameWidget/Controller/Controller.swift index 420c24e..2b0c41a 100644 --- a/Sources/GameWidget/Controller/Controller.swift +++ b/Sources/GameWidget/Controller/Controller.swift @@ -100,7 +100,7 @@ class ControllerAreaNode: SKSpriteNode { } -public struct ControllerArea: Widget { +public struct ControllerArea: Widget, ContextPresenter { public typealias Context = ControllerContext var id: ControllerData.Name diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index 4a64e86..d1f3e38 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -9,7 +9,7 @@ import SpriteKit /// 10 個以下の widget を一つの widget としてまとめます. 座標, スケール, 回転を内包するコンテンツと共に調整することができます. /// - note: 数値をもつため, 40バイトのメモリを必要とします. -public struct Node: Widget, WidgetList { +public struct Node: Widget, ContextPresenter, WidgetList { public typealias Context = NodeContext public var content: Content From 1104ba2e843f146ffcd79724f97274d93c48a0a7 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Wed, 4 Jan 2023 21:54:17 +0900 Subject: [PATCH 18/57] =?UTF-8?q?change=20ModifiableWidget=20=E3=81=8C?= =?UTF-8?q?=E6=BA=96=E6=8B=A0=E3=81=99=E3=82=8B=20protocol=20=E3=82=92=20W?= =?UTF-8?q?idget=20=E3=81=AE=E3=81=BF=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/ModifiableWidget.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index 41bec1a..0e9d329 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -7,7 +7,7 @@ import SpriteKit -public struct ModifiableWidget: WidgetListElementType, ParameterLessNodeGenerator where Body.Context == Builder.Mod.Context { +public struct ModifiableWidget: Widget where Body.Context == Builder.Mod.Context { public func node() -> SKNode { var context = Context() @@ -33,7 +33,7 @@ public struct Empty: Modifier { } -public extension Widget where Context: ContextProtocol { +public extension Widget where Self: ContextPresenter, Context: ContextProtocol { typealias Modifiable = ModifiableWidget>> var modifiable: Modifiable { From ed698b1682681209ff3a5bf9ffa1c1a76d235093 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Wed, 4 Jan 2023 21:55:43 +0900 Subject: [PATCH 19/57] =?UTF-8?q?remove=20Never=20=E3=81=AE=20WidgetContec?= =?UTF-8?q?tType=20=E5=AE=9F=E8=A3=85=E3=82=92=E5=89=8A=E9=99=A4=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/Context/Context.swift | 4 ---- Sources/GameWidget/Commons/Display.swift | 10 ---------- 2 files changed, 14 deletions(-) diff --git a/Sources/GameWidget/Commons/Context/Context.swift b/Sources/GameWidget/Commons/Context/Context.swift index 6101656..492884f 100644 --- a/Sources/GameWidget/Commons/Context/Context.swift +++ b/Sources/GameWidget/Commons/Context/Context.swift @@ -16,7 +16,3 @@ public protocol ParameterLessGeneratable { public protocol ContextProtocol: WidgetContextType, ParameterLessGeneratable { } - -extension Never: WidgetContextType { - -} diff --git a/Sources/GameWidget/Commons/Display.swift b/Sources/GameWidget/Commons/Display.swift index 4b96c64..2b25c6a 100644 --- a/Sources/GameWidget/Commons/Display.swift +++ b/Sources/GameWidget/Commons/Display.swift @@ -9,7 +9,6 @@ import SpriteKit /// SingleWidgetDisplay の place により生成され, 二つの WidgetList(一方は Display)を保持します. public struct RecursiveDisplay: Widget, WidgetList { - public typealias Context = Never var first: T var second: U @@ -22,10 +21,6 @@ public struct RecursiveDisplay: Widget, WidgetList self.first.widgetNodes() + self.second.widgetNodes() } - public func node(context: Never) -> SKNode { - - } - public func node() -> SKNode { let result = SKNode() @@ -41,7 +36,6 @@ public struct RecursiveDisplay: Widget, WidgetList /// 一つの widget から RecursiveDisplay を生成するためのラッパー. /// Display の place により生成され, 一つの WidgetList を保持します. public struct SingleWidgetDisplay: Widget, WidgetList { - public typealias Context = Never var widgetList: T @@ -53,10 +47,6 @@ public struct SingleWidgetDisplay: Widget, WidgetList { self.widgetList.widgetNodes() } - public func node(context: Never) -> SKNode { - - } - public func node() -> SKNode { let result = SKNode() for node in self.widgetList.widgetNodes() { From 81c73fd8f46e62dd62c5f4b11f242d185c34d79b Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 5 Feb 2023 13:53:41 +0900 Subject: [PATCH 20/57] =?UTF-8?q?change=20GameWidget=20sheme=20=E3=81=AB?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0=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 --- ...dgetTests.xcscheme => GameWidget.xcscheme} | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) rename .swiftpm/xcode/xcshareddata/xcschemes/{GameWidgetTests.xcscheme => GameWidget.xcscheme} (64%) diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/GameWidgetTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/GameWidget.xcscheme similarity index 64% rename from .swiftpm/xcode/xcshareddata/xcschemes/GameWidgetTests.xcscheme rename to .swiftpm/xcode/xcshareddata/xcschemes/GameWidget.xcscheme index c1901b6..3508b5d 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/GameWidgetTests.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/GameWidget.xcscheme @@ -1,10 +1,26 @@ + + + + + + + + + + From 9436bbfa5c5a4043efe60a8725b7c83c566f4f11 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:33:13 +0900 Subject: [PATCH 21/57] =?UTF-8?q?change=20`Node`=20=E3=82=92=20`NodeWidget?= =?UTF-8?q?`=20=E3=81=AB=E6=94=B9=E5=90=8D=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/NodeWidget/NodeWidget.swift | 8 +------- Tests/GameWidgetTests/GameWidgetTests.swift | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index d1f3e38..01c4780 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -9,7 +9,7 @@ import SpriteKit /// 10 個以下の widget を一つの widget としてまとめます. 座標, スケール, 回転を内包するコンテンツと共に調整することができます. /// - note: 数値をもつため, 40バイトのメモリを必要とします. -public struct Node: Widget, ContextPresenter, WidgetList { +public struct NodeWidget: Widget, ContextPresenter { public typealias Context = NodeContext public var content: Content @@ -17,12 +17,6 @@ public struct Node: Widget, ContextPresenter, WidgetList { self.content = content() } - public func widgetNodes() -> [SKNode] { - var result = [SKNode]() - self.addTo(parent: &result) - return result - } - public func node(context: NodeContext) -> SKNode { let result = SKNode() diff --git a/Tests/GameWidgetTests/GameWidgetTests.swift b/Tests/GameWidgetTests/GameWidgetTests.swift index ab419bf..4a7eaf2 100644 --- a/Tests/GameWidgetTests/GameWidgetTests.swift +++ b/Tests/GameWidgetTests/GameWidgetTests.swift @@ -3,7 +3,7 @@ import XCTest final class NodeTests: XCTestCase { func testModifiers() throws { - let node = Node { + let node = NodeWidget { Button(.init("test")) } .modifiable From 5354b3b3b2c65fe77701d4f316bcb0807f35929f Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:39:51 +0900 Subject: [PATCH 22/57] =?UTF-8?q?fix=20`NodeWidget`=20=E3=81=AE=20document?= =?UTF-8?q?ation=20comment=20=E3=82=92=E4=BF=AE=E6=AD=A3=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 --- Sources/GameWidget/NodeWidget/NodeWidget.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index 01c4780..5c6a407 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -8,7 +8,6 @@ import SpriteKit /// 10 個以下の widget を一つの widget としてまとめます. 座標, スケール, 回転を内包するコンテンツと共に調整することができます. -/// - note: 数値をもつため, 40バイトのメモリを必要とします. public struct NodeWidget: Widget, ContextPresenter { public typealias Context = NodeContext public var content: Content From 68b2a75b673e8d6f855e592dbfcd5c90d3da4be4 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:41:51 +0900 Subject: [PATCH 23/57] =?UTF-8?q?rename=20HorizontalBarChart=20=E3=82=92?= =?UTF-8?q?=20`Gauge`=20=E3=81=AB=E4=BF=AE=E6=AD=A3=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 これはファイルとフォルダの名前の変更です. --- Sources/GameWidget/{BarChart/BarChart.swift => Gauge/Gauge.swift} | 0 .../BarChartModifiers.swift => Gauge/GaugeModifiers.swift} | 0 .../{BarChart/BarChartNode.swift => Gauge/GaugeNode.swift} | 0 .../{BarChart/BarChartOutput.swift => Gauge/GaugeOutput.swift} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Sources/GameWidget/{BarChart/BarChart.swift => Gauge/Gauge.swift} (100%) rename Sources/GameWidget/{BarChart/BarChartModifiers.swift => Gauge/GaugeModifiers.swift} (100%) rename Sources/GameWidget/{BarChart/BarChartNode.swift => Gauge/GaugeNode.swift} (100%) rename Sources/GameWidget/{BarChart/BarChartOutput.swift => Gauge/GaugeOutput.swift} (100%) diff --git a/Sources/GameWidget/BarChart/BarChart.swift b/Sources/GameWidget/Gauge/Gauge.swift similarity index 100% rename from Sources/GameWidget/BarChart/BarChart.swift rename to Sources/GameWidget/Gauge/Gauge.swift diff --git a/Sources/GameWidget/BarChart/BarChartModifiers.swift b/Sources/GameWidget/Gauge/GaugeModifiers.swift similarity index 100% rename from Sources/GameWidget/BarChart/BarChartModifiers.swift rename to Sources/GameWidget/Gauge/GaugeModifiers.swift diff --git a/Sources/GameWidget/BarChart/BarChartNode.swift b/Sources/GameWidget/Gauge/GaugeNode.swift similarity index 100% rename from Sources/GameWidget/BarChart/BarChartNode.swift rename to Sources/GameWidget/Gauge/GaugeNode.swift diff --git a/Sources/GameWidget/BarChart/BarChartOutput.swift b/Sources/GameWidget/Gauge/GaugeOutput.swift similarity index 100% rename from Sources/GameWidget/BarChart/BarChartOutput.swift rename to Sources/GameWidget/Gauge/GaugeOutput.swift From 631ad374641f19a14576149727f889ca969a20f5 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:42:55 +0900 Subject: [PATCH 24/57] =?UTF-8?q?clean=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=86=85=E3=81=AE=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E5=90=8D=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=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/Gauge/Gauge.swift | 2 +- Sources/GameWidget/Gauge/GaugeModifiers.swift | 2 +- Sources/GameWidget/Gauge/GaugeNode.swift | 2 +- Sources/GameWidget/Gauge/GaugeOutput.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/GameWidget/Gauge/Gauge.swift b/Sources/GameWidget/Gauge/Gauge.swift index 5f46dbf..7323322 100644 --- a/Sources/GameWidget/Gauge/Gauge.swift +++ b/Sources/GameWidget/Gauge/Gauge.swift @@ -1,5 +1,5 @@ // -// BarChart.swift +// Gauge.swift // // // Created by rrbox on 2022/06/07. diff --git a/Sources/GameWidget/Gauge/GaugeModifiers.swift b/Sources/GameWidget/Gauge/GaugeModifiers.swift index a43c3e8..9c3ac3f 100644 --- a/Sources/GameWidget/Gauge/GaugeModifiers.swift +++ b/Sources/GameWidget/Gauge/GaugeModifiers.swift @@ -1,5 +1,5 @@ // -// BarChartModifiers.swift +// GaugeModifiers.swift // // // Created by rrbox on 2022/11/15. diff --git a/Sources/GameWidget/Gauge/GaugeNode.swift b/Sources/GameWidget/Gauge/GaugeNode.swift index efaabee..1a81269 100644 --- a/Sources/GameWidget/Gauge/GaugeNode.swift +++ b/Sources/GameWidget/Gauge/GaugeNode.swift @@ -1,5 +1,5 @@ // -// BarChartNode.swift +// GaugeNode.swift // // // Created by rrbox on 2022/11/28. diff --git a/Sources/GameWidget/Gauge/GaugeOutput.swift b/Sources/GameWidget/Gauge/GaugeOutput.swift index e809999..cad13c5 100644 --- a/Sources/GameWidget/Gauge/GaugeOutput.swift +++ b/Sources/GameWidget/Gauge/GaugeOutput.swift @@ -1,5 +1,5 @@ // -// BarChartOutput.swift +// GaugeOutput.swift // // // Created by rrbox on 2022/11/28. From 20a5840f3cd61038de5949cf2b7d7a7cec75ffd6 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:48:28 +0900 Subject: [PATCH 25/57] =?UTF-8?q?rename=20`HorizontalSingleBarChat`=20?= =?UTF-8?q?=E3=82=92=20`Gauge`=20=E3=81=AB=E6=94=B9=E5=90=8D=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/Gauge/Gauge.swift | 28 ++++++------- Sources/GameWidget/Gauge/GaugeModifiers.swift | 42 +++++++++---------- Sources/GameWidget/Gauge/GaugeNode.swift | 12 +++--- Sources/GameWidget/Gauge/GaugeOutput.swift | 40 +++++++++--------- Tests/GameWidgetTests/BarChartTests.swift | 2 +- 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/Sources/GameWidget/Gauge/Gauge.swift b/Sources/GameWidget/Gauge/Gauge.swift index 7323322..be3b797 100644 --- a/Sources/GameWidget/Gauge/Gauge.swift +++ b/Sources/GameWidget/Gauge/Gauge.swift @@ -7,7 +7,7 @@ import SpriteKit -public enum HorizontalBarChartAlignmentMode { +public enum GaugeAlignmentMode { case left, right, center static let anchorPointMap: [Self: CGPoint] = [ .left: CGPoint(x: 0, y: 0.5), @@ -19,7 +19,7 @@ public enum HorizontalBarChartAlignmentMode { } } -public struct HorizontalSingleBarChart { +public struct Gauge { public struct ID: Equatable { let id: String @@ -36,28 +36,28 @@ public struct HorizontalSingleBarChart { } -extension HorizontalSingleBarChart: Widget, ContextPresenter { - public typealias Context = HorizontalSingleBarChartContext +extension Gauge: Widget, ContextPresenter { + public typealias Context = GaugeContext - public func node(context: HorizontalSingleBarChartContext) -> SKNode { + public func node(context: GaugeContext) -> SKNode { - let bar = HorizontalBarChartNode(color: context.color, size: CGSize(width: context.length, height: context.width)) + let gauge = GaugeNode(color: context.color, size: CGSize(width: context.length, height: context.width)) - bar.alpha = context.alpha - bar.maxWidth = context.length - bar.registerTo(center: HorizontalBarChartNode.center, id: self.name) - bar.anchorPoint = context.alignment.anchorPoint() - bar.position = context.position - bar.zPosition = context.zPosition + gauge.alpha = context.alpha + gauge.maxWidth = context.length + gauge.registerTo(center: GaugeNode.center, id: self.name) + gauge.anchorPoint = context.alignment.anchorPoint() + gauge.position = context.position + gauge.zPosition = context.zPosition if let backgroundColor = context.backgroundColor { let backgound = SKSpriteNode(color: backgroundColor, size: CGSize(width: context.length, height: context.width)) backgound.anchorPoint = context.alignment.anchorPoint() backgound.zPosition = context.zPosition - 0.01 - bar.addChild(backgound) + gauge.addChild(backgound) } - return bar + return gauge } } diff --git a/Sources/GameWidget/Gauge/GaugeModifiers.swift b/Sources/GameWidget/Gauge/GaugeModifiers.swift index 9c3ac3f..86b12c1 100644 --- a/Sources/GameWidget/Gauge/GaugeModifiers.swift +++ b/Sources/GameWidget/Gauge/GaugeModifiers.swift @@ -7,7 +7,7 @@ import SpriteKit -public struct HorizontalSingleBarChartContext: +public struct GaugeContext: PositionContextProtocol, ColorizableContextProtocol, AlphaContextProtocol, @@ -21,63 +21,63 @@ public struct HorizontalSingleBarChartContext: public var zPosition: CGFloat = .zero var width = CGFloat(10) var length = CGFloat(100) - var alignment = HorizontalBarChartAlignmentMode.right + var alignment = GaugeAlignmentMode.right var backgroundColor: SKColor? } -public enum HorizontalSingleBarChartModiifers { +public enum GaugeModiifers { public struct Width: Modifier { - public typealias Context = HorizontalSingleBarChartContext + public typealias Context = GaugeContext var value: CGFloat - public func mod(context: inout HorizontalSingleBarChartContext) { + public func mod(context: inout GaugeContext) { context.width = self.value } } public struct Length: Modifier { - public typealias Context = HorizontalSingleBarChartContext + public typealias Context = GaugeContext var value: CGFloat - public func mod(context: inout HorizontalSingleBarChartContext) { + public func mod(context: inout GaugeContext) { context.length = self.value } } public struct Alignment: Modifier { - public typealias Context = HorizontalSingleBarChartContext - var value: HorizontalBarChartAlignmentMode + public typealias Context = GaugeContext + var value: GaugeAlignmentMode - public func mod(context: inout HorizontalSingleBarChartContext) { + public func mod(context: inout GaugeContext) { context.alignment = self.value } } public struct BackgroundColor: Modifier { - public typealias Context = HorizontalSingleBarChartContext + public typealias Context = GaugeContext var value: SKColor - public func mod(context: inout HorizontalSingleBarChartContext) { + public func mod(context: inout GaugeContext) { context.backgroundColor = self.value } } } -public extension ModifiableWidget where Context == HorizontalSingleBarChartContext { - func width(_ value: CGFloat) -> Next { - self.modifier(mod: HorizontalSingleBarChartModiifers.Width(value: value)) +public extension ModifiableWidget where Context == GaugeContext { + func width(_ value: CGFloat) -> Next { + self.modifier(mod: GaugeModiifers.Width(value: value)) } - func length(_ value: CGFloat) -> Next { - self.modifier(mod: HorizontalSingleBarChartModiifers.Length(value: value)) + func length(_ value: CGFloat) -> Next { + self.modifier(mod: GaugeModiifers.Length(value: value)) } - func alignment(_ value: HorizontalBarChartAlignmentMode) -> Next { - self.modifier(mod: HorizontalSingleBarChartModiifers.Alignment(value: value)) + func alignment(_ value: GaugeAlignmentMode) -> Next { + self.modifier(mod: GaugeModiifers.Alignment(value: value)) } - func backgroundColor(_ value: SKColor) -> Next { - self.modifier(mod: HorizontalSingleBarChartModiifers.BackgroundColor(value: value)) + func backgroundColor(_ value: SKColor) -> Next { + self.modifier(mod: GaugeModiifers.BackgroundColor(value: value)) } } diff --git a/Sources/GameWidget/Gauge/GaugeNode.swift b/Sources/GameWidget/Gauge/GaugeNode.swift index 1a81269..53058f7 100644 --- a/Sources/GameWidget/Gauge/GaugeNode.swift +++ b/Sources/GameWidget/Gauge/GaugeNode.swift @@ -7,7 +7,7 @@ import SpriteKit -class HorizontalBarChartNode: SKSpriteNode { +class GaugeNode: SKSpriteNode { static let center = NotificationCenter() var maxWidth: CGFloat = .zero @@ -29,10 +29,10 @@ class HorizontalBarChartNode: SKSpriteNode { self.run(.resize(toWidth: (notification.userInfo?["rate"] as! CGFloat) * self.maxWidth, duration: 0.5)) } - func registerTo(center: NotificationCenter, id: HorizontalSingleBarChart.ID) { - center.addObserver(self, selector: #selector(receiveValue(notification:)), name: .barChartPostValue(id: id), object: nil) - center.addObserver(self, selector: #selector(receiveRate(notification:)), name: .barChartPostRate(id: id), object: nil) - center.addObserver(self, selector: #selector(receiveValueWithAnimation(notification:)), name: .barChartPostValueWithAnimation(id: id), object: nil) - center.addObserver(self, selector: #selector(receiveRateWithAnimation(notification:)), name: .barChartPostRateWithAnimation(id: id), object: nil) + func registerTo(center: NotificationCenter, id: Gauge.ID) { + center.addObserver(self, selector: #selector(receiveValue(notification:)), name: .gaugePostValue(id: id), object: nil) + center.addObserver(self, selector: #selector(receiveRate(notification:)), name: .gaugePostRate(id: id), object: nil) + center.addObserver(self, selector: #selector(receiveValueWithAnimation(notification:)), name: .gaugePostValueWithAnimation(id: id), object: nil) + center.addObserver(self, selector: #selector(receiveRateWithAnimation(notification:)), name: .gaugePostRateWithAnimation(id: id), object: nil) } } diff --git a/Sources/GameWidget/Gauge/GaugeOutput.swift b/Sources/GameWidget/Gauge/GaugeOutput.swift index cad13c5..eef485a 100644 --- a/Sources/GameWidget/Gauge/GaugeOutput.swift +++ b/Sources/GameWidget/Gauge/GaugeOutput.swift @@ -8,39 +8,39 @@ import Foundation extension Notification.Name { - static func barChartPostRate(id: HorizontalSingleBarChart.ID) -> Self { - .init("barChartPostRate_\(id)") + static func gaugePostRate(id: Gauge.ID) -> Self { + .init("gaugePostRate_\(id)") } - static func barChartPostValue(id: HorizontalSingleBarChart.ID) -> Self { - .init("barChartPostValue_\(id)") + static func gaugePostValue(id: Gauge.ID) -> Self { + .init("gaugePostValue_\(id)") } - static func barChartPostRateWithAnimation(id: HorizontalSingleBarChart.ID) -> Self { - .init("barChartPostRateWithAnimation_\(id)") + static func gaugePostRateWithAnimation(id: Gauge.ID) -> Self { + .init("gaugePostRateWithAnimation_\(id)") } - static func barChartPostValueWithAnimation(id: HorizontalSingleBarChart.ID) -> Self { - .init("barChartPostValueWithAnimation_\(id)") + static func gaugePostValueWithAnimation(id: Gauge.ID) -> Self { + .init("gaugeValueWithAnimation_\(id)") } } -public protocol SingleBarChartDrawable { +public protocol GaugeDrawable { - func send(value: CGFloat, id: HorizontalSingleBarChart.ID) - func send(rate: CGFloat, id: HorizontalSingleBarChart.ID) + func send(value: CGFloat, id: Gauge.ID) + func send(rate: CGFloat, id: Gauge.ID) } -public extension SingleBarChartDrawable { - func send(value: CGFloat, id: HorizontalSingleBarChart.ID) { - HorizontalBarChartNode.center.post(name: .barChartPostValue(id: id), object: nil, userInfo: ["value": value]) +public extension GaugeDrawable { + func send(value: CGFloat, id: Gauge.ID) { + GaugeNode.center.post(name: .gaugePostValue(id: id), object: nil, userInfo: ["value": value]) } - func send(rate: CGFloat, id: HorizontalSingleBarChart.ID) { - HorizontalBarChartNode.center.post(name: .barChartPostRate(id: id), object: nil, userInfo: ["rate": rate]) + func send(rate: CGFloat, id: Gauge.ID) { + GaugeNode.center.post(name: .gaugePostRate(id: id), object: nil, userInfo: ["rate": rate]) } - func sendForAnimation(value: CGFloat, id: HorizontalSingleBarChart.ID) { - HorizontalBarChartNode.center.post(name: .barChartPostValueWithAnimation(id: id), object: nil, userInfo: ["value": value]) + func sendForAnimation(value: CGFloat, id: Gauge.ID) { + GaugeNode.center.post(name: .gaugePostValueWithAnimation(id: id), object: nil, userInfo: ["value": value]) } - func sendForAnimation(rate: CGFloat, id: HorizontalSingleBarChart.ID) { - HorizontalBarChartNode.center.post(name: .barChartPostRateWithAnimation(id: id), object: nil, userInfo: ["rate": rate]) + func sendForAnimation(rate: CGFloat, id: Gauge.ID) { + GaugeNode.center.post(name: .gaugePostRateWithAnimation(id: id), object: nil, userInfo: ["rate": rate]) } } diff --git a/Tests/GameWidgetTests/BarChartTests.swift b/Tests/GameWidgetTests/BarChartTests.swift index 2a55da8..949da1a 100644 --- a/Tests/GameWidgetTests/BarChartTests.swift +++ b/Tests/GameWidgetTests/BarChartTests.swift @@ -11,7 +11,7 @@ import SpriteKit final class BarChartTests: XCTestCase { func testModifiers() { - let barChart = HorizontalSingleBarChart(name: .init("test")) + let barChart = Gauge(name: .init("test")) .modifiable .position(CGPoint(x: 1, y: 1)) .color(.red) From 632334308f089feed5233e0d4697661444cbc852 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 12 Feb 2023 14:56:18 +0900 Subject: [PATCH 26/57] =?UTF-8?q?change=20Widget=20=E3=81=8C=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E3=81=99=E3=82=8B=E3=83=8E=E3=83=BC=E3=83=89=E3=81=AE?= =?UTF-8?q?=E5=9E=8B=E3=82=92=E5=85=B7=E4=BD=93=E5=8C=96=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/Commons/Widget.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/GameWidget/Commons/Widget.swift b/Sources/GameWidget/Commons/Widget.swift index ccdd6a4..9e52fbe 100644 --- a/Sources/GameWidget/Commons/Widget.swift +++ b/Sources/GameWidget/Commons/Widget.swift @@ -9,11 +9,13 @@ import SpriteKit public protocol ContextPresenter { associatedtype Context: WidgetContextType - func node(context: Context) -> SKNode + associatedtype Node: SKNode + func node(context: Context) -> Node } public protocol ParameterLessNodeGenerator { - func node() -> SKNode + associatedtype Node: SKNode + func node() -> Node } public protocol WidgetListElementType { @@ -31,7 +33,7 @@ public extension WidgetListElementType where Self: ParameterLessNodeGenerator { } public extension ParameterLessNodeGenerator where Self: ContextPresenter, Context: ParameterLessGeneratable { - func node() -> SKNode { + func node() -> Node { self.node(context: Context()) } } From 7b63f11dcb14ac5c80df82c288408443ac852be5 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 12 Feb 2023 15:12:33 +0900 Subject: [PATCH 27/57] =?UTF-8?q?rename=20WidgetListElementType=20?= =?UTF-8?q?=E3=81=AE=20`addTo`=20=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=81=AE=E5=BC=95=E6=95=B0=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4?= =?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/Group.swift | 8 ++++---- Sources/GameWidget/Commons/Widget.swift | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/Group.swift index 617cc4a..77ac36f 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/Group.swift @@ -158,7 +158,7 @@ public struct RecursiveGroup: WidgetLis public func widgetNodes() -> [SKNode] { var result = self.first.widgetNodes() - self.second.addTo(parent: &result) + self.second.addTo(buffer: &result) return result } @@ -175,7 +175,7 @@ struct Single: WidgetList { func widgetNodes() -> [SKNode] { var result = [SKNode]() - self.widget.addTo(parent: &result) + self.widget.addTo(buffer: &result) return result } @@ -191,9 +191,9 @@ public struct Extension: WidgetListElementType { self.content = content() } - public func addTo(parent list: inout [SKNode]) { + public func addTo(buffer: inout [SKNode]) { for node in self.content.widgetNodes() { - list.append(node) + buffer.append(node) } } diff --git a/Sources/GameWidget/Commons/Widget.swift b/Sources/GameWidget/Commons/Widget.swift index 9e52fbe..75175d1 100644 --- a/Sources/GameWidget/Commons/Widget.swift +++ b/Sources/GameWidget/Commons/Widget.swift @@ -19,7 +19,7 @@ public protocol ParameterLessNodeGenerator { } public protocol WidgetListElementType { - func addTo(parent list: inout [SKNode]) + func addTo(buffer: inout [SKNode]) } public protocol Widget: ParameterLessNodeGenerator, WidgetListElementType { @@ -27,8 +27,8 @@ public protocol Widget: ParameterLessNodeGenerator, WidgetListElementType { } public extension WidgetListElementType where Self: ParameterLessNodeGenerator { - func addTo(parent list: inout [SKNode]) { - list.append(self.node()) + func addTo(buffer: inout [SKNode]) { + buffer.append(self.node()) } } From c31d317ed61337f19b281638cb61efc2139c5ab6 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Thu, 16 Feb 2023 23:21:32 +0900 Subject: [PATCH 28/57] =?UTF-8?q?rename=20protocol=20=E3=81=AE=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ParameterLessNodeGenerator -> NodeGenerator - ContextPresenter -> ContextPresentPlugIn --- Sources/GameWidget/Button/Button.swift | 2 +- Sources/GameWidget/Commons/ModifiableWidget.swift | 4 ++-- Sources/GameWidget/Commons/Widget.swift | 10 +++++----- Sources/GameWidget/Controller/Controller.swift | 2 +- Sources/GameWidget/Gauge/Gauge.swift | 2 +- Sources/GameWidget/NodeWidget/NodeWidget.swift | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/GameWidget/Button/Button.swift b/Sources/GameWidget/Button/Button.swift index 0ba535e..5b07bf5 100644 --- a/Sources/GameWidget/Button/Button.swift +++ b/Sources/GameWidget/Button/Button.swift @@ -25,7 +25,7 @@ public struct Button { } -extension Button: Widget, ContextPresenter { +extension Button: Widget, ContextPresentPlugIn { public typealias Context = ButtonContext public func node(context: ButtonContext) -> SKNode { diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index 0e9d329..2e0e601 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -7,7 +7,7 @@ import SpriteKit -public struct ModifiableWidget: Widget where Body.Context == Builder.Mod.Context { +public struct ModifiableWidget: Widget where Body.Context == Builder.Mod.Context { public func node() -> SKNode { var context = Context() @@ -33,7 +33,7 @@ public struct Empty: Modifier { } -public extension Widget where Self: ContextPresenter, Context: ContextProtocol { +public extension Widget where Self: ContextPresentPlugIn, Context: ContextProtocol { typealias Modifiable = ModifiableWidget>> var modifiable: Modifiable { diff --git a/Sources/GameWidget/Commons/Widget.swift b/Sources/GameWidget/Commons/Widget.swift index 75175d1..dc73087 100644 --- a/Sources/GameWidget/Commons/Widget.swift +++ b/Sources/GameWidget/Commons/Widget.swift @@ -7,13 +7,13 @@ import SpriteKit -public protocol ContextPresenter { +public protocol ContextPresentPlugIn { associatedtype Context: WidgetContextType associatedtype Node: SKNode func node(context: Context) -> Node } -public protocol ParameterLessNodeGenerator { +public protocol NodeGenerator { associatedtype Node: SKNode func node() -> Node } @@ -22,17 +22,17 @@ public protocol WidgetListElementType { func addTo(buffer: inout [SKNode]) } -public protocol Widget: ParameterLessNodeGenerator, WidgetListElementType { +public protocol Widget: NodeGenerator, WidgetListElementType { } -public extension WidgetListElementType where Self: ParameterLessNodeGenerator { +public extension WidgetListElementType where Self: NodeGenerator { func addTo(buffer: inout [SKNode]) { buffer.append(self.node()) } } -public extension ParameterLessNodeGenerator where Self: ContextPresenter, Context: ParameterLessGeneratable { +public extension NodeGenerator where Self: ContextPresentPlugIn, Context: ParameterLessGeneratable { func node() -> Node { self.node(context: Context()) } diff --git a/Sources/GameWidget/Controller/Controller.swift b/Sources/GameWidget/Controller/Controller.swift index 2b0c41a..f58e973 100644 --- a/Sources/GameWidget/Controller/Controller.swift +++ b/Sources/GameWidget/Controller/Controller.swift @@ -100,7 +100,7 @@ class ControllerAreaNode: SKSpriteNode { } -public struct ControllerArea: Widget, ContextPresenter { +public struct ControllerArea: Widget, ContextPresentPlugIn { public typealias Context = ControllerContext var id: ControllerData.Name diff --git a/Sources/GameWidget/Gauge/Gauge.swift b/Sources/GameWidget/Gauge/Gauge.swift index be3b797..f9c7a66 100644 --- a/Sources/GameWidget/Gauge/Gauge.swift +++ b/Sources/GameWidget/Gauge/Gauge.swift @@ -36,7 +36,7 @@ public struct Gauge { } -extension Gauge: Widget, ContextPresenter { +extension Gauge: Widget, ContextPresentPlugIn { public typealias Context = GaugeContext public func node(context: GaugeContext) -> SKNode { diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index 5c6a407..73ee244 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -8,7 +8,7 @@ import SpriteKit /// 10 個以下の widget を一つの widget としてまとめます. 座標, スケール, 回転を内包するコンテンツと共に調整することができます. -public struct NodeWidget: Widget, ContextPresenter { +public struct NodeWidget: Widget, ContextPresentPlugIn { public typealias Context = NodeContext public var content: Content From 963b5ff63e3c238cc5297591635cfb771f1669bf Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Thu, 16 Feb 2023 23:23:23 +0900 Subject: [PATCH 29/57] =?UTF-8?q?clean=20=E3=83=95=E3=82=A9=E3=83=AB?= =?UTF-8?q?=E3=83=80=E6=A7=8B=E6=88=90=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commons に Widget フォルダを作成しました. --- Sources/GameWidget/Commons/{ => Widget}/Widget.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Sources/GameWidget/Commons/{ => Widget}/Widget.swift (100%) diff --git a/Sources/GameWidget/Commons/Widget.swift b/Sources/GameWidget/Commons/Widget/Widget.swift similarity index 100% rename from Sources/GameWidget/Commons/Widget.swift rename to Sources/GameWidget/Commons/Widget/Widget.swift From c156c7c329bdb5539a6e1dd567d5ff3687cfb520 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Thu, 16 Feb 2023 23:25:50 +0900 Subject: [PATCH 30/57] =?UTF-8?q?clean=20Widget=20=E5=AE=9A=E7=BE=A9=20pro?= =?UTF-8?q?tocol=20=E3=82=92=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=A7?= =?UTF-8?q?=E5=88=86=E5=89=B2=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 --- .../Commons/Widget/Widget+PlugIns.swift | 12 ++++++++++++ Sources/GameWidget/Commons/Widget/Widget.swift | 12 ------------ .../GameWidget/Commons/Widget/WidgetPlugIns.swift | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift create mode 100644 Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift new file mode 100644 index 0000000..df97239 --- /dev/null +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -0,0 +1,12 @@ +// +// Widget+PlugIns.swift +// +// +// Created by rrbox on 2023/02/16. +// + +public extension NodeGenerator where Self: ContextPresentPlugIn, Context: ParameterLessGeneratable { + func node() -> Node { + self.node(context: Context()) + } +} diff --git a/Sources/GameWidget/Commons/Widget/Widget.swift b/Sources/GameWidget/Commons/Widget/Widget.swift index dc73087..2216618 100644 --- a/Sources/GameWidget/Commons/Widget/Widget.swift +++ b/Sources/GameWidget/Commons/Widget/Widget.swift @@ -7,12 +7,6 @@ import SpriteKit -public protocol ContextPresentPlugIn { - associatedtype Context: WidgetContextType - associatedtype Node: SKNode - func node(context: Context) -> Node -} - public protocol NodeGenerator { associatedtype Node: SKNode func node() -> Node @@ -31,9 +25,3 @@ public extension WidgetListElementType where Self: NodeGenerator { buffer.append(self.node()) } } - -public extension NodeGenerator where Self: ContextPresentPlugIn, Context: ParameterLessGeneratable { - func node() -> Node { - self.node(context: Context()) - } -} diff --git a/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift new file mode 100644 index 0000000..1402f7a --- /dev/null +++ b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift @@ -0,0 +1,15 @@ +// +// WidgetPlugIns.swift +// +// +// Created by rrbox on 2023/02/16. +// + +import SpriteKit + + +public protocol ContextPresentPlugIn { + associatedtype Context: WidgetContextType + associatedtype Node: SKNode + func node(context: Context) -> Node +} From 1e17cc6ebd337ddad1f027fe71353507377af725 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Thu, 16 Feb 2023 23:34:56 +0900 Subject: [PATCH 31/57] rename #76 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `node(context:)` を `node(applying:)` に変更しました. --- Sources/GameWidget/Button/Button.swift | 2 +- Sources/GameWidget/Commons/ModifiableWidget.swift | 2 +- Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift | 2 +- Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift | 2 +- Sources/GameWidget/Controller/Controller.swift | 2 +- Sources/GameWidget/Gauge/Gauge.swift | 2 +- Sources/GameWidget/NodeWidget/NodeWidget.swift | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/GameWidget/Button/Button.swift b/Sources/GameWidget/Button/Button.swift index 5b07bf5..c09594c 100644 --- a/Sources/GameWidget/Button/Button.swift +++ b/Sources/GameWidget/Button/Button.swift @@ -28,7 +28,7 @@ public struct Button { extension Button: Widget, ContextPresentPlugIn { public typealias Context = ButtonContext - public func node(context: ButtonContext) -> SKNode { + public func node(applying context: ButtonContext) -> SKNode { let result = SKNode() let label = SKLabelNode(text: context.text ?? "\(self.name)") diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index 2e0e601..89cd06b 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -12,7 +12,7 @@ public struct ModifiableWidget SKNode { var context = Context() self.builder.mod(context: &context) - return body.node(context: context) + return body.node(applying: context) } public typealias Context = Body.Context diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index df97239..3e49a74 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -7,6 +7,6 @@ public extension NodeGenerator where Self: ContextPresentPlugIn, Context: ParameterLessGeneratable { func node() -> Node { - self.node(context: Context()) + self.node(applying: Context()) } } diff --git a/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift index 1402f7a..53b84da 100644 --- a/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift @@ -11,5 +11,5 @@ import SpriteKit public protocol ContextPresentPlugIn { associatedtype Context: WidgetContextType associatedtype Node: SKNode - func node(context: Context) -> Node + func node(applying context: Context) -> Node } diff --git a/Sources/GameWidget/Controller/Controller.swift b/Sources/GameWidget/Controller/Controller.swift index f58e973..78fb524 100644 --- a/Sources/GameWidget/Controller/Controller.swift +++ b/Sources/GameWidget/Controller/Controller.swift @@ -109,7 +109,7 @@ public struct ControllerArea: Widget, ContextPresentPlugIn { self.id = id } - public func node(context: ControllerContext) -> SKNode { + public func node(applying context: ControllerContext) -> SKNode { let result = ControllerAreaNode(color: .black, size: context.size) result.id = self.id ControllerData.inputs.value[self.id] = ControllerData.Input(weight: 0, direction: []) diff --git a/Sources/GameWidget/Gauge/Gauge.swift b/Sources/GameWidget/Gauge/Gauge.swift index f9c7a66..00c8fc3 100644 --- a/Sources/GameWidget/Gauge/Gauge.swift +++ b/Sources/GameWidget/Gauge/Gauge.swift @@ -39,7 +39,7 @@ public struct Gauge { extension Gauge: Widget, ContextPresentPlugIn { public typealias Context = GaugeContext - public func node(context: GaugeContext) -> SKNode { + public func node(applying context: GaugeContext) -> SKNode { let gauge = GaugeNode(color: context.color, size: CGSize(width: context.length, height: context.width)) diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index 73ee244..6bb072b 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -16,7 +16,7 @@ public struct NodeWidget: Widget, ContextPresentPlugIn { self.content = content() } - public func node(context: NodeContext) -> SKNode { + public func node(applying context: NodeContext) -> SKNode { let result = SKNode() result.position = context.position From 9ce1a615d878c689a15eb2ab907f013a48876b80 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 17 Feb 2023 01:49:17 +0900 Subject: [PATCH 32/57] =?UTF-8?q?fix=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=AE=E4=B8=80=E9=83=A8=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{BarChartTests.swift => GaugeTests.swift} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename Tests/GameWidgetTests/{BarChartTests.swift => GaugeTests.swift} (61%) diff --git a/Tests/GameWidgetTests/BarChartTests.swift b/Tests/GameWidgetTests/GaugeTests.swift similarity index 61% rename from Tests/GameWidgetTests/BarChartTests.swift rename to Tests/GameWidgetTests/GaugeTests.swift index 949da1a..27d201e 100644 --- a/Tests/GameWidgetTests/BarChartTests.swift +++ b/Tests/GameWidgetTests/GaugeTests.swift @@ -9,9 +9,9 @@ import XCTest import GameWidget import SpriteKit -final class BarChartTests: XCTestCase { +final class GaugeTests: XCTestCase { func testModifiers() { - let barChart = Gauge(name: .init("test")) + let gauge = Gauge(name: .init("test")) .modifiable .position(CGPoint(x: 1, y: 1)) .color(.red) @@ -23,17 +23,17 @@ final class BarChartTests: XCTestCase { .zPosition(2) .node() - guard let barChart = barChart as? SKSpriteNode, - let background = barChart.children[0] as? SKSpriteNode else { + guard let gauge = gauge as? SKSpriteNode, + let background = gauge.children[0] as? SKSpriteNode else { XCTFail() return } - XCTAssertEqual(barChart.position, CGPoint(x: 1, y: 1)) - XCTAssertEqual(barChart.color.cgColor.components, SKColor.red.cgColor.components) - XCTAssertEqual(barChart.size, CGSize(width: 90, height: 90)) - XCTAssertEqual(barChart.alpha, 0.5) - XCTAssertEqual(barChart.zPosition, 2) + XCTAssertEqual(gauge.position, CGPoint(x: 1, y: 1)) + XCTAssertEqual(gauge.color.cgColor.components, SKColor.red.cgColor.components) + XCTAssertEqual(gauge.size, CGSize(width: 90, height: 90)) + XCTAssertEqual(gauge.alpha, 0.5) + XCTAssertEqual(gauge.zPosition, 2) XCTAssertEqual(background.color.cgColor.components, SKColor.blue.cgColor.components) XCTAssertEqual(background.size, CGSize(width: 90, height: 90)) From 6610a4a49c03ca30b8827112b7e6c9d8af90523e Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 17 Feb 2023 23:39:56 +0900 Subject: [PATCH 33/57] =?UTF-8?q?add=20DataOutputPlugIn=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=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 ObserveableNode プロトコルに依存します. --- .../Widget/Notification/ObserveableNode.swift | 13 +++++++++++++ .../GameWidget/Commons/Widget/WidgetPlugIns.swift | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift diff --git a/Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift b/Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift new file mode 100644 index 0000000..7d864a9 --- /dev/null +++ b/Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift @@ -0,0 +1,13 @@ +// +// ObserveableNode.swift +// +// +// Created by rrbox on 2023/02/17. +// + +import SpriteKit + +public protocol ObserveableNode: SKNode { + associatedtype Identifier + func registerTo(center: NotificationCenter, id: Identifier) +} diff --git a/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift index 53b84da..f69986c 100644 --- a/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift @@ -7,9 +7,12 @@ import SpriteKit - public protocol ContextPresentPlugIn { associatedtype Context: WidgetContextType associatedtype Node: SKNode func node(applying context: Context) -> Node } + +public protocol DataOutputPlugIn: NodeGenerator where Node: ObserveableNode { + var id: Node.Identifier { get } +} From 8fb85fa92fe198743860110ba4338580b09b0b1b Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 17 Feb 2023 23:41:31 +0900 Subject: [PATCH 34/57] =?UTF-8?q?add=20NodeGenerator=20=E3=81=AB=20combine?= =?UTF-8?q?=20=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=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 作成するノードと notification center を接続する処理を記述できます. --- Sources/GameWidget/Commons/Widget/Widget.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/GameWidget/Commons/Widget/Widget.swift b/Sources/GameWidget/Commons/Widget/Widget.swift index 2216618..ada516b 100644 --- a/Sources/GameWidget/Commons/Widget/Widget.swift +++ b/Sources/GameWidget/Commons/Widget/Widget.swift @@ -10,6 +10,7 @@ import SpriteKit public protocol NodeGenerator { associatedtype Node: SKNode func node() -> Node + func combine(node: Node, center: NotificationCenter) } public protocol WidgetListElementType { From 4e682ddaab6d3043d23c105735dfa8004f252c38 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 17 Feb 2023 23:45:19 +0900 Subject: [PATCH 35/57] =?UTF-8?q?change=20Widget=20=E3=82=92=20Notificatio?= =?UTF-8?q?nCenter=20=E3=81=A8=E9=80=A3=E6=90=BA=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E6=A7=98=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 - NodeGenerator に createModels を追加 - WidgetListElementType の addTo メソッドに NotificationCenter の引数を追加 --- .../Commons/Widget/Widget+PlugIns.swift | 23 +++++++++++++++++++ .../GameWidget/Commons/Widget/Widget.swift | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index 3e49a74..aa51c67 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -5,6 +5,29 @@ // Created by rrbox on 2023/02/16. // +import SpriteKit + +public extension NodeGenerator { + func combine(node: Node, center: NotificationCenter) { + + } + + func createModels() -> (Node, NotificationCenter) { + let center = NotificationCenter() + let node = self.node() + self.combine(node: node, center: center) + return (node, center) + } +} + +public extension WidgetListElementType where Self: NodeGenerator { + func addTo(buffer: inout [SKNode], center: NotificationCenter) { + let node = self.node() + self.combine(node: node, center: center) + buffer.append(node) + } +} + public extension NodeGenerator where Self: ContextPresentPlugIn, Context: ParameterLessGeneratable { func node() -> Node { self.node(applying: Context()) diff --git a/Sources/GameWidget/Commons/Widget/Widget.swift b/Sources/GameWidget/Commons/Widget/Widget.swift index ada516b..7499c7c 100644 --- a/Sources/GameWidget/Commons/Widget/Widget.swift +++ b/Sources/GameWidget/Commons/Widget/Widget.swift @@ -14,7 +14,7 @@ public protocol NodeGenerator { } public protocol WidgetListElementType { - func addTo(buffer: inout [SKNode]) + func addTo(buffer: inout [SKNode], center: NotificationCenter) } public protocol Widget: NodeGenerator, WidgetListElementType { From 3eadaf5df9309aaf1a58bdfa3f68298f9bf10d27 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 17 Feb 2023 23:52:29 +0900 Subject: [PATCH 36/57] =?UTF-8?q?change=20=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=81=AE=E4=BB=95=E6=A7=98=E5=A4=89=E6=9B=B4=E3=81=AB?= =?UTF-8?q?=E4=BC=B4=E3=81=86=E3=82=B3=E3=83=B3=E3=83=91=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E4=BF=AE=E6=AD=A3=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 WidgetListElementType の addTo メソッドの修正です. --- Sources/GameWidget/Button/Button.swift | 1 + Sources/GameWidget/Commons/Group.swift | 6 +++--- Sources/GameWidget/Commons/Widget/Widget.swift | 6 ------ 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Sources/GameWidget/Button/Button.swift b/Sources/GameWidget/Button/Button.swift index c09594c..3f5443f 100644 --- a/Sources/GameWidget/Button/Button.swift +++ b/Sources/GameWidget/Button/Button.swift @@ -26,6 +26,7 @@ public struct Button { } extension Button: Widget, ContextPresentPlugIn { + public typealias Context = ButtonContext public func node(applying context: ButtonContext) -> SKNode { diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/Group.swift index 77ac36f..3886983 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/Group.swift @@ -158,7 +158,7 @@ public struct RecursiveGroup: WidgetLis public func widgetNodes() -> [SKNode] { var result = self.first.widgetNodes() - self.second.addTo(buffer: &result) + self.second.addTo(buffer: &result, center: <#T##NotificationCenter#>) return result } @@ -175,7 +175,7 @@ struct Single: WidgetList { func widgetNodes() -> [SKNode] { var result = [SKNode]() - self.widget.addTo(buffer: &result) + self.widget.addTo(buffer: &result, center: <#T##NotificationCenter#>) return result } @@ -191,7 +191,7 @@ public struct Extension: WidgetListElementType { self.content = content() } - public func addTo(buffer: inout [SKNode]) { + public func addTo(buffer: inout [SKNode], center: NotificationCenter) { for node in self.content.widgetNodes() { buffer.append(node) } diff --git a/Sources/GameWidget/Commons/Widget/Widget.swift b/Sources/GameWidget/Commons/Widget/Widget.swift index 7499c7c..2d69075 100644 --- a/Sources/GameWidget/Commons/Widget/Widget.swift +++ b/Sources/GameWidget/Commons/Widget/Widget.swift @@ -20,9 +20,3 @@ public protocol WidgetListElementType { public protocol Widget: NodeGenerator, WidgetListElementType { } - -public extension WidgetListElementType where Self: NodeGenerator { - func addTo(buffer: inout [SKNode]) { - buffer.append(self.node()) - } -} From e0105c781a628631633b1bb3742ee4c4847aadc2 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 17 Feb 2023 23:55:11 +0900 Subject: [PATCH 37/57] =?UTF-8?q?add=20DataOutputPlugIn=20=E3=81=AE?= =?UTF-8?q?=E3=83=87=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E5=AE=9F=E8=A3=85?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=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 combine メソッドの実装を追加しました. --- Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index aa51c67..b09a1f0 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -33,3 +33,9 @@ public extension NodeGenerator where Self: ContextPresentPlugIn, Context: Parame self.node(applying: Context()) } } + +public extension DataOutputPlugIn { + func combine(node: Node, center: NotificationCenter) { + node.registerTo(center: center, id: self.id) + } +} From 41805e4d5c0d16dde83b99256408add96ad46988 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:13:15 +0900 Subject: [PATCH 38/57] =?UTF-8?q?change=20Display=20=E3=82=92=20notificati?= =?UTF-8?q?on=20center=20=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/Commons/Display.swift | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Sources/GameWidget/Commons/Display.swift b/Sources/GameWidget/Commons/Display.swift index 2b25c6a..c1f22a6 100644 --- a/Sources/GameWidget/Commons/Display.swift +++ b/Sources/GameWidget/Commons/Display.swift @@ -17,18 +17,18 @@ public struct RecursiveDisplay: Widget, WidgetList .init(first: self, second: block()) } - public func widgetNodes() -> [SKNode] { - self.first.widgetNodes() + self.second.widgetNodes() + public func widgetNodes(center: NotificationCenter) -> [SKNode] { + self.first.widgetNodes(center: center) + self.second.widgetNodes(center: center) } public func node() -> SKNode { - let result = SKNode() - - for node in self.first.widgetNodes() + self.second.widgetNodes() { - result.addChild(node) + return SKNode() + } + + public func combine(node: SKNode, center: NotificationCenter) { + for i in self.first.widgetNodes(center: center) + self.second.widgetNodes(center: center) { + node.addChild(i) } - - return result } } @@ -43,16 +43,18 @@ public struct SingleWidgetDisplay: Widget, WidgetList { RecursiveDisplay(first: self, second: block()) } - public func widgetNodes() -> [SKNode] { - self.widgetList.widgetNodes() + public func widgetNodes(center: NotificationCenter) -> [SKNode] { + self.widgetList.widgetNodes(center: center) } public func node() -> SKNode { - let result = SKNode() - for node in self.widgetList.widgetNodes() { - result.addChild(node) + return SKNode() + } + + public func combine(node: SKNode, center: NotificationCenter) { + for i in self.widgetList.widgetNodes(center: center) { + node.addChild(i) } - return result } } From 576d66103329c2a67bc445c83e3df9a0d846f8af Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:15:39 +0900 Subject: [PATCH 39/57] =?UTF-8?q?change=20modifieable=20widget=20=E3=82=92?= =?UTF-8?q?=20notification=20center=20=E3=81=AB=E5=AF=BE=E5=BF=9C=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/ModifiableWidget.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index 89cd06b..fab5ab7 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -7,9 +7,12 @@ import SpriteKit -public struct ModifiableWidget: Widget where Body.Context == Builder.Mod.Context { +public struct ModifiableWidget: Widget where Body: NodeGenerator, + Body: ContextPresentPlugIn, + Builder: ContextBuilder, + Body.Context == Builder.Mod.Context { - public func node() -> SKNode { + public func node() -> Body.Node { var context = Context() self.builder.mod(context: &context) return body.node(applying: context) @@ -24,6 +27,10 @@ public struct ModifiableWidget(mod: T) -> Next { .init(body: self.body, builder: self.builder.modifiered(mod: mod)) } + + public func combine(node: Body.Node, center: NotificationCenter) { + self.body.combine(node: node, center: center) + } } public struct Empty: Modifier { From 90c456601d21a88b5a5dc49c4fc90f308a5e900b Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:18:51 +0900 Subject: [PATCH 40/57] =?UTF-8?q?change=20WidgetList=20=E3=82=92=20notific?= =?UTF-8?q?ation=20center=20=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/Commons/Group.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/Group.swift index 3886983..87a2e37 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/Group.swift @@ -143,7 +143,7 @@ import SpriteKit } public protocol WidgetList { - func widgetNodes() -> [SKNode] + func widgetNodes(center: NotificationCenter) -> [SKNode] } /// 再帰可能. widget のペアです. オーバーヘッドはありません. @@ -156,9 +156,9 @@ public struct RecursiveGroup: WidgetLis .init(first: self, second: newWidget) } - public func widgetNodes() -> [SKNode] { - var result = self.first.widgetNodes() - self.second.addTo(buffer: &result, center: <#T##NotificationCenter#>) + public func widgetNodes(center: NotificationCenter) -> [SKNode] { + var result = self.first.widgetNodes(center: center) + self.second.addTo(buffer: &result, center: center) return result } @@ -173,9 +173,9 @@ struct Single: WidgetList { .init(first: self, second: newWidget) } - func widgetNodes() -> [SKNode] { + func widgetNodes(center: NotificationCenter) -> [SKNode] { var result = [SKNode]() - self.widget.addTo(buffer: &result, center: <#T##NotificationCenter#>) + self.widget.addTo(buffer: &result, center: center) return result } @@ -192,7 +192,7 @@ public struct Extension: WidgetListElementType { } public func addTo(buffer: inout [SKNode], center: NotificationCenter) { - for node in self.content.widgetNodes() { + for node in self.content.widgetNodes(center: center) { buffer.append(node) } } From 5b90baca13600b389d05c032e96dcb4151feae5f Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:19:19 +0900 Subject: [PATCH 41/57] =?UTF-8?q?change=20NodeWidget=20=E3=82=92=20notific?= =?UTF-8?q?ation=20center=20=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/NodeWidget/NodeWidget.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index 6bb072b..202b029 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -25,10 +25,13 @@ public struct NodeWidget: Widget, ContextPresentPlugIn { result.yScale = context.yScale result.zPosition = context.zPosition - for i in self.content.widgetNodes() { - result.addChild(i) - } return result } + public func combine(node: SKNode, center: NotificationCenter) { + for i in self.content.widgetNodes(center: center) { + node.addChild(i) + } + } + } From 458fec8cd9c7a12f46ea19bfc1d59d624a226421 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 18 Feb 2023 00:20:25 +0900 Subject: [PATCH 42/57] =?UTF-8?q?update=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E6=9B=B4=E6=96=B0=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 --- Tests/GameWidgetTests/DisplayTests.swift | 2 +- Tests/GameWidgetTests/GameWidgetTests.swift | 2 +- Tests/GameWidgetTests/GroupTests.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/GameWidgetTests/DisplayTests.swift b/Tests/GameWidgetTests/DisplayTests.swift index ae99901..3e79686 100644 --- a/Tests/GameWidgetTests/DisplayTests.swift +++ b/Tests/GameWidgetTests/DisplayTests.swift @@ -19,7 +19,7 @@ final class DisplayTests: XCTestCase { TextNode(value: "2") TextNode(value: "3") } - .node() + .createModels().0 XCTAssertEqual(displayNode.children.count, 4) XCTAssertEqual(displayNode.children.reduce(into: "", { partialResult, node in diff --git a/Tests/GameWidgetTests/GameWidgetTests.swift b/Tests/GameWidgetTests/GameWidgetTests.swift index 4a7eaf2..bde2b45 100644 --- a/Tests/GameWidgetTests/GameWidgetTests.swift +++ b/Tests/GameWidgetTests/GameWidgetTests.swift @@ -11,7 +11,7 @@ final class NodeTests: XCTestCase { .scale(2) .zRotation(2) .zPosition(1) - .node() + .createModels().0 XCTAssertEqual(node.position, CGPoint(x: 1, y: 1)) XCTAssertEqual(node.xScale, 2) diff --git a/Tests/GameWidgetTests/GroupTests.swift b/Tests/GameWidgetTests/GroupTests.swift index 37bb6d0..dff4749 100644 --- a/Tests/GameWidgetTests/GroupTests.swift +++ b/Tests/GameWidgetTests/GroupTests.swift @@ -11,7 +11,7 @@ import GameWidget final class GroupTest: XCTestCase { func generateNodesNameReduced(@GroupBuilder _ list: () -> T) -> String { - list().widgetNodes().reduce(into: "") { partialResult, node in + list().widgetNodes(center: .default).reduce(into: "") { partialResult, node in guard let name = node.name else { XCTFail() return From fad6b193e177acb739076ef708675ef0241850f6 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 18 Feb 2023 20:29:32 +0900 Subject: [PATCH 43/57] =?UTF-8?q?add=20WidgetNotificationSystem=20?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=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 --- .../WidgetNotificationSystem.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift diff --git a/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift b/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift new file mode 100644 index 0000000..8065b22 --- /dev/null +++ b/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift @@ -0,0 +1,25 @@ +// +// WidgetNotificationSystem.swift +// +// +// Created by rrbox on 2023/02/18. +// + +import Foundation + +@objc public protocol WidgetObserver { + func registerTo(_ system: WidgetNotificationSystem) +} + +final public class WidgetNotificationSystem: NotificationCenter { + public static weak var activated: WidgetNotificationSystem? + + public func activate() { + WidgetNotificationSystem.activated = self + } + + public func add(observer: some WidgetObserver) -> Self { + observer.registerTo(self) + return self + } +} From 519b07a74da40e3def73130dc859e2f61ab52c12 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 18 Feb 2023 20:30:30 +0900 Subject: [PATCH 44/57] =?UTF-8?q?change=20NodeGenerator=20=E3=82=92=20Widg?= =?UTF-8?q?etNotificationSystem=20=E3=81=AB=E5=AF=BE=E5=BF=9C=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/Widget/Widget+PlugIns.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index b09a1f0..c771a18 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -12,8 +12,8 @@ public extension NodeGenerator { } - func createModels() -> (Node, NotificationCenter) { - let center = NotificationCenter() + func createModels() -> (Node, WidgetNotificationSystem) { + let center = WidgetNotificationSystem() let node = self.node() self.combine(node: node, center: center) return (node, center) From f3d7155dff7cc2428075b6cb6972d8c1e19c359b Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 19 Feb 2023 13:33:01 +0900 Subject: [PATCH 45/57] =?UTF-8?q?remove=20WidgetObserver=20=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4=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 --- .../Widget/Notification/WidgetNotificationSystem.swift | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift b/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift index 8065b22..de40fd1 100644 --- a/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift +++ b/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift @@ -7,19 +7,10 @@ import Foundation -@objc public protocol WidgetObserver { - func registerTo(_ system: WidgetNotificationSystem) -} - final public class WidgetNotificationSystem: NotificationCenter { public static weak var activated: WidgetNotificationSystem? public func activate() { WidgetNotificationSystem.activated = self } - - public func add(observer: some WidgetObserver) -> Self { - observer.registerTo(self) - return self - } } From ad5755a9fe92738f08b63de23c843a33874f0630 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 19 Feb 2023 13:39:42 +0900 Subject: [PATCH 46/57] =?UTF-8?q?change=20Entity=20=E3=82=92=20WidgetNotif?= =?UTF-8?q?icationSystem=20=E3=81=AB=E5=AF=BE=E5=BF=9C=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 UserInterfaceDisplay への変更です. --- Sources/GameWidget/Commons/Entity.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/GameWidget/Commons/Entity.swift b/Sources/GameWidget/Commons/Entity.swift index 5dca957..f0ca3c9 100644 --- a/Sources/GameWidget/Commons/Entity.swift +++ b/Sources/GameWidget/Commons/Entity.swift @@ -11,8 +11,12 @@ final private class UserInterfaceBaseNode: GKSKNodeComponent {} final public class UserInterfaceDisplay: GKSKNodeComponent { + public let nofiticationSystem: WidgetNotificationSystem + init(_ display: T) { - super.init(node: display.node()) + let (node, sys) = display.createModels() + self.nofiticationSystem = sys + super.init(node: node) } required init?(coder: NSCoder) { From 4252949f8b677969b2eb7154e4f5fb88db362e64 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 19 Feb 2023 13:46:58 +0900 Subject: [PATCH 47/57] =?UTF-8?q?change=20Button=20=E3=82=92=20WidgetNotif?= =?UTF-8?q?icationSystem=20=E3=81=AB=E5=AF=BE=E5=BF=9C=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 --- Sources/GameWidget/Button/ButtonNode.swift | 6 +-- .../Button/ButtonNotification.swift | 47 ++++++------------- 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/Sources/GameWidget/Button/ButtonNode.swift b/Sources/GameWidget/Button/ButtonNode.swift index c237387..f3d067a 100644 --- a/Sources/GameWidget/Button/ButtonNode.swift +++ b/Sources/GameWidget/Button/ButtonNode.swift @@ -63,8 +63,7 @@ final class ButtonSensor: SKSpriteNode { self.parent?.removeAllActions() self.parent?.run(self.selectAction!) self.isSelected = true - // UserInterfaceSystem.activated?.center.post(name: .buttonTouchUp, object: nil, userInfo: ["buttonName": self.roleName!]) - ButtonNotificationCenter.touchDownButton(self.roleName!) + WidgetNotificationSystem.touchDownButton(self.roleName!) } func touchMoved(toPoint pos: CGPoint) { @@ -82,8 +81,7 @@ final class ButtonSensor: SKSpriteNode { self.selectEndAction!, SKAction.run { self.isSelected = false - // UserInterfaceSystem.activated?.center.post(name: .buttonTouchUp, object: nil, userInfo: ["buttonName": self.roleName!]) - ButtonNotificationCenter.touchUpButton(self.roleName!) + WidgetNotificationSystem.touchUpButton(self.roleName!) } ])) } diff --git a/Sources/GameWidget/Button/ButtonNotification.swift b/Sources/GameWidget/Button/ButtonNotification.swift index fff4ce0..1174c63 100644 --- a/Sources/GameWidget/Button/ButtonNotification.swift +++ b/Sources/GameWidget/Button/ButtonNotification.swift @@ -8,42 +8,26 @@ import Foundation @objc public protocol ButtonResopnder { - @objc func touchDownButton(notification: Notification) - @objc func touchUpButton(notification: Notification) - } -final public class ButtonNotificationCenter: NSObject { - - let center: NotificationCenter - private static weak var activated: ButtonNotificationCenter? - - public override init() { - self.center = NotificationCenter() - } - - public func activate() { - ButtonNotificationCenter.activated = self - } - +public extension WidgetNotificationSystem { func touchDownButton(_ button: Button.Role) { - self.center.post(name: .buttonTouchDown, object: nil, userInfo: ["buttonName": button]) + self.post(name: .buttonTouchDown, object: nil, userInfo: ["buttonName": button]) } func touchUpButton(_ button: Button.Role) { - self.center.post(name: .buttonTouchUp, object: nil, userInfo: ["buttonName": button]) + self.post(name: .buttonTouchUp, object: nil, userInfo: ["buttonName": button]) } static func touchDownButton(_ button: Button.Role) { - ButtonNotificationCenter.activated?.touchDownButton(button) + WidgetNotificationSystem.activated?.touchDownButton(button) } static func touchUpButton(_ button: Button.Role) { - ButtonNotificationCenter.activated?.touchUpButton(button) + WidgetNotificationSystem.activated?.touchUpButton(button) } - } extension Notification.Name { @@ -54,19 +38,18 @@ extension Notification.Name { } -public extension ButtonResopnder { - - func getButtonEvent(_ notification: Notification) -> Button.Role { - notification.userInfo!["buttonName"] as! Button.Role - } - - func registerTo(_ system: ButtonNotificationCenter) { - system.center.addObserver(self, selector: #selector(touchDownButton(notification:)), name: .buttonTouchDown, object: nil) - system.center.addObserver(self, selector: #selector(touchUpButton(notification:)), name: .buttonTouchUp, object: nil) +public extension WidgetNotificationSystem { + func add(buttonObserver: T) -> WidgetNotificationSystem where T: ButtonResopnder { + self.addObserver(buttonObserver, selector: #selector(buttonObserver.touchDownButton(notification:)), name: .buttonTouchDown, object: nil) + self.addObserver(buttonObserver, selector: #selector(buttonObserver.touchUpButton(notification:)), name: .buttonTouchUp, object: nil) + return self } +} + +extension ButtonResopnder { - func removeFrom(_ system: ButtonNotificationCenter) { - system.center.removeObserver(self) + public func getButtonEvent(_ notification: Notification) -> Button.Role { + notification.userInfo!["buttonName"] as! Button.Role } } From 0b677942c0325ac96398fec719c5175fd55ea11d Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 19 Feb 2023 13:49:29 +0900 Subject: [PATCH 48/57] =?UTF-8?q?change=20Gauge=20=E3=82=92=20WidgetNotifi?= =?UTF-8?q?cationSystem=20=E3=81=AB=E5=AF=BE=E5=BF=9C=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 --- Sources/GameWidget/Gauge/Gauge.swift | 15 +++++++++------ Sources/GameWidget/Gauge/GaugeNode.swift | 5 ++--- Sources/GameWidget/Gauge/GaugeOutput.swift | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Sources/GameWidget/Gauge/Gauge.swift b/Sources/GameWidget/Gauge/Gauge.swift index 00c8fc3..c6650de 100644 --- a/Sources/GameWidget/Gauge/Gauge.swift +++ b/Sources/GameWidget/Gauge/Gauge.swift @@ -19,7 +19,7 @@ public enum GaugeAlignmentMode { } } -public struct Gauge { +public struct Gauge: DataOutputPlugIn { public struct ID: Equatable { let id: String @@ -28,24 +28,23 @@ public struct Gauge { } } - public init(name: ID) { - self.name = name + public init(id: ID) { + self.id = id } - var name: ID + public var id: GaugeNode.Identifier } extension Gauge: Widget, ContextPresentPlugIn { public typealias Context = GaugeContext - public func node(applying context: GaugeContext) -> SKNode { + public func node(applying context: GaugeContext) -> GaugeNode { let gauge = GaugeNode(color: context.color, size: CGSize(width: context.length, height: context.width)) gauge.alpha = context.alpha gauge.maxWidth = context.length - gauge.registerTo(center: GaugeNode.center, id: self.name) gauge.anchorPoint = context.alignment.anchorPoint() gauge.position = context.position gauge.zPosition = context.zPosition @@ -60,4 +59,8 @@ extension Gauge: Widget, ContextPresentPlugIn { return gauge } + public func combine(node: GaugeNode, center: NotificationCenter) { + node.registerTo(center: center, id: self.id) + } + } diff --git a/Sources/GameWidget/Gauge/GaugeNode.swift b/Sources/GameWidget/Gauge/GaugeNode.swift index 53058f7..714f6d3 100644 --- a/Sources/GameWidget/Gauge/GaugeNode.swift +++ b/Sources/GameWidget/Gauge/GaugeNode.swift @@ -7,8 +7,7 @@ import SpriteKit -class GaugeNode: SKSpriteNode { - static let center = NotificationCenter() +public class GaugeNode: SKSpriteNode, ObserveableNode { var maxWidth: CGFloat = .zero @objc func receiveValue(notification: Notification) { @@ -29,7 +28,7 @@ class GaugeNode: SKSpriteNode { self.run(.resize(toWidth: (notification.userInfo?["rate"] as! CGFloat) * self.maxWidth, duration: 0.5)) } - func registerTo(center: NotificationCenter, id: Gauge.ID) { + public func registerTo(center: NotificationCenter, id: Gauge.ID) { center.addObserver(self, selector: #selector(receiveValue(notification:)), name: .gaugePostValue(id: id), object: nil) center.addObserver(self, selector: #selector(receiveRate(notification:)), name: .gaugePostRate(id: id), object: nil) center.addObserver(self, selector: #selector(receiveValueWithAnimation(notification:)), name: .gaugePostValueWithAnimation(id: id), object: nil) diff --git a/Sources/GameWidget/Gauge/GaugeOutput.swift b/Sources/GameWidget/Gauge/GaugeOutput.swift index eef485a..1bcaded 100644 --- a/Sources/GameWidget/Gauge/GaugeOutput.swift +++ b/Sources/GameWidget/Gauge/GaugeOutput.swift @@ -31,16 +31,16 @@ public protocol GaugeDrawable { public extension GaugeDrawable { func send(value: CGFloat, id: Gauge.ID) { - GaugeNode.center.post(name: .gaugePostValue(id: id), object: nil, userInfo: ["value": value]) + WidgetNotificationSystem.activated?.post(name: .gaugePostValue(id: id), object: nil, userInfo: ["value": value]) } func send(rate: CGFloat, id: Gauge.ID) { - GaugeNode.center.post(name: .gaugePostRate(id: id), object: nil, userInfo: ["rate": rate]) + WidgetNotificationSystem.activated?.post(name: .gaugePostRate(id: id), object: nil, userInfo: ["rate": rate]) } func sendForAnimation(value: CGFloat, id: Gauge.ID) { - GaugeNode.center.post(name: .gaugePostValueWithAnimation(id: id), object: nil, userInfo: ["value": value]) + WidgetNotificationSystem.activated?.post(name: .gaugePostValueWithAnimation(id: id), object: nil, userInfo: ["value": value]) } func sendForAnimation(rate: CGFloat, id: Gauge.ID) { - GaugeNode.center.post(name: .gaugePostRateWithAnimation(id: id), object: nil, userInfo: ["rate": rate]) + WidgetNotificationSystem.activated?.post(name: .gaugePostRateWithAnimation(id: id), object: nil, userInfo: ["rate": rate]) } } From 06f3c02c47d8c6c736e0ec4d4a1f0813f6cd9492 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 19 Feb 2023 14:46:54 +0900 Subject: [PATCH 49/57] =?UTF-8?q?fix=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=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 --- Tests/GameWidgetTests/GaugeTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/GameWidgetTests/GaugeTests.swift b/Tests/GameWidgetTests/GaugeTests.swift index 27d201e..2780902 100644 --- a/Tests/GameWidgetTests/GaugeTests.swift +++ b/Tests/GameWidgetTests/GaugeTests.swift @@ -11,7 +11,7 @@ import SpriteKit final class GaugeTests: XCTestCase { func testModifiers() { - let gauge = Gauge(name: .init("test")) + let gauge = Gauge(id: .init("test")) .modifiable .position(CGPoint(x: 1, y: 1)) .color(.red) From 422cc25a245a71f71de2033cc197f9be90c706d5 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 19 Feb 2023 21:45:46 +0900 Subject: [PATCH 50/57] =?UTF-8?q?change=20WidgetNotificationSystem=20?= =?UTF-8?q?=E3=82=92=E5=85=B1=E6=9C=89=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4=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 以前は NotificationCenter を共有していました. --- Sources/GameWidget/Commons/Display.swift | 8 ++++---- Sources/GameWidget/Commons/Group.swift | 8 ++++---- Sources/GameWidget/Commons/ModifiableWidget.swift | 2 +- .../Commons/Widget/Notification/ObserveableNode.swift | 2 +- Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift | 6 +++--- Sources/GameWidget/Commons/Widget/Widget.swift | 4 ++-- Sources/GameWidget/Gauge/Gauge.swift | 2 +- Sources/GameWidget/Gauge/GaugeNode.swift | 2 +- Sources/GameWidget/NodeWidget/NodeWidget.swift | 2 +- Tests/GameWidgetTests/GroupTests.swift | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/GameWidget/Commons/Display.swift b/Sources/GameWidget/Commons/Display.swift index c1f22a6..dce258b 100644 --- a/Sources/GameWidget/Commons/Display.swift +++ b/Sources/GameWidget/Commons/Display.swift @@ -17,7 +17,7 @@ public struct RecursiveDisplay: Widget, WidgetList .init(first: self, second: block()) } - public func widgetNodes(center: NotificationCenter) -> [SKNode] { + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { self.first.widgetNodes(center: center) + self.second.widgetNodes(center: center) } @@ -25,7 +25,7 @@ public struct RecursiveDisplay: Widget, WidgetList return SKNode() } - public func combine(node: SKNode, center: NotificationCenter) { + public func combine(node: SKNode, center: WidgetNotificationSystem) { for i in self.first.widgetNodes(center: center) + self.second.widgetNodes(center: center) { node.addChild(i) } @@ -43,7 +43,7 @@ public struct SingleWidgetDisplay: Widget, WidgetList { RecursiveDisplay(first: self, second: block()) } - public func widgetNodes(center: NotificationCenter) -> [SKNode] { + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { self.widgetList.widgetNodes(center: center) } @@ -51,7 +51,7 @@ public struct SingleWidgetDisplay: Widget, WidgetList { return SKNode() } - public func combine(node: SKNode, center: NotificationCenter) { + public func combine(node: SKNode, center: WidgetNotificationSystem) { for i in self.widgetList.widgetNodes(center: center) { node.addChild(i) } diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/Group.swift index 87a2e37..be84ef7 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/Group.swift @@ -143,7 +143,7 @@ import SpriteKit } public protocol WidgetList { - func widgetNodes(center: NotificationCenter) -> [SKNode] + func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] } /// 再帰可能. widget のペアです. オーバーヘッドはありません. @@ -156,7 +156,7 @@ public struct RecursiveGroup: WidgetLis .init(first: self, second: newWidget) } - public func widgetNodes(center: NotificationCenter) -> [SKNode] { + public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { var result = self.first.widgetNodes(center: center) self.second.addTo(buffer: &result, center: center) return result @@ -173,7 +173,7 @@ struct Single: WidgetList { .init(first: self, second: newWidget) } - func widgetNodes(center: NotificationCenter) -> [SKNode] { + func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { var result = [SKNode]() self.widget.addTo(buffer: &result, center: center) return result @@ -191,7 +191,7 @@ public struct Extension: WidgetListElementType { self.content = content() } - public func addTo(buffer: inout [SKNode], center: NotificationCenter) { + public func addTo(buffer: inout [SKNode], center: WidgetNotificationSystem) { for node in self.content.widgetNodes(center: center) { buffer.append(node) } diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifiableWidget.swift index fab5ab7..7ef07a4 100644 --- a/Sources/GameWidget/Commons/ModifiableWidget.swift +++ b/Sources/GameWidget/Commons/ModifiableWidget.swift @@ -28,7 +28,7 @@ public struct ModifiableWidget: Widget where Body: NodeGenerator, .init(body: self.body, builder: self.builder.modifiered(mod: mod)) } - public func combine(node: Body.Node, center: NotificationCenter) { + public func combine(node: Body.Node, center: WidgetNotificationSystem) { self.body.combine(node: node, center: center) } } diff --git a/Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift b/Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift index 7d864a9..e380f59 100644 --- a/Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift +++ b/Sources/GameWidget/Commons/Widget/Notification/ObserveableNode.swift @@ -9,5 +9,5 @@ import SpriteKit public protocol ObserveableNode: SKNode { associatedtype Identifier - func registerTo(center: NotificationCenter, id: Identifier) + func registerTo(center: WidgetNotificationSystem, id: Identifier) } diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index c771a18..23337dd 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -8,7 +8,7 @@ import SpriteKit public extension NodeGenerator { - func combine(node: Node, center: NotificationCenter) { + func combine(node: Node, center: WidgetNotificationSystem) { } @@ -21,7 +21,7 @@ public extension NodeGenerator { } public extension WidgetListElementType where Self: NodeGenerator { - func addTo(buffer: inout [SKNode], center: NotificationCenter) { + func addTo(buffer: inout [SKNode], center: WidgetNotificationSystem) { let node = self.node() self.combine(node: node, center: center) buffer.append(node) @@ -35,7 +35,7 @@ public extension NodeGenerator where Self: ContextPresentPlugIn, Context: Parame } public extension DataOutputPlugIn { - func combine(node: Node, center: NotificationCenter) { + func combine(node: Node, center: WidgetNotificationSystem) { node.registerTo(center: center, id: self.id) } } diff --git a/Sources/GameWidget/Commons/Widget/Widget.swift b/Sources/GameWidget/Commons/Widget/Widget.swift index 2d69075..ac3ffba 100644 --- a/Sources/GameWidget/Commons/Widget/Widget.swift +++ b/Sources/GameWidget/Commons/Widget/Widget.swift @@ -10,11 +10,11 @@ import SpriteKit public protocol NodeGenerator { associatedtype Node: SKNode func node() -> Node - func combine(node: Node, center: NotificationCenter) + func combine(node: Node, center: WidgetNotificationSystem) } public protocol WidgetListElementType { - func addTo(buffer: inout [SKNode], center: NotificationCenter) + func addTo(buffer: inout [SKNode], center: WidgetNotificationSystem) } public protocol Widget: NodeGenerator, WidgetListElementType { diff --git a/Sources/GameWidget/Gauge/Gauge.swift b/Sources/GameWidget/Gauge/Gauge.swift index c6650de..69734de 100644 --- a/Sources/GameWidget/Gauge/Gauge.swift +++ b/Sources/GameWidget/Gauge/Gauge.swift @@ -59,7 +59,7 @@ extension Gauge: Widget, ContextPresentPlugIn { return gauge } - public func combine(node: GaugeNode, center: NotificationCenter) { + public func combine(node: GaugeNode, center: WidgetNotificationSystem) { node.registerTo(center: center, id: self.id) } diff --git a/Sources/GameWidget/Gauge/GaugeNode.swift b/Sources/GameWidget/Gauge/GaugeNode.swift index 714f6d3..79dd6aa 100644 --- a/Sources/GameWidget/Gauge/GaugeNode.swift +++ b/Sources/GameWidget/Gauge/GaugeNode.swift @@ -28,7 +28,7 @@ public class GaugeNode: SKSpriteNode, ObserveableNode { self.run(.resize(toWidth: (notification.userInfo?["rate"] as! CGFloat) * self.maxWidth, duration: 0.5)) } - public func registerTo(center: NotificationCenter, id: Gauge.ID) { + public func registerTo(center: WidgetNotificationSystem, id: Gauge.ID) { center.addObserver(self, selector: #selector(receiveValue(notification:)), name: .gaugePostValue(id: id), object: nil) center.addObserver(self, selector: #selector(receiveRate(notification:)), name: .gaugePostRate(id: id), object: nil) center.addObserver(self, selector: #selector(receiveValueWithAnimation(notification:)), name: .gaugePostValueWithAnimation(id: id), object: nil) diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/NodeWidget/NodeWidget.swift index 202b029..4bd1632 100644 --- a/Sources/GameWidget/NodeWidget/NodeWidget.swift +++ b/Sources/GameWidget/NodeWidget/NodeWidget.swift @@ -28,7 +28,7 @@ public struct NodeWidget: Widget, ContextPresentPlugIn { return result } - public func combine(node: SKNode, center: NotificationCenter) { + public func combine(node: SKNode, center: WidgetNotificationSystem) { for i in self.content.widgetNodes(center: center) { node.addChild(i) } diff --git a/Tests/GameWidgetTests/GroupTests.swift b/Tests/GameWidgetTests/GroupTests.swift index dff4749..d66b013 100644 --- a/Tests/GameWidgetTests/GroupTests.swift +++ b/Tests/GameWidgetTests/GroupTests.swift @@ -11,7 +11,7 @@ import GameWidget final class GroupTest: XCTestCase { func generateNodesNameReduced(@GroupBuilder _ list: () -> T) -> String { - list().widgetNodes(center: .default).reduce(into: "") { partialResult, node in + list().widgetNodes(center: WidgetNotificationSystem()).reduce(into: "") { partialResult, node in guard let name = node.name else { XCTFail() return From 83fc4a639248ebd4d2b7583e960440ec9b888a36 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 19 Feb 2023 22:03:11 +0900 Subject: [PATCH 51/57] =?UTF-8?q?remove=20WidgetNotificationSystem=20?= =?UTF-8?q?=E3=81=AE=E3=82=B0=E3=83=AD=E3=83=BC=E3=83=90=E3=83=AB=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E3=82=92=E5=89=8A=E9=99=A4=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameWidget/Button/Button.swift | 6 +++--- Sources/GameWidget/Button/ButtonNode.swift | 12 ++++++++++-- .../GameWidget/Button/ButtonNotification.swift | 7 ------- .../Widget/Notification/InputPublisher.swift | 16 ++++++++++++++++ .../Notification/WidgetNotificationSystem.swift | 4 ---- .../Commons/Widget/Widget+PlugIns.swift | 6 ++++++ .../Commons/Widget/WidgetPlugIns.swift | 4 ++++ Sources/GameWidget/Gauge/GaugeOutput.swift | 11 ++++++----- 8 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 Sources/GameWidget/Commons/Widget/Notification/InputPublisher.swift diff --git a/Sources/GameWidget/Button/Button.swift b/Sources/GameWidget/Button/Button.swift index 3f5443f..4cc3015 100644 --- a/Sources/GameWidget/Button/Button.swift +++ b/Sources/GameWidget/Button/Button.swift @@ -25,12 +25,12 @@ public struct Button { } -extension Button: Widget, ContextPresentPlugIn { +extension Button: Widget, ContextPresentPlugIn, UserInputPlugIn { public typealias Context = ButtonContext - public func node(applying context: ButtonContext) -> SKNode { - let result = SKNode() + public func node(applying context: ButtonContext) -> ButtonNode { + let result = ButtonNode() let label = SKLabelNode(text: context.text ?? "\(self.name)") label.verticalAlignmentMode = .center diff --git a/Sources/GameWidget/Button/ButtonNode.swift b/Sources/GameWidget/Button/ButtonNode.swift index f3d067a..b30ce4d 100644 --- a/Sources/GameWidget/Button/ButtonNode.swift +++ b/Sources/GameWidget/Button/ButtonNode.swift @@ -12,6 +12,10 @@ public enum ActionType { case alpha } +public class ButtonNode: SKNode, PublisherNode { + public weak var notificationSystem: WidgetNotificationSystem? +} + final class ButtonSensor: SKSpriteNode { override var isUserInteractionEnabled: Bool { @@ -19,6 +23,10 @@ final class ButtonSensor: SKSpriteNode { set {} } + var buttonNode: ButtonNode? { + self.parent as? ButtonNode + } + var roleName: Button.Role? private var isSelected = false @@ -63,7 +71,7 @@ final class ButtonSensor: SKSpriteNode { self.parent?.removeAllActions() self.parent?.run(self.selectAction!) self.isSelected = true - WidgetNotificationSystem.touchDownButton(self.roleName!) + self.buttonNode?.notificationSystem?.touchDownButton(self.roleName!) } func touchMoved(toPoint pos: CGPoint) { @@ -81,7 +89,7 @@ final class ButtonSensor: SKSpriteNode { self.selectEndAction!, SKAction.run { self.isSelected = false - WidgetNotificationSystem.touchUpButton(self.roleName!) + self.buttonNode?.notificationSystem?.touchUpButton(self.roleName!) } ])) } diff --git a/Sources/GameWidget/Button/ButtonNotification.swift b/Sources/GameWidget/Button/ButtonNotification.swift index 1174c63..eaef919 100644 --- a/Sources/GameWidget/Button/ButtonNotification.swift +++ b/Sources/GameWidget/Button/ButtonNotification.swift @@ -21,13 +21,6 @@ public extension WidgetNotificationSystem { self.post(name: .buttonTouchUp, object: nil, userInfo: ["buttonName": button]) } - static func touchDownButton(_ button: Button.Role) { - WidgetNotificationSystem.activated?.touchDownButton(button) - } - - static func touchUpButton(_ button: Button.Role) { - WidgetNotificationSystem.activated?.touchUpButton(button) - } } extension Notification.Name { diff --git a/Sources/GameWidget/Commons/Widget/Notification/InputPublisher.swift b/Sources/GameWidget/Commons/Widget/Notification/InputPublisher.swift new file mode 100644 index 0000000..908fe79 --- /dev/null +++ b/Sources/GameWidget/Commons/Widget/Notification/InputPublisher.swift @@ -0,0 +1,16 @@ +// +// InputPublisher.swift +// +// +// Created by rrbox on 2023/02/19. +// + +import SpriteKit + +public protocol NotificationPublisher { + var notificationSystem: WidgetNotificationSystem? { get set } +} + +public protocol PublisherNode: SKNode { + var notificationSystem: WidgetNotificationSystem? { get set } +} diff --git a/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift b/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift index de40fd1..88456d9 100644 --- a/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift +++ b/Sources/GameWidget/Commons/Widget/Notification/WidgetNotificationSystem.swift @@ -8,9 +8,5 @@ import Foundation final public class WidgetNotificationSystem: NotificationCenter { - public static weak var activated: WidgetNotificationSystem? - public func activate() { - WidgetNotificationSystem.activated = self - } } diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index 23337dd..8490e51 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -39,3 +39,9 @@ public extension DataOutputPlugIn { node.registerTo(center: center, id: self.id) } } + +public extension UserInputPlugIn { + func combine(node: Node, center: WidgetNotificationSystem) { + node.notificationSystem = center + } +} diff --git a/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift index f69986c..f38d6e4 100644 --- a/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/WidgetPlugIns.swift @@ -16,3 +16,7 @@ public protocol ContextPresentPlugIn { public protocol DataOutputPlugIn: NodeGenerator where Node: ObserveableNode { var id: Node.Identifier { get } } + +public protocol UserInputPlugIn: NodeGenerator where Node: PublisherNode { + +} diff --git a/Sources/GameWidget/Gauge/GaugeOutput.swift b/Sources/GameWidget/Gauge/GaugeOutput.swift index 1bcaded..a38f247 100644 --- a/Sources/GameWidget/Gauge/GaugeOutput.swift +++ b/Sources/GameWidget/Gauge/GaugeOutput.swift @@ -22,25 +22,26 @@ extension Notification.Name { } } -public protocol GaugeDrawable { +public protocol GaugeDrawable: NotificationPublisher { func send(value: CGFloat, id: Gauge.ID) func send(rate: CGFloat, id: Gauge.ID) + } public extension GaugeDrawable { func send(value: CGFloat, id: Gauge.ID) { - WidgetNotificationSystem.activated?.post(name: .gaugePostValue(id: id), object: nil, userInfo: ["value": value]) + self.notificationSystem?.post(name: .gaugePostValue(id: id), object: nil, userInfo: ["value": value]) } func send(rate: CGFloat, id: Gauge.ID) { - WidgetNotificationSystem.activated?.post(name: .gaugePostRate(id: id), object: nil, userInfo: ["rate": rate]) + self.notificationSystem?.post(name: .gaugePostRate(id: id), object: nil, userInfo: ["rate": rate]) } func sendForAnimation(value: CGFloat, id: Gauge.ID) { - WidgetNotificationSystem.activated?.post(name: .gaugePostValueWithAnimation(id: id), object: nil, userInfo: ["value": value]) + self.notificationSystem?.post(name: .gaugePostValueWithAnimation(id: id), object: nil, userInfo: ["value": value]) } func sendForAnimation(rate: CGFloat, id: Gauge.ID) { - WidgetNotificationSystem.activated?.post(name: .gaugePostRateWithAnimation(id: id), object: nil, userInfo: ["rate": rate]) + self.notificationSystem?.post(name: .gaugePostRateWithAnimation(id: id), object: nil, userInfo: ["rate": rate]) } } From a4898fe1efd834fbb62b4a250e43906cfaa25eae Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:54:16 +0900 Subject: [PATCH 52/57] =?UTF-8?q?clean=20=E3=83=95=E3=82=A9=E3=83=AB?= =?UTF-8?q?=E3=83=80=E6=A7=8B=E6=88=90=E3=82=92=E6=95=B4=E7=90=86=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 --- .../Context/Context.swift | 0 .../Context/ContextBuilder.swift | 0 .../Context/LinkedModifier.swift | 0 .../ModifiableWidget.swift | 0 .../{ => ModifierSystem}/Modifier.swift | 0 .../Commons/StructuringTools/Extension.swift | 28 +++++++++++++++++++ .../NodeWidget/NodeContext.swift | 0 .../NodeWidget/NodeWidget.swift | 0 .../Commons/{Group.swift => WidgetList.swift} | 20 ------------- .../{Commons => }/Modifiers/Colorizable.swift | 0 .../{Commons => }/Modifiers/ForAllNode.swift | 0 .../{Commons => }/Modifiers/Resizeable.swift | 0 .../{Commons => }/Modifiers/TextVisible.swift | 0 13 files changed, 28 insertions(+), 20 deletions(-) rename Sources/GameWidget/Commons/{ => ModifierSystem}/Context/Context.swift (100%) rename Sources/GameWidget/Commons/{ => ModifierSystem}/Context/ContextBuilder.swift (100%) rename Sources/GameWidget/Commons/{ => ModifierSystem}/Context/LinkedModifier.swift (100%) rename Sources/GameWidget/Commons/{ => ModifierSystem}/ModifiableWidget.swift (100%) rename Sources/GameWidget/Commons/{ => ModifierSystem}/Modifier.swift (100%) create mode 100644 Sources/GameWidget/Commons/StructuringTools/Extension.swift rename Sources/GameWidget/{ => Commons/StructuringTools}/NodeWidget/NodeContext.swift (100%) rename Sources/GameWidget/{ => Commons/StructuringTools}/NodeWidget/NodeWidget.swift (100%) rename Sources/GameWidget/Commons/{Group.swift => WidgetList.swift} (91%) rename Sources/GameWidget/{Commons => }/Modifiers/Colorizable.swift (100%) rename Sources/GameWidget/{Commons => }/Modifiers/ForAllNode.swift (100%) rename Sources/GameWidget/{Commons => }/Modifiers/Resizeable.swift (100%) rename Sources/GameWidget/{Commons => }/Modifiers/TextVisible.swift (100%) diff --git a/Sources/GameWidget/Commons/Context/Context.swift b/Sources/GameWidget/Commons/ModifierSystem/Context/Context.swift similarity index 100% rename from Sources/GameWidget/Commons/Context/Context.swift rename to Sources/GameWidget/Commons/ModifierSystem/Context/Context.swift diff --git a/Sources/GameWidget/Commons/Context/ContextBuilder.swift b/Sources/GameWidget/Commons/ModifierSystem/Context/ContextBuilder.swift similarity index 100% rename from Sources/GameWidget/Commons/Context/ContextBuilder.swift rename to Sources/GameWidget/Commons/ModifierSystem/Context/ContextBuilder.swift diff --git a/Sources/GameWidget/Commons/Context/LinkedModifier.swift b/Sources/GameWidget/Commons/ModifierSystem/Context/LinkedModifier.swift similarity index 100% rename from Sources/GameWidget/Commons/Context/LinkedModifier.swift rename to Sources/GameWidget/Commons/ModifierSystem/Context/LinkedModifier.swift diff --git a/Sources/GameWidget/Commons/ModifiableWidget.swift b/Sources/GameWidget/Commons/ModifierSystem/ModifiableWidget.swift similarity index 100% rename from Sources/GameWidget/Commons/ModifiableWidget.swift rename to Sources/GameWidget/Commons/ModifierSystem/ModifiableWidget.swift diff --git a/Sources/GameWidget/Commons/Modifier.swift b/Sources/GameWidget/Commons/ModifierSystem/Modifier.swift similarity index 100% rename from Sources/GameWidget/Commons/Modifier.swift rename to Sources/GameWidget/Commons/ModifierSystem/Modifier.swift diff --git a/Sources/GameWidget/Commons/StructuringTools/Extension.swift b/Sources/GameWidget/Commons/StructuringTools/Extension.swift new file mode 100644 index 0000000..e3b2e50 --- /dev/null +++ b/Sources/GameWidget/Commons/StructuringTools/Extension.swift @@ -0,0 +1,28 @@ +// +// Extension.swift +// +// +// Created by rrbox on 2023/02/23. +// + +import SpriteKit + +/// widget 数を増やす際に使用します. 10 個以下の widget を内包することができます. +/// - note: モディファイアはありませんが, メモリのオーバーヘッドがありません. +public struct Extension: WidgetListElementType { + + var content: Content + + public init(@GroupBuilder _ content: () -> Content) { + self.content = content() + } + + public func addTo(buffer: inout [SKNode], center: WidgetNotificationSystem) { + for node in self.content.widgetNodes(center: center) { + buffer.append(node) + } + } + +} + + diff --git a/Sources/GameWidget/NodeWidget/NodeContext.swift b/Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeContext.swift similarity index 100% rename from Sources/GameWidget/NodeWidget/NodeContext.swift rename to Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeContext.swift diff --git a/Sources/GameWidget/NodeWidget/NodeWidget.swift b/Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeWidget.swift similarity index 100% rename from Sources/GameWidget/NodeWidget/NodeWidget.swift rename to Sources/GameWidget/Commons/StructuringTools/NodeWidget/NodeWidget.swift diff --git a/Sources/GameWidget/Commons/Group.swift b/Sources/GameWidget/Commons/WidgetList.swift similarity index 91% rename from Sources/GameWidget/Commons/Group.swift rename to Sources/GameWidget/Commons/WidgetList.swift index be84ef7..7f2dc6f 100644 --- a/Sources/GameWidget/Commons/Group.swift +++ b/Sources/GameWidget/Commons/WidgetList.swift @@ -180,23 +180,3 @@ struct Single: WidgetList { } } - -/// widget 数を増やす際に使用します. 10 個以下の widget を内包することができます. -/// - note: モディファイアはありませんが, メモリのオーバーヘッドがありません. -public struct Extension: WidgetListElementType { - - var content: Content - - public init(@GroupBuilder _ content: () -> Content) { - self.content = content() - } - - public func addTo(buffer: inout [SKNode], center: WidgetNotificationSystem) { - for node in self.content.widgetNodes(center: center) { - buffer.append(node) - } - } - -} - - diff --git a/Sources/GameWidget/Commons/Modifiers/Colorizable.swift b/Sources/GameWidget/Modifiers/Colorizable.swift similarity index 100% rename from Sources/GameWidget/Commons/Modifiers/Colorizable.swift rename to Sources/GameWidget/Modifiers/Colorizable.swift diff --git a/Sources/GameWidget/Commons/Modifiers/ForAllNode.swift b/Sources/GameWidget/Modifiers/ForAllNode.swift similarity index 100% rename from Sources/GameWidget/Commons/Modifiers/ForAllNode.swift rename to Sources/GameWidget/Modifiers/ForAllNode.swift diff --git a/Sources/GameWidget/Commons/Modifiers/Resizeable.swift b/Sources/GameWidget/Modifiers/Resizeable.swift similarity index 100% rename from Sources/GameWidget/Commons/Modifiers/Resizeable.swift rename to Sources/GameWidget/Modifiers/Resizeable.swift diff --git a/Sources/GameWidget/Commons/Modifiers/TextVisible.swift b/Sources/GameWidget/Modifiers/TextVisible.swift similarity index 100% rename from Sources/GameWidget/Commons/Modifiers/TextVisible.swift rename to Sources/GameWidget/Modifiers/TextVisible.swift From c8b8da06597279f1e7bcaf82b8814776f593cc9a Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Thu, 23 Feb 2023 18:55:21 +0900 Subject: [PATCH 53/57] =?UTF-8?q?update=20documentation=20=E3=82=92?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=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/GameWidget.docc/Button_widget.md | 1 - Sources/GameWidget/GameWidget.docc/GameWidget.md | 6 +++--- ...izontalSingleBarChart_widget.md => Gauge_widget.md} | 4 ++-- .../{Node_widget.md => NodeWidget_widget.md} | 4 ++-- Sources/GameWidget/GameWidget.docc/WidgetUsage.md | 10 ++++++---- 5 files changed, 13 insertions(+), 12 deletions(-) rename Sources/GameWidget/GameWidget.docc/{HorizontalSingleBarChart_widget.md => Gauge_widget.md} (82%) rename Sources/GameWidget/GameWidget.docc/{Node_widget.md => NodeWidget_widget.md} (91%) diff --git a/Sources/GameWidget/GameWidget.docc/Button_widget.md b/Sources/GameWidget/GameWidget.docc/Button_widget.md index 5239c5c..972f010 100644 --- a/Sources/GameWidget/GameWidget.docc/Button_widget.md +++ b/Sources/GameWidget/GameWidget.docc/Button_widget.md @@ -19,4 +19,3 @@ ### Handling button event - ``ButtonResopnder`` -- ``ButtonNotificationCenter`` diff --git a/Sources/GameWidget/GameWidget.docc/GameWidget.md b/Sources/GameWidget/GameWidget.docc/GameWidget.md index 746337c..7d9538f 100644 --- a/Sources/GameWidget/GameWidget.docc/GameWidget.md +++ b/Sources/GameWidget/GameWidget.docc/GameWidget.md @@ -15,15 +15,15 @@ User interface widgets for SpriteKit. ### Widgets - -- +- - -- +- ### Layout widgets - ``Display`` - ``Extension`` -- +- ### Create custom Widget diff --git a/Sources/GameWidget/GameWidget.docc/HorizontalSingleBarChart_widget.md b/Sources/GameWidget/GameWidget.docc/Gauge_widget.md similarity index 82% rename from Sources/GameWidget/GameWidget.docc/HorizontalSingleBarChart_widget.md rename to Sources/GameWidget/GameWidget.docc/Gauge_widget.md index 342155c..168fe04 100644 --- a/Sources/GameWidget/GameWidget.docc/HorizontalSingleBarChart_widget.md +++ b/Sources/GameWidget/GameWidget.docc/Gauge_widget.md @@ -1,4 +1,4 @@ -# HorizontalSingleBarChart +# Gauge ## overview @@ -6,7 +6,7 @@ ### Widget type -- ``HorizontalSingleBarChart`` +- ``Gauge`` ### modifiers diff --git a/Sources/GameWidget/GameWidget.docc/Node_widget.md b/Sources/GameWidget/GameWidget.docc/NodeWidget_widget.md similarity index 91% rename from Sources/GameWidget/GameWidget.docc/Node_widget.md rename to Sources/GameWidget/GameWidget.docc/NodeWidget_widget.md index 7543f87..49be529 100644 --- a/Sources/GameWidget/GameWidget.docc/Node_widget.md +++ b/Sources/GameWidget/GameWidget.docc/NodeWidget_widget.md @@ -1,4 +1,4 @@ -# Node +# NodeWidget ## overview @@ -6,7 +6,7 @@ ### Widget type -- ``Node`` +- ``NodeWidget`` ### modifiers diff --git a/Sources/GameWidget/GameWidget.docc/WidgetUsage.md b/Sources/GameWidget/GameWidget.docc/WidgetUsage.md index e17c8d7..0ad79ef 100644 --- a/Sources/GameWidget/GameWidget.docc/WidgetUsage.md +++ b/Sources/GameWidget/GameWidget.docc/WidgetUsage.md @@ -13,15 +13,17 @@ let button = Button(.init("test")) .node() ``` -## Create node instance +## Create user inerface models -Widget から SKNode サブクラスインスタンスを作成するには, Widget ととして定義された構造体から実行できる `node()` を使用します. +Widget から UI モデルを作成するには, Widget として定義された構造体から実行できる `createModels()` を使用します. ```swift -let button = Button(.init("test")) - .node() +let (button, notificationCenter) = Button(.init("test")) + .createModels() ``` +`createModels()` の返り値は, その Widget に関連づけられた `SKNode` サブクラスと, そのノードと紐づけられた ``WidgetNotificationSystem`` のインスタンスです. + ## Modify widget Widget はビルダーパターンでレイアウトを編集するインターフェースを提供します. まずは Widget の ``Widget/modifiable-swift.property`` を呼び出しましょう. From 0263fce46b4c5ec2b42c16960d8000ab622efe14 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Thu, 23 Feb 2023 21:36:39 +0900 Subject: [PATCH 54/57] =?UTF-8?q?fix=20Display=20=E3=81=AE=E3=83=97?= =?UTF-8?q?=E3=83=AD=E3=83=91=E3=83=86=E3=82=A3=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - タプルに変更 - 命名を `value` に変更 - 不変にしました --- Sources/GameWidget/Commons/Display.swift | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Sources/GameWidget/Commons/Display.swift b/Sources/GameWidget/Commons/Display.swift index dce258b..2768b28 100644 --- a/Sources/GameWidget/Commons/Display.swift +++ b/Sources/GameWidget/Commons/Display.swift @@ -10,15 +10,14 @@ import SpriteKit /// SingleWidgetDisplay の place により生成され, 二つの WidgetList(一方は Display)を保持します. public struct RecursiveDisplay: Widget, WidgetList { - var first: T - var second: U + let value: (T, U) public func place(@GroupBuilder block: () -> V) -> RecursiveDisplay { - .init(first: self, second: block()) + .init(value: (self, block())) } public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { - self.first.widgetNodes(center: center) + self.second.widgetNodes(center: center) + self.value.0.widgetNodes(center: center) + self.value.1.widgetNodes(center: center) } public func node() -> SKNode { @@ -26,7 +25,7 @@ public struct RecursiveDisplay: Widget, WidgetList } public func combine(node: SKNode, center: WidgetNotificationSystem) { - for i in self.first.widgetNodes(center: center) + self.second.widgetNodes(center: center) { + for i in self.value.0.widgetNodes(center: center) + self.value.1.widgetNodes(center: center) { node.addChild(i) } } @@ -37,14 +36,14 @@ public struct RecursiveDisplay: Widget, WidgetList /// Display の place により生成され, 一つの WidgetList を保持します. public struct SingleWidgetDisplay: Widget, WidgetList { - var widgetList: T + let value: T public func place(@GroupBuilder block: () -> U) -> RecursiveDisplay { - RecursiveDisplay(first: self, second: block()) + .init(value: (self, block())) } public func widgetNodes(center: WidgetNotificationSystem) -> [SKNode] { - self.widgetList.widgetNodes(center: center) + self.value.widgetNodes(center: center) } public func node() -> SKNode { @@ -52,7 +51,7 @@ public struct SingleWidgetDisplay: Widget, WidgetList { } public func combine(node: SKNode, center: WidgetNotificationSystem) { - for i in self.widgetList.widgetNodes(center: center) { + for i in self.value.widgetNodes(center: center) { node.addChild(i) } } @@ -65,7 +64,7 @@ public struct Display { public init() {} public func place(@GroupBuilder block: () -> T) -> SingleWidgetDisplay { - SingleWidgetDisplay(widgetList: block()) + SingleWidgetDisplay(value: block()) } } From 85fb186868176d47c0e7fb76d7f666d32356399e Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Fri, 24 Feb 2023 01:41:03 +0900 Subject: [PATCH 55/57] =?UTF-8?q?rename=20Display=20=E3=81=AE=E9=80=A3?= =?UTF-8?q?=E7=B5=90=E3=83=AA=E3=82=B9=E3=83=88=E7=94=A8=E3=81=AE=E6=A7=8B?= =?UTF-8?q?=E9=80=A0=E4=BD=93=E3=81=AE=E5=91=BD=E5=90=8D=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Display を名前空間として利用しました. - 1単語になるように命名しました. --- Sources/GameWidget/Commons/Display.swift | 51 ++++++++++++------------ Tests/GameWidgetTests/GaugeTests.swift | 3 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Sources/GameWidget/Commons/Display.swift b/Sources/GameWidget/Commons/Display.swift index 2768b28..fc96ff1 100644 --- a/Sources/GameWidget/Commons/Display.swift +++ b/Sources/GameWidget/Commons/Display.swift @@ -7,12 +7,32 @@ import SpriteKit -/// SingleWidgetDisplay の place により生成され, 二つの WidgetList(一方は Display)を保持します. -public struct RecursiveDisplay: Widget, WidgetList { +/// Widget のレイアウトの起点. place メソッドチェーンで無制限に Widget を配置できます. +/// - note: 一回の place メソッドで配置可能な widget の数は 10 個までです. +public struct Display { + public init() {} - let value: (T, U) + /// ``Display/Single`` の ``Display/Single/place(block:)`` により生成され, 二つの ``WidgetList`` を保持します. + public struct Link { + let value: (T, U) + } + + /// 一つの widget から ``Display/Link`` を生成するためのラッパー. + /// ``Display`` の ``Display/place(block:)`` により生成され, 一つの ``WidgetList`` を保持します. + public struct Single { + let value: T + } - public func place(@GroupBuilder block: () -> V) -> RecursiveDisplay { +} + +public extension Display { + func place(@GroupBuilder block: () -> T) -> Display.Single { + .init(value: block()) + } +} + +extension Display.Link: Widget, WidgetList { + public func place(@GroupBuilder block: () -> V) -> Display.Link { .init(value: (self, block())) } @@ -29,16 +49,10 @@ public struct RecursiveDisplay: Widget, WidgetList node.addChild(i) } } - } -/// 一つの widget から RecursiveDisplay を生成するためのラッパー. -/// Display の place により生成され, 一つの WidgetList を保持します. -public struct SingleWidgetDisplay: Widget, WidgetList { - - let value: T - - public func place(@GroupBuilder block: () -> U) -> RecursiveDisplay { +extension Display.Single: Widget, WidgetList { + public func place(@GroupBuilder block: () -> U) -> Display.Link { .init(value: (self, block())) } @@ -55,17 +69,4 @@ public struct SingleWidgetDisplay: Widget, WidgetList { node.addChild(i) } } - } - -/// Widget のレイアウトの起点. place メソッドチェーンで無制限に Widget を配置できます. -/// - note: 一回の place メソッドで配置可能な widget の数は 10 個までです. -public struct Display { - public init() {} - - public func place(@GroupBuilder block: () -> T) -> SingleWidgetDisplay { - SingleWidgetDisplay(value: block()) - } - -} - diff --git a/Tests/GameWidgetTests/GaugeTests.swift b/Tests/GameWidgetTests/GaugeTests.swift index 2780902..578994d 100644 --- a/Tests/GameWidgetTests/GaugeTests.swift +++ b/Tests/GameWidgetTests/GaugeTests.swift @@ -23,8 +23,7 @@ final class GaugeTests: XCTestCase { .zPosition(2) .node() - guard let gauge = gauge as? SKSpriteNode, - let background = gauge.children[0] as? SKSpriteNode else { + guard let background = gauge.children[0] as? SKSpriteNode else { XCTFail() return } From 108c80a1174a825bfa514e6c6f7c8ec03973e528 Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sat, 25 Feb 2023 23:05:29 +0900 Subject: [PATCH 56/57] =?UTF-8?q?add=20createInteraciveNode=20=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NotificationSystem を injection できるメソッドです. --- Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index 8490e51..32bea57 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -18,6 +18,12 @@ public extension NodeGenerator { self.combine(node: node, center: center) return (node, center) } + + func createInteraciveNode(_ center: WidgetNotificationSystem) -> Node { + let node = self.node() + self.combine(node: node, center: center) + return node + } } public extension WidgetListElementType where Self: NodeGenerator { From 5ca389117a1ee80f13235f52f3a3420f6fb882bf Mon Sep 17 00:00:00 2001 From: rrbox <87851278+rrbox@users.noreply.github.com> Date: Sun, 9 Apr 2023 22:17:37 +0900 Subject: [PATCH 57/57] =?UTF-8?q?change=20=E3=83=8E=E3=83=BC=E3=83=89?= =?UTF-8?q?=E7=94=9F=E6=88=90=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92?= =?UTF-8?q?=20node=20=E3=81=AB=E5=91=BD=E5=90=8D=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 --- Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift index 32bea57..46c3289 100644 --- a/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift +++ b/Sources/GameWidget/Commons/Widget/Widget+PlugIns.swift @@ -19,7 +19,7 @@ public extension NodeGenerator { return (node, center) } - func createInteraciveNode(_ center: WidgetNotificationSystem) -> Node { + func node(_ center: WidgetNotificationSystem) -> Node { let node = self.node() self.combine(node: node, center: center) return node