diff --git a/iOS/app/MMMemory.xcodeproj/project.pbxproj b/iOS/app/MMMemory.xcodeproj/project.pbxproj index 48ce22b..46df160 100644 --- a/iOS/app/MMMemory.xcodeproj/project.pbxproj +++ b/iOS/app/MMMemory.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* 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 */; }; - 4AC2B8BF716272D446F9E7E0 /* uts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 721855DB1A329E65128E36B5 /* uts.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 */; }; @@ -18,13 +17,14 @@ 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 */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 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 = ""; }; - 721855DB1A329E65128E36B5 /* uts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = uts.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; }; @@ -57,7 +57,7 @@ 6D5F2B2E3A26F03F6825608E /* Main.SectionSelection.swift */, 0DF762100A8EDF105B6E136D /* Main.swift */, 9C71EDBDFFDBC96F6E8E7762 /* Model.swift */, - 721855DB1A329E65128E36B5 /* uts.swift */, + 0F3E3A0EC0B9264E001C3DBC /* platfrom.swift */, ); name = src; path = ../src; @@ -149,8 +149,8 @@ 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 */, - 4AC2B8BF716272D446F9E7E0 /* uts.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; 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 91c14fb..d56bf83 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/platfrom.swift b/iOS/src/platfrom.swift new file mode 100644 index 0000000..ec5fd08 --- /dev/null +++ b/iOS/src/platfrom.swift @@ -0,0 +1,23 @@ +import Foundation + +// Memory. + +struct PositionInstance: Position { + var x: Float + var y: Float +} + +func memoryCreatePosition(_ x: Float, _ y: Float) -> PositionInstance { + return .init(x: x, y: y) +} + + +// UTS. + +func utsFloor(_ value: Float) -> Float { + floor(value) +} + +func utsIndexArray(_ count: Float) -> [Int] { + [Int](0.. [Int] { - [Int](0.. [Position] { // @ts-ignore let ids = utsIndexArray(c.itemsCount); - ids.forEach(i => { + ids.forEach { ii in + let i = Float(ii); // @ts-ignore let row = utsFloor(i / 4) let x = memoryGap() + (i - row * 4) * memoryGap() let y = memoryGap() + row * memoryGap() // @ts-ignore pos.push(memoryCreatePosition(x, y)) - }) + } return pos } diff --git a/toSwift b/toSwift index c94744f..8815e04 100755 --- a/toSwift +++ b/toSwift @@ -15,6 +15,7 @@ let globalReplacements = { "number": "Float", "):": ") ->", "interface": "protocol", + "})": "}", // forEach }; console.log(`Converting '${fileSrc}' to '${fileDst}'`); @@ -40,11 +41,31 @@ function convert(line) { } result = protocolReplace(result); result = typeArrayReplace(result); + result = forEachReplace(result); return result; } -var isProtocol = false; +// x.forEach(y => { -> x.forEach { y in +function forEachReplace(line) { + if (!line.includes("forEach")) { + return line; + } + + let partsFE = line.split("forEach"); + let identifier = partsFE[0]; + let closure = partsFE[1]; + + let partsC = closure.split(" => "); + let bracketAndVar = partsC[0]; + let bracket = partsC[1]; + let variable = bracketAndVar.substring(1); + let result = `${identifier}forEach { ${variable} in`; + return result; +} + + +var isProtocol = false; // interface -> protocol function protocolReplace(line) { if (line.includes("protocol")) { diff --git a/будущее b/будущее index b2170b7..69d1bcf 100644 --- a/будущее +++ b/будущее @@ -1,13 +1,6 @@ -09.06: 19:00- - -* заменить for на forEach в TS -* ввести функцию заполнения массива индексами: utsIndexArray -* ввести utsFloor -* ввести utsIndexArray в Swift НАДО: -* ввести utsFloor в Swift -* конвертировать forEach +* поправить Floor i/4 * перейти на один файл swift * генерить memoryItemPositions.swift * ввести общую библиотеку? diff --git a/прошлое b/прошлое index 1ee094e..b4fc89b 100644 --- a/прошлое +++ b/прошлое @@ -1,3 +1,12 @@ +09.06: 60 + +* заменить for на forEach в TS +* ввести функцию заполнения массива индексами: utsIndexArray +* ввести utsFloor +* ввести utsIndexArray в Swift +* конвертировать forEach +* ввести utsFloor в Swift + 08.06: 30 * перейти на один файл ts