Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

CATTY-446 Parse multiple scenes #1581

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions src/Catty.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "bc6a19702ac76ac4e488b68148710eb815f9bc56",
"version" : "1.7.0"
"revision" : "4e9bbf2808b8fee444e84a48f5f3c12641987d3e",
"version" : "1.7.2"
}
},
{
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 @@ -43,19 +43,21 @@ 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)
}

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 }

viewController.scene = project.scene
guard let scene = project.scenes[0] as? Scene else { return }
viewController.scene = scene
project.setAsLastUsedProject()
self.navigationController?.pushViewController(viewController, animated: true)
}

}

func openProjectDetails(projectId: String, storeProjectDownloader: StoreProjectDownloaderProtocol = StoreProjectDownloader()) {
if let baseTableViewController = self as? BaseTableViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,5 @@
- (void)backspace:(id)sender;
- (NSString*)interpretFormula:(Formula*)formula forSpriteObject:(SpriteObject*)spriteObject;
- (void)setParseErrorCursorAndSelection;

- (void)handleInput;

@end
16 changes: 9 additions & 7 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 Expand Up @@ -172,7 +174,7 @@
}

@objc func removeObjects(_ project: Project, objects: [SpriteObject]) {
let scene = project.scene
guard let scene = project.scenes[0] as? Scene else {return}
for object in objects where scene.objects().contains(object) {
scene.removeObject(object)
}
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
19 changes: 10 additions & 9 deletions src/Catty/PlayerEngine/Stage/Stage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,14 +36,16 @@ 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,
backend: CBBackendProtocol,
broadcastHandler: CBBroadcastHandlerProtocol,
formulaManager: FormulaManagerProtocol,
soundEngine: AudioEngineProtocol) {
self.CBScene = scene
self.logger = logger
self.scheduler = scheduler
self.frontend = frontend
Expand Down Expand Up @@ -149,16 +152,12 @@ final class Stage: SKScene, StageProtocol {
// MARK: - Start project

@objc func startProject() -> Bool {
guard let project = frontend.project else {
//fatalError
debugPrint("Invalid project. This should never happen!")
return false
}

guard let spriteObjectList = project.scene.objects() as NSArray? as? [SpriteObject],
guard let spriteObjectList = CBScene.objects() as NSArray? as? [SpriteObject],
let project = CBScene.project,
let variableList = UserDataContainer.allVariables(for: project) as NSArray? as? [UserVariable] else {
//fatalError
debugPrint("!! Invalid sprite object list given !! This should never happen!")
debugPrint("!! Invalid scene or sprite object list given !! This should never happen!")
return false
}
assert(Thread.current.isMainThread)
Expand Down Expand Up @@ -302,7 +301,9 @@ final class Stage: SKScene, StageProtocol {
DispatchQueue.main.async {
self.removeAllChildren() // remove all CBSpriteNodes from Scene
}
frontend.project?.removeReferences() // remove all references in project hierarchy
CBScene.objects().forEach {
$0.removeReferences()
}
formulaManager.stop()
logger.info("All SpriteObjects and Scripts have been removed from Scene!")
soundEngine.stop()
Expand Down
15 changes: 2 additions & 13 deletions src/Catty/ViewController/Stage/StagePresenterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,6 @@ - (void)setupStageAndStart
[self continueActionWithDuration:UIDefines.firstSwipeDuration];
}

-(void)resaveLooks
{
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
for (SpriteObject *object in self.project.scene.objects) {
for (Look *look in object.lookList) {
[[RuntimeImageCache sharedImageCache] loadImageFromDiskWithPath:look.fileName];
}
}
});
}

- (BOOL)prefersStatusBarHidden
{
return YES;
Expand Down Expand Up @@ -367,7 +356,7 @@ - (void)continueActionWithDuration:(CGFloat)duration
self.menuOpen = NO;
self.menuView.userInteractionEnabled = YES;
if (animateDuration == duration) {
[self takeAutomaticScreenshotForSKView:self.skView andProject:self.project.scene];
[self takeAutomaticScreenshotForSKView:self.skView andScene:[self.project.scenes objectAtIndex:0]];
}
}];
self.skView.paused = NO;
Expand Down Expand Up @@ -454,7 +443,7 @@ - (void)aspectRatioAction

- (void)takeScreenshotAction
{
[self takeManualScreenshotForSKView:self.skView andProject:self.project.scene];
[self takeManualScreenshotForSKView:self.skView andScene: [self.project.scenes objectAtIndex: 0]];
}

- (void)shareDSTAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ extension StagePresenterViewController {
func shareDST(embroideryService: EmbroideryProtocol) {

var embroideryStream = [EmbroideryStream]()
for object in project.scene.objects() where !object.spriteNode.embroideryStream.isEmpty {

guard let scene = project.scenes[0] as? Scene else {return}
for object in scene.objects() where !object.spriteNode.embroideryStream.isEmpty {
embroideryStream.append(object.spriteNode.embroideryStream)
}
let embroideryStreamMerged = EmbroideryStream(streams: embroideryStream)
Expand Down
Loading