DIRECTOR: Lingo: Do not error out on non-existent sprites/casts

This commit is contained in:
Eugene Sandulenko 2016-07-12 20:34:51 +02:00
parent d08e030da6
commit 0ad467f832
2 changed files with 65 additions and 19 deletions

View File

@ -188,7 +188,7 @@ void Lingo::setTheEntity(int entity, Datum &id, int field, Datum &d) {
warning("set to %d: %s", _floatPrecision, _floatPrecisionFormat.c_str()); warning("set to %d: %s", _floatPrecision, _floatPrecisionFormat.c_str());
break; break;
default: default:
error("Unprocessed setting field %d of entity %d", field, entity); warning("Unprocessed setting field %d of entity %d", field, entity);
} }
} }
@ -202,8 +202,16 @@ void Lingo::setTheSprite(Datum &id1, int field, Datum &d) {
d.toInt(); // Enforce Integer d.toInt(); // Enforce Integer
if (!_vm->_currentScore) {
warning("The sprite %d field %d setting over non-active score", id, field);
return;
}
Sprite *sprite = _vm->_currentScore->getSpriteById(id); Sprite *sprite = _vm->_currentScore->getSpriteById(id);
if (!sprite)
return;
switch (field) { switch (field) {
case kTheCastNum: case kTheCastNum:
if (_vm->_currentScore->_casts.contains(d.u.i)) { if (_vm->_currentScore->_casts.contains(d.u.i)) {
@ -234,7 +242,7 @@ void Lingo::setTheSprite(Datum &id1, int field, Datum &d) {
break; break;
default: default:
error("Unprocessed setting field %d of sprite", field); warning("Unprocessed setting field %d of sprite", field);
} }
} }
@ -255,7 +263,7 @@ Datum Lingo::getTheEntity(int entity, Datum &id, int field) {
d.u.i = _floatPrecision; d.u.i = _floatPrecision;
break; break;
default: default:
error("Unprocessed getting field %d of entity %d", field, entity); warning("Unprocessed getting field %d of entity %d", field, entity);
} }
return d; return d;
@ -270,8 +278,16 @@ Datum Lingo::getTheSprite(Datum &id1, int field) {
else else
warning("Unknown the sprite id type: %s", id1.type2str()); warning("Unknown the sprite id type: %s", id1.type2str());
if (!_vm->_currentScore) {
warning("The sprite %d field %d setting over non-active score", id, field);
return d;
}
Sprite *sprite = _vm->_currentScore->getSpriteById(id); Sprite *sprite = _vm->_currentScore->getSpriteById(id);
if (!sprite)
return d;
d.type = INT; d.type = INT;
switch (field) { switch (field) {
@ -300,7 +316,7 @@ Datum Lingo::getTheSprite(Datum &id1, int field) {
d.u.i = sprite->_constraint; d.u.i = sprite->_constraint;
break; break;
default: default:
error("Unprocessed getting field %d of sprite", field); warning("Unprocessed getting field %d of sprite", field);
} }
return d; return d;
@ -308,8 +324,6 @@ Datum Lingo::getTheSprite(Datum &id1, int field) {
Datum Lingo::getTheCast(Datum &id1, int field) { Datum Lingo::getTheCast(Datum &id1, int field) {
Datum d; Datum d;
d.type = INT;
int id = 0; int id = 0;
if (id1.type == INT) if (id1.type == INT)
@ -317,18 +331,27 @@ Datum Lingo::getTheCast(Datum &id1, int field) {
else else
warning("Unknown the cast id type: %s", id1.type2str()); warning("Unknown the cast id type: %s", id1.type2str());
if (!_vm->_currentScore) {
warning("The cast %d field %d setting over non-active score", id, field);
return d;
}
Cast *cast; Cast *cast;
if (!_vm->_currentScore->_casts.contains(id)) { if (!_vm->_currentScore->_casts.contains(id)) {
if (field == kTheLoaded) { if (field == kTheLoaded) {
d.type = INT;
d.u.i = 0; d.u.i = 0;
} }
return d; return d;
} else { } else {
error ("Not cast %d found", id); warning("The cast %d found", id);
return d;
} }
cast = _vm->_currentScore->_casts[id]; cast = _vm->_currentScore->_casts[id];
d.type = INT;
switch (field) { switch (field) {
case kTheCastType: case kTheCastType:
d.u.i = cast->type; d.u.i = cast->type;
@ -341,16 +364,24 @@ Datum Lingo::getTheCast(Datum &id1, int field) {
break; break;
case kTheBackColor: case kTheBackColor:
{ {
if (cast->type != kCastShape) if (cast->type != kCastShape) {
error("Field %d of cast %d not found", field, id); warning("Field %d of cast %d not found", field, id);
d.type = VOID;
return d;
}
ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]); ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]);
d.u.i = shape->bgCol; d.u.i = shape->bgCol;
} }
break; break;
case kTheForeColor: case kTheForeColor:
{ {
if (cast->type != kCastShape) if (cast->type != kCastShape) {
error("Field %d of cast %d not found", field, id); warning("Field %d of cast %d not found", field, id);
d.type = VOID;
return d;
}
ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]); ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]);
d.u.i = shape->fgCol; d.u.i = shape->fgCol;
} }
@ -359,7 +390,7 @@ Datum Lingo::getTheCast(Datum &id1, int field) {
d.u.i = 1; //Not loaded handled above d.u.i = 1; //Not loaded handled above
break; break;
default: default:
error("Unprocessed getting field %d of cast %d", field, id); warning("Unprocessed getting field %d of cast %d", field, id);
//TODO find out about String fields //TODO find out about String fields
} }
} }
@ -370,9 +401,20 @@ void Lingo::setTheCast(Datum &id1, int field, Datum &d) {
if (id1.type == INT) if (id1.type == INT)
id = id1.u.i; id = id1.u.i;
else else
warning("Unknown the sprite id type: %s", id1.type2str()); warning("Unknown the cast id type: %s", id1.type2str());
if (!_vm->_currentScore) {
warning("The cast %d field %d setting over non-active score", id, field);
return;
}
Cast *cast = _vm->_currentScore->_casts[id]; Cast *cast = _vm->_currentScore->_casts[id];
if (!cast) {
warning("The cast %d found", id);
return;
}
switch (field) { switch (field) {
case kTheCastType: case kTheCastType:
cast->type = static_cast<CastType>(d.u.i); cast->type = static_cast<CastType>(d.u.i);
@ -388,8 +430,9 @@ void Lingo::setTheCast(Datum &id1, int field, Datum &d) {
break; break;
case kTheBackColor: case kTheBackColor:
{ {
if (cast->type != kCastShape) if (cast->type != kCastShape) {
error("Field %d of cast %d not found", field, id); warning("Field %d of cast %d not found", field, id);
}
ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]); ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]);
shape->bgCol = d.u.i; shape->bgCol = d.u.i;
shape->modified = 1; shape->modified = 1;
@ -397,15 +440,17 @@ void Lingo::setTheCast(Datum &id1, int field, Datum &d) {
break; break;
case kTheForeColor: case kTheForeColor:
{ {
if (cast->type != kCastShape) if (cast->type != kCastShape) {
error("Field %d of cast %d not found", field, id); warning("Field %d of cast %d not found", field, id);
return;
}
ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]); ShapeCast *shape = static_cast<ShapeCast *>(_vm->_currentScore->_casts[id]);
shape->fgCol = d.u.i; shape->fgCol = d.u.i;
shape->modified = 1; shape->modified = 1;
} }
break; break;
default: default:
error("Unprocessed getting field %d of cast %d", field, id); warning("Unprocessed getting field %d of cast %d", field, id);
} }
} }

View File

@ -890,7 +890,8 @@ Sprite *Score::getSpriteById(uint16 id) {
if (_frames[_currentFrame]->_sprites[id]) { if (_frames[_currentFrame]->_sprites[id]) {
return _frames[_currentFrame]->_sprites[id]; return _frames[_currentFrame]->_sprites[id];
} else { } else {
error("Sprite on frame %d width id %d not found", _currentFrame, id); warning("Sprite on frame %d width id %d not found", _currentFrame, id);
return nullptr;
} }
} }