Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

156 lines (114 sloc) 4.52 KB
// OCGameDataController.h
// Created by Philip Regan on 4/12/12.
// Copyright (c) 2012 Jones & Bartlett Learning. All rights reserved.
This class is the go-between the view controllers and the Core Data store, and has
been designed to make a clean seperation of duties between the view controllers and
how data actually gets managed as opposed to just being displayed. This class, wherever
possible, manages all CRUD-related tasks for the game editor and player tracks.
The view controllers are intended to only go through here for what they need and not
talk to Core Data directly. The GameDataController, however, contains some game
logic via its public methods so that they address needs specific to various types
of views, effectively providing convenience methods for handling data, but it holds
only minimally necessary game data itself. It only holds enough data required to
successfully manage content to and from the data store between view controllers.
This class in intended to be passed from view controller to view controller so that
the current game being affected is properly tracked.
Errors generated by this class are generally a Very Bad Thing and while there is little
point in continuing with the runtime once something occurs, this class will absorb
as much of the impact as much as possible.
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface OCGameDataController : NSObject
#pragma mark - Properties
@property (strong, nonatomic, readwrite) NSManagedObject *currentUniverse;
#pragma mark - Object Lifecycle Stack
Designated initializer for the class
- (id)initWithManagedObjectContext:(NSManagedObjectContext *)moc;
#pragma mark - Content Lifecycle
Helper method that helps prevent unwanted content installs if it has happened once
already. Returns YES if it finds an instance of the Universe entity, else returns NO
on anything else.
- (BOOL)dataStoreIsPopulated;
Helper method that populates a newly-created Core Data store with sample games
- (BOOL) populateDefaults;
helper method that creates a sample game based on the specified type pass
- (BOOL)populateSampleGame:(int)type;
helper method that manages saving of the data store on behalf of external classes.
Returns NO upon any error returned by the context
- (void)updateChanges;
helper method that handles the deleting of the whole data store and repopulates with
the default games. Put in place for demoing purposes.
#pragma mark - MainViewController Stack
creates a new RPG for the user of the exact same architecture as the two samples
- (BOOL)createNewUniverse;
returns an array of NSManagedObjects of all the games held in the data store
- (NSMutableArray *)retrieveGames;
deletes a universe and everything contained within it
- (BOOL)deleteUniverse:(NSManagedObject *)targetUniverse;
#pragma mark - Player Metadata Stack
Content getters and setters for the player information
#pragma mark Name Stack
- (NSString *)retrievePlayerName;
// returns an empty string on any error
- (void)updatePlayerName:(NSString *)playerName;
#pragma mark Intro Stack
- (NSString *)retrievePlayerIntro;
// returns an empty string on any error
- (void)updatePlayerIntro:(NSString *)playerIntro;
#pragma mark - Game Object Selection Stack
#pragma mark Task Stack
CRUD convenience methods for tasks
- (BOOL)createNewTask;
- (NSMutableArray *)retrieveTasks;
- (BOOL)deleteTask:(NSManagedObject *)targetTask;
#pragma mark Quest Stack
CRUD convenience methods for quests
- (BOOL)createNewQuest;
- (NSMutableArray *)retrieveQuests;
- (BOOL)deleteQuest:(NSManagedObject *)targetQuest;
#pragma mark - Game Play Stack
-(NSManagedObject *)getHomeLocation;
-(NSArray *)getAccomplishmentsForLocation:(NSManagedObject *)location;
-(NSArray *)getLinkedLocationsForLocation:(NSManagedObject *)location;
#pragma mark - Game Object Linking Stack
returns an array containing all of the objects related to another object.
- (NSArray *)retrieveEntities:(NSString *)entity relatedToObject:(NSManagedObject *)sourceObject viaRelationship:(NSString *)targetRelationship;
convenience methods to manage the linking and de-linking of objects to and from a parent.
- (void)linkObjects:(NSMutableSet *)childObjects toParent:(NSManagedObject *)targetParent viaRelationship:(NSString *)relationship;
- (void)delinkObjects:(NSMutableSet *)childObjects fromParent:(NSManagedObject *)targetParent viaRelationship:(NSString *)relationship;
Jump to Line
Something went wrong with that request. Please try again.