diff --git a/src/Catty.xcodeproj/project.pbxproj b/src/Catty.xcodeproj/project.pbxproj index a55b5f5c55..49691ca5b0 100644 --- a/src/Catty.xcodeproj/project.pbxproj +++ b/src/Catty.xcodeproj/project.pbxproj @@ -34,6 +34,8 @@ 0594CE62275E55B0007DC3F9 /* SewUpBrickCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0594CE61275E55B0007DC3F9 /* SewUpBrickCell.swift */; }; 0594CE64275E55CD007DC3F9 /* SewUpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0594CE63275E55CD007DC3F9 /* SewUpTests.swift */; }; 0594CE66275E567E007DC3F9 /* SewUpBrickTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0594CE65275E567D007DC3F9 /* SewUpBrickTests.swift */; }; + 05744DF925C84328005455F9 /* XMLParseMultipleScenesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05744DF825C84328005455F9 /* XMLParseMultipleScenesTests.swift */; }; + 05744E0A25C8437C005455F9 /* MultipleScenes.xml in Resources */ = {isa = PBXBuildFile; fileRef = 05744E0925C8437C005455F9 /* MultipleScenes.xml */; }; 05A3CE6D24F5164A0051DB39 /* CatrobatTableViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05A3CE6A24F516490051DB39 /* CatrobatTableViewControllerExtension.swift */; }; 05A3D46824F517220051DB39 /* StoreProjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05A3D46724F517220051DB39 /* StoreProjectTests.swift */; }; 05CBC6BF286C5A4B007FBA61 /* TripleStitchPattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05CBC6BC286C5A4B007FBA61 /* TripleStitchPattern.swift */; }; @@ -2175,6 +2177,8 @@ 0594CE61275E55B0007DC3F9 /* SewUpBrickCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SewUpBrickCell.swift; sourceTree = ""; }; 0594CE63275E55CD007DC3F9 /* SewUpTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SewUpTests.swift; sourceTree = ""; }; 0594CE65275E567D007DC3F9 /* SewUpBrickTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SewUpBrickTests.swift; sourceTree = ""; }; + 05744DF825C84328005455F9 /* XMLParseMultipleScenesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XMLParseMultipleScenesTests.swift; sourceTree = ""; }; + 05744E0925C8437C005455F9 /* MultipleScenes.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = MultipleScenes.xml; sourceTree = ""; }; 05A3CE6A24F516490051DB39 /* CatrobatTableViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CatrobatTableViewControllerExtension.swift; sourceTree = ""; }; 05A3D46724F517220051DB39 /* StoreProjectTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreProjectTests.swift; sourceTree = ""; }; 05CBC6BC286C5A4B007FBA61 /* TripleStitchPattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TripleStitchPattern.swift; sourceTree = ""; }; @@ -4846,6 +4850,12 @@ 056677EC27DBD33E006B4477 /* ZigzagStitchPattern.swift */, ); path = Pattern; + 05744DEF25C84234005455F9 /* MultipleScenes */ = { + isa = PBXGroup; + children = ( + 05744E0925C8437C005455F9 /* MultipleScenes.xml */, + ); + path = MultipleScenes; sourceTree = ""; }; 05E68011255B5DAA00D1E295 /* Embroidery */ = { @@ -5449,6 +5459,7 @@ children = ( C8076A26267A0B2000801AF6 /* Functions */, E5C5D89525B1DEAF00D96E4B /* Object */, + 05744DEF25C84234005455F9 /* MultipleScenes */, 9E384934256191DC002D8F28 /* SamplerBricks */, D3EBE87C2488E6A90026F51A /* GoToBricks */, D3AF5C1C243F81FC00B04BC6 /* DisabledBricks */, @@ -6125,6 +6136,7 @@ 4C2CBB3125A5AA8400C1C143 /* Helper */, 4C2CBB0825A5AA8400C1C143 /* UserListXMLHandlerTests.m */, 4C2CBB0725A5AA8400C1C143 /* SceneXMLHandlerTest.m */, + 05744DF825C84328005455F9 /* XMLParseMultipleScenesTests.swift */, ); path = XML; sourceTree = ""; @@ -11999,6 +12011,9 @@ E5EC6D5426B00FF60031F13A /* Galaxy_War_09993.xml in Resources */, 7B37463529AD168A0085A90D /* StoreProjectUploader.upload.fail.validation.json in Resources */, E59108B926931E49008D254A /* DisabledBricks_0994.xml in Resources */, + 05744E0A25C8437C005455F9 /* MultipleScenes.xml in Resources */, + 2DCB4928212EA477005E8E3D /* StoreProjectDownloader.fetchMostViewedProjects.fail.request.json in Resources */, + 2ED41844241120B000AFE2FD /* Minions__093.xml in Resources */, 2ED41875241120B000AFE2FD /* LedFlashBrick0991.xml in Resources */, E5DAAD6026C5486000C2457F /* ValidHeader09997.xml in Resources */, E598BBC226A029C900D4825F /* EscapingChars_0996.xml in Resources */, @@ -12568,6 +12583,7 @@ 9E2C2D8E23257387004B66C6 /* AbstractBrickTest.swift in Sources */, 49402BA528117A63009FCBF8 /* MiddleFingerSensorTest.swift in Sources */, 4CD487761ED2C2A3001BB80A /* ChangeVariableBrickTests.swift in Sources */, + 05744DF925C84328005455F9 /* XMLParseMultipleScenesTests.swift in Sources */, E57E6D85254040B400E775DF /* ChangeVolumeByNBrickTests.swift in Sources */, 2E8780A82542BCE200816B52 /* WebRequestBrickTests.swift in Sources */, 499EBFE127EB07A900897349 /* EyeSensorTest.swift in Sources */, diff --git a/src/Catty/DataModel/Project/Project.h b/src/Catty/DataModel/Project/Project.h index 3e053001aa..dae1a2d022 100644 --- a/src/Catty/DataModel/Project/Project.h +++ b/src/Catty/DataModel/Project/Project.h @@ -31,7 +31,9 @@ @interface Project : NSObject @property (nonatomic, strong, nonnull) Header *header; -@property (nonatomic, strong, nonnull) Scene *scene; +@property (nonatomic, strong, nonnull) NSMutableArray *scenes; +@property (nonatomic, strong, nonnull) Scene *scene DEPRECATED_ATTRIBUTE; //needed for compadability with "Old Parser" +@property (nonatomic, strong, nonnull) Scene *activeScene; @property (nonatomic, strong, nonnull) UserDataContainer *userData; @property (nonatomic, strong, nonnull) NSMutableSet *unsupportedElements; @property (nonatomic, strong, nonnull) NSMutableSet *physicsObjectNames; diff --git a/src/Catty/DataModel/Project/Project.m b/src/Catty/DataModel/Project/Project.m index a8acb15a9f..0fc8d3097f 100644 --- a/src/Catty/DataModel/Project/Project.m +++ b/src/Catty/DataModel/Project/Project.m @@ -42,6 +42,8 @@ - (instancetype)init { _allBroadcastMessages = [[NSMutableOrderedSet alloc] init]; } + self.scenes = [[NSMutableArray alloc] init]; + [self.scenes addObject: [[Scene alloc] init]]; return self; } @@ -153,7 +155,11 @@ - (void)renameToProjectName:(NSString*)projectName andProjectId:(NSString*)proje - (NSArray*)allObjects { - return self.scene.objects; + NSMutableArray *objects = [[NSMutableArray alloc] init]; + for (Scene* scene in self.scenes) { + [objects addObjectsFromArray: [scene objects]]; + } + return objects; } - (void)setDescription:(NSString*)description @@ -163,7 +169,9 @@ - (void)setDescription:(NSString*)description - (void)removeReferences { - [self.scene.objects makeObjectsPerformSelector:@selector(removeReferences)]; + for (Scene* scene in self.scenes){ + [scene.objects makeObjectsPerformSelector:@selector(removeReferences)]; + } } - (BOOL)isEqualToProject:(Project*)project @@ -172,14 +180,23 @@ - (BOOL)isEqualToProject:(Project*)project return NO; if (! [self.userData isEqual:project.userData]) return NO; - if (![self.scene isEqual:project.scene]) + if ([self.scenes count] != [project.scenes count]) return NO; + for (int i = 0; i < [self.scenes count]; ++i) { + if (![[self.scenes objectAtIndex: i] isEqual: [project.scenes objectAtIndex: i]]) + return NO; + } + return YES; } - (NSInteger)getRequiredResources { - return [self.scene getRequiredResources]; + NSInteger requiredResources = 0; + for (Scene* scene in self.scenes) { + requiredResources |= [scene getRequiredResources]; + } + return requiredResources; } #pragma mark - helpers @@ -204,7 +221,7 @@ - (NSString*)description [ret appendFormat:@"Screen Height: %@\n", self.header.screenHeight]; [ret appendFormat:@"Screen Width: %@\n", self.header.screenWidth]; [ret appendFormat:@"Screen Mode: %@\n", self.header.screenMode]; - [ret appendFormat:@"Scene: %@\n", self.scene]; + [ret appendFormat:@"First Scene: %@\n", [self.scenes objectAtIndex:0]]; [ret appendFormat:@"URL: %@\n", self.header.url]; [ret appendFormat:@"User Handle: %@\n", self.header.userHandle]; [ret appendFormat:@"Variables: %@\n", self.userData]; @@ -397,19 +414,21 @@ + (void)removeProjectFromDiskWithProjectName:(NSString*)projectName projectID:(N - (void)translateDefaultProject { - NSUInteger index = 0; - for (SpriteObject *spriteObject in self.scene.objects) { - if (index == kBackgroundObjectIndex) { - spriteObject.name = kLocalizedBackground; - } else { - NSMutableString *spriteObjectName = [NSMutableString stringWithString:spriteObject.name]; - [spriteObjectName replaceOccurrencesOfString:kDefaultProjectBundleOtherObjectsNamePrefix - withString:kLocalizedMole - options:NSCaseInsensitiveSearch - range:NSMakeRange(0, spriteObjectName.length)]; - spriteObject.name = (NSString*)spriteObjectName; + for (Scene* scene in self.scenes) { + NSUInteger index = 0; + for (SpriteObject *spriteObject in scene.objects) { + if (index == kBackgroundObjectIndex) { + spriteObject.name = kLocalizedBackground; + } else { + NSMutableString *spriteObjectName = [NSMutableString stringWithString:spriteObject.name]; + [spriteObjectName replaceOccurrencesOfString:kDefaultProjectBundleOtherObjectsNamePrefix + withString:kLocalizedMole + options:NSCaseInsensitiveSearch + range:NSMakeRange(0, spriteObjectName.length)]; + spriteObject.name = (NSString*)spriteObjectName; + } + ++index; } - ++index; } [self renameToProjectName:kLocalizedMyFirstProject andShowSaveNotification:NO]; // saves to disk! } diff --git a/src/Catty/Extension&Delegate&Protocol/Extensions/UIViewController/UIViewControllerExtension.swift b/src/Catty/Extension&Delegate&Protocol/Extensions/UIViewController/UIViewControllerExtension.swift index 78dd64a855..f1bdfa51d6 100644 --- a/src/Catty/Extension&Delegate&Protocol/Extensions/UIViewController/UIViewControllerExtension.swift +++ b/src/Catty/Extension&Delegate&Protocol/Extensions/UIViewController/UIViewControllerExtension.swift @@ -44,15 +44,10 @@ extension UIViewController { @objc func openLoginScreen(_ delegate: AuthenticationDelegate? = nil) { let storyboard = UIStoryboard.init(name: "iPhone", bundle: nil) - guard let viewController = storyboard.instantiateViewController(withIdentifier: "LoginController") as? LoginViewController else { return } - viewController.delegate = delegate - self.navigationController?.pushViewController(viewController, animated: true) - } - - @objc func openProject(_ project: Project) { - guard let viewController = self.instantiateViewController("SceneTableViewController") as? SceneTableViewController else { return } + guard let viewController = storyboard.instantiateViewController(withIdentifier: "SceneTableViewController") + as? SceneTableViewController, let scene = project.scenes[0] as? Scene else { return } - viewController.scene = project.scene + viewController.scene = scene project.setAsLastUsedProject() self.navigationController?.pushViewController(viewController, animated: true) } diff --git a/src/Catty/IO/ProjectManager.swift b/src/Catty/IO/ProjectManager.swift index c81c82f209..49d89ed8d6 100644 --- a/src/Catty/IO/ProjectManager.swift +++ b/src/Catty/IO/ProjectManager.swift @@ -35,32 +35,34 @@ @objc func createProject(name: String, projectId: String?) -> Project { let project = Project() let projectName = Util.uniqueName(name, existingNames: Project.allProjectNames()) - project.scene = Scene(name: Util.defaultSceneName(forSceneNumber: 1)) - project.scene.project = project project.header = Header.default() project.header.programName = projectName project.header.programID = projectId + let scene = Scene(name: Util.defaultSceneName(forSceneNumber: 1)) + scene.project = project + if fileManager.directoryExists(projectName) == false { fileManager.createDirectory(project.projectPath()) } - let sceneDir = project.scene.path() + let sceneDir = scene.path() if !fileManager.directoryExists(sceneDir) { fileManager.createDirectory(sceneDir) } - let imagesDirName = project.scene.imagesPath() + let imagesDirName = scene.imagesPath() if fileManager.directoryExists(imagesDirName) == false { fileManager.createDirectory(imagesDirName) } - let soundDirName = project.scene.soundsPath() + let soundDirName = scene.soundsPath() if fileManager.directoryExists(soundDirName) == false { fileManager.createDirectory(soundDirName) } - project.scene.addObject(withName: kLocalizedBackground) + scene.addObject(withName: kLocalizedBackground) + project.scenes[0] = scene let filePath = project.projectPath() + kScreenshotAutoFilename let projectIconNames = UIDefines.defaultScreenshots diff --git a/src/Catty/PlayerEngine/Frontend/CBFrontend.swift b/src/Catty/PlayerEngine/Frontend/CBFrontend.swift index 18f290750f..c5e82886fb 100644 --- a/src/Catty/PlayerEngine/Frontend/CBFrontend.swift +++ b/src/Catty/PlayerEngine/Frontend/CBFrontend.swift @@ -24,13 +24,11 @@ final class CBFrontend: CBFrontendProtocol { // MARK: - Properties let logger: CBLogger - private(set) weak var project: Project? private lazy var _sequenceFilters = [CBFrontendSequenceFilterProtocol]() // MARK: - Initializers - init(logger: CBLogger, project: Project?) { + init(logger: CBLogger) { self.logger = logger - self.project = project } // MARK: - Operations diff --git a/src/Catty/PlayerEngine/Protocols/CBFrontendProtocol.swift b/src/Catty/PlayerEngine/Protocols/CBFrontendProtocol.swift index 39a29b1f68..3615910299 100644 --- a/src/Catty/PlayerEngine/Protocols/CBFrontendProtocol.swift +++ b/src/Catty/PlayerEngine/Protocols/CBFrontendProtocol.swift @@ -22,9 +22,6 @@ protocol CBFrontendProtocol { - var project: Project? { get } - func computeSequenceListForScript(_ script: Script) -> CBScriptSequenceList func addSequenceFilter(_ sequenceFilter: CBFrontendSequenceFilterProtocol) - } diff --git a/src/Catty/PlayerEngine/Sensors/Object/LayerSensor.swift b/src/Catty/PlayerEngine/Sensors/Object/LayerSensor.swift index 1d29479223..a2330d1388 100644 --- a/src/Catty/PlayerEngine/Sensors/Object/LayerSensor.swift +++ b/src/Catty/PlayerEngine/Sensors/Object/LayerSensor.swift @@ -61,11 +61,11 @@ } static func defaultRawValue(for spriteObject: SpriteObject) -> Double { - guard let project = spriteObject.scene.project else { + guard let scene = spriteObject.scene else { return defaultRawValue } - let objectList = project.scene.objects() + let objectList = scene.objects() var zPosition = defaultRawValue for object in objectList { if object == spriteObject { diff --git a/src/Catty/PlayerEngine/Stage/Builder/StageBuilder.swift b/src/Catty/PlayerEngine/Stage/Builder/StageBuilder.swift index bac035aad3..8282df47a6 100644 --- a/src/Catty/PlayerEngine/Stage/Builder/StageBuilder.swift +++ b/src/Catty/PlayerEngine/Stage/Builder/StageBuilder.swift @@ -90,7 +90,12 @@ let audioEngine = getAudioEngine() let scheduler = getScheduler(broadcastHandler: broadcastHandler, formulaInterpreter: formulaManager, audioEngine: audioEngine) - return Stage(size: size, + guard let scene = project.scenes[0] as? Scene else { + preconditionFailure() + } + + return Stage(scene: scene, + size: size, logger: logger, scheduler: scheduler, frontend: frontend, @@ -125,7 +130,7 @@ private func getFrontend() -> CBFrontendProtocol { guard let frontend = self.frontend else { guard let frontendLogger = Swell.getLogger(LoggerConfig.PlayerFrontendID) else { preconditionFailure() } - let frontend = CBFrontend(logger: frontendLogger, project: project) + let frontend = CBFrontend(logger: frontendLogger) frontend.addSequenceFilter(CBFilterDisabled()) return frontend } diff --git a/src/Catty/PlayerEngine/Stage/Stage.swift b/src/Catty/PlayerEngine/Stage/Stage.swift index 31732b0e5d..1f2df1a438 100644 --- a/src/Catty/PlayerEngine/Stage/Stage.swift +++ b/src/Catty/PlayerEngine/Stage/Stage.swift @@ -27,6 +27,7 @@ final class Stage: SKScene, StageProtocol { // MARK: - Properties final let scheduler: CBSchedulerProtocol + private final let CBScene: Scene private final let frontend: CBFrontendProtocol private final let backend: CBBackendProtocol private final let broadcastHandler: CBBroadcastHandlerProtocol @@ -35,7 +36,8 @@ final class Stage: SKScene, StageProtocol { private final let logger: CBLogger private var frameCounter: Int - init(size: CGSize, + init(scene: Scene, + size: CGSize, logger: CBLogger, scheduler: CBSchedulerProtocol, frontend: CBFrontendProtocol, @@ -43,6 +45,7 @@ final class Stage: SKScene, StageProtocol { broadcastHandler: CBBroadcastHandlerProtocol, formulaManager: FormulaManagerProtocol, soundEngine: AudioEngineProtocol) { + self.CBScene = scene self.logger = logger self.scheduler = scheduler self.frontend = frontend @@ -149,16 +152,12 @@ final class Stage: SKScene, StageProtocol { // MARK: - Start project @objc func startProject() -> Bool { - guard let project = frontend.project else { - //fatalError - debugPrint("Invalid project. This should never happen!") - return false - } - guard let spriteObjectList = project.scene.objects() as NSArray? as? [SpriteObject], + guard let spriteObjectList = CBScene.objects() as NSArray? as? [SpriteObject], + let project = CBScene.project, let variableList = UserDataContainer.allVariables(for: project) as NSArray? as? [UserVariable] else { //fatalError - debugPrint("!! Invalid sprite object list given !! This should never happen!") + debugPrint("!! Invalid scene or sprite object list given !! This should never happen!") return false } assert(Thread.current.isMainThread) diff --git a/src/Catty/ViewController/Stage/StagePresenterViewController.m b/src/Catty/ViewController/Stage/StagePresenterViewController.m index 18e595bcc3..57f5f4e1a1 100644 --- a/src/Catty/ViewController/Stage/StagePresenterViewController.m +++ b/src/Catty/ViewController/Stage/StagePresenterViewController.m @@ -304,17 +304,6 @@ - (void)setupStageAndStart [self continueActionWithDuration:UIDefines.firstSwipeDuration]; } --(void)resaveLooks -{ - dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ - for (SpriteObject *object in self.project.scene.objects) { - for (Look *look in object.lookList) { - [[RuntimeImageCache sharedImageCache] loadImageFromDiskWithPath:look.fileName]; - } - } - }); -} - - (BOOL)prefersStatusBarHidden { return YES; @@ -367,7 +356,7 @@ - (void)continueActionWithDuration:(CGFloat)duration self.menuOpen = NO; self.menuView.userInteractionEnabled = YES; if (animateDuration == duration) { - [self takeAutomaticScreenshotForSKView:self.skView andProject:self.project.scene]; + [self takeAutomaticScreenshotForSKView:self.skView andScene:[self.project.scenes objectAtIndex:0]]; } }]; self.skView.paused = NO; @@ -454,7 +443,7 @@ - (void)aspectRatioAction - (void)takeScreenshotAction { - [self takeManualScreenshotForSKView:self.skView andProject:self.project.scene]; + [self takeManualScreenshotForSKView:self.skView andScene: [self.project.scenes objectAtIndex: 0]]; } - (void)shareDSTAction diff --git a/src/Catty/ViewController/Stage/StagePresenterViewControllerScreenshotExtension.swift b/src/Catty/ViewController/Stage/StagePresenterViewControllerScreenshotExtension.swift index 33e81ac4e1..b986827836 100644 --- a/src/Catty/ViewController/Stage/StagePresenterViewControllerScreenshotExtension.swift +++ b/src/Catty/ViewController/Stage/StagePresenterViewControllerScreenshotExtension.swift @@ -25,13 +25,13 @@ public static var previewImageWidth: CGFloat { UIScreen.main.bounds.width } public static var previewImageHeight: CGFloat { previewImageWidth } - @objc(takeAutomaticScreenshotForSKView: andProject:) + @objc(takeAutomaticScreenshotForSKView: andScene:) func takeAutomaticScreenshot(for skView: SKView, and scene: Scene) { guard let snapshot = self.screenshot(for: skView) else { return } saveScreenshot(snapshot, for: scene, manualScreenshot: false) } - @objc(takeManualScreenshotForSKView: andProject:) + @objc(takeManualScreenshotForSKView: andScene:) func takeManualScreenshot(for skView: SKView, and scene: Scene) { guard let snapshot = self.screenshot(for: skView) else { return } saveScreenshot(snapshot, for: scene, manualScreenshot: true) diff --git a/src/Catty/XML/Old Parser/ProjectParser.m b/src/Catty/XML/Old Parser/ProjectParser.m index 74382c2ec0..7c6e7033b6 100644 --- a/src/Catty/XML/Old Parser/ProjectParser.m +++ b/src/Catty/XML/Old Parser/ProjectParser.m @@ -99,6 +99,7 @@ - (id)loadProject:(NSData*)xmlData { @try { NSInfo(@"Loading Project..."); project = [self parseNode:doc.rootElement withParent:nil]; + project.scenes[0] = project.scene; NSInfo(@"Loading done..."); } @catch(NSException* ex) { NSError(@"Project could not be loaded! %@", [ex description]); diff --git a/src/Catty/XML/XMLHandler/Project/Project+CBXMLHandler.m b/src/Catty/XML/XMLHandler/Project/Project+CBXMLHandler.m index fe27370336..7a70426517 100644 --- a/src/Catty/XML/XMLHandler/Project/Project+CBXMLHandler.m +++ b/src/Catty/XML/XMLHandler/Project/Project+CBXMLHandler.m @@ -42,25 +42,24 @@ + (instancetype)parseFromElement:(GDataXMLElement*)xmlElement withContext:(CBXML [XMLError exceptionIfNode:xmlElement isNilOrNodeNameNotEquals:@"program"]; [XMLError exceptionIfNil:context message:@"No context given!"]; Project *project = [Project new]; + [project.scenes removeAllObjects]; // IMPORTANT: DO NOT CHANGE ORDER HERE!! project.header = [self parseAndCreateHeaderFromElement:xmlElement withContext:context]; project.userData = [self parseAndCreateVariablesFromElement:xmlElement withContext:context]; if ([xmlElement childWithElementName:@"scenes"]) { - Scene *scene = [self parseAndCreateSceneFromElement:xmlElement withContext:context]; - scene.project = project; - project.scene = scene; + [self parseAndCreateSceneFromElement:xmlElement ofProject:project withContext:context]; } else { - project.scene = [[Scene alloc] initWithName: [Util defaultSceneNameForSceneNumber:1]]; - project.scene.project = project; + Scene *scene = [[Scene alloc] initWithName: [Util defaultSceneNameForSceneNumber:1]]; + project.scenes[0] = scene; + scene.project = project; for (SpriteObject *object in [Scene parseAndCreateObjectsFromElement:xmlElement withContext:context]) { //when project will contain [scenes] then object.scene will be equal to scene where the objects belongs to - object.scene = project.scene; + object.scene = scene; object.scene.project = project; //when project will contain [scenes] then object will be added to the scene where it belongs and add scene to [scene] of project - [project.scene addObject:object]; + [scene addObject:object]; } } - return project; } @@ -93,7 +92,8 @@ + (SpriteObject *)getSpriteObject:(NSString*)spriteName withContext:(CBXMLParser return object; } -+ (Scene *)parseAndCreateSceneFromElement:(GDataXMLElement*)projectElement withContext:(CBXMLParserContext*)context ++ (void)parseAndCreateSceneFromElement:(GDataXMLElement*)projectElement + ofProject: (Project*)project withContext:(CBXMLParserContext*)context { NSArray *scenesElements = [projectElement elementsForName:@"scenes"]; [XMLError exceptionIf:[scenesElements count] notEquals:1 message:@"No scenes given!"]; @@ -102,17 +102,23 @@ + (Scene *)parseAndCreateSceneFromElement:(GDataXMLElement*)projectElement withC message:@"No scene in scenes, but there must exist "\ "at least 1 scene!!"]; - GDataXMLElement *sceneElement = [sceneElements firstObject]; - Scene *scene = [context parseFromElement:sceneElement withClass:[Scene class]]; - - return scene; + for (GDataXMLElement *sceneElement in sceneElements) { + Scene* scene = [context parseFromElement:sceneElement withClass:[Scene class]]; + scene.project = project; + [project.scenes addObject: scene]; + [context.spriteObjectList removeAllObjects]; + [context.pointedSpriteObjectList removeAllObjects]; + } + return; } #pragma mark - Serialization - (GDataXMLElement*)xmlElementWithContext:(CBXMLSerializerContext*)context { + Scene* scene = [self.scenes objectAtIndex:0]; + // update context object - context.spriteObjectList = [[NSMutableArray alloc] initWithArray:self.scene.objects]; + context.spriteObjectList = [[NSMutableArray alloc] initWithArray: scene.objects]; // generate xml element for program GDataXMLElement *xmlElement = [GDataXMLElement elementWithName:@"program" context:context]; @@ -122,7 +128,7 @@ - (GDataXMLElement*)xmlElementWithContext:(CBXMLSerializerContext*)context [xmlElement addChild:[GDataXMLElement elementWithName:@"settings" context:nil]]; GDataXMLElement *scenes = [GDataXMLElement elementWithName:@"scenes" context:context]; - [scenes addChild:[self.scene xmlElementWithContext:context] context:context]; + [scenes addChild:[scene xmlElementWithContext:context] context:context]; [xmlElement addChild:scenes context:context]; if (self.userData) { diff --git a/src/CattyTests/Bricks/AskBrickTests.swift b/src/CattyTests/Bricks/AskBrickTests.swift index c56cdf7e2c..c6f5f6a16c 100644 --- a/src/CattyTests/Bricks/AskBrickTests.swift +++ b/src/CattyTests/Bricks/AskBrickTests.swift @@ -46,7 +46,7 @@ final class AskBrickTests: XCTestCase { spriteNode = CBSpriteNode(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/Bricks/BubbleBrickTests.swift b/src/CattyTests/Bricks/BubbleBrickTests.swift index 7431bc8b88..cc098faf80 100644 --- a/src/CattyTests/Bricks/BubbleBrickTests.swift +++ b/src/CattyTests/Bricks/BubbleBrickTests.swift @@ -50,12 +50,12 @@ final class BubbleBrickTests: XMLAbstractTest { spriteObject.scene = scene spriteObject.name = "SpriteObjectName" - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! let spriteNode = CBSpriteNodeMock(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene.add(object: spriteObject) + (project.scenes[0] as! Scene).add(object: spriteObject) spriteNode.mockedStage = StageBuilder(project: ProjectMock(width: CGFloat(kIphoneXStageWidth), andHeight: CGFloat(kIphoneXStageHeight))).build() BubbleBrickHelper.addBubble(to: spriteNode, withText: sentence, andType: CBBubbleType.thought) diff --git a/src/CattyTests/Bricks/ChangeBrightnessByNBrickTests.swift b/src/CattyTests/Bricks/ChangeBrightnessByNBrickTests.swift index cef05433a4..6f2d952dea 100644 --- a/src/CattyTests/Bricks/ChangeBrightnessByNBrickTests.swift +++ b/src/CattyTests/Bricks/ChangeBrightnessByNBrickTests.swift @@ -37,8 +37,8 @@ final class ChangeBrightnessByNBrickTests: AbstractBrickTest { brick = ChangeBrightnessByNBrick() script = WhenScript() object = SpriteObject() - project = ProjectManager.shared.createProject(name: "a", projectId: "1") - object.scene = project.scene + project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode object.scene.project = project diff --git a/src/CattyTests/Bricks/ChangeColorByNBrickTests.swift b/src/CattyTests/Bricks/ChangeColorByNBrickTests.swift index 03af184688..f5fbfe0da1 100644 --- a/src/CattyTests/Bricks/ChangeColorByNBrickTests.swift +++ b/src/CattyTests/Bricks/ChangeColorByNBrickTests.swift @@ -37,8 +37,8 @@ final class ChangeColorByNBrickTests: AbstractBrickTest { brick = ChangeColorByNBrick() script = WhenScript() object = SpriteObject() - project = ProjectManager.shared.createProject(name: "a", projectId: "1") - object.scene = project.scene + project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) spriteNode = CBSpriteNode(spriteObject: object) object.spriteNode = spriteNode object.scene.project = project diff --git a/src/CattyTests/Bricks/ChangeVariableBrickTests.swift b/src/CattyTests/Bricks/ChangeVariableBrickTests.swift index f484f854cf..aacbcf2987 100644 --- a/src/CattyTests/Bricks/ChangeVariableBrickTests.swift +++ b/src/CattyTests/Bricks/ChangeVariableBrickTests.swift @@ -38,7 +38,7 @@ final class ChangeVariableBrickTests: XCTestCase { let scene = Scene(name: "testScene") spriteObject = SpriteObject() spriteObject.scene = scene - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! spriteObject.name = "SpriteObjectName" spriteNode = CBSpriteNode(spriteObject: spriteObject) diff --git a/src/CattyTests/Bricks/ChooseCameraBrickTests.swift b/src/CattyTests/Bricks/ChooseCameraBrickTests.swift index a2bbf74797..bd94a84c5e 100644 --- a/src/CattyTests/Bricks/ChooseCameraBrickTests.swift +++ b/src/CattyTests/Bricks/ChooseCameraBrickTests.swift @@ -44,7 +44,7 @@ final class ChooseCameraBrickTests: XCTestCase { spriteNode = CBSpriteNode(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/Bricks/ClearGraphicEffectBrickTests.swift b/src/CattyTests/Bricks/ClearGraphicEffectBrickTests.swift index cc44af9493..8670eddea5 100644 --- a/src/CattyTests/Bricks/ClearGraphicEffectBrickTests.swift +++ b/src/CattyTests/Bricks/ClearGraphicEffectBrickTests.swift @@ -35,8 +35,8 @@ final class ClearGraphicEffectBrickTests: AbstractBrickTest { override func setUp() { super.setUp() object = SpriteObject() - project = ProjectManager.shared.createProject(name: "a", projectId: "1") - object.scene = project.scene + project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode self.stage.addChild(spriteNode) diff --git a/src/CattyTests/Bricks/ComeToFrontBrickTests.swift b/src/CattyTests/Bricks/ComeToFrontBrickTests.swift index f42369fa45..eb5085ae6b 100644 --- a/src/CattyTests/Bricks/ComeToFrontBrickTests.swift +++ b/src/CattyTests/Bricks/ComeToFrontBrickTests.swift @@ -30,7 +30,7 @@ final class ComeToFrontBrickTests: AbstractBrickTest { let project = Project() let scene = Scene(name: "testScene") scene.project = project - project.scene = scene + project.scenes[0] = scene let background = SpriteObject() background.scene = scene @@ -49,9 +49,9 @@ final class ComeToFrontBrickTests: AbstractBrickTest { object2.spriteNode = spriteNode2 spriteNode2.zPosition = 2 - project.scene.add(object: background) - project.scene.add(object: object1) - project.scene.add(object: object2) + (project.scenes[0] as! Scene).add(object: background) + (project.scenes[0] as! Scene).add(object: object1) + (project.scenes[0] as! Scene).add(object: object2) let script = WhenScript() script.object = object1 diff --git a/src/CattyTests/Bricks/DeleteItemOfUserListBrickTests.swift b/src/CattyTests/Bricks/DeleteItemOfUserListBrickTests.swift index ea2ac947f9..15bb013492 100644 --- a/src/CattyTests/Bricks/DeleteItemOfUserListBrickTests.swift +++ b/src/CattyTests/Bricks/DeleteItemOfUserListBrickTests.swift @@ -45,7 +45,7 @@ final class DeleteItemOfUserListBrickTests: XCTestCase { spriteNode = CBSpriteNode(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/Bricks/GoNStepsBackBrickTests.swift b/src/CattyTests/Bricks/GoNStepsBackBrickTests.swift index b1ed9fe031..310e6b1b65 100644 --- a/src/CattyTests/Bricks/GoNStepsBackBrickTests.swift +++ b/src/CattyTests/Bricks/GoNStepsBackBrickTests.swift @@ -40,7 +40,7 @@ final class GoNStepsBackBrickTests: AbstractBrickTest { project = Project() let scene = Scene(name: "testScene") scene.project = project - project.scene = scene + project.scenes[0] = scene object1 = SpriteObject() object1.scene = scene @@ -52,8 +52,8 @@ final class GoNStepsBackBrickTests: AbstractBrickTest { spriteNode2 = CBSpriteNode(spriteObject: object2) object2.spriteNode = spriteNode2 - project.scene.add(object: object1!) - project.scene.add(object: object2!) + (project.scenes[0] as! Scene).add(object: object1!) + (project.scenes[0] as! Scene).add(object: object2!) script = WhenScript() script.object = object1 diff --git a/src/CattyTests/Bricks/HideTextBrickTests.swift b/src/CattyTests/Bricks/HideTextBrickTests.swift index 35131fb398..07bf0e4e12 100644 --- a/src/CattyTests/Bricks/HideTextBrickTests.swift +++ b/src/CattyTests/Bricks/HideTextBrickTests.swift @@ -44,7 +44,7 @@ final class HideTextBrickTests: XCTestCase { spriteNode = CBSpriteNode(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/Bricks/InsertItemIntoUserListBrickTests.swift b/src/CattyTests/Bricks/InsertItemIntoUserListBrickTests.swift index 24cd61e6fa..fd44b33c6e 100644 --- a/src/CattyTests/Bricks/InsertItemIntoUserListBrickTests.swift +++ b/src/CattyTests/Bricks/InsertItemIntoUserListBrickTests.swift @@ -45,7 +45,7 @@ final class InsertItemIntoUserListBrickTests: XCTestCase { spriteNode = CBSpriteNode(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/Bricks/NextLookBrickTests.swift b/src/CattyTests/Bricks/NextLookBrickTests.swift index 60fa70e94c..368ef06cc3 100644 --- a/src/CattyTests/Bricks/NextLookBrickTests.swift +++ b/src/CattyTests/Bricks/NextLookBrickTests.swift @@ -30,6 +30,12 @@ final class NextLookBrickTests: AbstractBrickTest { var lookB: Look! var lookC: Look! var image: UIImage! + func testNextLookBrick() { + let object = SpriteObject() + let project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) + let spriteNode = CBSpriteNode(spriteObject: object) + object.spriteNode = spriteNode var scene: Scene! var spriteNode: CBSpriteNode! diff --git a/src/CattyTests/Bricks/PreviousLookBrickTests.swift b/src/CattyTests/Bricks/PreviousLookBrickTests.swift index 40a1ca1599..6f43210c6f 100644 --- a/src/CattyTests/Bricks/PreviousLookBrickTests.swift +++ b/src/CattyTests/Bricks/PreviousLookBrickTests.swift @@ -30,6 +30,12 @@ final class PreviousLookBrickTests: AbstractBrickTest { var lookB: Look! var lookC: Look! var image: UIImage! + func testNextLookBrick() { + let object = SpriteObject() + let project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) + let spriteNode = CBSpriteNode(spriteObject: object) + object.spriteNode = spriteNode var scene: Scene! var spriteNode: CBSpriteNode! diff --git a/src/CattyTests/Bricks/ReplaceItemInUserListBrickTests.swift b/src/CattyTests/Bricks/ReplaceItemInUserListBrickTests.swift index 9bba7a757f..6f16770c67 100644 --- a/src/CattyTests/Bricks/ReplaceItemInUserListBrickTests.swift +++ b/src/CattyTests/Bricks/ReplaceItemInUserListBrickTests.swift @@ -45,7 +45,7 @@ final class ReplaceItemInUserListBrickTests: XCTestCase { spriteNode = CBSpriteNode(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/Bricks/SetBrightnessBrickTests.swift b/src/CattyTests/Bricks/SetBrightnessBrickTests.swift index af7a844aec..596731a8ec 100644 --- a/src/CattyTests/Bricks/SetBrightnessBrickTests.swift +++ b/src/CattyTests/Bricks/SetBrightnessBrickTests.swift @@ -38,8 +38,8 @@ final class SetBrightnessBrickTests: AbstractBrickTest { script = WhenScript() object = SpriteObject() - project = ProjectManager.shared.createProject(name: "a", projectId: "1") - object.scene = project.scene + project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode diff --git a/src/CattyTests/Bricks/SetColorBrickTests.swift b/src/CattyTests/Bricks/SetColorBrickTests.swift index 46e89a9238..00e2593798 100644 --- a/src/CattyTests/Bricks/SetColorBrickTests.swift +++ b/src/CattyTests/Bricks/SetColorBrickTests.swift @@ -38,8 +38,8 @@ final class SetColorBrickTests: AbstractBrickTest { script = WhenScript() object = SpriteObject() - project = ProjectManager.shared.createProject(name: "a", projectId: "1") - object.scene = project.scene + project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode diff --git a/src/CattyTests/Bricks/SetLookBrickTests.swift b/src/CattyTests/Bricks/SetLookBrickTests.swift index 81f562caf1..9de70174ee 100644 --- a/src/CattyTests/Bricks/SetLookBrickTests.swift +++ b/src/CattyTests/Bricks/SetLookBrickTests.swift @@ -53,7 +53,6 @@ final class SetLookBrickTests: AbstractBrickTest { object.lookList.add(lookA!) object.lookList.add(lookB!) - spriteNode = CBSpriteNode(spriteObject: object) object.spriteNode = spriteNode diff --git a/src/CattyTests/Bricks/SetLookByIndexBrickTests.swift b/src/CattyTests/Bricks/SetLookByIndexBrickTests.swift index 5b8842ba59..c8a858604b 100644 --- a/src/CattyTests/Bricks/SetLookByIndexBrickTests.swift +++ b/src/CattyTests/Bricks/SetLookByIndexBrickTests.swift @@ -41,7 +41,7 @@ final class SetLookByIndexBrickTest: XCTestCase { override func setUp() { project = ProjectManager.shared.createProject(name: "setLookByIndexTest", projectId: "1") spriteObject = SpriteObject() - spriteObject.scene = project.scene + spriteObject.scene = (project.scenes[0] as! Scene) spriteObject.name = "SpriteObjectName" spriteNode = CBSpriteNode(spriteObject: spriteObject) diff --git a/src/CattyTests/Bricks/SetVariableBrickTests.swift b/src/CattyTests/Bricks/SetVariableBrickTests.swift index e060993cbb..ebd3d4658f 100644 --- a/src/CattyTests/Bricks/SetVariableBrickTests.swift +++ b/src/CattyTests/Bricks/SetVariableBrickTests.swift @@ -45,7 +45,7 @@ final class SetVariableBrickTests: XCTestCase { spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/Bricks/ShowTextBrickTests.swift b/src/CattyTests/Bricks/ShowTextBrickTests.swift index 16f58089c4..a5f76e4603 100644 --- a/src/CattyTests/Bricks/ShowTextBrickTests.swift +++ b/src/CattyTests/Bricks/ShowTextBrickTests.swift @@ -46,7 +46,7 @@ final class ShowTextBrickTests: XCTestCase { spriteObject.spriteNode = spriteNode spriteObject.scene.project = project - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! script = Script() script.object = spriteObject diff --git a/src/CattyTests/DataModel/LookTest.swift b/src/CattyTests/DataModel/LookTest.swift index 9bb2e9c83b..b2a5f37d8c 100644 --- a/src/CattyTests/DataModel/LookTest.swift +++ b/src/CattyTests/DataModel/LookTest.swift @@ -26,14 +26,10 @@ import XCTest final class LookTest: XCTestCase { - var project: Project! - var scene: Scene! - - override func setUp() { - project = Project() - scene = Scene(name: "testScene") - - project.scene = scene + func testPathForScene() { + let project = Project() + let scene = Scene(name: "testScene") + project.scenes[0] = scene scene.project = project } @@ -45,6 +41,11 @@ final class LookTest: XCTestCase { } func testIsEqual() { + let project = Project() + let scene = Scene(name: "testScene") + project.scenes[0] = scene + scene.project = project + let look = Look(name: "testLook", filePath: "testLookFile") let equalLook = Look(name: "testLook", filePath: "testLookFile") @@ -64,9 +65,9 @@ final class LookTest: XCTestCase { func testInitWithPath() { let object = SpriteObject() - object.scene = scene - - let spriteNode = CBSpriteNode(spriteObject: object) + let project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) + let spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode let bundle = Bundle(for: type(of: self)) @@ -82,9 +83,9 @@ final class LookTest: XCTestCase { func testInitWithName() { let object = SpriteObject() - object.scene = scene - - let spriteNode = CBSpriteNode(spriteObject: object) + let project = ProjectManager.createProject(name: "a", projectId: "1") + object.scene = (project.scenes[0] as! Scene) + let spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode let bundle = Bundle(for: type(of: self)) diff --git a/src/CattyTests/DataModel/SoundTest.swift b/src/CattyTests/DataModel/SoundTest.swift index 920a49d420..f734ff10b7 100644 --- a/src/CattyTests/DataModel/SoundTest.swift +++ b/src/CattyTests/DataModel/SoundTest.swift @@ -29,7 +29,7 @@ final class SoundTest: XCTestCase { func testPathForScene() { let project = Project() let scene = Scene(name: "testScene") - project.scene = scene + project.scenes[0] = scene scene.project = project let sound = Sound(name: "testSound", fileName: "testSoundFile") diff --git a/src/CattyTests/DataModel/UserDataContainerTest.swift b/src/CattyTests/DataModel/UserDataContainerTest.swift index e112030b7b..1ea878707d 100644 --- a/src/CattyTests/DataModel/UserDataContainerTest.swift +++ b/src/CattyTests/DataModel/UserDataContainerTest.swift @@ -39,7 +39,7 @@ final class UserDataContainerTest: XCTestCase { let scene = Scene(name: "testScene") - self.project.scene = scene + self.project.scenes[0] = scene self.objectA = SpriteObject() self.objectA.scene = scene @@ -51,10 +51,10 @@ final class UserDataContainerTest: XCTestCase { self.objectB.scene = scene self.objectB.scene.project = self.project - self.project.scene.add(object: objectA) - self.project.scene.add(object: objectB) + (self.project.scenes[0] as! Scene).add(object: objectA) + (self.project.scenes[0] as! Scene).add(object: objectB) - self.project.scene = objectA.scene + self.project.scenes[0] = objectA.scene! } func testAddObjectVariable() { @@ -359,7 +359,14 @@ final class UserDataContainerTest: XCTestCase { container.add(list) container.add(variable) - let copyContainer = container.mutableCopy(with: CBMutableCopyContext()) as! UserDataContainer + let copyContainer = container.mutableCopy() as! UserDataContainer + let copyProject = Project() + copyProject.scenes[0] = Scene() + (copyProject.scenes[0] as! Scene).add(object: objectA) + (copyProject.scenes[0] as! Scene).add(object: objectB) + copyProject.userData = copyContainer + + XCTAssertTrue(container.isEqual(copyContainer)) XCTAssertFalse(container === copyContainer) let copiedVariables = copyContainer.variables() diff --git a/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift b/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift index 3fa6ffb4df..cf8fe435e4 100644 --- a/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift +++ b/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift @@ -51,7 +51,7 @@ final class UIViewControllerExtensionTests: XCTestCase { let scene = Scene(name: "testScene") scene.project = project - project.scene = scene + project.scenes[0] = scene XCTAssertFalse(project.isLastUsedProject) diff --git a/src/CattyTests/PlayerEngine/CBBackendTests.swift b/src/CattyTests/PlayerEngine/CBBackendTests.swift index 69e44e9cc8..5c8e5f5ab7 100644 --- a/src/CattyTests/PlayerEngine/CBBackendTests.swift +++ b/src/CattyTests/PlayerEngine/CBBackendTests.swift @@ -42,7 +42,7 @@ final class CBBackendTests: XCTestCase { spriteNode = CBSpriteNode(spriteObject: spriteObject) spriteObject.spriteNode = spriteNode - frontend = CBFrontend(logger: logger, project: nil) + frontend = CBFrontend(logger: logger) backend = CBBackend(logger: logger) } diff --git a/src/CattyTests/PlayerEngine/Formula/FormulaManagerInterpreterTests.swift b/src/CattyTests/PlayerEngine/Formula/FormulaManagerInterpreterTests.swift index 9c31773c8d..9b95bb89ec 100644 --- a/src/CattyTests/PlayerEngine/Formula/FormulaManagerInterpreterTests.swift +++ b/src/CattyTests/PlayerEngine/Formula/FormulaManagerInterpreterTests.swift @@ -36,7 +36,7 @@ final class FormulaManagerInterpreterTests: XCTestCase { object = SpriteObject() object.scene = scene project = ProjectMock() - project.scene = object.scene + project.scenes[0] = object.scene! } func testInterpretDouble() { diff --git a/src/CattyTests/PlayerEngine/Frontend/CBFrontendTests.swift b/src/CattyTests/PlayerEngine/Frontend/CBFrontendTests.swift index 256c87b74f..ac40c956bf 100644 --- a/src/CattyTests/PlayerEngine/Frontend/CBFrontendTests.swift +++ b/src/CattyTests/PlayerEngine/Frontend/CBFrontendTests.swift @@ -29,7 +29,7 @@ final class CBFrontendTests: XCTestCase { let logger = Swell.getLogger(LoggerTestConfig.PlayerFrontendID)! func testComputeOperationSequence() { - let frontend = CBFrontend(logger: self.logger, project: nil) + let frontend = CBFrontend(logger: self.logger) let whenScript = WhenScript() whenScript.action = UIDefines.whenScriptDefaultAction let waitBrick = WaitBrick() @@ -79,7 +79,7 @@ final class CBFrontendTests: XCTestCase { } func testComputeIfElseConditionalSequence() { - let frontend = CBFrontend(logger: self.logger, project: nil) + let frontend = CBFrontend(logger: self.logger) let whenScript = WhenScript() whenScript.action = UIDefines.whenScriptDefaultAction let waitBrick = WaitBrick() @@ -195,7 +195,7 @@ final class CBFrontendTests: XCTestCase { } func testComputeIfThenConditionalSequence() { - let frontend = CBFrontend(logger: self.logger, project: nil) + let frontend = CBFrontend(logger: self.logger) let whenScript = WhenScript() whenScript.action = UIDefines.whenScriptDefaultAction let waitBrick = WaitBrick() diff --git a/src/CattyTests/PlayerEngine/Sensors/Object/BrightnessSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/Object/BrightnessSensorTest.swift index d4e30fec67..19dcbf3f42 100644 --- a/src/CattyTests/PlayerEngine/Sensors/Object/BrightnessSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/Object/BrightnessSensorTest.swift @@ -35,7 +35,7 @@ final class BrightnessSensorTest: XCTestCase { spriteObject = SpriteObject() spriteObject.scene = scene let project = Project() - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! spriteNode = CBSpriteNodeMock(spriteObject: spriteObject) sensor = BrightnessSensor() } diff --git a/src/CattyTests/PlayerEngine/Sensors/Object/LayerSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/Object/LayerSensorTest.swift index 57f8cf1a53..c386c1e3f6 100644 --- a/src/CattyTests/PlayerEngine/Sensors/Object/LayerSensorTest.swift +++ b/src/CattyTests/PlayerEngine/Sensors/Object/LayerSensorTest.swift @@ -48,16 +48,16 @@ final class LayerSensorTest: XCTestCase { func testDefaultRawValue() { let project = Project() scene.project = project - project.scene = scene + project.scenes[0] = scene! let spriteObjectA = SpriteObjectMock() - project.scene.add(object: spriteObjectA) + (project.scenes[0] as! Scene).add(object: spriteObjectA) let spriteObjectB = SpriteObjectMock() - project.scene.add(object: spriteObjectB) + (project.scenes[0] as! Scene).add(object: spriteObjectB) let spriteObjectC = SpriteObjectMock() - project.scene.add(object: spriteObjectC) + (project.scenes[0] as! Scene).add(object: spriteObjectC) XCTAssertEqual(type(of: sensor).defaultRawValue, type(of: sensor).defaultRawValue(for: spriteObjectA), accuracy: Double.epsilon) XCTAssertEqual(type(of: sensor).defaultRawValue, type(of: sensor).rawValue(for: spriteObjectA), accuracy: Double.epsilon) diff --git a/src/CattyTests/Project/ProjectMigratorTest.swift b/src/CattyTests/Project/ProjectMigratorTest.swift index c18c24b3eb..9a1a54ad21 100644 --- a/src/CattyTests/Project/ProjectMigratorTest.swift +++ b/src/CattyTests/Project/ProjectMigratorTest.swift @@ -40,8 +40,8 @@ class ProjectMigratorTest: XCTestCase { project = Project() project.header = header - project.scene = Scene(name: newFolderName) - project.scene.project = project + project.scenes[0] = Scene(name: newFolderName) + (project.scenes[0] as! Scene).project = project } func testMigrateToScene() { diff --git a/src/CattyTests/Project/ProjectTests.swift b/src/CattyTests/Project/ProjectTests.swift index 6f9db579cc..f95192bee0 100644 --- a/src/CattyTests/Project/ProjectTests.swift +++ b/src/CattyTests/Project/ProjectTests.swift @@ -38,7 +38,7 @@ class ProjectTests: XCTestCase { fileManager = CBFileManager.shared() deleteAllProjectsAndCreateDefaultProject() - self.scene = project.scene + self.scene = (project.scenes[0] as! Scene) self.object = SpriteObject() self.object.scene = scene } @@ -71,13 +71,13 @@ class ProjectTests: XCTestCase { } func testImagesDirectoryExists() { - let imageDirectory = project.scene.imagesPath() + let imageDirectory = (project.scenes[0] as! Scene).imagesPath() let directoryExists = fileManager.directoryExists(imageDirectory) XCTAssertTrue(directoryExists) } func testSoundsDirectoryExists() { - let soundsDirectory = project.scene.soundsPath() + let soundsDirectory = (project.scenes[0] as! Scene).soundsPath() let directoryExists = fileManager.directoryExists(soundsDirectory) XCTAssertTrue(directoryExists) } @@ -98,15 +98,15 @@ class ProjectTests: XCTestCase { let script = StartScript() script.brickList.addObjects(from: [ifThenLogicBeginBrick, ifThenLogicEndBrick] as [AnyObject]) object.scriptList.add(script) - project.scene.add(object: object) + (project.scenes[0] as! Scene).add(object: object) - let initialObjectSize = project.scene.objects().count + let initialObjectSize = (project.scenes[0] as! Scene).objects().count XCTAssertTrue(initialObjectSize > 0) - let copiedObject = project.scene.copy(object, withNameForCopiedObject: copiedObjectName)! + let copiedObject = (project.scenes[0] as! Scene).copy(object, withNameForCopiedObject: copiedObjectName)! XCTAssertEqual(1, copiedObject.scriptList.count) - let objectList = project.scene.objects() + let objectList = (project.scenes[0] as! Scene).objects() XCTAssertEqual(initialObjectSize + 1, objectList.count) XCTAssertEqual(copiedObjectName, (objectList[initialObjectSize] ).name) @@ -145,15 +145,15 @@ class ProjectTests: XCTestCase { let script = StartScript() script.brickList.addObjects(from: [ifLogicBeginBrick, ifLogicElseBrick, ifLogicEndBrick] as [AnyObject]) object.scriptList.add(script) - project.scene.add(object: object) + (project.scenes[0] as! Scene).add(object: object) - let initialObjectSize = project.scene.objects().count + let initialObjectSize = (project.scenes[0] as! Scene).objects().count XCTAssertTrue(initialObjectSize > 0) - let copiedObject = project.scene.copy(object, withNameForCopiedObject: copiedObjectName)! + let copiedObject = (project.scenes[0] as! Scene).copy(object, withNameForCopiedObject: copiedObjectName)! XCTAssertEqual(1, copiedObject.scriptList.count) - let objectList = project.scene.objects() + let objectList = (project.scenes[0] as! Scene).objects() XCTAssertEqual(initialObjectSize + 1, objectList.count) XCTAssertEqual(copiedObjectName, (objectList[initialObjectSize] ).name) @@ -184,7 +184,7 @@ class ProjectTests: XCTestCase { func testCopyObjectWithObjectVariable() { object.name = "newObjectName" - project.scene.add(object: object) + (project.scenes[0] as! Scene).add(object: object) let variable = UserVariable(name: "userVariable") object.userData.add(variable) @@ -196,16 +196,16 @@ class ProjectTests: XCTestCase { script.brickList.addObjects(from: [setVariableBrick] as [AnyObject]) object.scriptList.add(script) - let initialObjectSize = project.scene.objects().count + let initialObjectSize = (project.scenes[0] as! Scene).objects().count XCTAssertTrue(initialObjectSize > 0) let initialVariableSize = UserDataContainer.allVariables(for: project).count XCTAssertTrue(initialVariableSize > 0) - let copiedObject = project.scene.copy(object, withNameForCopiedObject: "copiedObjectName")! + let copiedObject = (project.scenes[0] as! Scene).copy(object, withNameForCopiedObject: "copiedObjectName")! XCTAssertEqual(1, copiedObject.scriptList.count) - let objectList = project.scene.objects() + let objectList = (project.scenes[0] as! Scene).objects() XCTAssertEqual(initialObjectSize + 1, objectList.count) XCTAssertEqual(initialVariableSize + 1, UserDataContainer.allVariables(for: project).count) XCTAssertEqual((objectList[initialObjectSize] ).name, copiedObject.name) @@ -223,7 +223,7 @@ class ProjectTests: XCTestCase { func testCopyObjectWithObjectList() { object.name = "newObjectName" - project.scene.add(object: object) + (project.scenes[0] as! Scene).add(object: object) let list = UserList(name: "userList") object.userData.add(list) @@ -235,16 +235,16 @@ class ProjectTests: XCTestCase { script.brickList.addObjects(from: [brick] as [AnyObject]) object.scriptList.add(script) - let initialObjectSize = project.scene.objects().count + let initialObjectSize = (project.scenes[0] as! Scene).objects().count XCTAssertTrue(initialObjectSize > 0) let initialListSize = UserDataContainer.allLists(for: project).count XCTAssertTrue(initialListSize > 0) - let copiedObject = project.scene.copy(object, withNameForCopiedObject: "copiedObjectName")! + let copiedObject = (project.scenes[0] as! Scene).copy(object, withNameForCopiedObject: "copiedObjectName")! XCTAssertEqual(1, copiedObject.scriptList.count) - let objectList = project.scene.objects() + let objectList = (project.scenes[0] as! Scene).objects() XCTAssertEqual(initialObjectSize + 1, objectList.count) XCTAssertEqual(initialListSize + 1, UserDataContainer.allLists(for: project).count) XCTAssertEqual((objectList[initialObjectSize] ).name, copiedObject.name) @@ -388,16 +388,16 @@ class ProjectTests: XCTestCase { func testAllObject() { self.project = Project() - self.project.scene = Scene() + self.project.scenes[0] = Scene() - XCTAssertEqual(0, self.project.scene.objects().count) + XCTAssertEqual(0, (self.project.scenes[0] as! Scene).objects().count) let objectA = SpriteObject() objectA.name = "objectA" - project.scene.add(object: objectA) - XCTAssertEqual(1, self.project.scene.objects().count) - XCTAssertTrue(self.project.scene.objects()[0] === objectA) + (project.scenes[0] as! Scene).add(object: objectA) + XCTAssertEqual(1, (self.project.scenes[0] as! Scene).objects().count) + XCTAssertTrue((self.project.scenes[0] as! Scene).objects()[0] === objectA) } func testChangeProjectOrientation() { diff --git a/src/CattyTests/Project/RequiredResourcesTests.swift b/src/CattyTests/Project/RequiredResourcesTests.swift index 0bccf1944f..68d999378e 100644 --- a/src/CattyTests/Project/RequiredResourcesTests.swift +++ b/src/CattyTests/Project/RequiredResourcesTests.swift @@ -48,13 +48,13 @@ final class RequiredResourcesTests: XCTestCase { func getProjectWithOneSpriteWithBrick(brick: Brick?) -> Project? { let project = Project() - project.scene = Scene() + project.scenes[0] = Scene() let obj = SpriteObject() let script = Script() script.brickList.add(brick as AnyObject) obj.scriptList.add(script) - project.scene.add(object: obj) + (project.scenes[0] as! Scene).add(object: obj) return project } @@ -840,7 +840,7 @@ final class RequiredResourcesTests: XCTestCase { // MARK: MoreScripts func getProjectWithTwoScriptsWithBricks(brickArray: [AnyObject]?, andBrickArray2 brickArray2: [AnyObject]?) -> Project { let project = Project() - project.scene = Scene() + project.scenes[0] = Scene() let obj = SpriteObject() let script = Script() let script2 = Script() @@ -859,7 +859,7 @@ final class RequiredResourcesTests: XCTestCase { obj.scriptList.add(script) obj.scriptList.add(script2) - project.scene.add(object: obj) + (project.scenes[0] as! Scene).add(object: obj) return project } @@ -957,8 +957,8 @@ final class RequiredResourcesTests: XCTestCase { obj.scriptList.add(script) obj1.scriptList.add(script2) - project.scene.add(object: obj) - project.scene.add(object: obj1) + (project.scenes[0] as! Scene).add(object: obj) + (project.scenes[0] as! Scene).add(object: obj1) return project } diff --git a/src/CattyTests/Resources/ParserTests/Custom/MultipleScenes/MultipleScenes.xml b/src/CattyTests/Resources/ParserTests/Custom/MultipleScenes/MultipleScenes.xml new file mode 100644 index 0000000000..52134d6709 --- /dev/null +++ b/src/CattyTests/Resources/ParserTests/Custom/MultipleScenes/MultipleScenes.xml @@ -0,0 +1,78 @@ + + +
+ + 0 + Pocket Code + 0.9.27 + 0.992 + + + Google Nexus 4 API 22 - CBL 0.992 + false + https://developer.catrobat.org/ccbysa_v4 + Android + 22.0 + https://developer.catrobat.org/agpl_v3 + Scenes + + true + 1184 + STRETCH + 768 + Experimental + /pocketcode/project/620ab113-e7ae-11ea-9251-005056a36f47 + catty +
+ + + + Scene 1 + + + + + 5235c2eecb956adf8c3ff3e3e9f295e9_automatic_screenshot.png + + + + + + + + + + + + + + 768 + 1184 + + + Scene 2 + + + + + 8ada7bc98ee101e3877ceb3bc9bcc254_North Pole.png + + + + + + + + + + + + + + 768 + 1184 + + + + +
diff --git a/src/CattyTests/Scripts/WhenBackgroundChangesScriptTests.swift b/src/CattyTests/Scripts/WhenBackgroundChangesScriptTests.swift index d4a0817aa5..b0cb4bbb57 100644 --- a/src/CattyTests/Scripts/WhenBackgroundChangesScriptTests.swift +++ b/src/CattyTests/Scripts/WhenBackgroundChangesScriptTests.swift @@ -39,7 +39,7 @@ final class WhenBackgroundChangesScriptTests: XCTestCase { project = ProjectMock(width: 400, andHeight: 800) scene = SceneMock(name: "sceneMock") scene.project = project - project.scene = scene + project.scenes[0] = scene! object = SpriteObject() object.name = "object" diff --git a/src/CattyTests/Scripts/WhenConditionScriptTests.swift b/src/CattyTests/Scripts/WhenConditionScriptTests.swift index 08c360608a..5964f6b116 100644 --- a/src/CattyTests/Scripts/WhenConditionScriptTests.swift +++ b/src/CattyTests/Scripts/WhenConditionScriptTests.swift @@ -39,7 +39,7 @@ project = ProjectMock(width: 400, andHeight: 800) scene = SceneMock(name: "sceneMock") scene.project = project - project.scene = scene + project.scenes[0] = (scene!) object = SpriteObject() object.name = "object" diff --git a/src/CattyTests/SpriteObject/SpriteObjectMutableCopyTests.swift b/src/CattyTests/SpriteObject/SpriteObjectMutableCopyTests.swift index 7658bf8d99..de2ccdac5e 100644 --- a/src/CattyTests/SpriteObject/SpriteObjectMutableCopyTests.swift +++ b/src/CattyTests/SpriteObject/SpriteObjectMutableCopyTests.swift @@ -88,9 +88,9 @@ final class SpriteObjectMutableCopyTests: XMLAbstractTest { func compareSpriteObjectsWithIsEqualMethodForProjectWithXML(xml: String) { let project = self.getProjectForXML(xmlFile: xml) - XCTAssertTrue(!project.scene.objects().isEmpty, "Invalid objectList") + XCTAssertTrue(!(project.scenes[0] as! Scene).objects().isEmpty, "Invalid objectList") - for spriteObject in project.scene.objects() { + for spriteObject in (project.scenes[0] as! Scene).objects() { let context = CBMutableCopyContext() let copiedSpriteObject = spriteObject.mutableCopy(with: context) as! SpriteObject XCTAssertTrue(spriteObject.isEqual(to: copiedSpriteObject), "SpriteObjects are not equal") diff --git a/src/CattyTests/Stage/StageTests.swift b/src/CattyTests/Stage/StageTests.swift index 11c630b4de..2a052568e3 100644 --- a/src/CattyTests/Stage/StageTests.swift +++ b/src/CattyTests/Stage/StageTests.swift @@ -109,7 +109,9 @@ final class StageTests: XCTestCase { func testVariableLabel() { let project = ProjectMock(width: self.screenSize.width, andHeight: self.screenSize.height) - project.scene = Scene() + let scene = Scene() + scene.project = project + project.scenes[0] = scene let stage = StageBuilder(project: project).build() let userVariable = UserVariable(name: "testName") diff --git a/src/CattyTests/Utils/UtilTests.swift b/src/CattyTests/Utils/UtilTests.swift index e3843c696b..30a754d42f 100644 --- a/src/CattyTests/Utils/UtilTests.swift +++ b/src/CattyTests/Utils/UtilTests.swift @@ -36,7 +36,7 @@ final class UtilTests: XCTestCase { override func setUp() { project = Project() - project.scene = Scene() + project.scenes[0] = Scene() super.setUp() } @@ -183,7 +183,7 @@ final class UtilTests: XCTestCase { project.allBroadcastMessages?.add("firstValue") spriteObject = SpriteObject() - project.scene.add(object: spriteObject!) + (project.scenes[0] as! Scene).add(object: spriteObject!) broadcastScript = BroadcastScript() spriteObject.scriptList.add(broadcastScript!) broadcastScript.receivedMessage = "secondValue" diff --git a/src/CattyTests/ViewController/FormulaEditorViewControllerTests.swift b/src/CattyTests/ViewController/FormulaEditorViewControllerTests.swift index 6a698e0e50..8a2b056f9d 100644 --- a/src/CattyTests/ViewController/FormulaEditorViewControllerTests.swift +++ b/src/CattyTests/ViewController/FormulaEditorViewControllerTests.swift @@ -30,6 +30,20 @@ final class FormulaEditorViewControllerTests: XCTestCase { override func setUp() { super.setUp() + + project = Project() + project.userData = UserDataContainer() + + scene = Scene(name: "testScene") + scene.project = project + project.scenes[0] = scene! + + spriteObject = SpriteObjectMock() + (project.scenes[0] as! Scene).add(object: spriteObject!) + + script = StartScript() + spriteObject.scriptList.add(script!) + controller = FormulaEditorViewController() } @@ -38,4 +52,236 @@ final class FormulaEditorViewControllerTests: XCTestCase { expect(self.controller.viewDidAppear(true)).to(postNotifications(contain(expectedNotification))) } + + func testIsVariableUsedGlobalWithoutBrick() { + let variable = UserVariable(name: "globalVariable") + project.userData.add(variable) + + XCTAssertFalse(controller.isVariableUsed(variable)) + } + + func testIsVariableUsedGlobalWithMultipleBricks() { + let variable = UserVariable(name: "globalVariable") + let brickA = HideTextBrick() + let brickB = HideTextBrick() + + project.userData.add(variable) + brickB.userVariable = variable + script.brickList.add(brickA) + + XCTAssertFalse(controller.isVariableUsed(variable)) + + script.brickList.add(brickB) + XCTAssertTrue(controller.isVariableUsed(variable)) + } + + func testIsVariableUsedGlobalWithMultipleScripts() { + let variable = UserVariable(name: "globalVariable") + let brick = HideTextBrick() + let scriptB = WhenScript() + + project.userData.add(variable) + brick.userVariable = variable + scriptB.brickList.add(brick) + + XCTAssertFalse(controller.isVariableUsed(variable)) + + spriteObject.scriptList.add(scriptB) + XCTAssertTrue(controller.isVariableUsed(variable)) + } + + func testIsVariableUsedGlobalWithMultipleObjects() { + let variable = UserVariable(name: "globalVariable") + let brick = HideTextBrick() + let scriptB = WhenScript() + let objectB = SpriteObject() + + project.userData.add(variable) + brick.userVariable = variable + scriptB.brickList.add(brick) + objectB.scriptList.add(scriptB) + + XCTAssertFalse(controller.isVariableUsed(variable)) + + (project.scenes[0] as! Scene).add(object: objectB) + XCTAssertTrue(controller.isVariableUsed(variable)) + } + + func testIsVariableUsedLocalWithoutBrick() { + let variable = UserVariable(name: "localVariable") + spriteObject.userData.add(variable) + + XCTAssertFalse(controller.isVariableUsed(variable)) + } + + func testIsVariableUsedLocalWithMultipleBricks() { + let variable = UserVariable(name: "localVariable") + let brickA = HideTextBrick() + let brickB = HideTextBrick() + + spriteObject.userData.add(variable) + brickB.userVariable = variable + script.brickList.add(brickA) + + XCTAssertFalse(controller.isVariableUsed(variable)) + + script.brickList.add(brickB) + XCTAssertTrue(controller.isVariableUsed(variable)) + } + + func testIsVariableUsedLocalWithMultipleScripts() { + let variable = UserVariable(name: "localVariable") + let brick = HideTextBrick() + let scriptB = WhenScript() + + spriteObject.userData.add(variable) + brick.userVariable = variable + scriptB.brickList.add(brick) + + XCTAssertFalse(controller.isVariableUsed(variable)) + + spriteObject.scriptList.add(scriptB) + XCTAssertTrue(controller.isVariableUsed(variable)) + } + + func testIsVariableUsedLocalWithMultipleObjects() { + let variable = UserVariable(name: "localVariable") + let brick = HideTextBrick() + let scriptB = WhenScript() + let objectB = SpriteObject() + + spriteObject.userData.add(variable) + brick.userVariable = variable + scriptB.brickList.add(brick) + objectB.scriptList.add(scriptB) + (project.scenes[0] as! Scene).add(object: objectB) + + XCTAssertFalse(controller.isVariableUsed(variable)) + + controller.object = objectB + XCTAssertTrue(controller.isVariableUsed(variable)) + } + + func testIsListUsedGlobalWithoutBrick() { + let list = UserList(name: "globalList") + project.userData.add(list) + + XCTAssertFalse(controller.isListUsed(list)) + } + + func testIsListUsedGlobalWithMultipleBricks() { + let list = UserList(name: "globalList") + let brickA = AddItemToUserListBrick() + let brickB = AddItemToUserListBrick() + + brickA.listFormula = Formula() + brickB.listFormula = Formula() + + project.userData.add(list) + brickB.userList = list + script.brickList.add(brickA) + + XCTAssertFalse(controller.isListUsed(list)) + + script.brickList.add(brickB) + XCTAssertTrue(controller.isListUsed(list)) + } + + func testIsListUsedGlobalWithMultipleScripts() { + let list = UserList(name: "globalList") + let brick = AddItemToUserListBrick() + let scriptB = WhenScript() + + brick.listFormula = Formula() + + project.userData.add(list) + brick.userList = list + scriptB.brickList.add(brick) + + XCTAssertFalse(controller.isListUsed(list)) + + spriteObject.scriptList.add(scriptB) + XCTAssertTrue(controller.isListUsed(list)) + } + + func testIsListUsedGlobalWithMultipleObjects() { + let list = UserList(name: "globalList") + let brick = AddItemToUserListBrick() + let scriptB = WhenScript() + let objectB = SpriteObject() + + brick.listFormula = Formula() + + project.userData.add(list) + brick.userList = list + scriptB.brickList.add(brick) + objectB.scriptList.add(scriptB) + + XCTAssertFalse(controller.isListUsed(list)) + + (project.scenes[0] as! Scene).add(object: objectB) + XCTAssertTrue(controller.isListUsed(list)) + } + + func testIsListUsedLocalWithoutBrick() { + let list = UserList(name: "localList") + spriteObject.userData.add(list) + + XCTAssertFalse(controller.isListUsed(list)) + } + + func testIsListUsedLocalWithMultipleBricks() { + let list = UserList(name: "localList") + let brickA = AddItemToUserListBrick() + let brickB = AddItemToUserListBrick() + + brickA.listFormula = Formula() + brickB.listFormula = Formula() + + spriteObject.userData.add(list) + brickB.userList = list + script.brickList.add(brickA) + + XCTAssertFalse(controller.isListUsed(list)) + + script.brickList.add(brickB) + XCTAssertTrue(controller.isListUsed(list)) + } + + func testIsListUsedLocalWithMultipleScripts() { + let list = UserList(name: "localList") + let brick = AddItemToUserListBrick() + let scriptB = WhenScript() + + brick.listFormula = Formula() + + spriteObject.userData.add(list) + brick.userList = list + scriptB.brickList.add(brick) + + XCTAssertFalse(controller.isListUsed(list)) + + spriteObject.scriptList.add(scriptB) + XCTAssertTrue(controller.isListUsed(list)) + } + + func testIsListUsedLocalWithMultipleObjects() { + let list = UserList(name: "localList") + let brick = AddItemToUserListBrick() + let scriptB = WhenScript() + let objectB = SpriteObject() + + brick.listFormula = Formula() + + spriteObject.userData.add(list) + brick.userList = list + scriptB.brickList.add(brick) + objectB.scriptList.add(scriptB) + (project.scenes[0] as! Scene).add(object: objectB) + + XCTAssertFalse(controller.isListUsed(list)) + + controller.object = objectB + XCTAssertTrue(controller.isListUsed(list)) + } } diff --git a/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift b/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift index cae953b486..1cc9102b9f 100644 --- a/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift +++ b/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift @@ -40,13 +40,13 @@ final class StagePresenterViewControllerScreenshotTest: XCTestCase { func testAutomaticScreenshot() { let expectedRootPath = project.projectPath() + kScreenshotAutoFilename - let expectedScenePath = project.scene.path()! + kScreenshotAutoFilename + let expectedScenePath = (project.scenes[0] as! Scene).path()! + kScreenshotAutoFilename XCTAssertFalse(FileManager.default.fileExists(atPath: expectedScenePath)) let exp = expectation(description: "screenshot saved") - vc.takeAutomaticScreenshot(for: skView, and: project.scene) + vc.takeAutomaticScreenshot(for: skView, and: (project.scenes[0] as! Scene)) DispatchQueue.main.async { exp.fulfill() } waitForExpectations(timeout: 5, handler: nil) @@ -68,13 +68,13 @@ final class StagePresenterViewControllerScreenshotTest: XCTestCase { func testManualScreenshot() { let expectedRootPath = project.projectPath() + kScreenshotManualFilename - let expectedScenePath = project.scene.path()! + kScreenshotManualFilename + let expectedScenePath = (project.scenes[0] as! Scene).path()! + kScreenshotManualFilename XCTAssertFalse(FileManager.default.fileExists(atPath: expectedScenePath)) XCTAssertFalse(FileManager.default.fileExists(atPath: expectedRootPath)) let exp = expectation(description: "screenshot saved") - vc.takeManualScreenshot(for: skView, and: project.scene) + vc.takeManualScreenshot(for: skView, and: (project.scenes[0] as! Scene)) DispatchQueue.main.async { exp.fulfill() } waitForExpectations(timeout: 5, handler: nil) @@ -107,7 +107,7 @@ final class StagePresenterViewControllerScreenshotTest: XCTestCase { XCTAssertNotNil(imageCache.cachedImage(forPath: existingPath)!) let exp = expectation(description: "screenshot saved") - vc.takeManualScreenshot(for: skView, and: project.scene) + vc.takeManualScreenshot(for: skView, and: (project.scenes[0] as! Scene)) DispatchQueue.main.async { exp.fulfill() } waitForExpectations(timeout: 5, handler: nil) diff --git a/src/CattyTests/Views/BrickCells/Data/BrickCellListDataTests.swift b/src/CattyTests/Views/BrickCells/Data/BrickCellListDataTests.swift index 455e44a1b3..2ccd7ee091 100644 --- a/src/CattyTests/Views/BrickCells/Data/BrickCellListDataTests.swift +++ b/src/CattyTests/Views/BrickCells/Data/BrickCellListDataTests.swift @@ -62,7 +62,7 @@ class BrickCellListDataTests: XCTestCase { userDataContainer.add(programList) project = Project() - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! project.userData = userDataContainer spriteObject.scene.project = project diff --git a/src/CattyTests/Views/BrickCells/Data/BrickCellVariableDataTests.swift b/src/CattyTests/Views/BrickCells/Data/BrickCellVariableDataTests.swift index 51aacce62c..adae1bacc2 100644 --- a/src/CattyTests/Views/BrickCells/Data/BrickCellVariableDataTests.swift +++ b/src/CattyTests/Views/BrickCells/Data/BrickCellVariableDataTests.swift @@ -61,7 +61,7 @@ class BrickCellVariableDataTests: XCTestCase { spriteObject2.userData.add(secondObjectVariable) userDataContainer.add(programVariable) project = Project() - project.scene = spriteObject.scene + project.scenes[0] = spriteObject.scene! project.userData = userDataContainer spriteObject.scene.project = project diff --git a/src/CattyTests/XML/Abstract/XMLAbstractTest.swift b/src/CattyTests/XML/Abstract/XMLAbstractTest.swift index 4c9ac49df4..85ce90036c 100644 --- a/src/CattyTests/XML/Abstract/XMLAbstractTest.swift +++ b/src/CattyTests/XML/Abstract/XMLAbstractTest.swift @@ -61,8 +61,8 @@ class XMLAbstractTest: XCTestCase { // FIXME: HACK => assign same header to both versions => this forces to ignore header firstProject.header = secondProject.header // FIXME: HACK => for background objects always replace german name "Hintergrund" with "Background" - let firstBgObject = firstProject.scene.object(at: 0)! - let secondBgObject = secondProject.scene.object(at: 0)! + let firstBgObject = (firstProject.scenes[0] as! Scene).object(at: 0)! + let secondBgObject = (secondProject.scenes[0] as! Scene).object(at: 0)! firstBgObject.name = firstBgObject.name.replacingOccurrences(of: "Hintergrund", with: "Background") secondBgObject.name = secondBgObject.name.replacingOccurrences(of: "Hintergrund", with: "Background") diff --git a/src/CattyTests/XML/Helper/CBXMLParserHelperTests.swift b/src/CattyTests/XML/Helper/CBXMLParserHelperTests.swift index 204a7de77b..42232eeb24 100644 --- a/src/CattyTests/XML/Helper/CBXMLParserHelperTests.swift +++ b/src/CattyTests/XML/Helper/CBXMLParserHelperTests.swift @@ -46,8 +46,8 @@ final class CBXMLParserHelperTests: XCTestCase { let scene = Scene(name: "testScene") let object = SpriteObject() object.scene = scene - let project = Project() - project.scene = object.scene + let project: Project! = ProjectManager.createProject(name: "a", projectId: "1") + project.scenes[0] = object.scene! let spriteNode = CBSpriteNode(spriteObject: object) let startScript = StartScript() diff --git a/src/CattyTests/XML/Parser/CatrobatLanguage0.92/XMLParserTests092.swift b/src/CattyTests/XML/Parser/CatrobatLanguage0.92/XMLParserTests092.swift index ac7b230aed..5cc98b6afc 100644 --- a/src/CattyTests/XML/Parser/CatrobatLanguage0.92/XMLParserTests092.swift +++ b/src/CattyTests/XML/Parser/CatrobatLanguage0.92/XMLParserTests092.swift @@ -29,9 +29,9 @@ class XMLParserTests092: XMLAbstractTest { func testConvertUnsupportedBrickToNoteBrick() { let project = getProjectForXML(xmlFile: "InvalidBricksAndScripts") XCTAssertNotNil(project, "Project should not be nil") - XCTAssertEqual(1, project.scene.objects().count) + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count) - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(3, object.scriptList.count) let startScript = object.scriptList[0] as! StartScript @@ -50,9 +50,9 @@ class XMLParserTests092: XMLAbstractTest { func testConvertUnsupportedScriptToBroadcastBrick() { let project = getProjectForXML(xmlFile: "InvalidBricksAndScripts") XCTAssertNotNil(project, "Project should not be nil") - XCTAssertEqual(1, project.scene.objects().count) + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count) - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(3, object.scriptList.count) let unknownScript = object.scriptList[1] as AnyObject @@ -77,9 +77,9 @@ class XMLParserTests092: XMLAbstractTest { func testWhackAMole() { let project = getProjectForXML(xmlFile: "Whack_A_Mole_092") XCTAssertNotNil(project, "Project should not be nil") - XCTAssertEqual(5, project.scene.objects().count) + XCTAssertEqual(5, (project.scenes[0] as! Scene).objects().count) - let object = project.scene.object(at: 1)! + let object = (project.scenes[0] as! Scene).object(at: 1)! XCTAssertEqual(3, object.lookList.count) XCTAssertEqual(1, object.soundList.count) diff --git a/src/CattyTests/XML/Parser/CatrobatLanguage0.93/XMLParserBrickTests093.swift b/src/CattyTests/XML/Parser/CatrobatLanguage0.93/XMLParserBrickTests093.swift index 329e0b9f51..5051a8c785 100644 --- a/src/CattyTests/XML/Parser/CatrobatLanguage0.93/XMLParserBrickTests093.swift +++ b/src/CattyTests/XML/Parser/CatrobatLanguage0.93/XMLParserBrickTests093.swift @@ -446,7 +446,7 @@ class XMLParserBrickTests093: XMLAbstractTest { let project = self.getProjectForXML(xmlFile: "PointToBrickWithoutSpriteObject") XCTAssertNotNil(project, "Project must not be nil!") - let moleTwo = project.scene.object(at: 1)! + let moleTwo = (project.scenes[0] as! Scene).object(at: 1)! XCTAssertNotNil(moleTwo, "SpriteObject must not be nil!") XCTAssertEqual(moleTwo.name, "Mole 2", "Invalid object name!") diff --git a/src/CattyTests/XML/Parser/CatrobatLanguage0.98/XMLParserTests098.swift b/src/CattyTests/XML/Parser/CatrobatLanguage0.98/XMLParserTests098.swift index 11a8705ffd..d4d2f2989d 100644 --- a/src/CattyTests/XML/Parser/CatrobatLanguage0.98/XMLParserTests098.swift +++ b/src/CattyTests/XML/Parser/CatrobatLanguage0.98/XMLParserTests098.swift @@ -40,8 +40,8 @@ final class XMLParserTests098: XMLAbstractTest { func testFlashBrick() { let project = self.getProjectForXML(xmlFile: "LedFlashBrick098") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -58,8 +58,8 @@ final class XMLParserTests098: XMLAbstractTest { func testLedBrick() { let project = self.getProjectForXML(xmlFile: "LedFlashBrick098") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -75,9 +75,9 @@ final class XMLParserTests098: XMLAbstractTest { func testAddItemToUserListBrick() { let project = self.getProjectForXML(xmlFile: "AddItemToUserListBrick098") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -99,9 +99,9 @@ final class XMLParserTests098: XMLAbstractTest { func testDeleteItemOfUserListBrick() { let project = self.getProjectForXML(xmlFile: "DeleteItemOfUserListBrick098") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -122,9 +122,9 @@ final class XMLParserTests098: XMLAbstractTest { func testInsertItemIntoUserListBrick() { let project = self.getProjectForXML(xmlFile: "InsertItemIntoUserListBrick098") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -151,9 +151,9 @@ final class XMLParserTests098: XMLAbstractTest { func testReplaceItemInUserListBrick() { let project = self.getProjectForXML(xmlFile: "ReplaceItemInUserListBrick098") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script diff --git a/src/CattyTests/XML/Parser/CatrobatLanguage0.991/XMLParserTests0991.swift b/src/CattyTests/XML/Parser/CatrobatLanguage0.991/XMLParserTests0991.swift index 9766f39eb2..1d22a7e973 100644 --- a/src/CattyTests/XML/Parser/CatrobatLanguage0.991/XMLParserTests0991.swift +++ b/src/CattyTests/XML/Parser/CatrobatLanguage0.991/XMLParserTests0991.swift @@ -35,8 +35,8 @@ class XMLParserTests0991: XMLAbstractTest { func testFlashBrick() { let project = self.getProjectForXML(xmlFile: "LedFlashBrick0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -53,8 +53,8 @@ class XMLParserTests0991: XMLAbstractTest { func testLedBrick() { let project = self.getProjectForXML(xmlFile: "LedFlashBrick0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -71,8 +71,8 @@ class XMLParserTests0991: XMLAbstractTest { func testIfThenLogicBeginBrick() { let project = self.getProjectForXML(xmlFile: "LogicBricks_0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -123,9 +123,9 @@ class XMLParserTests0991: XMLAbstractTest { func testObjectLookSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0991") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 2, "Invalid object list") - let background = project.scene.object(at: 0)! - let object = project.scene.object(at: 1)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 2, "Invalid object list") + let background = (project.scenes[0] as! Scene).object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 1)! XCTAssertEqual(1, background.scriptList.count, "Invalid script list") XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -161,7 +161,7 @@ class XMLParserTests0991: XMLAbstractTest { func testPreviousLookBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 26, "Invalid brick list") @@ -172,7 +172,7 @@ class XMLParserTests0991: XMLAbstractTest { func testRepeatUntilBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 27, "Invalid brick list") @@ -183,7 +183,7 @@ class XMLParserTests0991: XMLAbstractTest { func testSetBackgroundBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 29, "Invalid brick list") @@ -197,7 +197,7 @@ class XMLParserTests0991: XMLAbstractTest { func testSpeakAndWaitBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 30, "Invalid brick list") @@ -212,8 +212,8 @@ class XMLParserTests0991: XMLAbstractTest { func testLocationSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0991") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 3, "Invalid object list") - let object = project.scene.object(at: 2)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 3, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 2)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -239,8 +239,8 @@ class XMLParserTests0991: XMLAbstractTest { func testScreenTouchSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0991") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 4, "Invalid object list") - let object = project.scene.object(at: 3)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 4, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 3)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -265,7 +265,7 @@ class XMLParserTests0991: XMLAbstractTest { func testCameraBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 33, "Invalid brick list") @@ -281,7 +281,7 @@ class XMLParserTests0991: XMLAbstractTest { func testChooseCameraBrick() { let project = self.getProjectForXML(xmlFile: "CameraBricks_0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertEqual(backgroundScript.brickList.count, 4, "Invalid brick list") @@ -305,7 +305,7 @@ class XMLParserTests0991: XMLAbstractTest { func testSayBubbleBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 34, "Invalid brick list") @@ -317,7 +317,7 @@ class XMLParserTests0991: XMLAbstractTest { func testThinkBubbleBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 35, "Invalid brick list") @@ -329,7 +329,7 @@ class XMLParserTests0991: XMLAbstractTest { func testSayForBubbleBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 36, "Invalid brick list") @@ -342,7 +342,7 @@ class XMLParserTests0991: XMLAbstractTest { func testThinkForBubbleBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 37, "Invalid brick list") @@ -355,9 +355,9 @@ class XMLParserTests0991: XMLAbstractTest { func testAddItemToUserListBrick() { let project = self.getProjectForXML(xmlFile: "AddItemToUserListBrick0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -378,7 +378,7 @@ class XMLParserTests0991: XMLAbstractTest { func testWaitUntilBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertGreaterThanOrEqual(backgroundScript.brickList.count, 41, "Invalid brick list") @@ -391,9 +391,9 @@ class XMLParserTests0991: XMLAbstractTest { func testNumberOfItemsFunction() { let project = self.getProjectForXML(xmlFile: "NumberOfItemsInListFunction0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -410,9 +410,9 @@ class XMLParserTests0991: XMLAbstractTest { func testElementOfListFunction() { let project = self.getProjectForXML(xmlFile: "ElementOfListFunction0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -435,9 +435,9 @@ class XMLParserTests0991: XMLAbstractTest { func testDeleteItemOfUserListBrick() { let project = self.getProjectForXML(xmlFile: "DeleteItemOfUserListBrick0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -458,9 +458,9 @@ class XMLParserTests0991: XMLAbstractTest { func testInsertItemIntoUserListBrick() { let project = self.getProjectForXML(xmlFile: "InsertItemIntoUserListBrick0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -487,9 +487,9 @@ class XMLParserTests0991: XMLAbstractTest { func testReplaceItemInUserListBrick() { let project = self.getProjectForXML(xmlFile: "ReplaceItemInUserListBrick0991") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -516,21 +516,21 @@ class XMLParserTests0991: XMLAbstractTest { func testBroadcastScript() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let object = project.scene.object(at: 1)! + let object = (project.scenes[0] as! Scene).object(at: 1)! let broadcastScript = object.scriptList.object(at: 0) as! Script XCTAssertTrue(broadcastScript.isKind(of: BroadcastScript.self), "Invalid script type") } func testWhenScript() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let object = project.scene.object(at: 1)! + let object = (project.scenes[0] as! Scene).object(at: 1)! let whenScript = object.scriptList.object(at: 1) as! Script XCTAssertTrue(whenScript.isKind(of: WhenScript.self), "Invalid script type") } func testWhenTouchDownScript() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0991") - let object = project.scene.object(at: 1)! + let object = (project.scenes[0] as! Scene).object(at: 1)! let whenTouchDownScript = object.scriptList.object(at: 2) as! Script XCTAssertEqual(0, project.unsupportedElements.count) @@ -539,7 +539,7 @@ class XMLParserTests0991: XMLAbstractTest { func testPlaySoundAndWaitBrick() { let project = self.getProjectForXML(xmlFile: "PlaySoundAndWaitBrickContinueWhenFinished") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! let startScript = object.scriptList.object(at: 0) as! Script let playSoundAndWaitBrick = startScript.brickList.object(at: 0) as! PlaySoundAndWaitBrick @@ -549,7 +549,7 @@ class XMLParserTests0991: XMLAbstractTest { func testDisabledBricks() { let project = self.getProjectForXML(xmlFile: "DisabledBricks_0991") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! let startScript = object.scriptList.object(at: 0) as! Script let disabledBrick = startScript.brickList.object(at: 0) as! SetVariableBrick @@ -561,7 +561,7 @@ class XMLParserTests0991: XMLAbstractTest { func testSpeakBrickWithoutCommentedOut() { let project = self.getProjectForXML(xmlFile: "SpeakBrickWithoutCommentedOut_0991") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! let startScript = object.scriptList.object(at: 0) as! Script let speakBrick = startScript.brickList.object(at: 0) as! SpeakBrick @@ -571,9 +571,9 @@ class XMLParserTests0991: XMLAbstractTest { func testSetBackgroundBrickReference() { let project = self.getProjectForXML(xmlFile: "SetBackgroundBrick_0991") - let background = project.scene.object(at: 0)! - let objectA = project.scene.object(at: 1)! - let objectB = project.scene.object(at: 2)! + let background = (project.scenes[0] as! Scene).object(at: 0)! + let objectA = (project.scenes[0] as! Scene).object(at: 1)! + let objectB = (project.scenes[0] as! Scene).object(at: 2)! let brickWithValidBackgroundReference = (objectA.scriptList.object(at: 0) as! Script).brickList.object(at: 0) as! SetBackgroundBrick let brickWithInvalidBackgroundReference = (objectB.scriptList.object(at: 0) as! Script).brickList.object(at: 0) as! SetBackgroundBrick diff --git a/src/CattyTests/XML/Parser/CatrobatLanguage0.992/XMLParserTests0992.swift b/src/CattyTests/XML/Parser/CatrobatLanguage0.992/XMLParserTests0992.swift index e8b5ceb493..57f1f748b1 100644 --- a/src/CattyTests/XML/Parser/CatrobatLanguage0.992/XMLParserTests0992.swift +++ b/src/CattyTests/XML/Parser/CatrobatLanguage0.992/XMLParserTests0992.swift @@ -35,8 +35,8 @@ class XMLParserTests0992: XMLAbstractTest { func testFlashBrick() { let project = self.getProjectForXML(xmlFile: "LedFlashBrick0992") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -53,8 +53,8 @@ class XMLParserTests0992: XMLAbstractTest { func testIfThenLogicBeginBrick() { let project = self.getProjectForXML(xmlFile: "LogicBricks_0992") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -105,9 +105,9 @@ class XMLParserTests0992: XMLAbstractTest { func testObjectLookSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0992") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 2, "Invalid object list") - let background = project.scene.object(at: 0)! - let object = project.scene.object(at: 1)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 2, "Invalid object list") + let background = (project.scenes[0] as! Scene).object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 1)! XCTAssertEqual(1, background.scriptList.count, "Invalid script list") XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -144,8 +144,8 @@ class XMLParserTests0992: XMLAbstractTest { func testLocationSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0992") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 3, "Invalid object list") - let object = project.scene.object(at: 2)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 3, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 2)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -171,8 +171,8 @@ class XMLParserTests0992: XMLAbstractTest { func testScreenTouchSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0992") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 4, "Invalid object list") - let object = project.scene.object(at: 3)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 4, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 3)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -197,7 +197,7 @@ class XMLParserTests0992: XMLAbstractTest { func testChooseCameraBrick() { let project = self.getProjectForXML(xmlFile: "CameraBricks_0992") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertEqual(backgroundScript.brickList.count, 4, "Invalid brick list") @@ -221,9 +221,9 @@ class XMLParserTests0992: XMLAbstractTest { func testNumberOfItemsFunction() { let project = self.getProjectForXML(xmlFile: "NumberOfItemsInListFunction0992") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -240,9 +240,9 @@ class XMLParserTests0992: XMLAbstractTest { func testElementOfListFunction() { let project = self.getProjectForXML(xmlFile: "ElementOfListFunction0992") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -265,9 +265,9 @@ class XMLParserTests0992: XMLAbstractTest { func testDeleteItemOfUserListBrick() { let project = self.getProjectForXML(xmlFile: "DeleteItemOfUserListBrick0992") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -288,9 +288,9 @@ class XMLParserTests0992: XMLAbstractTest { func testInsertItemIntoUserListBrick() { let project = self.getProjectForXML(xmlFile: "InsertItemIntoUserListBrick0992") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -317,9 +317,9 @@ class XMLParserTests0992: XMLAbstractTest { func testReplaceItemInUserListBrick() { let project = self.getProjectForXML(xmlFile: "ReplaceItemInUserListBrick0992") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -346,7 +346,7 @@ class XMLParserTests0992: XMLAbstractTest { func testDisabledBricks() { let project = self.getProjectForXML(xmlFile: "DisabledBricks_0992") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! let startScript = object.scriptList.object(at: 0) as! Script let disabledBrick = startScript.brickList.object(at: 0) as! SetVariableBrick @@ -377,7 +377,7 @@ class XMLParserTests0992: XMLAbstractTest { func testAskBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0992") - let askBrick = (project.scene.object(at: 1)!.scriptList.object(at: 0) as! Script).brickList.object(at: 1) as! Brick + let askBrick = ((project.scenes[0] as! Scene).object(at: 1)!.scriptList.object(at: 0) as! Script).brickList.object(at: 1) as! Brick XCTAssertEqual(0, project.unsupportedElements.count) XCTAssertTrue(askBrick.isKind(of: AskBrick.self), "Invalid brick type") @@ -386,7 +386,7 @@ class XMLParserTests0992: XMLAbstractTest { func testSetInstrumentBrick() { let availableInstruments = Instrument.allCases let project = self.getProjectForXML(xmlFile: "SamplerBricks_0992") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! let startScript = object.scriptList.object(at: 0) as! Script XCTAssertEqual(availableInstruments.count, startScript.brickList.count) diff --git a/src/CattyTests/XML/Parser/CatrobatLanguage0.993/XMLParserTests0993.swift b/src/CattyTests/XML/Parser/CatrobatLanguage0.993/XMLParserTests0993.swift index b9867f3bfe..8b2b87d875 100644 --- a/src/CattyTests/XML/Parser/CatrobatLanguage0.993/XMLParserTests0993.swift +++ b/src/CattyTests/XML/Parser/CatrobatLanguage0.993/XMLParserTests0993.swift @@ -35,8 +35,8 @@ class XMLParserTests0993: XMLAbstractTest { func testFlashBrick() { let project = self.getProjectForXML(xmlFile: "LedFlashBrick0993") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -53,8 +53,8 @@ class XMLParserTests0993: XMLAbstractTest { func testIfThenLogicBeginBrick() { let project = self.getProjectForXML(xmlFile: "LogicBricks_0993") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -105,9 +105,9 @@ class XMLParserTests0993: XMLAbstractTest { func testObjectLookSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0993") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 2, "Invalid object list") - let background = project.scene.object(at: 0)! - let object = project.scene.object(at: 1)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 2, "Invalid object list") + let background = (project.scenes[0] as! Scene).object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 1)! XCTAssertEqual(1, background.scriptList.count, "Invalid script list") XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -144,8 +144,8 @@ class XMLParserTests0993: XMLAbstractTest { func testLocationSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0993") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 3, "Invalid object list") - let object = project.scene.object(at: 2)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 3, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 2)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -171,8 +171,8 @@ class XMLParserTests0993: XMLAbstractTest { func testScreenTouchSensors() { let project = self.getProjectForXML(xmlFile: "Sensors_0993") - XCTAssertGreaterThanOrEqual(project.scene.objects().count, 4, "Invalid object list") - let object = project.scene.object(at: 3)! + XCTAssertGreaterThanOrEqual((project.scenes[0] as! Scene).objects().count, 4, "Invalid object list") + let object = (project.scenes[0] as! Scene).object(at: 3)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") @@ -196,8 +196,9 @@ class XMLParserTests0993: XMLAbstractTest { } func testChooseCameraBrick() { + let project = self.getProjectForXML(xmlFile: "CameraBricks_0993") - let background = project.scene.object(at: 0)! + let background = (project.scenes[0] as! Scene).object(at: 0)! let backgroundScript = background.scriptList.object(at: 0) as! Script XCTAssertEqual(backgroundScript.brickList.count, 4, "Invalid brick list") @@ -221,9 +222,9 @@ class XMLParserTests0993: XMLAbstractTest { func testNumberOfItemsFunction() { let project = self.getProjectForXML(xmlFile: "NumberOfItemsInListFunction0993") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -240,9 +241,9 @@ class XMLParserTests0993: XMLAbstractTest { func testElementOfListFunction() { let project = self.getProjectForXML(xmlFile: "ElementOfListFunction0993") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -265,9 +266,9 @@ class XMLParserTests0993: XMLAbstractTest { func testDeleteItemOfUserListBrick() { let project = self.getProjectForXML(xmlFile: "DeleteItemOfUserListBrick0993") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -288,9 +289,9 @@ class XMLParserTests0993: XMLAbstractTest { func testInsertItemIntoUserListBrick() { let project = self.getProjectForXML(xmlFile: "InsertItemIntoUserListBrick0993") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -316,10 +317,10 @@ class XMLParserTests0993: XMLAbstractTest { } func testReplaceItemInUserListBrick() { - let project = self.getProjectForXML(xmlFile: "ReplaceItemInUserListBrick0993") - XCTAssertEqual(1, project.scene.objects().count, "Invalid object list") + let project = self.getProjectForXML(xmlFile: "ReplaceItemInUserListBrick0992") + XCTAssertEqual(1, (project.scenes[0] as! Scene).objects().count, "Invalid object list") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! XCTAssertEqual(1, object.scriptList.count, "Invalid script list") let script = object.scriptList.object(at: 0) as! Script @@ -346,7 +347,8 @@ class XMLParserTests0993: XMLAbstractTest { func testDisabledBricks() { let project = self.getProjectForXML(xmlFile: "DisabledBricks_0993") - let object = project.scene.object(at: 0)! + let object = (project.scenes[0] as! Scene).object(at: 0)! + let startScript = object.scriptList.object(at: 0) as! Script let disabledBrick = startScript.brickList.object(at: 0) as! SetVariableBrick @@ -377,7 +379,7 @@ class XMLParserTests0993: XMLAbstractTest { func testAskBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let askBrick = (project.scene.object(at: 1)!.scriptList.object(at: 0) as! Script).brickList.object(at: 1) as! Brick + let askBrick = ((project.scenes[0] as! Scene).object(at: 1)!.scriptList.object(at: 0) as! Script).brickList.object(at: 1) as! Brick XCTAssertEqual(0, project.unsupportedElements.count) XCTAssertTrue(askBrick.isKind(of: AskBrick.self), "Invalid brick type") diff --git a/src/CattyTests/XML/Serializer/XMLSerializerBlackBoxTests.swift b/src/CattyTests/XML/Serializer/XMLSerializerBlackBoxTests.swift index acbba8f09b..390723f423 100644 --- a/src/CattyTests/XML/Serializer/XMLSerializerBlackBoxTests.swift +++ b/src/CattyTests/XML/Serializer/XMLSerializerBlackBoxTests.swift @@ -31,8 +31,8 @@ final class XMLSerializerBlackBoxTests: XMLAbstractTest { } func testInvalidAirFight() { - let project095 = self.getProjectForXML(xmlFile: "Air_fight_0.5_093") - let background = project095.scene.object(at: 0)! + let project095 = self.getProjectForXML(xmlFile: "Air_fight_0.5_095") + let background = (project095.scenes[0] as! Scene).object(at: 0)! background.name = "Invalid" let equal = self.isProject(firstProject: project095, equalToXML: "Air_fight_0.5_09993") XCTAssertFalse(equal, "Serialized project and XML are not equal") diff --git a/src/CattyTests/XML/Serializer/XMLSerializerTests.swift b/src/CattyTests/XML/Serializer/XMLSerializerTests.swift index 5f2f7fbb82..ed7211213c 100644 --- a/src/CattyTests/XML/Serializer/XMLSerializerTests.swift +++ b/src/CattyTests/XML/Serializer/XMLSerializerTests.swift @@ -42,10 +42,11 @@ final class XMLSerializerTests: XMLAbstractTest { } func testFormulaAndMoveNStepsBrick() { - let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 5) as! MoveNStepsBrick - let xmlElementPath = "//program/scenes/scene/objectList/object[1]/scriptList/script[1]/brickList/brick[6]" - let equal = self.isXMLElement(xmlElement: brick.xmlElement(with: nil), equalToXMLElementForXPath: xmlElementPath, inProjectForXML: "ValidProjectAllBricks0994") + let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 5) as! MoveNStepsBrick + + let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[6]" + let equal = self.isXMLElement(xmlElement: brick.xmlElement(with: nil), equalToXMLElementForXPath: xmlElementPath, inProjectForXML: "ValidProjectAllBricks0991") XCTAssertTrue(equal, "XMLElement invalid!") } @@ -53,17 +54,17 @@ final class XMLSerializerTests: XMLAbstractTest { let projectName = "ValidProjectAllBricks09993" let referenceProject = self.getProjectForXML(xmlFile: projectName) let project = self.getProjectForXML(xmlFile: projectName) - - XCTAssertTrue(project.scene.objects().count > 1) - - let firstObject = project.scene.object(at: 1)! - project.scene.removeObject(firstObject) + XCTAssertEqual(1, project.scenes.count) + let moleOne = (project.scenes[0] as! Scene).object(at: 1)! + (project.scenes[0] as! Scene).removeObject(moleOne) let serializerContext = CBXMLSerializerContext(project: project) let xmlElement = project.xmlElement(with: serializerContext) XCTAssertNotNil(xmlElement, "Error during serialization of removed object") - XCTAssertEqual(project.scene.objects().count + 1, referenceProject.scene.objects().count, "Object not properly removed") + XCTAssertEqual((project.scenes[0] as! Scene).objects().count + 1, + (referenceProject.scenes[0] as! Scene).objects().count, + "Object not properly removed") XCTAssertFalse((referenceProject.xmlElement(with: CBXMLSerializerContext(project: Project())).isEqual(to: xmlElement)), "Object not properly removed") let parserContext = CBXMLParserContext(languageVersion: CGFloat(Float32(0.9993)), andRootElement: xmlElement) @@ -76,7 +77,7 @@ final class XMLSerializerTests: XMLAbstractTest { let project = self.getProjectForXML(xmlFile: "PointToBrickWithoutSpriteObject") XCTAssertNotNil(project, "Project must not be nil!") - let moleTwo = project.scene.object(at: 1)! + let moleTwo = (project.scenes[0] as! Scene).object(at: 1)! XCTAssertNotNil(moleTwo, "SpriteObject must not be nil!") XCTAssertEqual(moleTwo.name, "Mole 2", "Invalid object name!") @@ -87,7 +88,7 @@ final class XMLSerializerTests: XMLAbstractTest { XCTAssertNotNil(pointToBrick, "PointToBrick must not be nil!") let context = CBXMLSerializerContext(project: project) - context?.spriteObjectList = NSMutableArray(array: project.scene.objects()) + context?.spriteObjectList = NSMutableArray(array: (project.scenes[0] as! Scene).objects()) let xmlElementPath = "//program/objectList/object[2]/scriptList/script[1]/brickList/brick[8]" let equal = self.isXMLElement(xmlElement: pointToBrick.xmlElement(with: context), equalToXMLElementForXPath: xmlElementPath, inProjectForXML: "PointToBrickWithoutSpriteObject") @@ -98,7 +99,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testPenDownBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 42) as! PenDownBrick + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 41) as! PenDownBrick let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[42]" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else { @@ -112,7 +113,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testPenUpBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 43) as! PenUpBrick + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 42) as! PenUpBrick let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[43]" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else { @@ -126,7 +127,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testPenClearBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 44) as! PenClearBrick + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 43) as! PenClearBrick let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[44]" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else { @@ -140,7 +141,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testSetPenSizeBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 45) as! SetPenSizeBrick + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 44) as! SetPenSizeBrick let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[45]" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else { @@ -154,8 +155,8 @@ final class XMLSerializerTests: XMLAbstractTest { func testSetPenColorBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! SetPenColorBrick - let xmlElementPath = "//program/scenes/scene/objectList/object[1]/scriptList/script[1]/brickList/brick[47]" + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 45) as! SetPenColorBrick + let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[46]" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: project)) else { XCTFail("xmlElement is nil") @@ -169,7 +170,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testStampBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 47) as! StampBrick + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) as! StampBrick let xmlElementPath = "//program/objectList/object[1]/scriptList/script[1]/brickList/brick[47]" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: Project())) else { @@ -183,8 +184,8 @@ final class XMLSerializerTests: XMLAbstractTest { func testAddItemToUserListBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks09993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 48) as! AddItemToUserListBrick - let xmlElementPath = "//program/scenes/scene[1]/objectList/object[1]/scriptList/script[1]/brickList/brick[49]" + let brick = ((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 0) as! AddItemToUserListBrick + let xmlElementPath = "//program/scenes/scene[1]/objectList/object[1]/scriptList/script[1]/brickList/brick[1]" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: project)) else { XCTFail("xmlElement is nil") @@ -197,7 +198,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testUserVariables() { let project = self.getProjectForXML(xmlFile: "UserVariables_09993") - let brick = ((project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 2) as! ChangeVariableBrick).userVariable as UserVariable + let brick = (((project.scenes[0] as! Scene).object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 2) as! ChangeVariableBrick).userVariable as UserVariable let xmlElementPath = "//program/scenes/scene[1]/objectList/object[1]/scriptList/script[1]/brickList/brick[3]/userVariable" guard let xmlElement = brick.xmlElement(with: CBXMLSerializerContext(project: project)) else { diff --git a/src/CattyTests/XML/XMLParseMultipleScenesTests.swift b/src/CattyTests/XML/XMLParseMultipleScenesTests.swift new file mode 100644 index 0000000000..e0911f818c --- /dev/null +++ b/src/CattyTests/XML/XMLParseMultipleScenesTests.swift @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2010-2020 The Catrobat Team + * (http://developer.catrobat.org/credits) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * (http://developer.catrobat.org/license_additional_term) + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +import Foundation +import XCTest + +@testable import Pocket_Code + +class ParseMultipleScenesTests: XMLAbstractTest { + + func testBasicTwoSceneFile() { + let project = self.getProjectForXML(xmlFile: "MultipleScenes") + XCTAssertEqual(project.scenes.count, 2) + + let scene1 = project.scenes[0] as! Scene + XCTAssertEqual(scene1.name, "Scene 1") + XCTAssertEqual(scene1.objects().count, 1) + + let obj1 = scene1.objects()[0] + XCTAssertEqual(obj1.name, "Background") + XCTAssertEqual(obj1.lookList.count, 1) + XCTAssertEqual(obj1.scriptList.count, 0) + XCTAssertEqual(obj1.soundList.count, 0) + + let look1 = obj1.lookList[0] as! Look + XCTAssertEqual(look1.name, "automatic_screenshot") + XCTAssertEqual(look1.fileName, "5235c2eecb956adf8c3ff3e3e9f295e9_automatic_screenshot.png") + + let scene2 = project.scenes[1] as! Scene + XCTAssertEqual(scene2.name, "Scene 2") + XCTAssertEqual(scene2.objects().count, 1) + + let obj2 = scene2.objects()[0] + XCTAssertEqual(obj2.name, "Background") + XCTAssertEqual(obj2.lookList.count, 1) + XCTAssertEqual(obj2.scriptList.count, 0) + XCTAssertEqual(obj2.soundList.count, 0) + + let look2 = obj2.lookList[0] as! Look + XCTAssertEqual(look2.name, "North Pole") + XCTAssertEqual(look2.fileName, "8ada7bc98ee101e3877ceb3bc9bcc254_North Pole.png") + } +}