├── .gitignore ├── .swift-version ├── Images └── lights.png ├── LICENSE ├── Minecraft.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── Redstone.xcscheme ├── Minecraft ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── README.md ├── Redstone.podspec ├── Redstone ├── Info.plist ├── Redstone.h └── StateMachine.swift └── RedstoneTests ├── Info.plist └── RedstoneTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | ## macOS 2 | .DS_Store 3 | 4 | ## Build generated 5 | build/ 6 | DerivedData 7 | 8 | ## Various settings 9 | *.pbxuser 10 | !default.pbxuser 11 | *.mode1v3 12 | !default.mode1v3 13 | *.mode2v3 14 | !default.mode2v3 15 | *.perspectivev3 16 | !default.perspectivev3 17 | xcuserdata 18 | 19 | ## Other 20 | *.xccheckout 21 | *.moved-aside 22 | *.xcuserstate 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | 29 | # CocoaPods 30 | Pods/ 31 | 32 | # Carthage 33 | Carthage/Checkouts 34 | Carthage/Build 35 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /Images/lights.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixzhu/Redstone/881be21cb77a59fac8e3c030e98ed1055fc14ea8/Images/lights.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 nixzhu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Minecraft.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5089F1A61E1FDCBC00FADE27 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5089F1A51E1FDCBC00FADE27 /* AppDelegate.swift */; }; 11 | 5089F1A81E1FDCBC00FADE27 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5089F1A71E1FDCBC00FADE27 /* ViewController.swift */; }; 12 | 5089F1AB1E1FDCBC00FADE27 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5089F1A91E1FDCBC00FADE27 /* Main.storyboard */; }; 13 | 5089F1AD1E1FDCBC00FADE27 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5089F1AC1E1FDCBC00FADE27 /* Assets.xcassets */; }; 14 | 5089F1B01E1FDCBC00FADE27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5089F1AE1E1FDCBC00FADE27 /* LaunchScreen.storyboard */; }; 15 | 5089F1C51E1FDD3800FADE27 /* Redstone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5089F1BC1E1FDD3800FADE27 /* Redstone.framework */; }; 16 | 5089F1CC1E1FDD3800FADE27 /* RedstoneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5089F1CB1E1FDD3800FADE27 /* RedstoneTests.swift */; }; 17 | 5089F1CE1E1FDD3800FADE27 /* Redstone.h in Headers */ = {isa = PBXBuildFile; fileRef = 5089F1BE1E1FDD3800FADE27 /* Redstone.h */; settings = {ATTRIBUTES = (Public, ); }; }; 18 | 5089F1D11E1FDD3800FADE27 /* Redstone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5089F1BC1E1FDD3800FADE27 /* Redstone.framework */; }; 19 | 5089F1D21E1FDD3800FADE27 /* Redstone.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5089F1BC1E1FDD3800FADE27 /* Redstone.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 20 | 5089F1DB1E1FDD5300FADE27 /* StateMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5089F1DA1E1FDD5300FADE27 /* StateMachine.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 5089F1C61E1FDD3800FADE27 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 5089F19A1E1FDCBC00FADE27 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 5089F1BB1E1FDD3800FADE27; 29 | remoteInfo = Redstone; 30 | }; 31 | 5089F1C81E1FDD3800FADE27 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 5089F19A1E1FDCBC00FADE27 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 5089F1A11E1FDCBC00FADE27; 36 | remoteInfo = Minecraft; 37 | }; 38 | 5089F1CF1E1FDD3800FADE27 /* PBXContainerItemProxy */ = { 39 | isa = PBXContainerItemProxy; 40 | containerPortal = 5089F19A1E1FDCBC00FADE27 /* Project object */; 41 | proxyType = 1; 42 | remoteGlobalIDString = 5089F1BB1E1FDD3800FADE27; 43 | remoteInfo = Redstone; 44 | }; 45 | /* End PBXContainerItemProxy section */ 46 | 47 | /* Begin PBXCopyFilesBuildPhase section */ 48 | 5089F1D61E1FDD3800FADE27 /* Embed Frameworks */ = { 49 | isa = PBXCopyFilesBuildPhase; 50 | buildActionMask = 2147483647; 51 | dstPath = ""; 52 | dstSubfolderSpec = 10; 53 | files = ( 54 | 5089F1D21E1FDD3800FADE27 /* Redstone.framework in Embed Frameworks */, 55 | ); 56 | name = "Embed Frameworks"; 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXCopyFilesBuildPhase section */ 60 | 61 | /* Begin PBXFileReference section */ 62 | 5089F1A21E1FDCBC00FADE27 /* Minecraft.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Minecraft.app; sourceTree = BUILT_PRODUCTS_DIR; }; 63 | 5089F1A51E1FDCBC00FADE27 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 64 | 5089F1A71E1FDCBC00FADE27 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 65 | 5089F1AA1E1FDCBC00FADE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 66 | 5089F1AC1E1FDCBC00FADE27 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 67 | 5089F1AF1E1FDCBC00FADE27 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 68 | 5089F1B11E1FDCBC00FADE27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 69 | 5089F1BC1E1FDD3800FADE27 /* Redstone.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Redstone.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 70 | 5089F1BE1E1FDD3800FADE27 /* Redstone.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Redstone.h; sourceTree = ""; }; 71 | 5089F1BF1E1FDD3800FADE27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 72 | 5089F1C41E1FDD3800FADE27 /* RedstoneTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RedstoneTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 73 | 5089F1CB1E1FDD3800FADE27 /* RedstoneTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedstoneTests.swift; sourceTree = ""; }; 74 | 5089F1CD1E1FDD3800FADE27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 75 | 5089F1DA1E1FDD5300FADE27 /* StateMachine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StateMachine.swift; sourceTree = ""; }; 76 | /* End PBXFileReference section */ 77 | 78 | /* Begin PBXFrameworksBuildPhase section */ 79 | 5089F19F1E1FDCBC00FADE27 /* Frameworks */ = { 80 | isa = PBXFrameworksBuildPhase; 81 | buildActionMask = 2147483647; 82 | files = ( 83 | 5089F1D11E1FDD3800FADE27 /* Redstone.framework in Frameworks */, 84 | ); 85 | runOnlyForDeploymentPostprocessing = 0; 86 | }; 87 | 5089F1B81E1FDD3800FADE27 /* Frameworks */ = { 88 | isa = PBXFrameworksBuildPhase; 89 | buildActionMask = 2147483647; 90 | files = ( 91 | ); 92 | runOnlyForDeploymentPostprocessing = 0; 93 | }; 94 | 5089F1C11E1FDD3800FADE27 /* Frameworks */ = { 95 | isa = PBXFrameworksBuildPhase; 96 | buildActionMask = 2147483647; 97 | files = ( 98 | 5089F1C51E1FDD3800FADE27 /* Redstone.framework in Frameworks */, 99 | ); 100 | runOnlyForDeploymentPostprocessing = 0; 101 | }; 102 | /* End PBXFrameworksBuildPhase section */ 103 | 104 | /* Begin PBXGroup section */ 105 | 5089F1991E1FDCBC00FADE27 = { 106 | isa = PBXGroup; 107 | children = ( 108 | 5089F1A41E1FDCBC00FADE27 /* Minecraft */, 109 | 5089F1BD1E1FDD3800FADE27 /* Redstone */, 110 | 5089F1CA1E1FDD3800FADE27 /* RedstoneTests */, 111 | 5089F1A31E1FDCBC00FADE27 /* Products */, 112 | ); 113 | sourceTree = ""; 114 | }; 115 | 5089F1A31E1FDCBC00FADE27 /* Products */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 5089F1A21E1FDCBC00FADE27 /* Minecraft.app */, 119 | 5089F1BC1E1FDD3800FADE27 /* Redstone.framework */, 120 | 5089F1C41E1FDD3800FADE27 /* RedstoneTests.xctest */, 121 | ); 122 | name = Products; 123 | sourceTree = ""; 124 | }; 125 | 5089F1A41E1FDCBC00FADE27 /* Minecraft */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 5089F1A51E1FDCBC00FADE27 /* AppDelegate.swift */, 129 | 5089F1A71E1FDCBC00FADE27 /* ViewController.swift */, 130 | 5089F1A91E1FDCBC00FADE27 /* Main.storyboard */, 131 | 5089F1AC1E1FDCBC00FADE27 /* Assets.xcassets */, 132 | 5089F1AE1E1FDCBC00FADE27 /* LaunchScreen.storyboard */, 133 | 5089F1B11E1FDCBC00FADE27 /* Info.plist */, 134 | ); 135 | path = Minecraft; 136 | sourceTree = ""; 137 | }; 138 | 5089F1BD1E1FDD3800FADE27 /* Redstone */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | 5089F1BE1E1FDD3800FADE27 /* Redstone.h */, 142 | 5089F1DA1E1FDD5300FADE27 /* StateMachine.swift */, 143 | 5089F1BF1E1FDD3800FADE27 /* Info.plist */, 144 | ); 145 | path = Redstone; 146 | sourceTree = ""; 147 | }; 148 | 5089F1CA1E1FDD3800FADE27 /* RedstoneTests */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | 5089F1CB1E1FDD3800FADE27 /* RedstoneTests.swift */, 152 | 5089F1CD1E1FDD3800FADE27 /* Info.plist */, 153 | ); 154 | path = RedstoneTests; 155 | sourceTree = ""; 156 | }; 157 | /* End PBXGroup section */ 158 | 159 | /* Begin PBXHeadersBuildPhase section */ 160 | 5089F1B91E1FDD3800FADE27 /* Headers */ = { 161 | isa = PBXHeadersBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 5089F1CE1E1FDD3800FADE27 /* Redstone.h in Headers */, 165 | ); 166 | runOnlyForDeploymentPostprocessing = 0; 167 | }; 168 | /* End PBXHeadersBuildPhase section */ 169 | 170 | /* Begin PBXNativeTarget section */ 171 | 5089F1A11E1FDCBC00FADE27 /* Minecraft */ = { 172 | isa = PBXNativeTarget; 173 | buildConfigurationList = 5089F1B41E1FDCBC00FADE27 /* Build configuration list for PBXNativeTarget "Minecraft" */; 174 | buildPhases = ( 175 | 5089F19E1E1FDCBC00FADE27 /* Sources */, 176 | 5089F19F1E1FDCBC00FADE27 /* Frameworks */, 177 | 5089F1A01E1FDCBC00FADE27 /* Resources */, 178 | 5089F1D61E1FDD3800FADE27 /* Embed Frameworks */, 179 | ); 180 | buildRules = ( 181 | ); 182 | dependencies = ( 183 | 5089F1D01E1FDD3800FADE27 /* PBXTargetDependency */, 184 | ); 185 | name = Minecraft; 186 | productName = Minecraft; 187 | productReference = 5089F1A21E1FDCBC00FADE27 /* Minecraft.app */; 188 | productType = "com.apple.product-type.application"; 189 | }; 190 | 5089F1BB1E1FDD3800FADE27 /* Redstone */ = { 191 | isa = PBXNativeTarget; 192 | buildConfigurationList = 5089F1D31E1FDD3800FADE27 /* Build configuration list for PBXNativeTarget "Redstone" */; 193 | buildPhases = ( 194 | 5089F1B71E1FDD3800FADE27 /* Sources */, 195 | 5089F1B81E1FDD3800FADE27 /* Frameworks */, 196 | 5089F1B91E1FDD3800FADE27 /* Headers */, 197 | 5089F1BA1E1FDD3800FADE27 /* Resources */, 198 | ); 199 | buildRules = ( 200 | ); 201 | dependencies = ( 202 | ); 203 | name = Redstone; 204 | productName = Redstone; 205 | productReference = 5089F1BC1E1FDD3800FADE27 /* Redstone.framework */; 206 | productType = "com.apple.product-type.framework"; 207 | }; 208 | 5089F1C31E1FDD3800FADE27 /* RedstoneTests */ = { 209 | isa = PBXNativeTarget; 210 | buildConfigurationList = 5089F1D71E1FDD3800FADE27 /* Build configuration list for PBXNativeTarget "RedstoneTests" */; 211 | buildPhases = ( 212 | 5089F1C01E1FDD3800FADE27 /* Sources */, 213 | 5089F1C11E1FDD3800FADE27 /* Frameworks */, 214 | 5089F1C21E1FDD3800FADE27 /* Resources */, 215 | ); 216 | buildRules = ( 217 | ); 218 | dependencies = ( 219 | 5089F1C71E1FDD3800FADE27 /* PBXTargetDependency */, 220 | 5089F1C91E1FDD3800FADE27 /* PBXTargetDependency */, 221 | ); 222 | name = RedstoneTests; 223 | productName = RedstoneTests; 224 | productReference = 5089F1C41E1FDD3800FADE27 /* RedstoneTests.xctest */; 225 | productType = "com.apple.product-type.bundle.unit-test"; 226 | }; 227 | /* End PBXNativeTarget section */ 228 | 229 | /* Begin PBXProject section */ 230 | 5089F19A1E1FDCBC00FADE27 /* Project object */ = { 231 | isa = PBXProject; 232 | attributes = { 233 | LastSwiftUpdateCheck = 0820; 234 | LastUpgradeCheck = 1010; 235 | ORGANIZATIONNAME = nixWork; 236 | TargetAttributes = { 237 | 5089F1A11E1FDCBC00FADE27 = { 238 | CreatedOnToolsVersion = 8.2; 239 | DevelopmentTeam = 8D957V42M6; 240 | LastSwiftMigration = 1010; 241 | ProvisioningStyle = Automatic; 242 | }; 243 | 5089F1BB1E1FDD3800FADE27 = { 244 | CreatedOnToolsVersion = 8.2; 245 | DevelopmentTeam = 8D957V42M6; 246 | LastSwiftMigration = 1010; 247 | ProvisioningStyle = Automatic; 248 | }; 249 | 5089F1C31E1FDD3800FADE27 = { 250 | CreatedOnToolsVersion = 8.2; 251 | DevelopmentTeam = 8D957V42M6; 252 | LastSwiftMigration = 1010; 253 | ProvisioningStyle = Automatic; 254 | TestTargetID = 5089F1A11E1FDCBC00FADE27; 255 | }; 256 | }; 257 | }; 258 | buildConfigurationList = 5089F19D1E1FDCBC00FADE27 /* Build configuration list for PBXProject "Minecraft" */; 259 | compatibilityVersion = "Xcode 3.2"; 260 | developmentRegion = English; 261 | hasScannedForEncodings = 0; 262 | knownRegions = ( 263 | en, 264 | Base, 265 | ); 266 | mainGroup = 5089F1991E1FDCBC00FADE27; 267 | productRefGroup = 5089F1A31E1FDCBC00FADE27 /* Products */; 268 | projectDirPath = ""; 269 | projectRoot = ""; 270 | targets = ( 271 | 5089F1A11E1FDCBC00FADE27 /* Minecraft */, 272 | 5089F1BB1E1FDD3800FADE27 /* Redstone */, 273 | 5089F1C31E1FDD3800FADE27 /* RedstoneTests */, 274 | ); 275 | }; 276 | /* End PBXProject section */ 277 | 278 | /* Begin PBXResourcesBuildPhase section */ 279 | 5089F1A01E1FDCBC00FADE27 /* Resources */ = { 280 | isa = PBXResourcesBuildPhase; 281 | buildActionMask = 2147483647; 282 | files = ( 283 | 5089F1B01E1FDCBC00FADE27 /* LaunchScreen.storyboard in Resources */, 284 | 5089F1AD1E1FDCBC00FADE27 /* Assets.xcassets in Resources */, 285 | 5089F1AB1E1FDCBC00FADE27 /* Main.storyboard in Resources */, 286 | ); 287 | runOnlyForDeploymentPostprocessing = 0; 288 | }; 289 | 5089F1BA1E1FDD3800FADE27 /* Resources */ = { 290 | isa = PBXResourcesBuildPhase; 291 | buildActionMask = 2147483647; 292 | files = ( 293 | ); 294 | runOnlyForDeploymentPostprocessing = 0; 295 | }; 296 | 5089F1C21E1FDD3800FADE27 /* Resources */ = { 297 | isa = PBXResourcesBuildPhase; 298 | buildActionMask = 2147483647; 299 | files = ( 300 | ); 301 | runOnlyForDeploymentPostprocessing = 0; 302 | }; 303 | /* End PBXResourcesBuildPhase section */ 304 | 305 | /* Begin PBXSourcesBuildPhase section */ 306 | 5089F19E1E1FDCBC00FADE27 /* Sources */ = { 307 | isa = PBXSourcesBuildPhase; 308 | buildActionMask = 2147483647; 309 | files = ( 310 | 5089F1A81E1FDCBC00FADE27 /* ViewController.swift in Sources */, 311 | 5089F1A61E1FDCBC00FADE27 /* AppDelegate.swift in Sources */, 312 | ); 313 | runOnlyForDeploymentPostprocessing = 0; 314 | }; 315 | 5089F1B71E1FDD3800FADE27 /* Sources */ = { 316 | isa = PBXSourcesBuildPhase; 317 | buildActionMask = 2147483647; 318 | files = ( 319 | 5089F1DB1E1FDD5300FADE27 /* StateMachine.swift in Sources */, 320 | ); 321 | runOnlyForDeploymentPostprocessing = 0; 322 | }; 323 | 5089F1C01E1FDD3800FADE27 /* Sources */ = { 324 | isa = PBXSourcesBuildPhase; 325 | buildActionMask = 2147483647; 326 | files = ( 327 | 5089F1CC1E1FDD3800FADE27 /* RedstoneTests.swift in Sources */, 328 | ); 329 | runOnlyForDeploymentPostprocessing = 0; 330 | }; 331 | /* End PBXSourcesBuildPhase section */ 332 | 333 | /* Begin PBXTargetDependency section */ 334 | 5089F1C71E1FDD3800FADE27 /* PBXTargetDependency */ = { 335 | isa = PBXTargetDependency; 336 | target = 5089F1BB1E1FDD3800FADE27 /* Redstone */; 337 | targetProxy = 5089F1C61E1FDD3800FADE27 /* PBXContainerItemProxy */; 338 | }; 339 | 5089F1C91E1FDD3800FADE27 /* PBXTargetDependency */ = { 340 | isa = PBXTargetDependency; 341 | target = 5089F1A11E1FDCBC00FADE27 /* Minecraft */; 342 | targetProxy = 5089F1C81E1FDD3800FADE27 /* PBXContainerItemProxy */; 343 | }; 344 | 5089F1D01E1FDD3800FADE27 /* PBXTargetDependency */ = { 345 | isa = PBXTargetDependency; 346 | target = 5089F1BB1E1FDD3800FADE27 /* Redstone */; 347 | targetProxy = 5089F1CF1E1FDD3800FADE27 /* PBXContainerItemProxy */; 348 | }; 349 | /* End PBXTargetDependency section */ 350 | 351 | /* Begin PBXVariantGroup section */ 352 | 5089F1A91E1FDCBC00FADE27 /* Main.storyboard */ = { 353 | isa = PBXVariantGroup; 354 | children = ( 355 | 5089F1AA1E1FDCBC00FADE27 /* Base */, 356 | ); 357 | name = Main.storyboard; 358 | sourceTree = ""; 359 | }; 360 | 5089F1AE1E1FDCBC00FADE27 /* LaunchScreen.storyboard */ = { 361 | isa = PBXVariantGroup; 362 | children = ( 363 | 5089F1AF1E1FDCBC00FADE27 /* Base */, 364 | ); 365 | name = LaunchScreen.storyboard; 366 | sourceTree = ""; 367 | }; 368 | /* End PBXVariantGroup section */ 369 | 370 | /* Begin XCBuildConfiguration section */ 371 | 5089F1B21E1FDCBC00FADE27 /* Debug */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ALWAYS_SEARCH_USER_PATHS = NO; 375 | CLANG_ANALYZER_NONNULL = YES; 376 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 377 | CLANG_CXX_LIBRARY = "libc++"; 378 | CLANG_ENABLE_MODULES = YES; 379 | CLANG_ENABLE_OBJC_ARC = YES; 380 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 381 | CLANG_WARN_BOOL_CONVERSION = YES; 382 | CLANG_WARN_COMMA = YES; 383 | CLANG_WARN_CONSTANT_CONVERSION = YES; 384 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 385 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 386 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 387 | CLANG_WARN_EMPTY_BODY = YES; 388 | CLANG_WARN_ENUM_CONVERSION = YES; 389 | CLANG_WARN_INFINITE_RECURSION = YES; 390 | CLANG_WARN_INT_CONVERSION = YES; 391 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 392 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 393 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 394 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 395 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 396 | CLANG_WARN_STRICT_PROTOTYPES = YES; 397 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 398 | CLANG_WARN_UNREACHABLE_CODE = YES; 399 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 400 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 401 | COPY_PHASE_STRIP = NO; 402 | DEBUG_INFORMATION_FORMAT = dwarf; 403 | ENABLE_STRICT_OBJC_MSGSEND = YES; 404 | ENABLE_TESTABILITY = YES; 405 | GCC_C_LANGUAGE_STANDARD = gnu99; 406 | GCC_DYNAMIC_NO_PIC = NO; 407 | GCC_NO_COMMON_BLOCKS = YES; 408 | GCC_OPTIMIZATION_LEVEL = 0; 409 | GCC_PREPROCESSOR_DEFINITIONS = ( 410 | "DEBUG=1", 411 | "$(inherited)", 412 | ); 413 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 414 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 415 | GCC_WARN_UNDECLARED_SELECTOR = YES; 416 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 417 | GCC_WARN_UNUSED_FUNCTION = YES; 418 | GCC_WARN_UNUSED_VARIABLE = YES; 419 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 420 | MTL_ENABLE_DEBUG_INFO = YES; 421 | ONLY_ACTIVE_ARCH = YES; 422 | SDKROOT = iphoneos; 423 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 424 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 425 | SWIFT_VERSION = 4.0; 426 | TARGETED_DEVICE_FAMILY = "1,2"; 427 | }; 428 | name = Debug; 429 | }; 430 | 5089F1B31E1FDCBC00FADE27 /* Release */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | ALWAYS_SEARCH_USER_PATHS = NO; 434 | CLANG_ANALYZER_NONNULL = YES; 435 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 436 | CLANG_CXX_LIBRARY = "libc++"; 437 | CLANG_ENABLE_MODULES = YES; 438 | CLANG_ENABLE_OBJC_ARC = YES; 439 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 440 | CLANG_WARN_BOOL_CONVERSION = YES; 441 | CLANG_WARN_COMMA = YES; 442 | CLANG_WARN_CONSTANT_CONVERSION = YES; 443 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 444 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 445 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 446 | CLANG_WARN_EMPTY_BODY = YES; 447 | CLANG_WARN_ENUM_CONVERSION = YES; 448 | CLANG_WARN_INFINITE_RECURSION = YES; 449 | CLANG_WARN_INT_CONVERSION = YES; 450 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 451 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 452 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 453 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 454 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 455 | CLANG_WARN_STRICT_PROTOTYPES = YES; 456 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 457 | CLANG_WARN_UNREACHABLE_CODE = YES; 458 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 459 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 460 | COPY_PHASE_STRIP = NO; 461 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 462 | ENABLE_NS_ASSERTIONS = NO; 463 | ENABLE_STRICT_OBJC_MSGSEND = YES; 464 | GCC_C_LANGUAGE_STANDARD = gnu99; 465 | GCC_NO_COMMON_BLOCKS = YES; 466 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 467 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 468 | GCC_WARN_UNDECLARED_SELECTOR = YES; 469 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 470 | GCC_WARN_UNUSED_FUNCTION = YES; 471 | GCC_WARN_UNUSED_VARIABLE = YES; 472 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 473 | MTL_ENABLE_DEBUG_INFO = NO; 474 | SDKROOT = iphoneos; 475 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 476 | SWIFT_VERSION = 4.0; 477 | TARGETED_DEVICE_FAMILY = "1,2"; 478 | VALIDATE_PRODUCT = YES; 479 | }; 480 | name = Release; 481 | }; 482 | 5089F1B51E1FDCBC00FADE27 /* Debug */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 486 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 487 | DEVELOPMENT_TEAM = 8D957V42M6; 488 | INFOPLIST_FILE = Minecraft/Info.plist; 489 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 490 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 491 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.Minecraft; 492 | PRODUCT_NAME = "$(TARGET_NAME)"; 493 | SWIFT_VERSION = 4.2; 494 | }; 495 | name = Debug; 496 | }; 497 | 5089F1B61E1FDCBC00FADE27 /* Release */ = { 498 | isa = XCBuildConfiguration; 499 | buildSettings = { 500 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 501 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 502 | DEVELOPMENT_TEAM = 8D957V42M6; 503 | INFOPLIST_FILE = Minecraft/Info.plist; 504 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 505 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 506 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.Minecraft; 507 | PRODUCT_NAME = "$(TARGET_NAME)"; 508 | SWIFT_VERSION = 4.2; 509 | }; 510 | name = Release; 511 | }; 512 | 5089F1D41E1FDD3800FADE27 /* Debug */ = { 513 | isa = XCBuildConfiguration; 514 | buildSettings = { 515 | APPLICATION_EXTENSION_API_ONLY = YES; 516 | CLANG_ENABLE_MODULES = YES; 517 | CODE_SIGN_IDENTITY = ""; 518 | CURRENT_PROJECT_VERSION = 1; 519 | DEFINES_MODULE = YES; 520 | DEVELOPMENT_TEAM = 8D957V42M6; 521 | DYLIB_COMPATIBILITY_VERSION = 1; 522 | DYLIB_CURRENT_VERSION = 1; 523 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 524 | INFOPLIST_FILE = Redstone/Info.plist; 525 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 526 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 527 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 528 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.Redstone; 529 | PRODUCT_NAME = "$(TARGET_NAME)"; 530 | SKIP_INSTALL = YES; 531 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 532 | SWIFT_VERSION = 4.2; 533 | VERSIONING_SYSTEM = "apple-generic"; 534 | VERSION_INFO_PREFIX = ""; 535 | }; 536 | name = Debug; 537 | }; 538 | 5089F1D51E1FDD3800FADE27 /* Release */ = { 539 | isa = XCBuildConfiguration; 540 | buildSettings = { 541 | APPLICATION_EXTENSION_API_ONLY = YES; 542 | CLANG_ENABLE_MODULES = YES; 543 | CODE_SIGN_IDENTITY = ""; 544 | CURRENT_PROJECT_VERSION = 1; 545 | DEFINES_MODULE = YES; 546 | DEVELOPMENT_TEAM = 8D957V42M6; 547 | DYLIB_COMPATIBILITY_VERSION = 1; 548 | DYLIB_CURRENT_VERSION = 1; 549 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 550 | INFOPLIST_FILE = Redstone/Info.plist; 551 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 552 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 553 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 554 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.Redstone; 555 | PRODUCT_NAME = "$(TARGET_NAME)"; 556 | SKIP_INSTALL = YES; 557 | SWIFT_VERSION = 4.2; 558 | VERSIONING_SYSTEM = "apple-generic"; 559 | VERSION_INFO_PREFIX = ""; 560 | }; 561 | name = Release; 562 | }; 563 | 5089F1D81E1FDD3800FADE27 /* Debug */ = { 564 | isa = XCBuildConfiguration; 565 | buildSettings = { 566 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 567 | DEVELOPMENT_TEAM = 8D957V42M6; 568 | INFOPLIST_FILE = RedstoneTests/Info.plist; 569 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 570 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 571 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.RedstoneTests; 572 | PRODUCT_NAME = "$(TARGET_NAME)"; 573 | SWIFT_VERSION = 4.2; 574 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Minecraft.app/Minecraft"; 575 | }; 576 | name = Debug; 577 | }; 578 | 5089F1D91E1FDD3800FADE27 /* Release */ = { 579 | isa = XCBuildConfiguration; 580 | buildSettings = { 581 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 582 | DEVELOPMENT_TEAM = 8D957V42M6; 583 | INFOPLIST_FILE = RedstoneTests/Info.plist; 584 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 585 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 586 | PRODUCT_BUNDLE_IDENTIFIER = com.nixWork.RedstoneTests; 587 | PRODUCT_NAME = "$(TARGET_NAME)"; 588 | SWIFT_VERSION = 4.2; 589 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Minecraft.app/Minecraft"; 590 | }; 591 | name = Release; 592 | }; 593 | /* End XCBuildConfiguration section */ 594 | 595 | /* Begin XCConfigurationList section */ 596 | 5089F19D1E1FDCBC00FADE27 /* Build configuration list for PBXProject "Minecraft" */ = { 597 | isa = XCConfigurationList; 598 | buildConfigurations = ( 599 | 5089F1B21E1FDCBC00FADE27 /* Debug */, 600 | 5089F1B31E1FDCBC00FADE27 /* Release */, 601 | ); 602 | defaultConfigurationIsVisible = 0; 603 | defaultConfigurationName = Release; 604 | }; 605 | 5089F1B41E1FDCBC00FADE27 /* Build configuration list for PBXNativeTarget "Minecraft" */ = { 606 | isa = XCConfigurationList; 607 | buildConfigurations = ( 608 | 5089F1B51E1FDCBC00FADE27 /* Debug */, 609 | 5089F1B61E1FDCBC00FADE27 /* Release */, 610 | ); 611 | defaultConfigurationIsVisible = 0; 612 | defaultConfigurationName = Release; 613 | }; 614 | 5089F1D31E1FDD3800FADE27 /* Build configuration list for PBXNativeTarget "Redstone" */ = { 615 | isa = XCConfigurationList; 616 | buildConfigurations = ( 617 | 5089F1D41E1FDD3800FADE27 /* Debug */, 618 | 5089F1D51E1FDD3800FADE27 /* Release */, 619 | ); 620 | defaultConfigurationIsVisible = 0; 621 | defaultConfigurationName = Release; 622 | }; 623 | 5089F1D71E1FDD3800FADE27 /* Build configuration list for PBXNativeTarget "RedstoneTests" */ = { 624 | isa = XCConfigurationList; 625 | buildConfigurations = ( 626 | 5089F1D81E1FDD3800FADE27 /* Debug */, 627 | 5089F1D91E1FDD3800FADE27 /* Release */, 628 | ); 629 | defaultConfigurationIsVisible = 0; 630 | defaultConfigurationName = Release; 631 | }; 632 | /* End XCConfigurationList section */ 633 | }; 634 | rootObject = 5089F19A1E1FDCBC00FADE27 /* Project object */; 635 | } 636 | -------------------------------------------------------------------------------- /Minecraft.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Minecraft.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Minecraft.xcodeproj/xcshareddata/xcschemes/Redstone.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Minecraft/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Minecraft 4 | // 5 | // Created by nixzhu on 2017/1/6. 6 | // Copyright © 2017年 nixWork. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | return true 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Minecraft/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Minecraft/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Minecraft/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Minecraft/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.1.0 19 | CFBundleVersion 20 | 13 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Minecraft/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Minecraft 4 | // 5 | // Created by nixzhu on 2017/1/6. 6 | // Copyright © 2017年 nixWork. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Redstone 11 | 12 | class ViewController: UIViewController { 13 | 14 | var statusBarStyle: UIStatusBarStyle = .default { 15 | didSet { 16 | setNeedsStatusBarAppearanceUpdate() 17 | } 18 | } 19 | 20 | override var preferredStatusBarStyle: UIStatusBarStyle { 21 | return statusBarStyle 22 | } 23 | 24 | lazy var promptLabel: UILabel = { 25 | let label = UILabel() 26 | label.textAlignment = .center 27 | return label 28 | }() 29 | 30 | enum State: Int { 31 | case off 32 | case on 33 | case broken 34 | } 35 | enum Transition: Int { 36 | case turn 37 | case cut 38 | } 39 | lazy var stateMachine: StateMachine = { 40 | let stateMachine = StateMachine() 41 | stateMachine.add(state: .off) { [weak self] in 42 | self?.statusBarStyle = .lightContent 43 | self?.view.backgroundColor = .black 44 | self?.promptLabel.textColor = .white 45 | self?.promptLabel.text = "Tap to turn lights on" 46 | } 47 | stateMachine.add(state: .on) { [weak self] in 48 | self?.statusBarStyle = .default 49 | self?.view.backgroundColor = .white 50 | self?.promptLabel.textColor = .black 51 | self?.promptLabel.text = "Tap to turn lights off" 52 | } 53 | stateMachine.add(state: .broken) { [weak self] in 54 | self?.statusBarStyle = .lightContent 55 | self?.view.backgroundColor = .black 56 | self?.promptLabel.textColor = .white 57 | self?.promptLabel.text = "The wire is broken :[" 58 | } 59 | stateMachine.add(transition: .turn, fromState: .off, toState: .on) 60 | stateMachine.add(transition: .turn, fromState: .on, toState: .off) 61 | stateMachine.add(transition: .cut, fromStates: [.on, .off], toState: .broken) 62 | return stateMachine 63 | }() 64 | 65 | override func loadView() { 66 | super.loadView() 67 | 68 | view.addSubview(promptLabel) 69 | promptLabel.translatesAutoresizingMaskIntoConstraints = false 70 | NSLayoutConstraint.activate([ 71 | NSLayoutConstraint(item: promptLabel, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0), 72 | NSLayoutConstraint(item: promptLabel, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: 1, constant: 0) 73 | ] 74 | ) 75 | } 76 | 77 | override func viewDidLoad() { 78 | super.viewDidLoad() 79 | 80 | stateMachine.initialState = .off 81 | 82 | let tap = UITapGestureRecognizer(target: self, action: #selector(tap(_:))) 83 | view.addGestureRecognizer(tap) 84 | 85 | let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPress(_:))) 86 | view.addGestureRecognizer(longPress) 87 | } 88 | 89 | @objc func tap(_ sender: UITapGestureRecognizer) { 90 | stateMachine.fire(transition: .turn) 91 | } 92 | 93 | @objc func longPress(_ sender: UILongPressGestureRecognizer) { 94 | stateMachine.fire(transition: .cut) 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 |

5 | 6 | # Redstone 7 | 8 | Redstone has a State Machine. 9 | 10 | ## Requirements 11 | 12 | Swift 4, iOS 8 13 | 14 | (Swift 3, use version 0.3.0) 15 | 16 | ## Example 17 | 18 | If your room has lights, you can turn it on or turn it off. If you cut the wire, it will borken. 19 | 20 | ![Lights](https://github.com/nixzhu/Redstone/raw/master/Images/lights.png) 21 | 22 | We can define states and transitions to descripe the state machine: 23 | 24 | ``` swift 25 | import Redstone 26 | 27 | class Lights { 28 | enum State: Int { 29 | case off 30 | case on 31 | case broken 32 | } 33 | enum Transition: Int { 34 | case turn 35 | case cut 36 | } 37 | lazy var stateMachine: StateMachine = { 38 | let stateMachine = StateMachine() 39 | stateMachine.add(state: .off) { 40 | print("Lights off") 41 | } 42 | stateMachine.add(state: .on) { 43 | print("Lights on") 44 | } 45 | stateMachine.add(state: .broken) { 46 | print("Lights broken") 47 | } 48 | stateMachine.add(transition: .turn, fromState: .off, toState: .on) 49 | stateMachine.add(transition: .turn, fromState: .on, toState: .off) 50 | stateMachine.add(transition: .cut, fromStates: [.on, .off], toState: .broken) 51 | return stateMachine 52 | }() 53 | } 54 | ``` 55 | 56 | We create a lights, set it's initial state to off. 57 | 58 | ``` swift 59 | let lights = Lights() 60 | lights.stateMachine.initialState = .off 61 | ``` 62 | 63 | Now you can turn the lights from off to on, or from on to off: 64 | 65 | ``` swift 66 | lights.stateMachine.fire(transition: .turn) 67 | ``` 68 | 69 | Or cut the wire: 70 | 71 | ``` swift 72 | lights.stateMachine.fire(transition: .cut) 73 | ``` 74 | 75 | It will can not been turn on again. 76 | 77 | Run the demo to feel it if you like. 78 | 79 | ## Installation 80 | 81 | ### Carthage 82 | 83 | ```ogdl 84 | github "nixzhu/Redstone" 85 | ``` 86 | 87 | ### CocoaPods 88 | 89 | ```ruby 90 | pod 'Redstone' 91 | ``` 92 | 93 | ## Contact 94 | 95 | NIX [@nixzhu](https://twitter.com/nixzhu) 96 | 97 | ## License 98 | 99 | Redstone is available under the MIT license. See the LICENSE file for more info. 100 | 101 | -------------------------------------------------------------------------------- /Redstone.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "Redstone" 4 | s.version = "0.4.0" 5 | s.summary = "Redstone has a State Machine." 6 | 7 | s.description = <<-DESC 8 | Redstone has a simple State Machine. 9 | DESC 10 | 11 | s.homepage = "https://github.com/nixzhu/Redstone" 12 | 13 | s.license = { :type => "MIT", :file => "LICENSE" } 14 | 15 | s.authors = { "nixzhu" => "zhuhongxu@gmail.com" } 16 | s.social_media_url = "https://twitter.com/nixzhu" 17 | 18 | s.ios.deployment_target = "8.0" 19 | 20 | s.source = { :git => "https://github.com/nixzhu/Redstone.git", :tag => s.version } 21 | s.source_files = "Redstone/*.swift" 22 | s.requires_arc = true 23 | 24 | end 25 | -------------------------------------------------------------------------------- /Redstone/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.4.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Redstone/Redstone.h: -------------------------------------------------------------------------------- 1 | // 2 | // Redstone.h 3 | // Redstone 4 | // 5 | // Created by nixzhu on 2017/1/6. 6 | // Copyright © 2017年 nixWork. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Redstone. 12 | FOUNDATION_EXPORT double RedstoneVersionNumber; 13 | 14 | //! Project version string for Redstone. 15 | FOUNDATION_EXPORT const unsigned char RedstoneVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Redstone/StateMachine.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StateMachine.swift 3 | // Redstone 4 | // 5 | // Created by nixzhu on 2017/1/6. 6 | // Copyright © 2017年 nixWork. All rights reserved. 7 | // 8 | 9 | public class StateMachine { 10 | public typealias Operation = () -> Void 11 | private var body = [State: Operation?]() 12 | public private(set) var previousState: State? 13 | public private(set) var lastTransition: Transition? 14 | public private(set) var currentState: State? { 15 | willSet { 16 | previousState = currentState 17 | } 18 | didSet { 19 | if let state = currentState { 20 | body[state]??() 21 | } 22 | } 23 | } 24 | public var initialState: State? { 25 | didSet { 26 | if oldValue == nil, initialState != nil { 27 | currentState = initialState 28 | } 29 | } 30 | } 31 | private var stateTransitionTable: [State: [Transition: State]] = [:] 32 | public init() { 33 | } 34 | public func add(state: State, entryOperation: Operation?) { 35 | body[state] = entryOperation 36 | } 37 | public func add(transition: Transition, fromState: State, toState: State) { 38 | var bag = stateTransitionTable[fromState] ?? [:] 39 | bag[transition] = toState 40 | stateTransitionTable[fromState] = bag 41 | } 42 | public func add(transition: Transition, fromStates: Set, toState: State) { 43 | fromStates.forEach { 44 | add(transition: transition, fromState: $0, toState: toState) 45 | } 46 | } 47 | public func fire(transition: Transition) { 48 | guard let state = currentState else { return } 49 | guard let toState = stateTransitionTable[state]?[transition] else { return } 50 | lastTransition = transition 51 | currentState = toState 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /RedstoneTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /RedstoneTests/RedstoneTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RedstoneTests.swift 3 | // RedstoneTests 4 | // 5 | // Created by nixzhu on 2017/1/6. 6 | // Copyright © 2017年 nixWork. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Redstone 11 | 12 | class RedstoneTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measure { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------