Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
//  DataManager.m
//  Location
//
//  Created by Fabrizio on 11/12/12.
//  Copyright (c) 2012 Odyssey. All rights reserved.
//

#import "DataManager.h"
#import "Scena.h"
#import "SceneButton.h"

#import "SceneObject.h"

@implementation DataManager

@synthesize scene;
@synthesize idScena;
@synthesize sceneObject;

static DataManager *instance;

+(DataManager *) getInstance {
	if (!instance) {
		instance = [[DataManager alloc] init];
	}
	return instance;
}

#pragma mark - Initialisation & View Admin

- (id) init {
	if((self = [super init])) {
		instance = self;
        isSaved = NO;
	}
	return self;
}

#pragma mark - Parse JON GLEEN JSON

- (void) jonGleenJSON {
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"JonGleen" ofType:@"js"];
    NSString *storyJSON = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

    NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[storyJSON dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];
       
    scene = [NSMutableArray array];
    
    for (NSDictionary *dictionary in [json objectForKey:@"results"]) {
        
//        LOG_INFO_X(@"dataDict: %@", dictionary);
        
        Scena *scena = [Scena alloc];
        scena.buttons = [NSMutableArray array];
        
        scena.idScena = [[dictionary  valueForKey:@"_id"] intValue];
        scena.testo = (NSString*)[dictionary valueForKey:@"text"];
        scena.bckImage = (NSString*)[dictionary valueForKey:@"topImage"];
        
        LOG_INFO_X(@"scena.id: %d", scena.idScena);
        LOG_INFO_X(@"scena.testo: %@", scena.testo);
        LOG_INFO_X(@"scena.bckImage: %@", scena.bckImage);
        
        for (NSDictionary *bDictionary in [dictionary objectForKey:@"scenebuttons"]) {
            
//            LOG_INFO_X(@"bDictionary: %@", bDictionary);
            
            /*
             "buttonImage": "button.png",
             "targetId": "2",
             "buttonText": "Ti Nascondi Sotto il letto",
             "buttonPreCond": "",
             "buttonPostCond": ""
             */
            
            SceneButton *sceneButton = [SceneButton alloc];
            
            sceneButton.image = (NSString*)[bDictionary valueForKey:@"buttonImage"];
            sceneButton.targetId = (NSString*)[bDictionary valueForKey:@"targetId"];
            sceneButton.text = (NSString*)[bDictionary valueForKey:@"buttonText"];
            sceneButton.preCond = (NSString*)[bDictionary valueForKey:@"buttonPreCond"];
            sceneButton.postCond = (NSString*)[bDictionary valueForKey:@"buttonPostCond"];
            
            LOG_INFO_X(@"Scene Button - image: %@", sceneButton.image);
            LOG_INFO_X(@"Scene Button - targetId: %@", sceneButton.targetId);
            LOG_INFO_X(@"Scene Button - text: %@", sceneButton.text);
            LOG_INFO_X(@"Scene Button - preCond: %@", sceneButton.preCond);
            LOG_INFO_X(@"Scene Button - postCond: %@", sceneButton.postCond);
            
            [scena.buttons addObject:sceneButton];
        }
        
        [scene addObject:scena];
    }
}

#pragma mark - Objects Creation
- (void) loadObjects {
    
    self.sceneObject = [SceneObject alloc];
    sceneObject.image = @"Jon.jpg";
    sceneObject.boolValue = NO;
}

#pragma mark - Scene Saving Management

- (void) saveScena:(int)anIdScena {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	
    [prefs setInteger:anIdScena forKey:@"idScena"];
    [prefs setBool:sceneObject.boolValue forKey:@"objectBool"];
	[prefs synchronize];
    
    isSaved = YES;
}

- (void) loadScena {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	self.idScena = [prefs integerForKey:@"idScena"];
    
    if(isSaved) {
        self.sceneObject.boolValue = [prefs boolForKey:@"objectBool"];
    }
}

- (void) removeScena {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	
	[prefs removeObjectForKey:@"idScena"];
    [prefs removeObjectForKey:@"objectBool"];
	[prefs synchronize];
}

@end

Commits for Nextrek/iOS/StoryBoard/StoryBoard/DataManager.m

Diff revisions: vs.
Revision Author Commited Message
52 FAquili picture FAquili Tue 10 Dec, 2013 21:18:24 +0000

1.0 Storyboards