diff --git a/iOS/app/MMMemory.xcodeproj/project.pbxproj b/iOS/app/MMMemory.xcodeproj/project.pbxproj index 46df160..722da7d 100644 --- a/iOS/app/MMMemory.xcodeproj/project.pbxproj +++ b/iOS/app/MMMemory.xcodeproj/project.pbxproj @@ -8,13 +8,9 @@ /* Begin PBXBuildFile section */ 1F083A14C69F20A6BA92A63E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16A7DD61EF6CD4FB4E3DE25 /* AppDelegate.swift */; }; - 3D03666F3BC2B1F2CBB49530 /* Main.SectionSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D5F2B2E3A26F03F6825608E /* Main.SectionSelection.swift */; }; - 79FB208C9DADDA6179E588C3 /* Main.SectionGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AC22F19366076CF4168BFBD /* Main.SectionGrid.swift */; }; - 89086E3972F560A9A1A76CE4 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C71EDBDFFDBC96F6E8E7762 /* Model.swift */; }; B19B3998FA2BA651ACB1E53C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C1742EFC5A1E818780679340 /* Assets.xcassets */; }; BE2994BF2FFF272E62883953 /* swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = D414A6174931F533B0B286E8 /* swift.swift */; }; CAFD870CA84084E45011CC23 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4E32B0495E4BCEA4EE0508D4 /* LaunchScreen.storyboard */; }; - D505E64F4CD6EAEB530BF851 /* Main.Section16Buttons.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38A1AA6B57483F6B44CDF78 /* Main.Section16Buttons.swift */; }; DB1010B8A246D47BEC6B3FA6 /* Main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DF762100A8EDF105B6E136D /* Main.swift */; }; EB8CC50236A211D932BA0DB0 /* Main.Platform.swift in Sources */ = {isa = PBXBuildFile; fileRef = A355A898E25602F45B88CCBA /* Main.Platform.swift */; }; F368609CC7635D385838A386 /* platfrom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F3E3A0EC0B9264E001C3DBC /* platfrom.swift */; }; @@ -24,12 +20,8 @@ 0DF762100A8EDF105B6E136D /* Main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Main.swift; sourceTree = ""; }; 0F3E3A0EC0B9264E001C3DBC /* platfrom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = platfrom.swift; sourceTree = ""; }; 4E32B0495E4BCEA4EE0508D4 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; - 6D5F2B2E3A26F03F6825608E /* Main.SectionSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Main.SectionSelection.swift; sourceTree = ""; }; - 9AC22F19366076CF4168BFBD /* Main.SectionGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Main.SectionGrid.swift; sourceTree = ""; }; - 9C71EDBDFFDBC96F6E8E7762 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; 9D774FEE86833E8A0A74387C /* App.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; }; A355A898E25602F45B88CCBA /* Main.Platform.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Main.Platform.swift; sourceTree = ""; }; - A38A1AA6B57483F6B44CDF78 /* Main.Section16Buttons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Main.Section16Buttons.swift; sourceTree = ""; }; C1742EFC5A1E818780679340 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; D414A6174931F533B0B286E8 /* swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = swift.swift; sourceTree = ""; }; F16A7DD61EF6CD4FB4E3DE25 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -52,11 +44,7 @@ C1742EFC5A1E818780679340 /* Assets.xcassets */, 4E32B0495E4BCEA4EE0508D4 /* LaunchScreen.storyboard */, A355A898E25602F45B88CCBA /* Main.Platform.swift */, - A38A1AA6B57483F6B44CDF78 /* Main.Section16Buttons.swift */, - 9AC22F19366076CF4168BFBD /* Main.SectionGrid.swift */, - 6D5F2B2E3A26F03F6825608E /* Main.SectionSelection.swift */, 0DF762100A8EDF105B6E136D /* Main.swift */, - 9C71EDBDFFDBC96F6E8E7762 /* Model.swift */, 0F3E3A0EC0B9264E001C3DBC /* platfrom.swift */, ); name = src; @@ -144,11 +132,7 @@ files = ( 1F083A14C69F20A6BA92A63E /* AppDelegate.swift in Sources */, EB8CC50236A211D932BA0DB0 /* Main.Platform.swift in Sources */, - D505E64F4CD6EAEB530BF851 /* Main.Section16Buttons.swift in Sources */, - 79FB208C9DADDA6179E588C3 /* Main.SectionGrid.swift in Sources */, - 3D03666F3BC2B1F2CBB49530 /* Main.SectionSelection.swift in Sources */, DB1010B8A246D47BEC6B3FA6 /* Main.swift in Sources */, - 89086E3972F560A9A1A76CE4 /* Model.swift in Sources */, F368609CC7635D385838A386 /* platfrom.swift in Sources */, BE2994BF2FFF272E62883953 /* swift.swift in Sources */, ); diff --git a/iOS/app/MMMemory.xcodeproj/project.xcworkspace/xcuserdata/mk.xcuserdatad/UserInterfaceState.xcuserstate b/iOS/app/MMMemory.xcodeproj/project.xcworkspace/xcuserdata/mk.xcuserdatad/UserInterfaceState.xcuserstate index d56bf83..ee60fab 100644 Binary files a/iOS/app/MMMemory.xcodeproj/project.xcworkspace/xcuserdata/mk.xcuserdatad/UserInterfaceState.xcuserstate and b/iOS/app/MMMemory.xcodeproj/project.xcworkspace/xcuserdata/mk.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iOS/src/AppDelegate.swift b/iOS/src/AppDelegate.swift index 09b2826..a3de474 100644 --- a/iOS/src/AppDelegate.swift +++ b/iOS/src/AppDelegate.swift @@ -17,3 +17,7 @@ extension AppDelegate { return true } } + +struct M: Context { + var itemsCount: Float = 16 +} diff --git a/iOS/src/Main.Platform.swift b/iOS/src/Main.Platform.swift index 0067960..9c82050 100644 --- a/iOS/src/Main.Platform.swift +++ b/iOS/src/Main.Platform.swift @@ -14,9 +14,36 @@ extension Main { view.backgroundColor = .white - Main.Section16Buttons.setupCore(self) - Main.SectionGrid.setupCore(self) - Main.SectionSelection.setupCore(self) + // Создаём 16 кнопок. + for i in 0..<16 { + let btn = UIButton() + btn.tag = i + view.addSubview(btn) + buttons.append(btn) + } + + // Расставляем кнопки в сетке 4x4. + for (id, p) in memoryItemPositions(c: M()).enumerated() { + let btn = buttons[id] + btn.frame = + CGRect( + x: CGFloat(p.x), + y: CGFloat(p.y), + width: CGFloat(memorySide()), + height: CGFloat(memorySide()) + ) + btn.backgroundColor = .blue + } + + // Учитываем нажатия кнопок. + for btn in buttons { + btn.addTarget(self, action: #selector(Main.Core.selectButton), for: .touchUpInside) + } + + // Выводим номер нажатой кнопки. + didSelectButton + .sink { i in print("ИГР MainP.viewDL didSB: '\(i)'") } + .store(in: &subscriptions) } @objc func selectButton(_ btn: UIButton) { diff --git a/iOS/src/Main.Section16Buttons.swift b/iOS/src/Main.Section16Buttons.swift deleted file mode 100644 index dd29dd9..0000000 --- a/iOS/src/Main.Section16Buttons.swift +++ /dev/null @@ -1,21 +0,0 @@ -import UIKit - -// MARK: - Протоколы - -protocol MainSection16Buttons { } - -// MARK: - Реализация - -extension Main { - enum Section16Buttons { - static func setupCore(_ core: Main.Core) { - // Создаём 16 кнопок. - for i in 0..<16 { - let btn = UIButton() - btn.tag = i - core.view.addSubview(btn) - core.buttons.append(btn) - } - } - } -} diff --git a/iOS/src/Main.SectionGrid.swift b/iOS/src/Main.SectionGrid.swift deleted file mode 100644 index 4f54493..0000000 --- a/iOS/src/Main.SectionGrid.swift +++ /dev/null @@ -1,26 +0,0 @@ -import UIKit - -// MARK: - Протоколы - -protocol MainSectionGrid { } - -// MARK: - Реализация - -extension Main { - enum SectionGrid { - static func setupCore(_ core: Main.Core) { - // Расставляем кнопки в сетке 4x4. - for (id, p) in memoryItemPositions(M()).enumerated() { - let btn = core.buttons[id] - btn.frame = - CGRect( - x: CGFloat(p.0), - y: CGFloat(p.1), - width: CGFloat(memorySide()), - height: CGFloat(memorySide()) - ) - btn.backgroundColor = .blue - } - } - } -} diff --git a/iOS/src/Main.SectionSelection.swift b/iOS/src/Main.SectionSelection.swift deleted file mode 100644 index fa3936d..0000000 --- a/iOS/src/Main.SectionSelection.swift +++ /dev/null @@ -1,23 +0,0 @@ -import UIKit - -// MARK: - Протоколы - -protocol MainSectionSelection { } - -// MARK: - Реализация - -extension Main { - enum SectionSelection { - static func setupCore(_ core: Main.Core) { - // Учитываем нажатия кнопок. - for btn in core.buttons { - btn.addTarget(core, action: #selector(Main.Core.selectButton), for: .touchUpInside) - } - - // Выводим номер нажатой кнопки. - core.didSelectButton - .sink { i in print("ИГР MainSS.setupC didSB: '\(i)'") } - .store(in: &core.subscriptions) - } - } -} diff --git a/iOS/src/Model.swift b/iOS/src/Model.swift deleted file mode 100644 index 0b64e15..0000000 --- a/iOS/src/Model.swift +++ /dev/null @@ -1,16 +0,0 @@ -import Foundation - -struct M { - var itemsCount: Int = 16 -} - -func memoryItemPositions(_ M: M) -> [(Float, Float)] { - var pos = [(Float, Float)]() - for i in stride(from: 0, to: M.itemsCount, by: 1) { - let row = floor(Float(i) / 4) - let x = memoryGap() + (Float(i) - row * 4) * memoryGap() - let y = memoryGap() + row * memoryGap() - pos.append((x, y)) - } - return pos -} diff --git a/shared/javaScript.js b/shared/javaScript.js index 298fd79..334a6c3 100644 --- a/shared/javaScript.js +++ b/shared/javaScript.js @@ -13,8 +13,8 @@ function memoryItemPositions(c) { var ids = utsIndexArray(c.itemsCount); ids.forEach(function (i) { // @ts-ignore - var row = utsFloor(i / 4); - var x = memoryGap() + (i - row * 4) * memoryGap(); + var row = utsFloor(Number(i) / 4); + var x = memoryGap() + (Number(i) - row * 4) * memoryGap(); var y = memoryGap() + row * memoryGap(); // @ts-ignore pos.push(memoryCreatePosition(x, y)); diff --git a/shared/swift.swift b/shared/swift.swift index a6f8131..58bb724 100644 --- a/shared/swift.swift +++ b/shared/swift.swift @@ -24,14 +24,13 @@ func memoryItemPositions(c: Context) -> [Position] { // @ts-ignore let ids = utsIndexArray(c.itemsCount); - ids.forEach { ii in - let i = Float(ii); + ids.forEach { i in // @ts-ignore - let row = utsFloor(i / 4) - let x = memoryGap() + (i - row * 4) * memoryGap() + let row = utsFloor(Float(i) / 4) + let x = memoryGap() + (Float(i) - row * 4) * memoryGap() let y = memoryGap() + row * memoryGap() // @ts-ignore - pos.push(memoryCreatePosition(x, y)) + pos.append(memoryCreatePosition(x, y)) } return pos } diff --git a/shared/typeScript.ts b/shared/typeScript.ts index f2457b7..04062c2 100644 --- a/shared/typeScript.ts +++ b/shared/typeScript.ts @@ -26,8 +26,8 @@ function memoryItemPositions(c: Context): Position[] { let ids = utsIndexArray(c.itemsCount); ids.forEach(i => { // @ts-ignore - let row = utsFloor(i / 4) - let x = memoryGap() + (i - row * 4) * memoryGap() + let row = utsFloor(Number(i) / 4) + let x = memoryGap() + (Number(i) - row * 4) * memoryGap() let y = memoryGap() + row * memoryGap() // @ts-ignore pos.push(memoryCreatePosition(x, y)) diff --git a/toSwift b/toSwift index 8815e04..4ecf034 100755 --- a/toSwift +++ b/toSwift @@ -13,9 +13,11 @@ let fileDst = process.argv[3]; let globalReplacements = { "function": "func", "number": "Float", + "Number": "Float", "):": ") ->", "interface": "protocol", "})": "}", // forEach + ".push(": ".append(", // array }; console.log(`Converting '${fileSrc}' to '${fileDst}'`); diff --git a/будущее b/будущее index 69d1bcf..f9d9cde 100644 --- a/будущее +++ b/будущее @@ -1,9 +1,16 @@ +15.06: 19:10- -НАДО: * поправить Floor i/4 + * попробовать number(i) +* поправить push + * переводить в append * перейти на один файл swift * генерить memoryItemPositions.swift * ввести общую библиотеку? + * ввёл пока platform с функциями uts +* упростить структуру iOS помещением содержимого секций в платформу + +НАДО: -* в конце: разделить функции на разные файлы +* в конце прототипа: разделить функции на разные файлы * будет ошибка tsc: cannot find name, так что придётся покумекать