예제 #1
0
bool SQLitePersister::init () {
	if (!open())
		return false;
	Log::info(LOG_CAMPAIGN, "loaded gamestate database");

	const char *sql =
	"CREATE TABLE IF NOT EXISTS " TABLE_GAMESTATE " ("
	"activecampaign TEXT DEFAULT '" DEFAULT_CAMPAIGN "', "
	"version TEXT"
	");"
	"CREATE TABLE IF NOT EXISTS " TABLE_LIVES " ("
	"campaignid TEXT DEFAULT '" DEFAULT_CAMPAIGN "', "
	"lives INTEGER DEFAULT 3 NOT NULL, "
	"version TEXT, "
	"PRIMARY KEY(campaignid)"
	");"
	"CREATE TABLE IF NOT EXISTS " TABLE_GAMEMAPS " ("
	"campaignid TEXT, "
	"mapid TEXT, "
	"locked INTEGER DEFAULT 1 NOT NULL, "
	"time INTEGER DEFAULT 0 NOT NULL, "
	"finishPoints INTEGER DEFAULT 0 NOT NULL, "
	"stars INTEGER DEFAULT 0 NOT NULL, "
	"version TEXT, "
	"PRIMARY KEY(campaignid, mapid)"
	");";

	Log::info(LOG_CAMPAIGN, "use %s as gamestate database file", getFilename().c_str());

	if (!exec(sql)) {
		Log::error(LOG_CAMPAIGN, "%s", getError().c_str());
		return false;
	}

	_activeCampaign = loadActiveCampaign();
	return true;
}
예제 #2
0
bool SQLitePersister::init () {
	if (!open())
		System.exit("Could not open gamestate database", 1);
	else
		info(LOG_CAMPAIGN, "loaded gamestate database");

	std::stringstream ss;
	ss << "CREATE TABLE IF NOT EXISTS " TABLE_GAMESTATE " (";
	ss << "activecampaign TEXT DEFAULT '" DEFAULT_CAMPAIGN << "', ";
	ss << "version TEXT";
	ss << ");";
	ss << "CREATE TABLE IF NOT EXISTS " TABLE_LIVES " (";
	ss << "campaignid TEXT DEFAULT '" DEFAULT_CAMPAIGN "', ";
	ss << "lives INTEGER DEFAULT " << INITIAL_LIVES << " NOT NULL, ";
	ss << "version TEXT, ";
	ss << "PRIMARY KEY(campaignid)";
	ss << ");";
	ss << "CREATE TABLE IF NOT EXISTS " TABLE_GAMEMAPS " (";
	ss << "campaignid TEXT, ";
	ss << "mapid TEXT, ";
	ss << "locked INTEGER DEFAULT 1 NOT NULL, ";
	ss << "time INTEGER DEFAULT 0 NOT NULL, ";
	ss << "finishPoints INTEGER DEFAULT 0 NOT NULL, ";
	ss << "stars INTEGER DEFAULT 0 NOT NULL, ";
	ss << "version TEXT, ";
	ss << "PRIMARY KEY(campaignid, mapid)";
	ss << ");";

	info(LOG_CAMPAIGN, "use " + getFilename() + " as gamestate database file");

	if (!exec(ss.str()))
		System.exit("Could not create initial gamestate tables", 1);

	_activeCampaign = loadActiveCampaign();
	return true;
}