Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SB template project with Swift AppDelegates, Swift autocomplete fixes, group paths fixed #1414

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
31 changes: 29 additions & 2 deletions SpriteBuilder/ccBuilder/CCBProjectCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ -(BOOL) createDefaultProjectAtPath:(NSString*)fileName engine:(CCBTargetEngine)e
inFile:pbxprojFile
search:@"MACOSX_DEPLOYMENT_TARGET = 10.10"];
[self removeLinesMatching:@".*MainScene[.]swift.*" inFile:pbxprojFile];
filesToRemove = @[@"Source/MainScene.swift"];
[self removeLinesMatching:@".*AppDelegate[.]swift.*" inFile:pbxprojFile];
filesToRemove = @[@"Source/MainScene.swift", @"Source/Platforms/iOS/AppDelegate.swift", @"Source/Platforms/Mac/AppDelegate.swift"];
}
else if (programmingLanguage == CCBProgrammingLanguageSwift)
{
[self removeLinesMatching:@".*MainScene[.][hm].*" inFile:pbxprojFile];
filesToRemove = @[@"Source/MainScene.h", @"Source/MainScene.m"];
[self removeLinesMatching:@".*AppDelegate[.][hm].*" inFile:pbxprojFile];
[self removeLinesMatching:@".*main[.][m].*" inFile:pbxprojFile];
filesToRemove = @[@"Source/MainScene.h", @"Source/MainScene.m",
@"Source/Platforms/iOS/AppDelegate.h", @"Source/Platforms/iOS/AppDelegate.m", @"Source/Platforms/iOS/main.m",
@"Source/Platforms/Mac/AppDelegate.h", @"Source/Platforms/Mac/AppDelegate.m", @"Source/Platforms/Mac/main.m"];
}

for (NSString *file in filesToRemove)
Expand Down Expand Up @@ -157,6 +162,12 @@ -(BOOL) createDefaultProjectAtPath:(NSString*)fileName engine:(CCBTargetEngine)e

// Update Mac Xib file
NSString* xibFileName = [parentPath stringByAppendingPathComponent:@"Source/Resources/Platforms/Mac/MainMenu.xib"];
if (programmingLanguage == CCBProgrammingLanguageObjectiveC)
{
// this fixes the ObjC Mac target not being able to "find" the AppDelegate class
// CAUTION: This has to be performed *before* the substitutions below since "PROJECTNAME" is a substring of the search string
[self removeAppDelegateModuleAndTargetFromXib:xibFileName];
}
[self setName:identifier inFile:xibFileName search:substitutableProjectIdentifier];
[self setName:projName inFile:xibFileName search:substitutableProjectName];

Expand Down Expand Up @@ -235,4 +246,20 @@ - (void) removeLinesMatching:(NSString*)pattern inFile:(NSString*)fileName
[updatedFileData writeToFile:fileName atomically:YES];
}

-(void) removeAppDelegateModuleAndTargetFromXib:(NSString*)xibFileName
{
// this fixes the ObjC Mac target not being able to "find" the AppDelegate class because the Xib specified a custom module and target,
// which coincidentally is necessary for the Mac target in Swift to find the AppDelegate - so best solution was to setup Main.xib so
// that it works with Swift and removing the module & target for ObjC projects
NSData *fileData = [NSData dataWithContentsOfFile:xibFileName];
NSString *fileString = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];

NSString* searchFor = @"customClass=\"AppDelegate\" customModule=\"PROJECTNAME\" customModuleProvider=\"target\"";
NSString* replaceWith = @"customClass=\"AppDelegate\"";
fileString = [fileString stringByReplacingOccurrencesOfString:searchFor withString:replaceWith];

NSData *updatedFileData = [fileString dataUsingEncoding:NSUTF8StringEncoding];
[updatedFileData writeToFile:xibFileName atomically:YES];
}

@end
4 changes: 2 additions & 2 deletions SpriteBuilder/ccBuilder/en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
Expand Down Expand Up @@ -221,7 +221,7 @@
<menuItem isSeparatorItem="YES" id="mar-Cw-LBm">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
<menuItem title="Open Project in XCode" keyEquivalent="O" id="1797" userLabel="Menu Item - p.A.">
<menuItem title="Open Project in Xcode" keyEquivalent="O" id="1797" userLabel="Menu Item - p.A.">
<connections>
<action selector="menuOpenProjectInXCode:" target="494" id="wcV-zy-HFJ"/>
<binding destination="494" name="enabled" keyPath="projectSettings" id="1799">
Expand Down
Loading