Add two new struct-level directives to the mini database scheme meta language:

* %preLoadTable which specifies a code block to be executed just __before__ loading in all rows in a database
 * %postLoadRow which specifies a code block to be executed after every row has been succesfully loaded in a struct


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5433 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-07-09 13:09:53 +00:00
parent 2b6b037ade
commit 74784e3f6e
2 changed files with 50 additions and 0 deletions

View File

@ -48,6 +48,24 @@ sub parseEnum
}
}
sub readTillEnd
{
my ($output) = @_;
while (<>)
{
chomp;
# See if we've reached the end of this block
if (/^\s*end\s*;\s*$/)
{
return;
}
push @$output, $_;
}
}
sub parseStruct
{
my %curStruct = (name => $_[0]);
@ -102,6 +120,19 @@ sub parseStruct
${$curStruct{"qualifiers"}}{"inherit"} = \%{$structMap{$1}};
}
elsif (/^preLoadTable(\s+maxId)?(\s+rowCount)?\s*$/)
{
push @{${${$curStruct{"qualifiers"}}{"preLoadTable"}}{"parameters"}}, $1 if $1;
push @{${${$curStruct{"qualifiers"}}{"preLoadTable"}}{"parameters"}}, $2 if $2;
readTillEnd(\@{${${$curStruct{"qualifiers"}}{"preLoadTable"}}{"code"}});
}
elsif (/^postLoadRow\s+curRow(\s+curId)?\s*$/)
{
push @{${${$curStruct{"qualifiers"}}{"postLoadRow"}}{"parameters"}}, $1 if $1;
readTillEnd(\@{${${$curStruct{"qualifiers"}}{"postLoadRow"}}{"code"}});
}
}
# Parse regular field declarations
elsif (/^\s*(count|real|bool)\s+(unique\s+)?(\w+)\s*;\s*$/)

View File

@ -51,6 +51,25 @@ end;
struct BODY
%inherit COMPONENT;
%loadFunc "loadBodyStatsFromDB";
%preLoadTable maxId;
if (!statsAllocBody($maxId))
ABORT;
end;
%postLoadRow curRow curId;
// set the max stat values for the design screen
if ($curRow->designable)
{
// use front armour value to prevent bodyStats corrupt problems
setMaxBodyArmour($curRow->armourValue[HIT_SIDE_FRONT][WC_KINETIC]);
setMaxBodyArmour($curRow->armourValue[HIT_SIDE_FRONT][WC_HEAT]);
setMaxBodyPower($curRow->powerOutput);
setMaxBodyPoints($curRow->body);
setMaxComponentWeight($curRow->weight);
}
// save the stats
statsSetBody($curRow, $curId - 1);
end;
# The number of available weaponSlots slots on the body
count weaponSlots;