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.