type
//Objektlist mit Objekten dieses Typs soll gespeichert werden!!
TBrickPrototype =
class(TObject)
{aus anderer Unit}
private
public
textures:
array of TTargaGraphic;
animationVelocities:
array of Real;
end;
//Subcollections:
TRealCollItem =
class(TCollectionItem)
private
fRealValue: Real;
public
procedure Assign(Source: TPersistent);
override;
published
property RealValue: Real
read fRealValue
write fRealValue;
end;
TTargaCollItem =
class(TCollectionItem)
private
fTarga: TTargaGraphic;
public
procedure Assign(Source: TPersistent);
override;
published
property Targa: TTargaGraphic
read fTarga
write fTarga;
end;
//Maincollection:
TBrickCollItem =
class(TCollectionItem)
private
fTargaCollItems: TJSCollection;
fRealCollItems: TJSCollection;
public
constructor Create(Collection: TCollection);
override;
destructor Destroy;
override;
procedure Assign(Source: TPersistent);
override;
published
property TargaCollItems: TJSCollection
read fTargaCollItems
write fTargaCollItems;
property RealCollItems: TJSCollection
read fRealCollItems
write fRealCollItems;
end;
//Administration:
TFileControler =
class(TOBject)
private
public
procedure LoadBricks;
//Bricks from File -> global TObjectList
procedure SaveBricks;
end;
implementation
uses UBrickEditor_Main;
{ TRealCollItem }
procedure TRealCollItem.Assign(Source: TPersistent);
begin
inherited;
if Source
is TRealCollItem
then
fRealValue := TRealCollItem(Source).RealValue
else
inherited Assign(Source);
end;
{ TTargaCollItem }
procedure TTargaCollItem.Assign(Source: TPersistent);
begin
inherited;
if Source
is TRealCollItem
then
fTarga := TTargaCollItem(Source).Targa
else
inherited Assign(Source);
end;
{ TBrickCollItem }
constructor TBrickCollItem.Create(Collection: TCollection);
begin
inherited Create(Collection);
fTargaCollItems := TJsCollection.Create(TTargaCollItem);
fRealCollItems := TJsCollection.Create(TRealCollItem);
end;
destructor TBrickCollItem.Destroy;
begin
fTargaCollItems.free;
fRealCollItems.free;
inherited Destroy;
end;
procedure TBrickCollItem.Assign(Source: TPersistent);
begin
inherited;
if Source
is TBrickCollItem
then
begin
fTargaCollItems.Assign(TBrickCollItem(Source).fTargaCollItems);
fRealCollItems.Assign(TBrickCollItem(Source).fRealCollItems);
end
else
inherited Assign(Source);
end;
{ TFileControler }
procedure TFileControler.LoadBricks;
var Coll: TmxJSCollection;
tempBrickPrototype: TBrickPrototype;
i, j: integer;
begin
Coll := TmxJSCollection.Create(TBrickCollItem);
Coll.LoadFromFile(filename);
BrickPrototypes.Clear;
for i:=0
to Coll.Count-1
do
begin
for j:=0
to TBrickCollItem(Coll.Items[i]).TargaCollItems.Count-1
do
begin
setlength(tempBrickPrototype.textures, length(tempBrickPrototype.textures)+1);
tempBrickPrototype.textures[high(tempBrickPrototype.textures)] := TTargaCollItem(TBrickCollItem(Coll.Items[i]).TargaCollItems).Targa;
end;
{}
for j:=0
to TBrickCollItem(Coll.Items[i]).RealCollItems.Count-1
do
begin
setlength(tempBrickPrototype.animationVelocities, length(tempBrickPrototype.animationVelocities)+1);
tempBrickPrototype.animationVelocities[high(tempBrickPrototype.animationVelocities)] := TRealCollItem(TBrickCollItem(Coll.Items[i]).RealCollItems).RealValue;
end;
BrickPrototypes.Add(tempBrickPrototype);
end;
{for i...}
Coll.free;
end;
procedure TFileControler.SaveBricks;
var Coll: TmxJSCollection;
i,j : integer;
begin
coll := TmxJSCollection.Create(TBrickCollItem);
for i:=0
to BrickPrototypes.Count-1
do
begin
with Coll.add
as TBrickCollItem
do
begin
for j:=0
to high(TBrickPrototype(BrickPrototypes[i]).textures)
do
with TargaCollItems.add
as TTargaCollItem
do
Targa := TBrickPrototype(BrickPrototypes[i]).textures[j];
for j:=0
to high(TBrickPrototype(BrickPrototypes[i]).animationVelocities)
do
with RealCollItems.add
as TRealCollItem
do
RealValue := TBrickPrototype(BrickPrototypes[i]).animationVelocities[j];
end;
{with Coll.add...}
end;
{for i...}
Coll.SaveToFile(filename);
Coll.free;
end;
end.