aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/base_game_settings.cpp
blob: 996bada997c723a19fb904a265a21886444ec548 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This file is based on WME Lite.
 * http://dead-code.org/redir.php?target=wmelite
 * Copyright (c) 2011 Jan Nedoma
 */

#include "engines/wintermute/base/base_game_settings.h"
#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/base/base_string_table.h"
#include "engines/wintermute/base/base_parser.h"
#include "engines/wintermute/wintypes.h"

namespace Wintermute {

BaseGameSettings::BaseGameSettings(BaseGame *gameRef) {
	_resWidth = 800;
	_resHeight = 600;
	_requireAcceleration = false;
	_requireSound = false;
	_TLMode = 0;
	_allowWindowed = true;
	_gameFile = nullptr;
	_allowAdvanced = false;
	_allowAccessTab = true;
	_allowAboutTab = true;
	_allowDesktopRes = false;

	_compressedSavegames = true;
	_richSavedGames = false;
	_savedGameExt = "dsv";

	_stringTable = new BaseStringTable(gameRef);
}

BaseGameSettings::~BaseGameSettings() {
	delete[] _gameFile;
	_gameFile = nullptr;
	delete _stringTable;
	_stringTable = nullptr;
}

TOKEN_DEF_START
TOKEN_DEF(GAME)
TOKEN_DEF(STRING_TABLE)
TOKEN_DEF(RESOLUTION)
TOKEN_DEF(SETTINGS)
TOKEN_DEF(REQUIRE_3D_ACCELERATION)
TOKEN_DEF(REQUIRE_SOUND)
TOKEN_DEF(HWTL_MODE)
TOKEN_DEF(ALLOW_WINDOWED_MODE)
TOKEN_DEF(ALLOW_ACCESSIBILITY_TAB)
TOKEN_DEF(ALLOW_ABOUT_TAB)
TOKEN_DEF(ALLOW_ADVANCED)
TOKEN_DEF(ALLOW_DESKTOP_RES)
TOKEN_DEF(REGISTRY_PATH)
TOKEN_DEF(RICH_SAVED_GAMES)
TOKEN_DEF(SAVED_GAME_EXT)
TOKEN_DEF(GUID)
TOKEN_DEF_END

//////////////////////////////////////////////////////////////////////////
bool BaseGameSettings::loadSettings(const char *filename) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(SETTINGS)
	TOKEN_TABLE(GAME)
	TOKEN_TABLE(STRING_TABLE)
	TOKEN_TABLE(RESOLUTION)
	TOKEN_TABLE(REQUIRE_3D_ACCELERATION)
	TOKEN_TABLE(REQUIRE_SOUND)
	TOKEN_TABLE(HWTL_MODE)
	TOKEN_TABLE(ALLOW_WINDOWED_MODE)
	TOKEN_TABLE(ALLOW_ACCESSIBILITY_TAB)
	TOKEN_TABLE(ALLOW_ABOUT_TAB)
	TOKEN_TABLE(ALLOW_ADVANCED)
	TOKEN_TABLE(ALLOW_DESKTOP_RES)
	TOKEN_TABLE(REGISTRY_PATH)
	TOKEN_TABLE(RICH_SAVED_GAMES)
	TOKEN_TABLE(SAVED_GAME_EXT)
	TOKEN_TABLE(GUID)
	TOKEN_TABLE_END


	char *origBuffer = (char *)BaseFileManager::getEngineInstance()->readWholeFile(filename);
	if (origBuffer == nullptr) {
		BaseEngine::LOG(0, "BaseGame::LoadSettings failed for file '%s'", filename);
		return STATUS_FAILED;
	}

	bool ret = STATUS_OK;

	char *buffer = origBuffer;
	char *params;
	int cmd;
	BaseParser parser;

	if (parser.getCommand(&buffer, commands, &params) != TOKEN_SETTINGS) {
		BaseEngine::LOG(0, "'SETTINGS' keyword expected in game settings file.");
		return STATUS_FAILED;
	}
	buffer = params;
	while ((cmd = parser.getCommand(&buffer, commands, &params)) > 0) {
		switch (cmd) {
			case TOKEN_GAME:
				delete[] _gameFile;
				_gameFile = new char[strlen(params) + 1];
				if (_gameFile) {
					strcpy(_gameFile, params);
				}
				break;

			case TOKEN_STRING_TABLE:
				if (DID_FAIL(_stringTable->loadFile(params))) {
					cmd = PARSERR_GENERIC;
				}
				break;

			case TOKEN_RESOLUTION:
				parser.scanStr(params, "%d,%d", &_resWidth, &_resHeight);
				break;

			case TOKEN_REQUIRE_3D_ACCELERATION:
				parser.scanStr(params, "%b", &_requireAcceleration);
				break;

			case TOKEN_REQUIRE_SOUND:
				parser.scanStr(params, "%b", &_requireSound);
				break;

			case TOKEN_HWTL_MODE:
				parser.scanStr(params, "%d", &_TLMode);
				break;

			case TOKEN_ALLOW_WINDOWED_MODE:
				parser.scanStr(params, "%b", &_allowWindowed);
				break;

			case TOKEN_ALLOW_DESKTOP_RES:
				parser.scanStr(params, "%b", &_allowDesktopRes);
				break;

			case TOKEN_ALLOW_ADVANCED:
				parser.scanStr(params, "%b", &_allowAdvanced);
				break;

			case TOKEN_ALLOW_ACCESSIBILITY_TAB:
				parser.scanStr(params, "%b", &_allowAccessTab);
				break;

			case TOKEN_ALLOW_ABOUT_TAB:
				parser.scanStr(params, "%b", &_allowAboutTab);
				break;

			case TOKEN_REGISTRY_PATH:
				//BaseEngine::instance().getRegistry()->setBasePath(params);
				break;

			case TOKEN_RICH_SAVED_GAMES:
				parser.scanStr(params, "%b", &_richSavedGames);
				break;

			case TOKEN_SAVED_GAME_EXT:
				_savedGameExt = params;
				break;

			case TOKEN_GUID:
				break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		BaseEngine::LOG(0, "Syntax error in game settings '%s'", filename);
		ret = STATUS_FAILED;
	}
	if (cmd == PARSERR_GENERIC) {
		BaseEngine::LOG(0, "Error loading game settings '%s'", filename);
		ret = STATUS_FAILED;
	}

	_allowWindowed = true; // TODO: These two settings should probably be cleaned out altogether.
	_compressedSavegames = true;

	delete[] origBuffer;

	return ret;
}

bool BaseGameSettings::loadStringTable(const char *filename, bool clearOld) {
	return _stringTable->loadFile(filename, clearOld);
}

//////////////////////////////////////////////////////////////////////////
void BaseGameSettings::expandStringByStringTable(char **str) const {
	_stringTable->expand(str);
}

//////////////////////////////////////////////////////////////////////////
void BaseGameSettings::expandStringByStringTable(Common::String &str) const {
	_stringTable->expand(str);
}

char *BaseGameSettings::getKeyFromStringTable(const char *str) const {
	return _stringTable->getKey(str);
}

bool BaseGameSettings::persist(BasePersistenceManager *persistMgr) {
	return _stringTable->persist(persistMgr);
}

} // End of namespace Wintermute