1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "titanic/core/named_item.h"
24 #include "titanic/core/node_item.h"
25 #include "titanic/core/room_item.h"
26 #include "titanic/core/view_item.h"
27 
28 namespace Titanic {
29 
30 EMPTY_MESSAGE_MAP(CNamedItem, CTreeItem);
31 
dumpItem(int indent) const32 CString CNamedItem::dumpItem(int indent) const {
33 	CString result = CTreeItem::dumpItem(indent);
34 	result += " " + _name;
35 
36 	return result;
37 }
38 
save(SimpleFile * file,int indent)39 void CNamedItem::save(SimpleFile *file, int indent) {
40 	file->writeNumberLine(0, indent);
41 	file->writeQuotedLine(_name, indent);
42 
43 	CTreeItem::save(file, indent);
44 }
45 
load(SimpleFile * file)46 void CNamedItem::load(SimpleFile *file) {
47 	int val = file->readNumber();
48 	if (!val)
49 		_name = file->readString();
50 
51 	CTreeItem::load(file);
52 }
53 
isEquals(const CString & name,bool startsWith) const54 bool CNamedItem::isEquals(const CString &name, bool startsWith) const {
55 	if (startsWith) {
56 		return getName().left(name.size()).compareToIgnoreCase(name) == 0;
57 	} else {
58 		return getName().compareToIgnoreCase(name) == 0;
59 	}
60 }
61 
findView() const62 CViewItem *CNamedItem::findView() const {
63 	for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
64 		CViewItem *view = dynamic_cast<CViewItem *>(parent);
65 		if (view)
66 			return view;
67 	}
68 
69 	error("Couldn't find parent view");
70 }
71 
findNode() const72 CNodeItem *CNamedItem::findNode() const {
73 	for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
74 		CNodeItem *node = dynamic_cast<CNodeItem *>(parent);
75 		if (node)
76 			return node;
77 	}
78 
79 	error("Couldn't find parent node");
80 }
81 
findRoom() const82 CRoomItem *CNamedItem::findRoom() const {
83 	for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
84 		CRoomItem *room = dynamic_cast<CRoomItem *>(parent);
85 		if (room)
86 			return room;
87 	}
88 
89 	error("Couldn't find parent node");
90 }
91 
92 } // End of namespace Titanic
93