Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/Session.pm view on Meta::CPAN
# Create two file objects for the two files objects associated with this profile,
# replacing the ones that we deleted earlier in this function
$otherProfFileObj = Games::Axmud::Obj::File->new('otherprof', $worldName, $self);
$worldModelFileObj = Games::Axmud::Obj::File->new('worldmodel', $worldName, $self);
if (! $otherProfFileObj || ! $worldModelFileObj) {
# (Improper arguments error already displayed)
return $self->writeError(
'Could not set up current profiles - error creating file objects',
$self->_objClass . '->setupProfiles',
);
} else {
# Add these file objects to the file object registries
$self->ivAdd('sessionFileObjHash', 'otherprof', $otherProfFileObj);
$self->ivAdd('sessionFileObjHash', 'worldmodel', $worldModelFileObj);
# The world profile's file object must appear in the GA::Client's registry and
# the GA::Session's registry too
$self->ivAdd(
'sessionFileObjHash',
$worldName,
$axmud::CLIENT->ivShow('fileObjHash', $worldName),
);
# Load the 'otherprof' and 'worldmodel' data files (which sets IVs such as the
# cage registries). If the files are big, show a 'loading...' popup
$otherProfPath = $axmud::DATA_DIR . $otherProfFileObj->standardPath;
if (
(-e $otherProfPath)
&& (-s $otherProfPath) > $axmud::CLIENT->constLargeFileSize
) {
$self->mainWin->showBusyWin();
}
if (! $otherProfFileObj->loadDataFile()) {
# Try loading the automatic backup, i.e. 'otherprof.axm.bu'
if (! $otherProfFileObj->loadDataFile(undef, undef, undef, TRUE)) {
# (Error not already displayed)
return $self->writeError(
'Could not set up current profiles - error loading the'
. ' \'otherprof\' file (file might be corrupt or missing)',
$self->_objClass . '->setupProfiles',
);
} else {
# The contents of the backup, now loaded into memory, must be saved at
# some point
$otherProfFileObj->set_modifyFlag(TRUE);
# Don't overwrite the existing backup file with the faulty one
$otherProfFileObj->set_preserveBackupFlag(TRUE);
}
}
$worldModelPath = $axmud::DATA_DIR . $worldModelFileObj->standardPath;
if (
! $axmud::CLIENT->busyWin
&& (-e $worldModelPath)
&& (-s $worldModelPath) > $axmud::CLIENT->constLargeFileSize
) {
$self->mainWin->showBusyWin();
}
if (! $worldModelFileObj->loadDataFile()) {
# Try loading the automatic backup, i.e. 'worldmodel.axm.bu'
if (! $worldModelFileObj->loadDataFile(undef, undef, undef, TRUE)) {
# (Error not already displayed)
return $self->writeError(
'Could not set up current profiles - error loading the'
. ' \'worldmodel\' file (file might be corrupt or missing)',
$self->_objClass . '->setupProfiles',
);
} else {
# The contents of the backup, now loaded into memory, must be saved at
# some point
$worldModelFileObj->set_modifyFlag(TRUE);
# Don't overwrite the existing backup file with the faulty one
$worldModelFileObj->set_preserveBackupFlag(TRUE);
}
}
if ($axmud::CLIENT->busyWin) {
$self->mainWin->closeDialogueWin($axmud::CLIENT->busyWin);
}
}
# If the user has coded (in Perl) any new cages, the new current world profile
# doesn't know about them yet. Make sure cages are up to date
$self->updateCages(TRUE); # TRUE - don't display create/destroy messages
$updateCageFlag = TRUE;
# Set the current dictionary
if ($worldObj->dict) {
if ($axmud::CLIENT->ivExists('dictHash', $worldObj->dict)) {
$dictObj = $axmud::CLIENT->ivShow('dictHash', $worldObj->dict);
} else {
# The dictionary is missing; this can happen when setting a pre-configured
# world as the current world for the first time. Silently create a new
# dictionary
$dictObj = Games::Axmud::Obj::Dict->new($self, $worldName);
if ($dictObj) {
# Update IVs. Add the dictionary object to its registry
$axmud::CLIENT->add_dict($dictObj);
# Some files have to be saved shortly
$saveMode = 'save_dict';
}
}
} else {
# If there is, by any chance, a dictionary with the same name as the world, use
# it
if ($axmud::CLIENT->ivExists('dictHash', $worldName)) {
$dictObj = $axmud::CLIENT->ivShow('dictHash', $worldName);
# Tell the profile that it has a dictionary
$worldObj->ivPoke('dict', $dictObj->name);
}
}
if (! $dictObj) {
$self->writeWarning(
'Could not mark a dictionary as the current dictionary - try creating one'
. ' with the \';setdictionary\' command',
$self->_objClass . '->setupProfiles',
);
} else {
$self->ivPoke('currentDict', $dictObj);
}
# If loading a pre-configured world, a /logs directory won't exist for it, so
# create one
$axmud::CLIENT->createWorldLogDir($worldObj->name);
}
}
( run in 3.951 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )