-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclsModels.pas
More file actions
executable file
·278 lines (252 loc) · 7.04 KB
/
clsModels.pas
File metadata and controls
executable file
·278 lines (252 loc) · 7.04 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
// V 1.01
unit clsModels;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
clsEntityDetails,
Dialogs, ComCtrls, ToolWin, JvExComCtrls, JvToolBar, JvComCtrls, jvstrings,
JvThread;
type
TModelsData =class(TObject)
private
Public
ID : Integer;
loadType : integer;
entName : String;
entFile : String;
entityModel : TEntityDetails;
constructor Create;
end;
type
TModelssData = class(TObject)
private
function stripEntity(entityLine:string):TModelsData;
function populateEntityDetails(aData:TModelsData):TModelsData;
procedure loadModelsFile;
//function getEntityType(itemIndex: Integer): String; overload;
public
modelsHeader,listEntities, modelsFile : TStringList;
function getEntityByName(entName:string):TEntityDetails;
function getEntityIndexByName(entName:string):integer;
function getEntityType(itemIndex:Integer):String; overload;
function getEntityIdleImage(itemIndex:Integer):String;
function getEntitydependencies(itemIndex:Integer):TStringList;
function getEntity(itemIndex:Integer):TEntityDetails;
procedure JvThread1Execute(Sender: TObject; Params: Pointer);
function getEntityTypeList:TStringList; overload;
constructor create(zmodelsFile:String);
destructor destroy; override;
end;
implementation
uses
unMain, unCommon;
{ TLevelsData }
destructor TModelssData.destroy;
begin
if(assigned(modelsHeader)) then freeAndNil(modelsHeader);
if(assigned(listEntities)) then FreeAndNil(listEntities);
if(assigned(modelsFile)) then FreeAndNil(modelsFile);
end;
constructor TModelssData.create(zmodelsFile:String);
begin
modelsFile := TStringList.Create;
modelsHeader := TStringList.Create;
listEntities := TStringList.Create;
listEntities.Sorted := true;
listEntities.Duplicates := dupIgnore;
if FileExists(zmodelsFile) then Begin
modelsFile.LoadFromFile(zmodelsFile);
loadModelsFile;
end;
end;
procedure TModelssData.JvThread1Execute(Sender: TObject; Params: Pointer);
begin
loadModelsFile;
end;
function TModelssData.getEntity(itemIndex: Integer): TEntityDetails;
Var
aData : TModelsData;
entity : TEntityDetails;
begin
aData := listEntities.Objects[itemIndex] as TModelsData;
entity := nil;
if aData <> nil then
entity := aData.entityModel;
Result := entity;
end;
function TModelssData.getEntityByName(entName: string): TEntityDetails;
Var
aData : TModelsData;
entity : TEntityDetails;
i : integer;
begin
i := 0;
entity := nil;
while i < listEntities.Count do Begin
aData := listEntities.Objects[i] as TModelsData;
if aData.entName = entName then Begin
entity := aData.entityModel;
i := listEntities.Count;
end;
inc(i);
end;
Result := entity;
end;
function TModelssData.getEntityIndexByName(entName: string): integer;
Var
aData : TModelsData;
entity : TEntityDetails;
i,j : integer;
begin
i := 0;
entity := nil;
while i < listEntities.Count do Begin
aData := listEntities.Objects[i] as TModelsData;
if aData.entName = entName then Begin
j := i;
i := listEntities.Count;
end;
inc(i);
end;
Result := j;
end;
function TModelssData.getEntitydependencies(
itemIndex: Integer): TStringList;
Var
aData : TModelsData;
s : string;
i : integer;
dependencieslist : TStringList;
begin
aData := listEntities.Objects[itemIndex] as TModelsData;
dependencieslist := TStringList.Create;
s := '';
if aData <> nil then
if aData.entityModel <> nil then Begin
i := 0;
while i < aData.entityModel.headers.Count do begin
s := strClearAll(aData.entityModel.headers.Strings[i]);
if pos('load',s) > 0 then Begin
StringDeleteUp2(s,' ');
StringDelete2End(s,' ');
dependencieslist.Add(s);
end;
inc(i);
end;
s := aData.entityModel.idleImageF;
end;
Result := dependencieslist;
end;
function TModelssData.getEntityIdleImage(itemIndex: Integer): String;
Var
aData : TModelsData;
s : string;
begin
aData := listEntities.Objects[itemIndex] as TModelsData;
s := '';
if aData <> nil then
if aData.entityModel <> nil then
s := aData.entityModel.idleImageF;
Result := s;
end;
function TModelssData.getEntityType(itemIndex: Integer): String;
Var
aData : TModelsData;
s : string;
begin
aData := listEntities.Objects[itemIndex] as TModelsData;
s := '';
if aData <> nil then
if aData.entityModel <> nil then
s := aData.entityModel.entityType;
Result := s;
end;
function TModelssData.getEntityTypeList: TStringList;
Var
aList : TStringList;
i : integer;
begin
aList := TStringList.Create;
aList.Sorted := true;
aList.Duplicates := dupIgnore;
for i := 0 to listEntities.Count -1 do Begin
aList.Add(getEntityType(i));
end;
Result := aList;
end;
procedure TModelssData.loadModelsFile;
Var
i: integer;
headerFinished : Boolean;
scriptFound : Boolean;
aData : TModelsData;
s : string;
begin
headerFinished := false;
for i := 0 to modelsFile.Count -1 do Begin
s := modelsFile.Strings[i];
//Detect scripts
if (PosStr('@script',s) > 0) then
scriptFound := true;
if (PosStr('@end_script',s) > 0) then
scriptFound := False;
if headerFinished = false then
modelsHeader.Add(s);
if (scriptFound = true) or
(PosStr('#',s) > 0) then Begin
end else Begin
s := strClearAll(s);
StringReplace(s,#09,' ');
aData := stripEntity(s);
if aData <> nil then Begin
aData := populateEntityDetails(aData);
listEntities.AddObject(aData.entName,aData);
headerFinished := true;
end;
end;
end;
end;
function TModelssData.populateEntityDetails(
aData: TModelsData): TModelsData;
var
athread : TJvThread;
temp: tEntityDetails;
begin
if FileExists(ses.dataDirecotry + '\' + aData.entFile) then Begin
temp := aData.entityModel.loadEntitryDetails(ses.dataDirecotry + '\' + aData.entFile);
freeAndNil(adata.entityModel);
aData.entityModel := temp;
end;
Result := aData;
end;
function TModelssData.stripEntity(entityLine: string): TModelsData;
Var
aData : TModelsData;
canProceed : Boolean;
s : string;
begin
canProceed := false;
aData := nil;
if (PosStr('load ', entityLine) > 0) or
(PosStr('know ', entityLine) > 0) then Begin
aData := TModelsData.Create;
StringDeleteUp2(entityLine,' ');
s := entityLine;
StringDelete2End(s,' ');
StringDeleteUp2(entityLine,' ');
aData.entName := strClearStartEnd(s);
StringReplace(entityLine,'data/','');
StringReplace(entityLine,'/','\');
aData.entFile := strClearStartEnd(entityLine);
end;
result := aData;
end;
{ TLevelData }
constructor TModelsData.Create;
begin
ID := 0;
entName := '';
entFile := '';
entityModel := nil;
end;
end.