From f65840feef59557d3c759e7fa44996ae76d199be Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Thu, 7 Apr 2011 23:05:22 +0200 Subject: MOHAWK: Add some more LBValue helpers. --- engines/mohawk/livingbooks.h | 1 + engines/mohawk/livingbooks_code.cpp | 43 +++++++++++++++++++++++++++++++++++++ engines/mohawk/livingbooks_code.h | 11 ++++++++++ 3 files changed, 55 insertions(+) (limited to 'engines/mohawk') diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index 123c2501c2..90540d2c9d 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -386,6 +386,7 @@ public: uint16 getId() { return _itemId; } const Common::String &getName() { return _desc; } + const Common::Rect &getRect() { return _rect; } uint16 getSoundPriority() { return _soundMode; } bool isAmbient() { return _isAmbient; } diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index 78345ab43e..dc72b2f974 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -71,6 +71,19 @@ bool LBValue::isZero() const { return toInt() == 0; // FIXME } +Common::String LBValue::toString() const { + switch (type) { + case kLBValueString: + return string; + case kLBValueInteger: + return Common::String::format("%d", integer); + case kLBValueReal: + return Common::String::format("%f", real); + default: + return string; // FIXME + } +} + int LBValue::toInt() const { return integer; // FIXME } @@ -79,6 +92,36 @@ double LBValue::toDouble() const { return real; // FIXME } +Common::Point LBValue::toPoint() const { + switch (type) { + case kLBValueString: + // FIXME + return Common::Point(); + case kLBValueInteger: + return Common::Point(integer, integer); + case kLBValuePoint: + return point; + default: + error("failed to convert to point"); + } +} + +Common::Rect LBValue::toRect() const { + switch (type) { + case kLBValueString: + // FIXME + return Common::Rect(); + case kLBValueInteger: + return Common::Rect(integer, integer, integer, integer); + case kLBValueRect: + return rect; + case kLBValueItemPtr: + return item->getRect(); + default: + error("failed to convert to rect"); + } +} + LBCode::LBCode(MohawkEngine_LivingBooks *vm) : _vm(vm) { Common::SeekableSubReadStreamEndian *bcodStream = _vm->wrapStreamEndian(ID_BCOD, 1000); diff --git a/engines/mohawk/livingbooks_code.h b/engines/mohawk/livingbooks_code.h index 71174cc09e..50b5783bbf 100644 --- a/engines/mohawk/livingbooks_code.h +++ b/engines/mohawk/livingbooks_code.h @@ -57,6 +57,14 @@ struct LBValue { type = kLBValueString; string = str; } + LBValue(const Common::Point &p) { + type = kLBValuePoint; + point = p; + } + LBValue(const Common::Rect &r) { + type = kLBValueRect; + rect = r; + } LBValue(LBItem *itm) { type = kLBValueItemPtr; item = itm; @@ -99,8 +107,11 @@ struct LBValue { bool isNumeric() const; bool isZero() const; + Common::String toString() const; int toInt() const; double toDouble() const; + Common::Point toPoint() const; + Common::Rect toRect() const; }; enum { -- cgit v1.2.3