From 573b183ad5caa62a43af296fd6e70f8157495a3c Mon Sep 17 00:00:00 2001 From: fabian Date: Wed, 9 Dec 2020 10:48:49 +0100 Subject: [PATCH] CATTY-446 Parse multiple scenes --- src/Catty.xcodeproj/project.pbxproj | 16 ++++ .../xcschemes/Catty (DEBUG).xcscheme | 20 ----- src/Catty/DataModel/Project/Project.h | 4 +- src/Catty/DataModel/Project/Project.m | 53 +++++++---- .../UIViewControllerExtension.swift | 5 +- src/Catty/IO/ProjectManager.swift | 14 +-- .../XMLHandler/Project/Project+CBXMLHandler.m | 36 ++++---- .../Old Parser/ProjectParser.m | 1 + .../PlayerEngine/Frontend/CBFrontend.swift | 4 +- .../Protocols/CBFrontendProtocol.swift | 3 - .../Sensors/Object/LayerSensor.swift | 4 +- .../Stage/Builder/StageBuilder.swift | 9 +- src/Catty/PlayerEngine/Stage/Stage.swift | 20 +++-- .../Stage/StagePresenterViewController.m | 15 +--- ...terViewControllerScreenshotExtension.swift | 4 +- src/CattyTests/Bricks/AskBrickTests.swift | 2 +- src/CattyTests/Bricks/BubbleBrickTests.swift | 4 +- .../ChangeBrightnessByNBrickTests.swift | 2 +- .../Bricks/ChangeColorByNBrickTests.swift | 2 +- .../Bricks/ChangeVariableBrickTests.swift | 2 +- .../Bricks/ChooseCameraBrickTests.swift | 2 +- .../Bricks/ClearGraphicEffectBrickTests.swift | 2 +- .../Bricks/ComeToFrontBrickTests.swift | 8 +- .../DeleteItemOfUserListBrickTests.swift | 2 +- .../Bricks/GoNStepsBackBrickTests.swift | 6 +- .../Bricks/HideTextBrickTests.swift | 2 +- .../InsertItemIntoUserListBrickTests.swift | 2 +- .../Bricks/NextLookBrickTests.swift | 2 +- .../Bricks/PreviousLookBrickTests.swift | 2 +- .../ReplaceItemInUserListBrickTests.swift | 2 +- .../Bricks/SetBrightnessBrickTests.swift | 2 +- .../Bricks/SetColorBrickTests.swift | 2 +- src/CattyTests/Bricks/SetLookBrickTests.swift | 1 - .../Bricks/SetLookByIndexBrickTests.swift | 2 +- .../Bricks/SetVariableBrickTests.swift | 2 +- .../Bricks/ShowTextBrickTests.swift | 2 +- src/CattyTests/DataModel/LookTest.swift | 8 +- src/CattyTests/DataModel/SoundTest.swift | 2 +- .../DataModel/UserDataContainerTest.swift | 14 +-- .../UIViewControllerExtensionTests.swift | 2 +- .../Abstract/XMLAbstractTest.swift | 4 +- .../XMLParserTests092.swift | 12 +-- .../Unit Tests/XMLParserBrickTests093.swift | 2 +- .../Unit Tests/XMLParserTests098.swift | 24 ++--- .../Unit Tests/XMLParserTests0991.swift | 90 +++++++++---------- .../Unit Tests/XMLParserTests0992.swift | 50 +++++------ .../Unit Tests/XMLParserTests0993.swift | 52 +++++------ .../XMLSerializerBlackBoxTests.swift | 2 +- .../XMLSerializerTests.swift | 32 +++---- .../Helper/CBXMLParserHelperTests.swift | 2 +- .../XMLParseMultipleScenesTests.swift | 62 +++++++++++++ .../PlayerEngine/CBBackendTests.swift | 2 +- .../FormulaManagerInterpreterTests.swift | 2 +- .../Frontend/CBFrontendTests.swift | 6 +- .../Sensors/Object/BrightnessSensorTest.swift | 2 +- .../Sensors/Object/LayerSensorTest.swift | 8 +- .../Project/ProjectMigratorTest.swift | 4 +- src/CattyTests/Project/ProjectTests.swift | 48 +++++----- .../Project/RequiredResourcesTests.swift | 12 +-- .../Custom/MultipleScenes/MultipleScenes.xml | 78 ++++++++++++++++ src/CattyTests/Scene/StageTests.swift | 4 +- .../WhenBackgroundChangesScriptTests.swift | 2 +- .../Scripts/WhenConditionScriptTests.swift | 2 +- .../SpriteObjectMutableCopyTests.swift | 4 +- src/CattyTests/Utils/UtilTests.swift | 4 +- .../FormulaEditorViewControllerTests.swift | 12 +-- ...esenterViewControllerScreenshotTests.swift | 10 +-- .../Data/BrickCellListDataTests.swift | 2 +- .../Data/BrickCellVariableDataTests.swift | 2 +- 69 files changed, 493 insertions(+), 330 deletions(-) create mode 100644 src/CattyTests/Parser & Serialization/XMLParseMultipleScenesTests.swift create mode 100644 src/CattyTests/Resources/ParserTests/Custom/MultipleScenes/MultipleScenes.xml diff --git a/src/Catty.xcodeproj/project.pbxproj b/src/Catty.xcodeproj/project.pbxproj index 9c22902b26..2d003bfcda 100644 --- a/src/Catty.xcodeproj/project.pbxproj +++ b/src/Catty.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 05501DE7255E106F00C64E58 /* color_change.dst in Resources */ = {isa = PBXBuildFile; fileRef = 05501DE4255E106F00C64E58 /* color_change.dst */; }; + 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 */; }; 05A3D46A24F517350051DB39 /* CatrobatTableViewControllerExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05A3D46924F517350051DB39 /* CatrobatTableViewControllerExtensionTests.swift */; }; @@ -1853,6 +1855,8 @@ 04A3B489CBF02EB8C919DC3B /* sr */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.strings; name = sr; path = sr.lproj/Localizable.strings; sourceTree = ""; }; 04FC473CDF0FCFB7BD890320 /* el */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.strings; name = el; path = el.lproj/Localizable.strings; sourceTree = ""; }; 05501DE4255E106F00C64E58 /* color_change.dst */ = {isa = PBXFileReference; lastKnownFileType = file; path = color_change.dst; 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 = ""; }; 05A3D46924F517350051DB39 /* CatrobatTableViewControllerExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CatrobatTableViewControllerExtensionTests.swift; sourceTree = ""; }; @@ -4298,6 +4302,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 05744DEF25C84234005455F9 /* MultipleScenes */ = { + isa = PBXGroup; + children = ( + 05744E0925C8437C005455F9 /* MultipleScenes.xml */, + ); + path = MultipleScenes; + sourceTree = ""; + }; 05E68011255B5DAA00D1E295 /* Embroidery */ = { isa = PBXGroup; children = ( @@ -4960,6 +4972,7 @@ 2ED4175F241120AF00AFE2FD /* Custom */ = { isa = PBXGroup; children = ( + 05744DEF25C84234005455F9 /* MultipleScenes */, 9E384934256191DC002D8F28 /* SamplerBricks */, D3EBE87C2488E6A90026F51A /* GoToBricks */, D3AF5C1C243F81FC00B04BC6 /* DisabledBricks */, @@ -5305,6 +5318,7 @@ 4C2CBB3A25A5AA8400C1C143 /* CatrobatLanguage0.993 */, 4C2CBB0825A5AA8400C1C143 /* UserListXMLHandlerTests.m */, 4C2CBB0725A5AA8400C1C143 /* SceneXMLHandlerTest.m */, + 05744DF825C84328005455F9 /* XMLParseMultipleScenesTests.swift */, ); path = "Parser & Serialization"; sourceTree = ""; @@ -11080,6 +11094,7 @@ 2D7BE51E21441DE500F78A10 /* StoreProjectDownloader.searchProjects.success.json in Resources */, 4C55CCE924BF2AA700FB8393 /* Nyancat_1.0_0992.xml in Resources */, 4C55CD0F24BF2C0600FB8393 /* ReplaceItemInUserListBrick0992.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 */, @@ -11626,6 +11641,7 @@ 5912C21623C4EAC700B3D9C0 /* FormulaTest.swift in Sources */, 9E2C2D8E23257387004B66C6 /* AbstractBrickTest.swift in Sources */, 4CD487761ED2C2A3001BB80A /* ChangeVariableBrickTests.swift in Sources */, + 05744DF925C84328005455F9 /* XMLParseMultipleScenesTests.swift in Sources */, E57E6D85254040B400E775DF /* ChangeVolumeByNBrickTests.swift in Sources */, 4C0A209824CEA46700CC9B04 /* PaintViewControllerMock.swift in Sources */, 4C82267B213FA7A400F3D750 /* BackgroundNumberSensorTest.swift in Sources */, diff --git a/src/Catty.xcodeproj/xcshareddata/xcschemes/Catty (DEBUG).xcscheme b/src/Catty.xcodeproj/xcshareddata/xcschemes/Catty (DEBUG).xcscheme index 8e440c991e..5bcc636711 100644 --- a/src/Catty.xcodeproj/xcshareddata/xcschemes/Catty (DEBUG).xcscheme +++ b/src/Catty.xcodeproj/xcshareddata/xcschemes/Catty (DEBUG).xcscheme @@ -77,26 +77,6 @@ ReferencedContainer = "container:Catty.xcodeproj"> - - - - - - - - *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) BOOL requiresBluetooth; diff --git a/src/Catty/DataModel/Project/Project.m b/src/Catty/DataModel/Project/Project.m index fbe2c3f2fe..66b456d896 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]; @@ -401,19 +418,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 51dbad896e..32d9e3f8c7 100644 --- a/src/Catty/Extension&Delegate&Protocol/Extensions/UIViewController/UIViewControllerExtension.swift +++ b/src/Catty/Extension&Delegate&Protocol/Extensions/UIViewController/UIViewControllerExtension.swift @@ -34,9 +34,10 @@ extension UIViewController { @objc func openProject(_ project: Project) { let storyboard = UIStoryboard.init(name: "iPhone", bundle: nil) - guard let viewController = storyboard.instantiateViewController(withIdentifier: "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 0f4050cc7d..4dc85e614e 100644 --- a/src/Catty/IO/ProjectManager.swift +++ b/src/Catty/IO/ProjectManager.swift @@ -31,32 +31,34 @@ 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/Parser&Serialializer/New Parser & Serializer/XMLHandler/Project/Project+CBXMLHandler.m b/src/Catty/Parser&Serialializer/New Parser & Serializer/XMLHandler/Project/Project+CBXMLHandler.m index 89dd4ad56a..d10e9df04d 100644 --- a/src/Catty/Parser&Serialializer/New Parser & Serializer/XMLHandler/Project/Project+CBXMLHandler.m +++ b/src/Catty/Parser&Serialializer/New Parser & Serializer/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/Catty/Parser&Serialializer/Old Parser/ProjectParser.m b/src/Catty/Parser&Serialializer/Old Parser/ProjectParser.m index 7cbae50827..ab55dbe78b 100644 --- a/src/Catty/Parser&Serialializer/Old Parser/ProjectParser.m +++ b/src/Catty/Parser&Serialializer/Old Parser/ProjectParser.m @@ -100,6 +100,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/PlayerEngine/Frontend/CBFrontend.swift b/src/Catty/PlayerEngine/Frontend/CBFrontend.swift index 52eadaffa7..eef03880c4 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 97ca87b15d..c6599e7c21 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 e99ca80937..a16b2ac4a4 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 a140df9b0d..9a538d75c1 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 53975a4fb9..5ff591b1d0 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 @@ -146,16 +149,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) @@ -296,7 +295,10 @@ final class Stage: SKScene, StageProtocol { view?.isPaused = true scheduler.shutdown() // stops all script contexts of all objects and removes all ressources removeAllChildren() // remove all CBSpriteNodes from Scene - frontend.project?.removeReferences() // remove all references in project hierarchy + CBScene.objects().forEach { + $0.removeReferences() + } + //CBScene.project!.removeReferences() formulaManager.stop() logger.info("All SpriteObjects and Scripts have been removed from Scene!") soundEngine.stop() diff --git a/src/Catty/ViewController/Stage/StagePresenterViewController.m b/src/Catty/ViewController/Stage/StagePresenterViewController.m index e60dcfd144..745986f8ff 100644 --- a/src/Catty/ViewController/Stage/StagePresenterViewController.m +++ b/src/Catty/ViewController/Stage/StagePresenterViewController.m @@ -306,17 +306,6 @@ - (void)setupStageAndStart [self continueAction:nil withDuration:kFirstSwipeDuration]; } --(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; @@ -364,7 +353,7 @@ - (void)continueAction:(UIButton*)sender withDuration:(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; @@ -445,7 +434,7 @@ - (void)manageAspectRatioAction:(UIButton *)sender - (void)takeScreenshotAction:(UIButton*)sender { - [self takeManualScreenshotForSKView:self.skView andProject:self.project.scene]; + [self takeManualScreenshotForSKView:self.skView andScene: [self.project.scenes objectAtIndex: 0]]; } #pragma mark - Pan Gesture Handler diff --git a/src/Catty/ViewController/Stage/StagePresenterViewControllerScreenshotExtension.swift b/src/Catty/ViewController/Stage/StagePresenterViewControllerScreenshotExtension.swift index 13a918b198..498da2c967 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/CattyTests/Bricks/AskBrickTests.swift b/src/CattyTests/Bricks/AskBrickTests.swift index a976e7dfcc..1682f93149 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 a8b5a9a266..19b3548792 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 a6c8572139..03472f6ece 100644 --- a/src/CattyTests/Bricks/ChangeBrightnessByNBrickTests.swift +++ b/src/CattyTests/Bricks/ChangeBrightnessByNBrickTests.swift @@ -38,7 +38,7 @@ final class ChangeBrightnessByNBrickTests: AbstractBrickTest { script = WhenScript() object = SpriteObject() project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + 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 e5b8cf3050..de292c6c7e 100644 --- a/src/CattyTests/Bricks/ChangeColorByNBrickTests.swift +++ b/src/CattyTests/Bricks/ChangeColorByNBrickTests.swift @@ -38,7 +38,7 @@ final class ChangeColorByNBrickTests: AbstractBrickTest { script = WhenScript() object = SpriteObject() project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + 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 bae14af65c..dc49c3575a 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 507a56708f..bff9742c4f 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 fb2c576c7d..11a33a76fb 100644 --- a/src/CattyTests/Bricks/ClearGraphicEffectBrickTests.swift +++ b/src/CattyTests/Bricks/ClearGraphicEffectBrickTests.swift @@ -36,7 +36,7 @@ final class ClearGraphicEffectBrickTests: AbstractBrickTest { super.setUp() object = SpriteObject() project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + 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 ea66d9a30a..c2b8455220 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 8b4920b567..cec2670484 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 73a0f4fab1..ad651c8974 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 3ce72bde80..5fb9295d8c 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 912c60c255..bfd605cd95 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 7ad5b1daed..f0f4b9f79a 100644 --- a/src/CattyTests/Bricks/NextLookBrickTests.swift +++ b/src/CattyTests/Bricks/NextLookBrickTests.swift @@ -29,7 +29,7 @@ final class NextLookBrickTests: AbstractBrickTest { func testNextLookBrick() { let object = SpriteObject() let project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + object.scene = (project.scenes[0] as! Scene) let spriteNode = CBSpriteNode(spriteObject: object) object.spriteNode = spriteNode diff --git a/src/CattyTests/Bricks/PreviousLookBrickTests.swift b/src/CattyTests/Bricks/PreviousLookBrickTests.swift index 493fafb723..f4d6c15296 100644 --- a/src/CattyTests/Bricks/PreviousLookBrickTests.swift +++ b/src/CattyTests/Bricks/PreviousLookBrickTests.swift @@ -29,7 +29,7 @@ final class PreviousLookBrickTests: AbstractBrickTest { func testNextLookBrick() { let object = SpriteObject() let project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + object.scene = (project.scenes[0] as! Scene) let spriteNode = CBSpriteNode(spriteObject: object) object.spriteNode = spriteNode diff --git a/src/CattyTests/Bricks/ReplaceItemInUserListBrickTests.swift b/src/CattyTests/Bricks/ReplaceItemInUserListBrickTests.swift index 07d6af25b9..b6a3b51b4b 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 78103d7f00..52caa1ade1 100644 --- a/src/CattyTests/Bricks/SetBrightnessBrickTests.swift +++ b/src/CattyTests/Bricks/SetBrightnessBrickTests.swift @@ -39,7 +39,7 @@ final class SetBrightnessBrickTests: AbstractBrickTest { object = SpriteObject() project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + 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 27005c334b..da33a16b1c 100644 --- a/src/CattyTests/Bricks/SetColorBrickTests.swift +++ b/src/CattyTests/Bricks/SetColorBrickTests.swift @@ -39,7 +39,7 @@ final class SetColorBrickTests: AbstractBrickTest { object = SpriteObject() project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + 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 f0d37676e4..37b7b88d65 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 e652987c1b..c8223135fe 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.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 ef2e7a5987..3826e52d1f 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 a85d3b184b..da05f52b35 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 698f299295..4938832b42 100644 --- a/src/CattyTests/DataModel/LookTest.swift +++ b/src/CattyTests/DataModel/LookTest.swift @@ -29,7 +29,7 @@ final class LookTest: XCTestCase { func testPathForScene() { let project = Project() let scene = Scene(name: "testScene") - project.scene = scene + project.scenes[0] = scene scene.project = project let look = Look(name: "testLook", filePath: "testLookFile") @@ -41,7 +41,7 @@ final class LookTest: XCTestCase { func testIsEqual() { let project = Project() let scene = Scene(name: "testScene") - project.scene = scene + project.scenes[0] = scene scene.project = project let look = Look(name: "testLook", filePath: "testLookFile") @@ -64,7 +64,7 @@ final class LookTest: XCTestCase { func testInitWithPath() { let object = SpriteObject() let project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + object.scene = (project.scenes[0] as! Scene) let spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode object.scene.project = project @@ -83,7 +83,7 @@ final class LookTest: XCTestCase { func testInitWithName() { let object = SpriteObject() let project = ProjectManager.createProject(name: "a", projectId: "1") - object.scene = project.scene + object.scene = (project.scenes[0] as! Scene) let spriteNode = CBSpriteNode.init(spriteObject: object) object.spriteNode = spriteNode object.scene.project = project diff --git a/src/CattyTests/DataModel/SoundTest.swift b/src/CattyTests/DataModel/SoundTest.swift index 533f8a23bc..1a05abbade 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 d9fa057b65..3b7320b292 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() { @@ -362,9 +362,9 @@ final class UserDataContainerTest: XCTestCase { let copyContainer = container.mutableCopy() as! UserDataContainer let copyProject = Project() - copyProject.scene = Scene() - copyProject.scene.add(object: objectA) - copyProject.scene.add(object: objectB) + 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)) diff --git a/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift b/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift index 2a56093ae1..ed9af1e5f6 100644 --- a/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift +++ b/src/CattyTests/Extensions/UIViewControllerExtensionTests.swift @@ -42,7 +42,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/Parser & Serialization/Abstract/XMLAbstractTest.swift b/src/CattyTests/Parser & Serialization/Abstract/XMLAbstractTest.swift index 49c0ae52e8..b53a0b75c8 100644 --- a/src/CattyTests/Parser & Serialization/Abstract/XMLAbstractTest.swift +++ b/src/CattyTests/Parser & Serialization/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/Parser & Serialization/CatrobatLanguage0.92/XMLParserTests092.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.92/XMLParserTests092.swift index 333bb66151..735abc2929 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.92/XMLParserTests092.swift +++ b/src/CattyTests/Parser & Serialization/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/Parser & Serialization/CatrobatLanguage0.93/Unit Tests/XMLParserBrickTests093.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.93/Unit Tests/XMLParserBrickTests093.swift index 930a04f7ee..8aa328092f 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.93/Unit Tests/XMLParserBrickTests093.swift +++ b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.93/Unit Tests/XMLParserBrickTests093.swift @@ -450,7 +450,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/Parser & Serialization/CatrobatLanguage0.98/XMLParserTests/Unit Tests/XMLParserTests098.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.98/XMLParserTests/Unit Tests/XMLParserTests098.swift index bdf77752ae..0e164e9877 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.98/XMLParserTests/Unit Tests/XMLParserTests098.swift +++ b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.98/XMLParserTests/Unit Tests/XMLParserTests098.swift @@ -35,8 +35,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 @@ -53,8 +53,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 @@ -70,9 +70,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 @@ -94,9 +94,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 @@ -117,9 +117,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 @@ -146,9 +146,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/Parser & Serialization/CatrobatLanguage0.991/XMLParserTests/Unit Tests/XMLParserTests0991.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.991/XMLParserTests/Unit Tests/XMLParserTests0991.swift index a872c76b1d..f5c4f265cc 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.991/XMLParserTests/Unit Tests/XMLParserTests0991.swift +++ b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.991/XMLParserTests/Unit Tests/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/Parser & Serialization/CatrobatLanguage0.992/XMLParserTests/Unit Tests/XMLParserTests0992.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.992/XMLParserTests/Unit Tests/XMLParserTests0992.swift index 422037b4e1..82cbf6f169 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.992/XMLParserTests/Unit Tests/XMLParserTests0992.swift +++ b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.992/XMLParserTests/Unit Tests/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/Parser & Serialization/CatrobatLanguage0.993/XMLParserTests/Unit Tests/XMLParserTests0993.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLParserTests/Unit Tests/XMLParserTests0993.swift index bf51b5311c..95a1e3e529 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLParserTests/Unit Tests/XMLParserTests0993.swift +++ b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLParserTests/Unit Tests/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/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerBlackBoxTests.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerBlackBoxTests.swift index cc32f67fd5..04c3974e42 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerBlackBoxTests.swift +++ b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerBlackBoxTests.swift @@ -31,7 +31,7 @@ final class XMLSerializerBlackBoxTests: XMLAbstractTest { func testInvalidAirFight() { let project095 = self.getProjectForXML(xmlFile: "Air_fight_0.5_095") - let background = project095.scene.object(at: 0)! + let background = (project095.scenes[0] as! Scene).object(at: 0)! background.name = "Invalid" let equal = self.isProject(firstProject: project095, equalToXML: "Air_fight_0.5_0993") XCTAssertFalse(equal, "Serialized project and XML are not equal") diff --git a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerTests.swift b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerTests.swift index d3b2871dac..8068709e01 100644 --- a/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerTests.swift +++ b/src/CattyTests/Parser & Serialization/CatrobatLanguage0.993/XMLSerializerTests/XMLSerializerTests.swift @@ -43,7 +43,8 @@ final class XMLSerializerTests: XMLAbstractTest { func testFormulaAndMoveNStepsBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 5) as! MoveNStepsBrick + 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,15 +54,16 @@ final class XMLSerializerTests: XMLAbstractTest { let projectName = "ValidProject0993" let referenceProject = self.getProjectForXML(xmlFile: projectName) let project = self.getProjectForXML(xmlFile: projectName) - - let moleOne = project.scene.object(at: 1)! - project.scene.removeObject(moleOne) + 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.993)), andRootElement: xmlElement) @@ -74,7 +76,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!") @@ -85,7 +87,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") @@ -96,7 +98,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testPenDownBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 41) 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 { @@ -110,7 +112,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testPenUpBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 42) 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 { @@ -124,7 +126,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testPenClearBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 43) 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 { @@ -138,7 +140,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testSetPenSizeBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 44) 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 { @@ -152,7 +154,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testSetPenColorBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 45) as! SetPenColorBrick + 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 { @@ -167,7 +169,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testStampBrick() { let project = self.getProjectForXML(xmlFile: "ValidProjectAllBricks0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 46) 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 { @@ -181,7 +183,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testAddItemToUserListBrick() { let project = self.getProjectForXML(xmlFile: "AddItemToUserListBrick0993") - let brick = (project.scene.object(at: 0)!.scriptList.object(at: 0) as! Script).brickList.object(at: 0) as! AddItemToUserListBrick + 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 { @@ -195,7 +197,7 @@ final class XMLSerializerTests: XMLAbstractTest { func testUserVariables() { let project = self.getProjectForXML(xmlFile: "UserVariables_0993") - 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/Parser & Serialization/Helper/CBXMLParserHelperTests.swift b/src/CattyTests/Parser & Serialization/Helper/CBXMLParserHelperTests.swift index e244220379..f48f79db24 100644 --- a/src/CattyTests/Parser & Serialization/Helper/CBXMLParserHelperTests.swift +++ b/src/CattyTests/Parser & Serialization/Helper/CBXMLParserHelperTests.swift @@ -48,7 +48,7 @@ final class CBXMLParserHelperTests: XCTestCase { let object = SpriteObject() object.scene = scene let project: Project! = ProjectManager.createProject(name: "a", projectId: "1") - project.scene = object.scene + project.scenes[0] = object.scene! let spriteNode = CBSpriteNode(spriteObject: object) let startScript = StartScript() diff --git a/src/CattyTests/Parser & Serialization/XMLParseMultipleScenesTests.swift b/src/CattyTests/Parser & Serialization/XMLParseMultipleScenesTests.swift new file mode 100644 index 0000000000..e0911f818c --- /dev/null +++ b/src/CattyTests/Parser & Serialization/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") + } +} diff --git a/src/CattyTests/PlayerEngine/CBBackendTests.swift b/src/CattyTests/PlayerEngine/CBBackendTests.swift index 97b0bcaa87..c66314e3d4 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 a18ac777f4..077db3c1ec 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 cd4c0104ca..37a34bec65 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 = kWhenScriptDefaultAction 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 = kWhenScriptDefaultAction 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 = kWhenScriptDefaultAction let waitBrick = WaitBrick() diff --git a/src/CattyTests/PlayerEngine/Sensors/Object/BrightnessSensorTest.swift b/src/CattyTests/PlayerEngine/Sensors/Object/BrightnessSensorTest.swift index 73029945a3..7fa8f88078 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 b35719cbfc..a5277c93b4 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 61e6ce74c9..19e4dd266f 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 14a064ca96..7106ccfeea 100644 --- a/src/CattyTests/Project/ProjectTests.swift +++ b/src/CattyTests/Project/ProjectTests.swift @@ -38,7 +38,7 @@ class ProjectTest: 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 ProjectTest: 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 ProjectTest: 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 ProjectTest: 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 ProjectTest: 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 ProjectTest: 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 ProjectTest: 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 ProjectTest: 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) @@ -370,16 +370,16 @@ class ProjectTest: 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 0096e481e7..8c0e83e6ff 100644 --- a/src/CattyTests/Project/RequiredResourcesTests.swift +++ b/src/CattyTests/Project/RequiredResourcesTests.swift @@ -40,13 +40,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 } @@ -814,7 +814,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() @@ -833,7 +833,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 } @@ -931,8 +931,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/Scene/StageTests.swift b/src/CattyTests/Scene/StageTests.swift index aa474a4ad3..124b7be869 100644 --- a/src/CattyTests/Scene/StageTests.swift +++ b/src/CattyTests/Scene/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/Scripts/WhenBackgroundChangesScriptTests.swift b/src/CattyTests/Scripts/WhenBackgroundChangesScriptTests.swift index c0353aced3..ae1ebfcd80 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 1ce1e60c6d..1bb2bb9a4b 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 e2be2a4e0a..f8f2e4e0d2 100644 --- a/src/CattyTests/SpriteObject/SpriteObjectMutableCopyTests.swift +++ b/src/CattyTests/SpriteObject/SpriteObjectMutableCopyTests.swift @@ -128,9 +128,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/Utils/UtilTests.swift b/src/CattyTests/Utils/UtilTests.swift index c34d23bc77..815b9d07cd 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() } @@ -176,7 +176,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 e2b2fa71d6..647841fbdb 100644 --- a/src/CattyTests/ViewController/FormulaEditorViewControllerTests.swift +++ b/src/CattyTests/ViewController/FormulaEditorViewControllerTests.swift @@ -41,10 +41,10 @@ final class FormulaEditorViewControllerTests: XCTestCase { scene = Scene(name: "testScene") scene.project = project - project.scene = scene + project.scenes[0] = scene! spriteObject = SpriteObjectMock() - project.scene.add(object: spriteObject!) + (project.scenes[0] as! Scene).add(object: spriteObject!) script = StartScript() spriteObject.scriptList.add(script!) @@ -109,7 +109,7 @@ final class FormulaEditorViewControllerTests: XCTestCase { XCTAssertFalse(controller.isVariableUsed(variable)) - project.scene.add(object: objectB) + (project.scenes[0] as! Scene).add(object: objectB) XCTAssertTrue(controller.isVariableUsed(variable)) } @@ -160,7 +160,7 @@ final class FormulaEditorViewControllerTests: XCTestCase { brick.userVariable = variable scriptB.brickList.add(brick) objectB.scriptList.add(scriptB) - project.scene.add(object: objectB) + (project.scenes[0] as! Scene).add(object: objectB) XCTAssertFalse(controller.isVariableUsed(variable)) @@ -225,7 +225,7 @@ final class FormulaEditorViewControllerTests: XCTestCase { XCTAssertFalse(controller.isListUsed(list)) - project.scene.add(object: objectB) + (project.scenes[0] as! Scene).add(object: objectB) XCTAssertTrue(controller.isListUsed(list)) } @@ -283,7 +283,7 @@ final class FormulaEditorViewControllerTests: XCTestCase { brick.userList = list scriptB.brickList.add(brick) objectB.scriptList.add(scriptB) - project.scene.add(object: objectB) + (project.scenes[0] as! Scene).add(object: objectB) XCTAssertFalse(controller.isListUsed(list)) diff --git a/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift b/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift index 99537de23e..f9b4fc4fc7 100644 --- a/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift +++ b/src/CattyTests/ViewController/Stage/StagePresenterViewControllerScreenshotTests.swift @@ -41,13 +41,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) @@ -69,13 +69,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) @@ -108,7 +108,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 eaa8795f9f..03fc66d54b 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 ad2da137ca..332b6862c7 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