SLUDGE: Refactor save/load costume to Persona

This commit is contained in:
Simei Yin 2018-04-15 21:56:20 +02:00
parent 53c79fdde9
commit 2cf79dc67c
3 changed files with 35 additions and 33 deletions

View File

@ -214,7 +214,7 @@ bool saveVariable(Variable *from, Common::WriteStream *stream) {
return saveStackRef(from->varData.theStack, stream); return saveStackRef(from->varData.theStack, stream);
case SVT_COSTUME: case SVT_COSTUME:
g_sludge->_peopleMan->saveCostume(from->varData.costumeHandler, stream); from->varData.costumeHandler->save(stream);
return false; return false;
case SVT_ANIM: case SVT_ANIM:
@ -253,7 +253,7 @@ bool loadVariable(Variable *to, Common::SeekableReadStream *stream) {
to->varData.costumeHandler = new Persona; to->varData.costumeHandler = new Persona;
if (!checkNew(to->varData.costumeHandler)) if (!checkNew(to->varData.costumeHandler))
return false; return false;
g_sludge->_peopleMan->loadCostume(to->varData.costumeHandler, stream); to->varData.costumeHandler->load(stream);
return true; return true;
case SVT_ANIM: case SVT_ANIM:

View File

@ -158,6 +158,33 @@ bool PersonaAnimation::load(Common::SeekableReadStream *stream) {
return true; return true;
} }
bool Persona::save(Common::WriteStream *stream) {
int a;
stream->writeUint16BE(numDirections);
for (a = 0; a < numDirections * 3; a++) {
if (!animation[a]->save(stream))
return false;
}
return true;
}
bool Persona::load(Common::SeekableReadStream *stream) {
int a;
numDirections = stream->readUint16BE();
animation = new PersonaAnimation *[numDirections * 3];
if (!checkNew(animation))
return false;
for (a = 0; a < numDirections * 3; a++) {
animation[a] = new PersonaAnimation ;
if (!checkNew(animation[a]))
return false;
if (!animation[a]->load(stream))
return false;
}
return true;
}
PeopleManager::PeopleManager(SludgeEngine *vm) { PeopleManager::PeopleManager(SludgeEngine *vm) {
_vm = vm; _vm = vm;
_allPeople = nullptr; _allPeople = nullptr;
@ -971,33 +998,6 @@ void PeopleManager::removeOneCharacter(int i) {
} }
} }
bool PeopleManager::saveCostume(Persona *cossy, Common::WriteStream *stream) {
int a;
stream->writeUint16BE(cossy->numDirections);
for (a = 0; a < cossy->numDirections * 3; a++) {
if (!cossy->animation[a]->save(stream))
return false;
}
return true;
}
bool PeopleManager::loadCostume(Persona *cossy, Common::SeekableReadStream *stream) {
int a;
cossy->numDirections = stream->readUint16BE();
cossy->animation = new PersonaAnimation *[cossy->numDirections * 3];
if (!checkNew(cossy->animation))
return false;
for (a = 0; a < cossy->numDirections * 3; a++) {
cossy->animation[a] = new PersonaAnimation ;
if (!checkNew(cossy->animation[a]))
return false;
if (!cossy->animation[a]->load(stream))
return false;
}
return true;
}
bool PeopleManager::savePeople(Common::WriteStream *stream) { bool PeopleManager::savePeople(Common::WriteStream *stream) {
OnScreenPerson *me = _allPeople; OnScreenPerson *me = _allPeople;
int countPeople = 0, a; int countPeople = 0, a;
@ -1018,7 +1018,7 @@ bool PeopleManager::savePeople(Common::WriteStream *stream) {
stream->writeFloatLE(me->x); stream->writeFloatLE(me->x);
stream->writeFloatLE(me->y); stream->writeFloatLE(me->y);
saveCostume(me->myPersona, stream); me->myPersona->save(stream);
me->myAnim->save(stream); me->myAnim->save(stream);
stream->writeByte(me->myAnim == me->lastUsedAnim); stream->writeByte(me->myAnim == me->lastUsedAnim);
@ -1094,7 +1094,7 @@ bool PeopleManager::loadPeople(Common::SeekableReadStream *stream) {
me->x = stream->readFloatLE(); me->x = stream->readFloatLE();
me->y = stream->readFloatLE(); me->y = stream->readFloatLE();
loadCostume(me->myPersona, stream); me->myPersona->load(stream);
me->myAnim->load(stream); me->myAnim->load(stream);
me->lastUsedAnim = stream->readByte() ? me->myAnim : NULL; me->lastUsedAnim = stream->readByte() ? me->myAnim : NULL;

View File

@ -65,6 +65,10 @@ struct PersonaAnimation {
struct Persona { struct Persona {
PersonaAnimation **animation; PersonaAnimation **animation;
int numDirections; int numDirections;
// Save & load
bool save(Common::WriteStream *stream);
bool load(Common::SeekableReadStream *stream);
}; };
struct OnScreenPerson { struct OnScreenPerson {
@ -135,8 +139,6 @@ public:
// Loading and saving // Loading and saving
bool savePeople(Common::WriteStream *stream); bool savePeople(Common::WriteStream *stream);
bool loadPeople(Common::SeekableReadStream *stream); bool loadPeople(Common::SeekableReadStream *stream);
bool saveCostume(Persona *cossy, Common::WriteStream *stream);
bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream);
// Freeze // Freeze
void freeze(FrozenStuffStruct *frozenStuff); void freeze(FrozenStuffStruct *frozenStuff);