]> Dogcows Code - chaz/thecheat/blob - CheatData.m
update contact information and project URL
[chaz/thecheat] / CheatData.m
1
2 /*
3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
5 *
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
7 *
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
10 */
11
12 #import "CheatData.h"
13
14
15 @implementation CheatData
16
17
18 // #############################################################################
19 #pragma mark Initialization
20 // #############################################################################
21
22 - (id)init
23 {
24 if ( self = [super init] )
25 {
26 // set defaults
27 [self setWindowTitle:@""];
28 [self setCheatInfo:@""];
29 [self setProcess:[[[Process alloc] initWithName:@"No Target Set" version:@""] autorelease]];
30
31 myRepeats = NO;
32 myRepeatInterval = 5.0;
33
34 // create objects
35 myVariables = [[NSMutableArray alloc] init];
36 }
37 return self;
38 }
39
40 - (void)dealloc
41 {
42 // release objects
43 [myWindowTitle release];
44 [myCheatInfo release];
45 [myProcess release];
46 [myVariables release];
47
48 [super dealloc];
49 }
50
51
52 // #############################################################################
53 #pragma mark NSCoding
54 // #############################################################################
55
56 - (id)initWithCoder:(NSCoder *)coder
57 {
58 if ( self = [super init] )
59 {
60 [self setWindowTitle:[coder decodeObject]];
61 [self setCheatInfo:[coder decodeObject]];
62 [self setProcess:[coder decodeObject]];
63 myVariables = [[coder decodeObject] retain];
64 [coder decodeValueOfObjCType:@encode(BOOL) at:&myRepeats];
65 [coder decodeValueOfObjCType:@encode(NSTimeInterval) at:&myRepeatInterval];
66 }
67 return self;
68 }
69
70 - (void)encodeWithCoder:(NSCoder *)coder
71 {
72 [coder encodeObject:myWindowTitle];
73 [coder encodeObject:myCheatInfo];
74 [coder encodeObject:myProcess];
75 [coder encodeObject:myVariables];
76 [coder encodeValueOfObjCType:@encode(BOOL) at:&myRepeats];
77 [coder encodeValueOfObjCType:@encode(NSTimeInterval) at:&myRepeatInterval];
78 }
79
80
81 // #############################################################################
82 #pragma mark Accessing Properties
83 // #############################################################################
84
85
86 - (NSString *)windowTitle
87 {
88 return myWindowTitle;
89 }
90
91 - (NSString *)cheatInfo
92 {
93 return myCheatInfo;
94 }
95
96 - (NSString *)gameName
97 {
98 return [myProcess name];
99 }
100
101 - (NSString *)gameVersion
102 {
103 return [myProcess version];
104 }
105
106 - (Process *)process
107 {
108 return myProcess;
109 }
110
111 - (BOOL)repeats
112 {
113 return myRepeats;
114 }
115
116 - (NSTimeInterval)repeatInterval
117 {
118 return myRepeatInterval;
119 }
120
121
122 - (void)setWindowTitle:(NSString *)title
123 {
124 if ( !title ) {
125 title = [NSString stringWithString:@""];
126 }
127 [title retain];
128 [myWindowTitle release];
129 myWindowTitle = title;
130 }
131
132 - (void)setCheatInfo:(NSString *)info
133 {
134 if ( !info ) {
135 info = [NSString stringWithString:@"Description not provided."];
136 }
137 [info retain];
138 [myCheatInfo release];
139 myCheatInfo = info;
140 }
141
142 - (void)setProcess:(Process *)process
143 {
144 [process retain];
145 [myProcess release];
146 myProcess = process;
147 }
148
149 - (void)setRepeats:(BOOL)repeats
150 {
151 myRepeats = repeats;
152 }
153
154 - (void)setRepeatInterval:(NSTimeInterval)interval
155 {
156 myRepeatInterval = interval;
157 }
158
159
160 // #############################################################################
161 #pragma mark Variables
162 // #############################################################################
163
164 - (NSArray *)variables
165 {
166 return [NSArray arrayWithArray:myVariables];
167 }
168
169 - (unsigned)variableCount
170 {
171 return [myVariables count];
172 }
173
174 - (unsigned)indexOfVariable:(Variable *)variable
175 {
176 return [myVariables indexOfObject:variable];
177 }
178
179 - (Variable *)variableAtIndex:(unsigned)index
180 {
181 return [myVariables objectAtIndex:index];
182 }
183
184 - (Variable *)lastVariable
185 {
186 return [myVariables lastObject];
187 }
188
189
190 - (void)addVariable:(Variable *)variable
191 {
192 [myVariables addObject:variable];
193 }
194
195 - (void)insertVariable:(Variable *)variable atIndex:(unsigned)index
196 {
197 [myVariables insertObject:variable atIndex:index];
198 }
199
200
201 - (void)removeAllVariables
202 {
203 [myVariables removeAllObjects];
204 }
205
206 - (void)removeVariable:(Variable *)variable
207 {
208 [myVariables removeObject:variable];
209 }
210
211 - (void)removeVariableAtIndex:(unsigned)index
212 {
213 [myVariables removeObjectAtIndex:index];
214 }
215
216
217 - (NSArray *)enabledVariables
218 {
219 NSMutableArray *vars;
220 int i, top;
221
222 top = [myVariables count];
223 vars = [[NSMutableArray alloc] init];
224
225 for ( i = 0; i < top; i++ ) {
226 Variable *var = [myVariables objectAtIndex:i];
227 if ( [var isEnabled] ) {
228 [vars addObject:var];
229 }
230 }
231 return [vars autorelease];
232 }
233
234 - (unsigned)enabledVariableCount
235 {
236 return [[self enabledVariables] count];
237 }
238
239
240 @end
This page took 0.04051 seconds and 4 git commands to generate.