Skip to content

Commit

Permalink
CATTY-446 Parse multiple scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
afibian authored and lucatp committed Aug 28, 2023
1 parent e488257 commit 9800c53
Show file tree
Hide file tree
Showing 69 changed files with 860 additions and 420 deletions.
16 changes: 16 additions & 0 deletions src/Catty.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
0594CE62275E55B0007DC3F9 /* SewUpBrickCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0594CE61275E55B0007DC3F9 /* SewUpBrickCell.swift */; };
0594CE64275E55CD007DC3F9 /* SewUpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0594CE63275E55CD007DC3F9 /* SewUpTests.swift */; };
0594CE66275E567E007DC3F9 /* SewUpBrickTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0594CE65275E567D007DC3F9 /* SewUpBrickTests.swift */; };
05744DF925C84328005455F9 /* XMLParseMultipleScenesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05744DF825C84328005455F9 /* XMLParseMultipleScenesTests.swift */; };
05744E0A25C8437C005455F9 /* MultipleScenes.xml in Resources */ = {isa = PBXBuildFile; fileRef = 05744E0925C8437C005455F9 /* MultipleScenes.xml */; };
05A3CE6D24F5164A0051DB39 /* CatrobatTableViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05A3CE6A24F516490051DB39 /* CatrobatTableViewControllerExtension.swift */; };
05A3D46824F517220051DB39 /* StoreProjectTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05A3D46724F517220051DB39 /* StoreProjectTests.swift */; };
05CBC6BF286C5A4B007FBA61 /* TripleStitchPattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05CBC6BC286C5A4B007FBA61 /* TripleStitchPattern.swift */; };
Expand Down Expand Up @@ -2175,6 +2177,8 @@
0594CE61275E55B0007DC3F9 /* SewUpBrickCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SewUpBrickCell.swift; sourceTree = "<group>"; };
0594CE63275E55CD007DC3F9 /* SewUpTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SewUpTests.swift; sourceTree = "<group>"; };
0594CE65275E567D007DC3F9 /* SewUpBrickTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SewUpBrickTests.swift; sourceTree = "<group>"; };
05744DF825C84328005455F9 /* XMLParseMultipleScenesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XMLParseMultipleScenesTests.swift; sourceTree = "<group>"; };
05744E0925C8437C005455F9 /* MultipleScenes.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = MultipleScenes.xml; sourceTree = "<group>"; };
05A3CE6A24F516490051DB39 /* CatrobatTableViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CatrobatTableViewControllerExtension.swift; sourceTree = "<group>"; };
05A3D46724F517220051DB39 /* StoreProjectTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreProjectTests.swift; sourceTree = "<group>"; };
05CBC6BC286C5A4B007FBA61 /* TripleStitchPattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TripleStitchPattern.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4846,6 +4850,12 @@
056677EC27DBD33E006B4477 /* ZigzagStitchPattern.swift */,
);
path = Pattern;
05744DEF25C84234005455F9 /* MultipleScenes */ = {
isa = PBXGroup;
children = (
05744E0925C8437C005455F9 /* MultipleScenes.xml */,
);
path = MultipleScenes;
sourceTree = "<group>";
};
05E68011255B5DAA00D1E295 /* Embroidery */ = {
Expand Down Expand Up @@ -5449,6 +5459,7 @@
children = (
C8076A26267A0B2000801AF6 /* Functions */,
E5C5D89525B1DEAF00D96E4B /* Object */,
05744DEF25C84234005455F9 /* MultipleScenes */,
9E384934256191DC002D8F28 /* SamplerBricks */,
D3EBE87C2488E6A90026F51A /* GoToBricks */,
D3AF5C1C243F81FC00B04BC6 /* DisabledBricks */,
Expand Down Expand Up @@ -6125,6 +6136,7 @@
4C2CBB3125A5AA8400C1C143 /* Helper */,
4C2CBB0825A5AA8400C1C143 /* UserListXMLHandlerTests.m */,
4C2CBB0725A5AA8400C1C143 /* SceneXMLHandlerTest.m */,
05744DF825C84328005455F9 /* XMLParseMultipleScenesTests.swift */,
);
path = XML;
sourceTree = "<group>";
Expand Down Expand Up @@ -11999,6 +12011,9 @@
E5EC6D5426B00FF60031F13A /* Galaxy_War_09993.xml in Resources */,
7B37463529AD168A0085A90D /* StoreProjectUploader.upload.fail.validation.json in Resources */,
E59108B926931E49008D254A /* DisabledBricks_0994.xml in Resources */,
05744E0A25C8437C005455F9 /* MultipleScenes.xml in Resources */,
2DCB4928212EA477005E8E3D /* StoreProjectDownloader.fetchMostViewedProjects.fail.request.json in Resources */,
2ED41844241120B000AFE2FD /* Minions__093.xml in Resources */,
2ED41875241120B000AFE2FD /* LedFlashBrick0991.xml in Resources */,
E5DAAD6026C5486000C2457F /* ValidHeader09997.xml in Resources */,
E598BBC226A029C900D4825F /* EscapingChars_0996.xml in Resources */,
Expand Down Expand Up @@ -12568,6 +12583,7 @@
9E2C2D8E23257387004B66C6 /* AbstractBrickTest.swift in Sources */,
49402BA528117A63009FCBF8 /* MiddleFingerSensorTest.swift in Sources */,
4CD487761ED2C2A3001BB80A /* ChangeVariableBrickTests.swift in Sources */,
05744DF925C84328005455F9 /* XMLParseMultipleScenesTests.swift in Sources */,
E57E6D85254040B400E775DF /* ChangeVolumeByNBrickTests.swift in Sources */,
2E8780A82542BCE200816B52 /* WebRequestBrickTests.swift in Sources */,
499EBFE127EB07A900897349 /* EyeSensorTest.swift in Sources */,
Expand Down
42 changes: 8 additions & 34 deletions src/Catty.xcodeproj/xcshareddata/xcschemes/Catty (DEBUG).xcscheme
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
version = "1.7">
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand Down Expand Up @@ -29,8 +29,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CA7698A91B0E4A97000D0340"
BuildableName = "CattyTests.xctest"
BlueprintName = "CattyTests"
BuildableName = "Catty Tests.xctest"
BlueprintName = "Catty Tests"
ReferencedContainer = "container:Catty.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -43,8 +43,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "187E079F24E26CED00E652C4"
BuildableName = "CattyUISnapshots.xctest"
BlueprintName = "CattyUISnapshots"
BuildableName = "Catty UISnapshots.xctest"
BlueprintName = "Catty UISnapshots"
ReferencedContainer = "container:Catty.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -66,43 +66,17 @@
ReferencedContainer = "container:Catty.xcodeproj">
</BuildableReference>
</MacroExpansion>
<TestPlans>
<TestPlanReference
reference = "container:Catty.xcodeproj/CattyTestplan.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CA7698A91B0E4A97000D0340"
BuildableName = "CattyTests.xctest"
BlueprintName = "CattyTests"
BuildableName = "Catty Tests.xctest"
BlueprintName = "Catty Tests"
ReferencedContainer = "container:Catty.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AAADA0031B9B29D500E0CA9A"
BuildableName = "CattyUITests.xctest"
BlueprintName = "CattyUITests"
ReferencedContainer = "container:Catty.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "92EC98A91BC3C32A0003A891"
BuildableName = "BluetoothHelperTests.xctest"
BlueprintName = "BluetoothHelperTests"
ReferencedContainer = "container:Catty/BluetoothHelper/BluetoothHelper.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
4 changes: 3 additions & 1 deletion src/Catty/DataModel/Project/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
@interface Project : NSObject

@property (nonatomic, strong, nonnull) Header *header;
@property (nonatomic, strong, nonnull) Scene *scene;
@property (nonatomic, strong, nonnull) NSMutableArray<Scene*> *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<NSString*> *unsupportedElements;
@property (nonatomic, strong, nonnull) NSMutableSet<NSString*> *physicsObjectNames;
Expand Down
53 changes: 36 additions & 17 deletions src/Catty/DataModel/Project/Project.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ - (instancetype)init
{
_allBroadcastMessages = [[NSMutableOrderedSet alloc] init];
}
self.scenes = [[NSMutableArray alloc] init];
[self.scenes addObject: [[Scene alloc] init]];
return self;
}

Expand Down Expand Up @@ -153,7 +155,11 @@ - (void)renameToProjectName:(NSString*)projectName andProjectId:(NSString*)proje

- (NSArray<SpriteObject*>*)allObjects
{
return self.scene.objects;
NSMutableArray<SpriteObject*> *objects = [[NSMutableArray<SpriteObject*> alloc] init];
for (Scene* scene in self.scenes) {
[objects addObjectsFromArray: [scene objects]];
}
return objects;
}

- (void)setDescription:(NSString*)description
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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];
Expand Down Expand Up @@ -397,19 +414,21 @@ + (void)removeProjectFromDiskWithProjectName:(NSString*)projectName projectID:(N

- (void)translateDefaultProject
{
NSUInteger index = 0;
for (SpriteObject *spriteObject in self.scene.objects) {
if (index == kBackgroundObjectIndex) {
spriteObject.name = kLocalizedBackground;
} else {
NSMutableString *spriteObjectName = [NSMutableString stringWithString:spriteObject.name];
[spriteObjectName replaceOccurrencesOfString:kDefaultProjectBundleOtherObjectsNamePrefix
withString:kLocalizedMole
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, spriteObjectName.length)];
spriteObject.name = (NSString*)spriteObjectName;
for (Scene* scene in self.scenes) {
NSUInteger index = 0;
for (SpriteObject *spriteObject in scene.objects) {
if (index == kBackgroundObjectIndex) {
spriteObject.name = kLocalizedBackground;
} else {
NSMutableString *spriteObjectName = [NSMutableString stringWithString:spriteObject.name];
[spriteObjectName replaceOccurrencesOfString:kDefaultProjectBundleOtherObjectsNamePrefix
withString:kLocalizedMole
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, spriteObjectName.length)];
spriteObject.name = (NSString*)spriteObjectName;
}
++index;
}
++index;
}
[self renameToProjectName:kLocalizedMyFirstProject andShowSaveNotification:NO]; // saves to disk!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ extension UIViewController {

@objc func openLoginScreen(_ delegate: AuthenticationDelegate? = nil) {
let storyboard = UIStoryboard.init(name: "iPhone", bundle: nil)
guard let viewController = storyboard.instantiateViewController(withIdentifier: "LoginController") as? LoginViewController else { return }
viewController.delegate = delegate
self.navigationController?.pushViewController(viewController, animated: true)
}

@objc func openProject(_ project: Project) {
guard let viewController = self.instantiateViewController("SceneTableViewController") as? SceneTableViewController else { return }
guard let viewController = storyboard.instantiateViewController(withIdentifier: "SceneTableViewController")
as? SceneTableViewController, let scene = project.scenes[0] as? Scene else { return }

viewController.scene = project.scene
viewController.scene = scene
project.setAsLastUsedProject()
self.navigationController?.pushViewController(viewController, animated: true)
}
Expand Down
14 changes: 8 additions & 6 deletions src/Catty/IO/ProjectManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,34 @@
@objc func createProject(name: String, projectId: String?) -> Project {
let project = Project()
let projectName = Util.uniqueName(name, existingNames: Project.allProjectNames())
project.scene = Scene(name: Util.defaultSceneName(forSceneNumber: 1))
project.scene.project = project
project.header = Header.default()
project.header.programName = projectName
project.header.programID = projectId

let scene = Scene(name: Util.defaultSceneName(forSceneNumber: 1))
scene.project = project

if fileManager.directoryExists(projectName) == false {
fileManager.createDirectory(project.projectPath())
}

let sceneDir = project.scene.path()
let sceneDir = scene.path()
if !fileManager.directoryExists(sceneDir) {
fileManager.createDirectory(sceneDir)
}

let imagesDirName = project.scene.imagesPath()
let imagesDirName = scene.imagesPath()
if fileManager.directoryExists(imagesDirName) == false {
fileManager.createDirectory(imagesDirName)
}

let soundDirName = project.scene.soundsPath()
let soundDirName = scene.soundsPath()
if fileManager.directoryExists(soundDirName) == false {
fileManager.createDirectory(soundDirName)
}

project.scene.addObject(withName: kLocalizedBackground)
scene.addObject(withName: kLocalizedBackground)
project.scenes[0] = scene

let filePath = project.projectPath() + kScreenshotAutoFilename
let projectIconNames = UIDefines.defaultScreenshots
Expand Down
4 changes: 1 addition & 3 deletions src/Catty/PlayerEngine/Frontend/CBFrontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/Catty/PlayerEngine/Protocols/CBFrontendProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

protocol CBFrontendProtocol {

var project: Project? { get }

func computeSequenceListForScript(_ script: Script) -> CBScriptSequenceList
func addSequenceFilter(_ sequenceFilter: CBFrontendSequenceFilterProtocol)

}
4 changes: 2 additions & 2 deletions src/Catty/PlayerEngine/Sensors/Object/LayerSensor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/Catty/PlayerEngine/Stage/Builder/StageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 9800c53

Please sign in to comment.