[go: up one dir, main page]

Menu

[r51]: / trunk / core / model.pas  Maximize  Restore  History

Download this file

365 lines (314 with data), 9.6 kB

  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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
unit Model;
{$MODE ObjFpc}
{$H+}
{$M+}
interface
uses
Classes, SysUtils, Fgl,
(* project libs *)
EasySqliteOrm;
type
TBaseObject = class(TObject)
private
FId: Integer;
FName: String;
public
constructor Create;
constructor Create(AnId: Integer; const AName: String);
published
property Id: Integer read FId write FId;
property Name: String read FName write FName;
end;
TSetting = class(TObject)
private
FKey: String;
FValue: String;
published
property Key: String read FKey write FKey;
property Value: String read FValue write FValue;
end;
TSettingList = class(specialize TFPGObjectList<TSetting>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
end;
TPage = class(TBaseObject)
private
FChapterId: Integer;
FContent: String;
FContentType: Integer;
FImageId: Integer;
FPageType: Integer;
FTitle: String;
published
property ChapterId: Integer read FChapterId write FChapterId;
property PageType: Integer read FPageType write FPageType;
property Title: String read FTitle write FTitle;
property Content: String read FContent write FContent;
property ContentType: Integer read FContentType write FContentType;
property ImageId: Integer read FImageId write FImageId;
end;
TPageList = class(specialize TFPGObjectList<TPage>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
end;
TPageExit = class(TBaseObject)
private
FCaption: String;
FIsCOnditional: Boolean;
FPageId: Integer;
FTargetPageId: Integer;
published
property PageId: Integer read FPageId write FPageId;
property TargetPageId: Integer read FTargetPageId write FTargetPageId;
property Caption: String read FCaption write FCaption;
property IsConditional: Boolean read FIsCOnditional write FIsCOnditional;
end;
TPageExitList = class(specialize TFPGObjectList<TPageExit>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
function FindById(Id: Integer): TPageExit;
end;
TPageExitCondition = class(TBaseObject)
private
FConditionObjectId: Integer;
FConditionType: Integer;
FConditionValue: Integer;
FPageExitId: Integer;
published
property PageExitId: Integer read FPageExitId write FPageExitId;
property ConditionType: Integer read FConditionType write FConditionType;
property ConditionObjectId: Integer read FConditionObjectId write FConditionObjectId;
property ConditionValue: Integer read FConditionValue write FConditionValue;
end;
TPageExitConditionList = class(specialize TFPGObjectList<TPageExitCondition>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
end;
TAction = class(TBaseObject)
private
FActionObjectId: Integer;
FActionType: Integer;
FActionValue: String;
FPageId: Integer;
published
property PageId: Integer read FPageId write FPageId;
property ActionType: Integer read FActionType write FActionType;
property ActionObjectId: Integer read FActionObjectId write FActionObjectId;
property ActionValue: String read FActionValue write FActionValue;
end;
TActionList = class(specialize TFPGObjectList<TAction>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
end;
TAttribute = class(TBaseObject)
private
FCaption: String;
FDeathPageId: Integer;
FDeathType: Integer;
FImageId: Integer;
FInitialValue: String;
FIsVisible: Boolean;
FMaxValue: Integer;
FMinValue: Integer;
FShortDescription: String;
FValue: Integer;
procedure SetValue(AValue: Integer);
public
property Value: Integer read FValue write SetValue;
public
function IsDeathCausedByValue: Boolean;
function FormattedValue: String;
published
property Caption: String read FCaption write FCaption;
property ShortDescription: String read FShortDescription write FShortDescription;
property ImageId: Integer read FImageId write FImageId;
property InitialValue: String read FInitialValue write FInitialValue;
property IsVisible: Boolean read FIsVisible write FIsVisible;
property MaxValue: Integer read FMaxValue write FMaxValue;
property MinValue: Integer read FMinValue write FMinValue;
property DeathType: Integer read FDeathType write FDeathType;
property DeathPageId: Integer read FDeathPageId write FDeathPageId;
end;
TAttributeList = class(specialize TFPGObjectList<TAttribute>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
function FindById(Id: Integer): TAttribute;
end;
TItem = class(TBaseObject)
private
FCaption: String;
FImageId: Integer;
FIsPresent: Boolean;
FIsVisible: Boolean;
FLongDescription: String;
FShortDescription: String;
public
property IsPresent: Boolean read FIsPresent write FIsPresent;
published
property Caption: String read FCaption write FCaption;
property ShortDescription: String read FShortDescription write FShortDescription;
property LongDescription: String read FLongDescription write FLongDescription;
property ImageId: Integer read FImageId write FImageId;
property IsVisible: Boolean read FIsVisible write FIsVisible;
end;
TItemList = class(specialize TFPGObjectList<TItem>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
function FindById(Id: Integer): TItem;
end;
TImageFolder = class(TBaseObject);
TImageFolderList = class(specialize TFPGObjectList<TImageFolder>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
end;
TImage = class(TBaseObject)
private
FData: String;
FImageFolderId: Integer;
published
property ImageFolderId: Integer read FImageFolderId write FImageFolderId;
property Data: String read FData write FData;
end;
TImageList = class(specialize TFPGObjectList<TImage>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
end;
TChapter = class(TBaseObject)
private
FChapterType: Integer;
published
property ChapterType: Integer read FChapterType write FChapterType;
end;
TChapterList = class(specialize TFPGObjectList<TChapter>, IObjectContainer)
public
procedure AddObject(AnObject: TObject);
end;
const
ACTIONTYPE_INC_ATTRIBUTE = 0;
ACTIONTYPE_DEC_ATTRIBUTE = 1;
ACTIONTYPE_RESET_ATTRIBUTE = 2;
ACTIONTYPE_ENABLE_ITEM = 3;
ACTIONTYPE_DISABLE_ITEM = 4;
ACTIONTYPE_SWITCH_ITEM = 5;
CHAPTERTYPE_STANDARD = 0;
CHAPTERTYPE_START = 1;
CONDITIONTYPE_ITEM_EXISTANT = 0;
CONDITIONTYPE_ITEM_NONEXISTANT = 1;
CONDITIONTYPE_ATTRIBUTE_HIGHER = 2;
CONDITIONTYPE_ATTRIBUTE_LOWER = 3;
CONDITIONTYPE_ATTRIBUTE_EQUAL = 4;
CONTENTTYPE_PLAINTEXT = 0;
CONTENTTYPE_HTML = 1;
CONTENTTYPE_FIGHT = 2;
DEATHTYPE_NONE = 0;
DEATHTYPE_IF_LOWER = 1;
DEATHTYPE_IF_HIGHER = 2;
PAGETYPE_STANDARD = 0;
PAGETYPE_STARTPAGE = 1;
PAGETYPE_WINPAGE = 2;
PAGETYPE_FAILPAGE =3;
implementation
constructor TBaseObject.Create;
begin
Create(0, EmptyStr);
end;
constructor TBaseObject.Create(AnId: Integer; const AName: String);
begin
inherited Create;
FId := AnId;
FName := AName;
end;
procedure TChapterList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TChapter);
end;
procedure TAttribute.SetValue(AValue: Integer);
begin
if FValue = AValue then Exit;
FValue := AValue;
if FDeathType = DEATHTYPE_NONE then begin
if (FValue > FMaxValue) then
FValue := FMaxValue
else if (FValue < FMinValue) then
FValue := FMinValue;
end;
end;
function TAttribute.IsDeathCausedByValue: Boolean;
begin
case FDeathType of
DEATHTYPE_IF_HIGHER:
Result := Value > MaxValue;
DEATHTYPE_IF_LOWER:
Result := Value < MinValue;
else
Result := False;
end;
end;
function TAttribute.FormattedValue: String;
begin
Result := Format('%d / %d', [FValue, FMaxValue])
end;
procedure TActionList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TAction);
end;
procedure TSettingList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TSetting);
end;
procedure TImageList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TImage);
end;
procedure TImageFolderList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TImageFolder);
end;
procedure TItemList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TItem);
end;
function TItemList.FindById(Id: Integer): TItem;
var
o: TItem;
begin
Result := nil;
for o in Self do begin
if o.Id = Id then Result := o;
end;
end;
procedure TAttributeList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TAttribute);
end;
function TAttributeList.FindById(Id: Integer): TAttribute;
var
o: TAttribute;
begin
Result := nil;
for o in Self do begin
if o.Id = Id then Result := o;
end;
end;
procedure TPageExitConditionList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TPageExitCondition);
end;
procedure TPageExitList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TPageExit);
end;
function TPageExitList.FindById(Id: Integer): TPageExit;
var
o: TPageExit;
begin
Result := nil;
for o in Self do begin
if o.Id = Id then Result := o;
end;
end;
procedure TPageList.AddObject(AnObject: TObject);
begin
Self.Add(AnObject as TPage);
end;
end.