aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/agt/agt.cpp
blob: 37d1d77846090f0f3f5739c320800bd3fda7f7b4 (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
/* 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.
 *
 */

#include "glk/agt/agt.h"
#include "glk/quetzal.h"
#include "common/config-manager.h"
#include "glk/agt/agility.h"
#include "glk/agt/interp.h"
#include "glk/agt/exec.h"

namespace Glk {
namespace AGT {

AGT *g_vm;

extern void glk_main();
extern int glk_startup_code();
extern void gagt_finalizer();

AGT::AGT(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
		gagt_main_window(nullptr), gagt_status_window(nullptr), gagt_gamefile(nullptr),
		gagt_game_message(nullptr), gagt_delay_mode(DELAY_SHORT), gagt_font_mode(FONT_AUTOMATIC),
		gagt_transcript_stream(nullptr), gagt_inputlog_stream(nullptr),
		gagt_readlog_stream(nullptr), gagt_replacement_enabled(true),
		gagt_extended_status_enabled(true), gagt_abbreviations_enabled(true),
		gagt_commands_enabled(true), gagt_clean_exit_test(false) {
	g_vm = this;
}

void AGT::runGame() {
	initialize();
	glk_main();

	gagt_finalizer();
}

void AGT::initialize() {
	_gameFile.close();
	gagt_gamefile = getFilename().c_str();

	initializeSettings();
	glk_startup_code();
}

void AGT::initializeSettings() {
	// Delay
	if (ConfMan.hasKey("delay")) {
		Common::String delay = ConfMan.get("delay");
		switch (tolower(delay.firstChar())) {
		case 'f':
			// Full
			gagt_delay_mode = DELAY_FULL;
			break;
		case 's':
			// Short
			gagt_delay_mode = DELAY_SHORT;
			break;
		case 'n':
		case 'o':
			// None/off
			gagt_delay_mode = DELAY_OFF;
			break;
		default:
			break;
		}
	}

	// Boolean flags
	if (ConfMan.hasKey("replacement"))
		gagt_replacement_enabled = ConfMan.getBool("replacement");
	if (ConfMan.hasKey("abbreviations"))
		gagt_abbreviations_enabled = ConfMan.getBool("abbreviations");
	if (ConfMan.hasKey("extended_status"))
		gagt_extended_status_enabled = ConfMan.getBool("extended_status");
	if (ConfMan.hasKey("commands"))
		gagt_commands_enabled = ConfMan.getBool("commands");
}

Common::Error AGT::readSaveData(Common::SeekableReadStream *rs) {
	return loadgame(rs);
}

Common::Error AGT::writeGameData(Common::WriteStream *ws) {
	return savegame(ws);
}

} // End of namespace AGT
} // End of namespace Glk