Skip to content

Commit

Permalink
Set Game metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
NikosSiak committed Sep 28, 2020
1 parent 1e316f3 commit d67b89e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 2 deletions.
8 changes: 8 additions & 0 deletions xbmc/FileItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3559,6 +3559,14 @@ CGameInfoTag* CFileItem::GetGameInfoTag()
return m_gameInfoTag;
}

void CFileItem::SetGameInfoTag(const KODI::GAME::CGameInfoTag& game)
{
if (!m_gameInfoTag)
m_gameInfoTag = new CGameInfoTag;

*m_gameInfoTag = game;
}

std::string CFileItem::FindTrailer() const
{
std::string strFile2;
Expand Down
2 changes: 2 additions & 0 deletions xbmc/FileItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ class CFileItem :
return m_gameInfoTag;
}

void SetGameInfoTag(const KODI::GAME::CGameInfoTag& game);

CPictureInfoTag* GetPictureInfoTag();

/*!
Expand Down
13 changes: 13 additions & 0 deletions xbmc/GUIInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Util.h"
#include "cores/DataCacheCore.h"
#include "filesystem/File.h"
#include "games/tags/GameInfoTag.h"
#include "guilib/guiinfo/GUIInfo.h"
#include "guilib/guiinfo/GUIInfoHelper.h"
#include "guilib/guiinfo/GUIInfoLabels.h"
Expand Down Expand Up @@ -10784,6 +10785,11 @@ void CGUIInfoManager::ResetCache()
++m_refreshCounter;
}

void CGUIInfoManager::SetCurrentGameTag(const KODI::GAME::CGameInfoTag& tag)
{
m_currentFile->SetGameInfoTag(tag);
}

void CGUIInfoManager::SetCurrentVideoTag(const CVideoInfoTag &tag)
{
m_currentFile->SetFromVideoInfoTag(tag);
Expand Down Expand Up @@ -10812,6 +10818,11 @@ const CVideoInfoTag* CGUIInfoManager::GetCurrentMovieTag() const
return nullptr;
}

const KODI::GAME::CGameInfoTag* CGUIInfoManager::GetCurrentGameTag() const
{
return m_currentFile->GetGameInfoTag();
}

int CGUIInfoManager::RegisterSkinVariableString(const CSkinVariableString* info)
{
if (!info)
Expand Down Expand Up @@ -10896,6 +10907,8 @@ void CGUIInfoManager::OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg)
SetCurrentSongTag(*item->GetMusicInfoTag());
else if (pMsg->param1 == 2 && item->HasVideoInfoTag()) // only grab video tag
SetCurrentVideoTag(*item->GetVideoInfoTag());
else if (pMsg->param1 == 3 && item->HasGameInfoTag()) // only grab game tag
SetCurrentGameTag(*item->GetGameInfoTag());
else
SetCurrentItem(*item);

Expand Down
8 changes: 8 additions & 0 deletions xbmc/GUIInfoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ typedef std::shared_ptr<CGUIListItem> CGUIListItemPtr;

namespace KODI
{
namespace GAME
{
class CGameInfoTag;
}
namespace GUILIB
{
namespace GUIINFO
Expand Down Expand Up @@ -122,6 +126,9 @@ class CGUIInfoManager : public KODI::MESSAGING::IMessageTarget
// Current video stuff
const CVideoInfoTag* GetCurrentMovieTag() const;

// Current game stuff
const KODI::GAME::CGameInfoTag* GetCurrentGameTag() const;

void UpdateAVInfo();

int RegisterSkinVariableString(const INFO::CSkinVariableString* info);
Expand Down Expand Up @@ -190,6 +197,7 @@ class CGUIInfoManager : public KODI::MESSAGING::IMessageTarget
int ResolveMultiInfo(int info) const;
bool IsListItemInfo(int info) const;

void SetCurrentGameTag(const KODI::GAME::CGameInfoTag& tag);
void SetCurrentSongTag(const MUSIC_INFO::CMusicInfoTag &tag);
void SetCurrentVideoTag(const CVideoInfoTag &tag);

Expand Down
47 changes: 47 additions & 0 deletions xbmc/cores/RetroPlayer/cheevos/Cheevos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@

#include "Cheevos.h"

#include "FileItem.h"
#include "GUIInfoManager.h"
#include "URL.h"
#include "filesystem/CurlFile.h"
#include "filesystem/File.h"
#include "games/addons/GameClient.h"
#include "games/tags/GameInfoTag.h"
#include "guilib/GUIComponent.h"
#include "interfaces/AnnouncementManager.h"
#include "messaging/ApplicationMessenger.h"
#include "ServiceBroker.h"
#include "utils/JSONVariantParser.h"
#include "utils/URIUtils.h"
#include "utils/Variant.h"
Expand Down Expand Up @@ -43,6 +50,12 @@ CCheevos::CCheevos(GAME::CGameClient* gameClient,
const std::string loginToken)
: m_gameClient(gameClient), m_userName(userName), m_loginToken(loginToken)
{
CServiceBroker::GetAnnouncementManager()->AddAnnouncer(this);
}

CCheevos::~CCheevos()
{
CServiceBroker::GetAnnouncementManager()->RemoveAnnouncer(this);
}

void CCheevos::ResetRuntime()
Expand Down Expand Up @@ -151,6 +164,16 @@ bool CCheevos::GetRichPresenceEvaluation(char* evaluation, size_t size)

m_gameClient->GetRichPresenceEvaluation(evaluation, size);

CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager();
GAME::CGameInfoTag tag = *infoMgr.GetCurrentGameTag();

tag.SetCaption(evaluation);

CFileItem* file = new CFileItem();
file->SetGameInfoTag(tag);
MESSAGING::CApplicationMessenger::GetInstance().PostMsg(TMSG_UPDATE_CURRENT_ITEM, 3, -1,
static_cast<void*>(file));

char url[URL_SIZE];
char postData[POST_DATA_SIZE];
if (m_gameClient->RCPostRichPresenceUrl(url, URL_SIZE, postData, POST_DATA_SIZE,
Expand All @@ -164,3 +187,27 @@ bool CCheevos::GetRichPresenceEvaluation(char* evaluation, size_t size)

return true;
}

void CCheevos::Announce(ANNOUNCEMENT::AnnouncementFlag flag,
const char* sender,
const char* message,
const CVariant& data)
{
if (flag == ANNOUNCEMENT::Info && strcmp(message, "OnChanged") == 0)
{
CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager();
GAME::CGameInfoTag tag = *infoMgr.GetCurrentGameTag();

tag.SetURL(m_gameClient->GetGamePath());
tag.SetTitle(m_title);
tag.SetPublisher(m_publisher);
tag.SetDeveloper(m_developer);
tag.SetGenres({m_gerne});
tag.SetPlatform(m_consoleName);

CFileItem* file = new CFileItem();
file->SetGameInfoTag(tag);
MESSAGING::CApplicationMessenger::GetInstance().PostMsg(TMSG_UPDATE_CURRENT_ITEM, 3, -1,
static_cast<void*>(file));
}
}
9 changes: 8 additions & 1 deletion xbmc/cores/RetroPlayer/cheevos/Cheevos.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "interfaces/IAnnouncer.h"
#include "RConsoleIDs.h"

#include <map>
Expand All @@ -22,10 +23,11 @@ class CGameClient;

namespace RETRO
{
class CCheevos
class CCheevos : public ANNOUNCEMENT::IAnnouncer
{
public:
CCheevos(GAME::CGameClient* gameClient, const std::string userName, const std::string loginToken);
~CCheevos() override;
void ResetRuntime();
void EnableRichPresence();
bool GetRichPresenceEvaluation(char* evaluation, size_t size);
Expand All @@ -37,6 +39,11 @@ class CCheevos
std::string GetConsoleName() { return m_consoleName; }
std::string GetReleased() { return m_released; }

void Announce(ANNOUNCEMENT::AnnouncementFlag flag,
const char* sender,
const char* message,
const CVariant& data) override;

private:
bool LoadData();

Expand Down
5 changes: 4 additions & 1 deletion xbmc/interfaces/legacy/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ namespace XBMCAddon
if (!g_application.GetAppPlayer().IsPlayingGame())
throw PlayerException("XBMC is not playing any game file");

return new InfoTagGame(*g_application.CurrentFileItem().GetGameInfoTag());
const KODI::GAME::CGameInfoTag* game =
CServiceBroker::GetGUI()->GetInfoManager().GetCurrentGameTag();

return new InfoTagGame(*game);
}

InfoTagVideo* Player::getVideoInfoTag()
Expand Down

0 comments on commit d67b89e

Please sign in to comment.