gameinfoctx.h 3.39 KB
Newer Older
sm's avatar
sm committed
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
/*
 * File:   gameinfoctx.h
 *
 * Copyright © 2019  Stefano Marsili, <stemars@gmx.ch>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>
 */

#ifndef STMG_GAME_INFO_CTX_H
#define STMG_GAME_INFO_CTX_H

#include "xmlconditionalparser.h"

#include <stmm-games-gtk/file.h>
#include <stmm-games-gtk/gameloader.h>

#include <stmm-games/gamewidget.h>

namespace stmg
{

class GameInfoCtx : public ConditionalCtx
{
public:
sm's avatar
sm committed
36
	GameInfoCtx(const shared_ptr<AppConfig>& refAppConfig, const File& oGameFile, XmlConditionalParser& oXmlConditionalParser)
sm's avatar
sm committed
37 38
	: ConditionalCtx(refAppConfig, s_oDummy, oXmlConditionalParser)
	{
sm's avatar
sm committed
39
		m_oGameInfo.m_oGameFile = oGameFile;
sm's avatar
sm committed
40 41
		s_oDummy.clear();
	}
sm's avatar
sm committed
42
	GameInfoCtx(const shared_ptr<AppPreferences>& refAppPreferences, Named& oNamed, const File& oGameFile, XmlConditionalParser& oXmlConditionalParser)
sm's avatar
sm committed
43 44
	: ConditionalCtx(refAppPreferences, oNamed, oXmlConditionalParser)
	{
sm's avatar
sm committed
45
		m_oGameInfo.m_oGameFile = oGameFile;
sm's avatar
sm committed
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
	}

	const GameConstraints& getGameConstraints() const { return m_oGameInfo.m_oGameConstraints; }
	const shared_ptr<HighscoresDefinition>& getHighscoresDefinition() const { return m_oGameInfo.m_refHighscoresDefinition; }

	inline const NamedObjIndex<Variable::VariableType>& getGameVariableTypes() const { return m_oGameVariableTypes; }
	inline const NamedObjIndex<Variable::VariableType>& getTeamVariableTypes() const { return m_oTeamVariableTypes; }
	inline const NamedObjIndex<Variable::VariableType>& getMateVariableTypes() const { return m_oMateVariableTypes; }
	const NamedObjIndex<Variable::VariableType>& getVariableTypes(OwnerType eOwnerType) const
	{
		if (eOwnerType == OwnerType::GAME) {
			//
		} else if (eOwnerType == OwnerType::TEAM) {
			return m_oTeamVariableTypes;
		} else if (eOwnerType == OwnerType::PLAYER) {
			return m_oMateVariableTypes;
		} else {
			assert(false);
		}
		return m_oGameVariableTypes;
	}
	double getMinGameInterval() const { return m_fMinGameInterval; }
	double getInitialGameInterval() const { return m_fInitialGameInterval; }
protected:
	std::string err(const std::string& sErr) override
	{
		std::string sExtError;
		assert(!m_oGameInfo.m_oGameFile.isBuffered());
		sExtError.append(m_oGameInfo.m_oGameFile.getFullPath());
		sExtError.append(": ");
		sExtError.append(sErr);
		return ConditionalCtx::err(sExtError);
	}

private:
	friend class XmlGameInfoParser;
	GameLoader::GameInfo m_oGameInfo;
	NamedObjIndex<Variable::VariableType> m_oGameVariableTypes;
	NamedObjIndex<Variable::VariableType> m_oTeamVariableTypes;
	NamedObjIndex<Variable::VariableType> m_oMateVariableTypes;
	double m_fMinGameInterval;
	double m_fInitialGameInterval;
	static AssignableNamed s_oDummy;
private:
	GameInfoCtx() = delete;
	GameInfoCtx(const GameInfoCtx& oSource) = delete;
	GameInfoCtx& operator=(const GameInfoCtx& oSource) = delete;
};

} // namespace stmg

#endif	/* STMG_GAME_INFO_CTX_H */