1
0
Fork 0

Add: scaffolding for finding social plugins on disk

pull/11628/head
Patric Stout 2024-01-21 10:48:53 +01:00
parent 218e9be10e
commit 3122a992bf
7 changed files with 80 additions and 2 deletions

View File

@ -393,6 +393,8 @@ add_files(
slope_type.h slope_type.h
smallmap_gui.cpp smallmap_gui.cpp
smallmap_gui.h smallmap_gui.h
social_integration.cpp
social_integration.h
sortlist_type.h sortlist_type.h
sound.cpp sound.cpp
sound_func.h sound_func.h

View File

@ -2141,6 +2141,7 @@ DEF_CONSOLE_CMD(ConListDirs)
{ SAVE_DIR, "save", true }, { SAVE_DIR, "save", true },
{ AUTOSAVE_DIR, "autosave", true }, { AUTOSAVE_DIR, "autosave", true },
{ SCREENSHOT_DIR, "screenshot", true }, { SCREENSHOT_DIR, "screenshot", true },
{ SOCIAL_INTEGRATION_DIR, "social_integration", true },
}; };
if (argc != 2) { if (argc != 2) {

View File

@ -52,6 +52,7 @@ static const char * const _subdirs[] = {
"game" PATHSEP, "game" PATHSEP,
"game" PATHSEP "library" PATHSEP, "game" PATHSEP "library" PATHSEP,
"screenshot" PATHSEP, "screenshot" PATHSEP,
"social_integration" PATHSEP,
}; };
static_assert(lengthof(_subdirs) == NUM_SUBDIRS); static_assert(lengthof(_subdirs) == NUM_SUBDIRS);
@ -1054,7 +1055,7 @@ void DeterminePaths(const char *exe, bool only_local_path)
Debug(misc, 1, "{} found as personal directory", _personal_dir); Debug(misc, 1, "{} found as personal directory", _personal_dir);
static const Subdirectory default_subdirs[] = { static const Subdirectory default_subdirs[] = {
SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SCREENSHOT_DIR SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SCREENSHOT_DIR, SOCIAL_INTEGRATION_DIR
}; };
for (uint i = 0; i < lengthof(default_subdirs); i++) { for (uint i = 0; i < lengthof(default_subdirs); i++) {
@ -1068,7 +1069,7 @@ void DeterminePaths(const char *exe, bool only_local_path)
FillValidSearchPaths(only_local_path); FillValidSearchPaths(only_local_path);
/* Create the directory for each of the types of content */ /* Create the directory for each of the types of content */
const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR }; const Subdirectory dirs[] = { SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SOCIAL_INTEGRATION_DIR };
for (uint i = 0; i < lengthof(dirs); i++) { for (uint i = 0; i < lengthof(dirs); i++) {
FioCreateDirectory(FioGetDirectory(SP_AUTODOWNLOAD_DIR, dirs[i])); FioCreateDirectory(FioGetDirectory(SP_AUTODOWNLOAD_DIR, dirs[i]));
} }

View File

@ -121,6 +121,7 @@ enum Subdirectory {
GAME_DIR, ///< Subdirectory for all game scripts GAME_DIR, ///< Subdirectory for all game scripts
GAME_LIBRARY_DIR, ///< Subdirectory for all GS libraries GAME_LIBRARY_DIR, ///< Subdirectory for all GS libraries
SCREENSHOT_DIR, ///< Subdirectory for all screenshots SCREENSHOT_DIR, ///< Subdirectory for all screenshots
SOCIAL_INTEGRATION_DIR, ///< Subdirectory for all social integration plugins
NUM_SUBDIRS, ///< Number of subdirectories NUM_SUBDIRS, ///< Number of subdirectories
NO_DIRECTORY, ///< A path without any base directory NO_DIRECTORY, ///< A path without any base directory
}; };

View File

@ -75,6 +75,7 @@
#include "timer/timer_game_economy.h" #include "timer/timer_game_economy.h"
#include "timer/timer_game_realtime.h" #include "timer/timer_game_realtime.h"
#include "timer/timer_game_tick.h" #include "timer/timer_game_tick.h"
#include "social_integration.h"
#include "linkgraph/linkgraphschedule.h" #include "linkgraph/linkgraphschedule.h"
@ -752,6 +753,7 @@ int openttd_main(int argc, char *argv[])
/* The video driver is now selected, now initialise GUI zoom */ /* The video driver is now selected, now initialise GUI zoom */
AdjustGUIZoom(false); AdjustGUIZoom(false);
SocialIntegration::Initialize();
NetworkStartUp(); // initialize network-core NetworkStartUp(); // initialize network-core
if (!HandleBootstrap()) { if (!HandleBootstrap()) {

View File

@ -0,0 +1,50 @@
/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file social_integration.cpp Base implementation of social integration support. */
#include "stdafx.h"
#include "social_integration.h"
#include "3rdparty/openttd_social_integration_api/openttd_social_integration_api.h"
#include "debug.h"
#include "fileio_func.h"
#include "library_loader.h"
#include "rev.h"
#include "string_func.h"
#include "safeguards.h"
/** Helper for scanning for files with SocialIntegration as extension */
class SocialIntegrationFileScanner : FileScanner {
public:
void Scan()
{
#ifdef _WIN32
std::string extension = "-social.dll";
#elif defined(__APPLE__)
std::string extension = "-social.dylib";
#else
std::string extension = "-social.so";
#endif
this->FileScanner::Scan(extension.c_str(), SOCIAL_INTEGRATION_DIR, false);
}
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &) override
{
std::string basepath = filename.substr(basepath_length);
Debug(misc, 1, "[Social Integration: {}] Loading ...", basepath);
}
};
void SocialIntegration::Initialize()
{
SocialIntegrationFileScanner fs;
fs.Scan();
}

View File

@ -0,0 +1,21 @@
/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD 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 OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file social_integration.h Interface definitions for game to report/respond to social integration. */
#ifndef SOCIAL_INTEGRATION_H
#define SOCIAL_INTEGRATION_H
class SocialIntegration {
public:
/**
* Initialize the social integration system, loading any social integration plugins that are available.
*/
static void Initialize();
};
#endif /* SOCIAL_INTEGRATION_H */